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

Side by Side Diff: lib/elemHide.js

Issue 29329754: Issue 3251 - Delegate processing of element hiding hits to shouldAllowAsync() so that hits show up (Closed)
Patch Set: Rebased Created Nov. 12, 2015, 3:04 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
« lib/child/elemHide.js ('K') | « lib/contentPolicy.js ('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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 * Inidicates whether the element hiding stylesheet is currently applied. 73 * Inidicates whether the element hiding stylesheet is currently applied.
74 * @type Boolean 74 * @type Boolean
75 */ 75 */
76 applied: false, 76 applied: false,
77 77
78 /** 78 /**
79 * Called on module startup. 79 * Called on module startup.
80 */ 80 */
81 init: function() 81 init: function()
82 { 82 {
83 Utils.addChildMessageListener("AdblockPlus:ElemHideHit", (data) => {
84 return ElemHide.shouldHide(data);
85 });
86
87 Prefs.addListener(function(name) 83 Prefs.addListener(function(name)
88 { 84 {
89 if (name == "enabled") 85 if (name == "enabled")
90 ElemHide.apply(); 86 ElemHide.apply();
91 }); 87 });
92 onShutdown.add(() => ElemHide.unapply()); 88 onShutdown.add(() => ElemHide.unapply());
93 89
94 let styleFile = IO.resolveFilePath(Prefs.data_directory); 90 let styleFile = IO.resolveFilePath(Prefs.data_directory);
95 styleFile.append("elemhide.css"); 91 styleFile.append("elemhide.css");
96 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL); 92 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 178
183 let list = exceptions[filter.selector]; 179 let list = exceptions[filter.selector];
184 for (let i = list.length - 1; i >= 0; i--) 180 for (let i = list.length - 1; i >= 0; i--)
185 if (list[i].isActiveOnDomain(docDomain)) 181 if (list[i].isActiveOnDomain(docDomain))
186 return list[i]; 182 return list[i];
187 183
188 return null; 184 return null;
189 }, 185 },
190 186
191 /** 187 /**
192 * Processes an element hiding hit
193 * @param {String} message.key
194 * key of the matching element hiding rule
195 * @param {Object[]} message.frames
196 * information required to reconstruct frame
197 * data for the hit
198 * @return {Boolean}
199 */
200 shouldHide: function(message)
201 {
202 let filter = ElemHide.getFilterByKey(message.key);
203 if (!filter || !message.frames.length)
204 return false;
205
206 let {Policy} = require("contentPolicy");
207 return !Policy.shouldAllow({
208 contentType: "ELEMHIDE",
209 location: filter,
210 frames: message.frames,
211 isPrivate: message.isPrivate
212 }).allow;
213 },
214
215 /**
216 * Will be set to true if apply() is running (reentrance protection). 188 * Will be set to true if apply() is running (reentrance protection).
217 * @type Boolean 189 * @type Boolean
218 */ 190 */
219 _applying: false, 191 _applying: false,
220 192
221 /** 193 /**
222 * Will be set to true if an apply() call arrives while apply() is already 194 * Will be set to true if an apply() call arrives while apply() is already
223 * running (delayed execution). 195 * running (delayed execution).
224 * @type Boolean 196 * @type Boolean
225 */ 197 */
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 let filter = filterByKey[key]; 380 let filter = filterByKey[key];
409 if (specificOnly && (!filter.domains || filter.domains[""])) 381 if (specificOnly && (!filter.domains || filter.domains[""]))
410 continue; 382 continue;
411 383
412 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) 384 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain))
413 result.push(filter.selector); 385 result.push(filter.selector);
414 } 386 }
415 return result; 387 return result;
416 } 388 }
417 }; 389 };
OLDNEW
« lib/child/elemHide.js ('K') | « lib/contentPolicy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld