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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | lib/contentPolicy.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 "use strict";
19
20 (function()
21 {
22 let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
23
24 let {port} = require("messaging");
25 let {getFrames} = require("child/utils");
26
27 let senderWindow = null;
28
29 let scope = {
30 ext: {
31 backgroundPage: {
32 sendMessage: function(data, callback)
33 {
34 data = {payload: data, frames: getFrames(senderWindow)};
35 if (typeof callback == "function")
36 port.emitWithResponse("cssPropertiesRequest", data).then(callback);
37 else
38 port.emit("cssPropertiesRequest", data);
39 }
40 }
41 }
42 };
43
44 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
45 {
46 Services.scriptloader.loadSubScript(script, scope);
47 }
48
49 function addUserCSS(window, cssCode)
50 {
51 let uri = Services.io.newURI("data:text/css," + encodeURIComponent(cssCode),
52 null, null);
53 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
54 .getInterface(Ci.nsIDOMWindowUtils);
55 utils.loadSheet(uri, Ci.nsIDOMWindowUtils.USER_SHEET);
56 }
57
58 function initCSSPropertyFilters()
59 {
60 loadScript("chrome://adblockplus/content/cssProperties.js");
61
62 let onContentWindow = (subject, topic, data) =>
63 {
64 if (!(subject instanceof Ci.nsIDOMWindow))
65 return;
66
67 let onReady = event =>
68 {
69 subject.removeEventListener("DOMContentLoaded", onReady);
70 let handler = new scope.CSSPropertyFilters(subject, selectors =>
71 {
72 if (selectors.length == 0)
73 return;
74
75 addUserCSS(subject, selectors.map(
76 selector => selector + "{display: none !important;}"
77 ).join("\n"));
78 });
79
80 // HACK: The content script just calls ext.backgroundPage.sendMessage
81 // without indicating which window this is about. We'll store the window
82 // 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.
83 senderWindow = subject;
84 handler.load(() => handler.apply());
85 senderWindow = null;
86 };
87
88 subject.addEventListener("DOMContentLoaded", onReady);
89 };
90
91 Services.obs.addObserver(onContentWindow, "content-document-global-created",
92 false);
93 onShutdown.add(() =>
94 {
95 Services.obs.removeObserver(onContentWindow,
96 "content-document-global-created");
97 });
98 }
99
100 initCSSPropertyFilters();
101 })();
OLDNEW
« 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