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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 6201308310667264: Issue 521- Inject our stylesheet on per-site basis rather than globally (Closed)
Left Patch Set: New patch set that is a lot simpler and retains compatibility with old Firefox versions where the F… Created June 28, 2014, 10:38 a.m.
Right Patch Set: Version 1.0 Created Aug. 6, 2014, 4:30 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/contentPolicy.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 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
(...skipping 10 matching lines...) Expand all
21 21
22 Cu.import("resource://gre/modules/Services.jsm"); 22 Cu.import("resource://gre/modules/Services.jsm");
23 23
24 let {Utils} = require("utils"); 24 let {Utils} = require("utils");
25 let {IO} = require("io"); 25 let {IO} = require("io");
26 let {Prefs} = require("prefs"); 26 let {Prefs} = require("prefs");
27 let {ElemHideException} = require("filterClasses"); 27 let {ElemHideException} = require("filterClasses");
28 let {FilterNotifier} = require("filterNotifier"); 28 let {FilterNotifier} = require("filterNotifier");
29 let {AboutHandler} = require("elemHideHitRegistration"); 29 let {AboutHandler} = require("elemHideHitRegistration");
30 let {TimeLine} = require("timeline"); 30 let {TimeLine} = require("timeline");
31 let {Policy} = require("contentPolicy"); 31 let Policy = null;
32 32
33 /** 33 /**
34 * Lookup table, filters by their associated key 34 * Lookup table, filters by their associated key
35 * @type Object 35 * @type Object
36 */ 36 */
37 let filterByKey = Object.create(null); 37 let filterByKey = Object.create(null);
38 38
39 /** 39 /**
40 * Lookup table, keys of the filters by filter text 40 * Lookup table, keys of the filters by filter text
41 * @type Object 41 * @type Object
(...skipping 17 matching lines...) Expand all
59 * @type nsIURI 59 * @type nsIURI
60 */ 60 */
61 let styleURL = null; 61 let styleURL = null;
62 62
63 /** 63 /**
64 * Global stylesheet that should be loaded into content windows. 64 * Global stylesheet that should be loaded into content windows.
65 * @type nsIStyleSheet 65 * @type nsIStyleSheet
66 */ 66 */
67 let styleSheet = null; 67 let styleSheet = null;
68 68
69 /**
70 * Use the new way of injecting styles per window that exists since Firefox 33.
71 * @type boolean
72 */
69 let useNew = ('preloadSheet' in Utils.styleService); 73 let useNew = ('preloadSheet' in Utils.styleService);
70 74
71 /** 75 /**
72 * Element hiding component 76 * Element hiding component
73 * @class 77 * @class
74 */ 78 */
75 let ElemHide = exports.ElemHide = 79 let ElemHide = exports.ElemHide =
76 { 80 {
77 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]), 81 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence]),
78 82
79 /** 83 /**
80 * Indicates whether filters have been added or removed since the last apply() call. 84 * Indicates whether filters have been added or removed since the last apply() call.
81 * @type Boolean 85 * @type Boolean
82 */ 86 */
83 isDirty: false, 87 isDirty: false,
84 88
85 /** 89 /**
86 * Inidicates whether the element hiding stylesheet is currently applied. 90 * Inidicates whether the element hiding stylesheet is currently applied.
87 * @type Boolean 91 * @type Boolean
88 */ 92 */
89 applied: false, 93 applied: false,
90 94
91 /** 95 /**
92 * Called on module startup. 96 * Called on module startup.
93 */ 97 */
94 init: function() 98 init: function()
95 { 99 {
96 TimeLine.enter("Entered ElemHide.init()"); 100 TimeLine.enter("Entered ElemHide.init()");
101
102 if (useNew) {
103 // Avoid dependency issue.
104 Policy = require("contentPolicy").Policy;
105 }
106
97 Prefs.addListener(function(name) 107 Prefs.addListener(function(name)
98 { 108 {
99 if (name == "enabled") 109 if (name == "enabled")
100 ElemHide.apply(); 110 ElemHide.apply();
101 }); 111 });
102 112
103 if (useNew) 113 if (useNew)
104 Services.obs.addObserver(this, "content-document-global-created", true); 114 Services.obs.addObserver(this, "content-document-global-created", true);
105 115
106 onShutdown.add(() => 116 onShutdown.add(() =>
(...skipping 14 matching lines...) Expand all
121 }, 131 },
122 132
123 observe: function (subject, topic, data, additional) 133 observe: function (subject, topic, data, additional)
124 { 134 {
125 if (topic != "content-document-global-created") 135 if (topic != "content-document-global-created")
126 return; 136 return;
127 137
128 if (!Prefs.enabled) 138 if (!Prefs.enabled)
129 return; 139 return;
130 140
131 let process = Policy.processWindow(subject); 141 if (Policy.shouldNeverBlockWindow(subject))
132 dump(subject.document.documentURIObject.spec + " is okay " + process + "\n" );
133 if (process)
134 return; 142 return;
135 143
136 // XXX at this point the window might still be whitelisted 144 if (styleSheet)
137 try 145 {
138 { 146 try
139 let utils = subject.QueryInterface(Ci.nsIInterfaceRequestor) 147 {
140 .getInterface(Ci.nsIDOMWindowUtils); 148 let utils = subject.QueryInterface(Ci.nsIInterfaceRequestor)
141 utils.addSheet(styleSheet, Ci.nsIStyleSheetService.USER_SHEET); 149 .getInterface(Ci.nsIDOMWindowUtils);
142 } 150 utils.addSheet(styleSheet, Ci.nsIStyleSheetService.USER_SHEET);
143 catch (e) 151 }
144 { 152 catch (e)
145 Cu.reportError(e); 153 {
154 Cu.reportError(e);
155 }
146 } 156 }
147 }, 157 },
148 158
149 /** 159 /**
150 * Removes all known filters 160 * Removes all known filters
151 */ 161 */
152 clear: function() 162 clear: function()
153 { 163 {
154 filterByKey = Object.create(null); 164 filterByKey = Object.create(null);
155 keyByFilter = Object.create(null); 165 keyByFilter = Object.create(null);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 { 328 {
319 ElemHide.isDirty = false; 329 ElemHide.isDirty = false;
320 330
321 ElemHide.unapply(); 331 ElemHide.unapply();
322 TimeLine.log("ElemHide.unapply() finished"); 332 TimeLine.log("ElemHide.unapply() finished");
323 333
324 if (!noFilters) 334 if (!noFilters)
325 { 335 {
326 try 336 try
327 { 337 {
328 if (!useNew) { 338 if (!useNew)
329 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheet Service.USER_SHEET); 339 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheet Service.USER_SHEET);
330 } else { 340 else
331 styleSheet = Utils.styleService.preloadSheet(styleURL, Ci.nsIStyle SheetService.USER_SHEET); 341 styleSheet = Utils.styleService.preloadSheet(styleURL, Ci.nsIStyle SheetService.USER_SHEET);
332 }
333 ElemHide.applied = true; 342 ElemHide.applied = true;
334 } 343 }
335 catch (e) 344 catch (e)
336 { 345 {
337 Cu.reportError(e); 346 Cu.reportError(e);
338 } 347 }
339 TimeLine.log("Applying stylesheet finished"); 348 TimeLine.log("Applying stylesheet finished");
340 } 349 }
341 350
342 FilterNotifier.triggerListeners("elemhideupdate"); 351 FilterNotifier.triggerListeners("elemhideupdate");
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 459
451 if (specificOnly && (!domains || domains[""])) 460 if (specificOnly && (!domains || domains[""]))
452 continue; 461 continue;
453 462
454 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) 463 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain))
455 result.push(filter.selector); 464 result.push(filter.selector);
456 } 465 }
457 return result; 466 return result;
458 } 467 }
459 }; 468 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld