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: Addressed comments Created March 30, 2016, 6:41 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') | no next file with comments »
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 addUserCSS(window, cssCode)
45 {
46 let uri = Services.io.newURI("data:text/css," + encodeURIComponent(cssCode),
47 null, null);
48 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
49 .getInterface(Ci.nsIDOMWindowUtils);
50 utils.loadSheet(uri, Ci.nsIDOMWindowUtils.USER_SHEET);
51 }
52
53 function initCSSPropertyFilters()
54 {
55 Services.scriptloader.loadSubScript(
56 "chrome://adblockplus/content/cssProperties.js", scope);
57
58 let onContentWindow = (subject, topic, data) =>
59 {
60 if (!(subject instanceof Ci.nsIDOMWindow))
61 return;
62
63 let onReady = event =>
64 {
65 subject.removeEventListener("DOMContentLoaded", onReady);
66 let handler = new scope.CSSPropertyFilters(subject, selectors =>
67 {
68 if (selectors.length == 0)
69 return;
70
71 addUserCSS(subject, selectors.map(
72 selector => selector + "{display: none !important;}"
73 ).join("\n"));
74 });
75
76 // HACK: The content script just calls ext.backgroundPage.sendMessage
77 // without indicating which window this is about. We'll store the window
78 // here because we know that messaging happens synchronously.
79 senderWindow = subject;
80 handler.load(() => handler.apply());
81 senderWindow = null;
82 };
83
84 subject.addEventListener("DOMContentLoaded", onReady);
85 };
86
87 Services.obs.addObserver(onContentWindow, "content-document-global-created",
88 false);
89 onShutdown.add(() =>
90 {
91 Services.obs.removeObserver(onContentWindow,
92 "content-document-global-created");
93 });
94 }
95
96 initCSSPropertyFilters();
97 })();
OLDNEW
« no previous file with comments | « no previous file | lib/child/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld