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

Side by Side Diff: lib/child/cssProperties.js

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

Powered by Google App Engine
This is Rietveld