| Index: lib/child/cssProperties.js |
| =================================================================== |
| --- a/lib/child/cssProperties.js |
| +++ b/lib/child/cssProperties.js |
| @@ -19,71 +19,64 @@ |
| (function() |
| { |
| let {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
| let {port} = require("messaging"); |
| let {getFrames} = require("child/utils"); |
| - let senderWindow = null; |
| - |
| - let scope = { |
| - ext: { |
| - backgroundPage: { |
| - sendMessage: function(payload, callback) |
| - { |
| - let message = {payload, frames: getFrames(senderWindow)}; |
| - if (typeof callback == "function") |
| - port.emitWithResponse("ext_message", message).then(callback); |
| - else |
| - port.emit("ext_message", message); |
| - } |
| + function getFilters(window, callback) |
| + { |
| + let message = { |
| + frames: getFrames(window), |
| + payload: { |
| + type: "filters.get", |
| + what: "cssproperties" |
| } |
| - } |
| - }; |
| + }; |
| + port.emitWithResponse("ext_message", message).then(callback); |
| + } |
| function addUserCSS(window, cssCode) |
| { |
| let uri = Services.io.newURI("data:text/css," + encodeURIComponent(cssCode), |
| null, null); |
| let utils = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| .getInterface(Ci.nsIDOMWindowUtils); |
| utils.loadSheet(uri, Ci.nsIDOMWindowUtils.USER_SHEET); |
| } |
| function initCSSPropertyFilters() |
| { |
| + let scope = {}; |
| Services.scriptloader.loadSubScript( |
| "chrome://adblockplus/content/cssProperties.js", scope); |
| let onContentWindow = (subject, topic, data) => |
| { |
| if (!(subject instanceof Ci.nsIDOMWindow)) |
| return; |
| let onReady = event => |
| { |
| subject.removeEventListener("load", onReady); |
| - let handler = new scope.CSSPropertyFilters(subject, selectors => |
| - { |
| - if (selectors.length == 0) |
| - return; |
| + let handler = new scope.CSSPropertyFilters( |
| + subject, getFilters.bind(null, subject), selectors => |
| + { |
| + if (selectors.length == 0) |
| + return; |
| - addUserCSS(subject, selectors.map( |
| - selector => selector + "{display: none !important;}" |
| - ).join("\n")); |
| - }); |
| + addUserCSS(subject, selectors.map( |
| + selector => selector + "{display: none !important;}" |
| + ).join("\n")); |
| + } |
| + ); |
| - // HACK: The content script just calls ext.backgroundPage.sendMessage |
| - // without indicating which window this is about. We'll store the window |
| - // here because we know that messaging happens synchronously. |
| - senderWindow = subject; |
| handler.load(() => handler.apply()); |
| - senderWindow = null; |
| }; |
| subject.addEventListener("load", onReady); |
| }; |
| Services.obs.addObserver(onContentWindow, "content-document-global-created", |
| false); |
| onShutdown.add(() => |