Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/child/cssProperties.js

Issue 29338638: Issue 2401 - Integrate CSS property rule handling in Firefox (Closed)
Patch Set: Created March 18, 2016, 3:05 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | lib/contentPolicy.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/cssProperties.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/child/cssProperties.js
@@ -0,0 +1,101 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+(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(data, callback)
+ {
+ data = {payload: data, frames: getFrames(senderWindow)};
+ if (typeof callback == "function")
+ port.emitWithResponse("cssPropertiesRequest", data).then(callback);
+ else
+ port.emit("cssPropertiesRequest", data);
+ }
+ }
+ }
+ };
+
+ function loadScript(script)
Thomas Greiner 2016/03/30 18:02:05 Detail: This function seems redundant since it's o
Wladimir Palant 2016/03/30 18:42:17 The idea was originally that this would be a gener
+ {
+ Services.scriptloader.loadSubScript(script, scope);
+ }
+
+ 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()
+ {
+ loadScript("chrome://adblockplus/content/cssProperties.js");
+
+ let onContentWindow = (subject, topic, data) =>
+ {
+ if (!(subject instanceof Ci.nsIDOMWindow))
+ return;
+
+ let onReady = event =>
+ {
+ subject.removeEventListener("DOMContentLoaded", onReady);
+ let handler = new scope.CSSPropertyFilters(subject, selectors =>
+ {
+ if (selectors.length == 0)
+ return;
+
+ 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.
Wladimir Palant 2016/03/18 15:25:24 This is rather ugly. While we made CSSPropertyFilt
Thomas Greiner 2016/03/30 18:02:05 Can't think of a better alternative than passing a
Wladimir Palant 2016/03/30 18:42:17 Yes, we'll need to fix this later.
+ senderWindow = subject;
+ handler.load(() => handler.apply());
+ senderWindow = null;
+ };
+
+ subject.addEventListener("DOMContentLoaded", onReady);
+ };
+
+ Services.obs.addObserver(onContentWindow, "content-document-global-created",
+ false);
+ onShutdown.add(() =>
+ {
+ Services.obs.removeObserver(onContentWindow,
+ "content-document-global-created");
+ });
+ }
+
+ initCSSPropertyFilters();
+})();
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | lib/contentPolicy.js » ('J')

Powered by Google App Engine
This is Rietveld