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

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

Issue 29356270: Issue 4499 - Consider $generichide exceptions when applying element hiding rules (Closed) Base URL: https://hg.adblockplus.org/adblockplus
Patch Set: Created Oct. 6, 2016, 8:52 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/elemHideFF.js » ('j') | 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
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 { 87 {
88 return Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT; 88 return Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
89 }, 89 },
90 90
91 newChannel: function(uri, loadInfo) 91 newChannel: function(uri, loadInfo)
92 { 92 {
93 let match = /\?hit(\d+)$/.exec(uri.path); 93 let match = /\?hit(\d+)$/.exec(uri.path);
94 if (match) 94 if (match)
95 return new HitRegistrationChannel(uri, loadInfo, match[1]); 95 return new HitRegistrationChannel(uri, loadInfo, match[1]);
96 96
97 match = /\?css(?:=(.*?))?$/.exec(uri.path); 97 match = /\?css(?:=(.*?))?(&specificonly)?$/.exec(uri.path);
98 if (match) 98 if (match)
99 { 99 {
100 return new StyleDataChannel(uri, loadInfo, 100 return new StyleDataChannel(uri, loadInfo,
101 match[1] ? decodeURIComponent(match[1]) : null); 101 match[1] ? decodeURIComponent(match[1]) : null, !!match[2]);
102 } 102 }
103 103
104 throw Cr.NS_ERROR_FAILURE; 104 throw Cr.NS_ERROR_FAILURE;
105 }, 105 },
106 106
107 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule]) 107 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
108 }; 108 };
109 AboutHandler.init(); 109 AboutHandler.init();
110 110
111 /** 111 /**
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 suspend: notImplemented, 206 suspend: notImplemented,
207 resume: notImplemented, 207 resume: notImplemented,
208 208
209 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest]) 209 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest])
210 }; 210 };
211 211
212 /** 212 /**
213 * Channel returning CSS data for the global as well as site-specific stylesheet . 213 * Channel returning CSS data for the global as well as site-specific stylesheet .
214 * @constructor 214 * @constructor
215 */ 215 */
216 function StyleDataChannel(uri, loadInfo, domain) 216 function StyleDataChannel(uri, loadInfo, domain, specificOnly)
217 { 217 {
218 BaseChannel.call(this, uri, loadInfo); 218 BaseChannel.call(this, uri, loadInfo);
219 this._domain = domain; 219 this._domain = domain;
220 this._specificOnly = specificOnly;
220 } 221 }
221 StyleDataChannel.prototype = { 222 StyleDataChannel.prototype = {
222 __proto__: BaseChannel.prototype, 223 __proto__: BaseChannel.prototype,
223 contentType: "text/css", 224 contentType: "text/css",
224 _domain: null, 225 _domain: null,
225 226
226 _getResponse: function() 227 _getResponse: function()
227 { 228 {
228 function escapeChar(match) 229 function escapeChar(match)
229 { 230 {
230 return "\\" + match.charCodeAt(0).toString(16) + " "; 231 return "\\" + match.charCodeAt(0).toString(16) + " ";
231 } 232 }
232 233
233 // Would be great to avoid sync messaging here but nsIStyleSheetService 234 // Would be great to avoid sync messaging here but nsIStyleSheetService
234 // insists on opening channels synchronously. 235 // insists on opening channels synchronously.
235 let [selectors, keys] = (this._domain ? 236 let [selectors, keys] = (this._domain ?
236 port.emitSync("getSelectorsForDomain", this._domain) : 237 port.emitSync("getSelectorsForDomain", [this._domain, this._specificOnly ]) :
237 port.emitSync("getUnconditionalSelectors")); 238 port.emitSync("getUnconditionalSelectors"));
238 239
239 let cssPrefix = "{-moz-binding: url(about:abp-elemhide?hit"; 240 let cssPrefix = "{-moz-binding: url(about:abp-elemhide?hit";
240 let cssSuffix = "#dummy) !important;}\n"; 241 let cssSuffix = "#dummy) !important;}\n";
241 let result = []; 242 let result = [];
242 243
243 for (let i = 0; i < selectors.length; i++) 244 for (let i = 0; i < selectors.length; i++)
244 { 245 {
245 let selector = selectors[i]; 246 let selector = selectors[i];
246 let key = keys[i]; 247 let key = keys[i];
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 }) => 334 }) =>
334 { 335 {
335 if (Cu.isDeadWrapper(window)) 336 if (Cu.isDeadWrapper(window))
336 { 337 {
337 // We are too late, the window is gone already. 338 // We are too late, the window is gone already.
338 return; 339 return;
339 } 340 }
340 341
341 if (enabled) 342 if (enabled)
342 { 343 {
343 if (!this.sheet)
344 {
345 this.sheet = Utils.styleService.preloadSheet(this.styleURL,
346 Ci.nsIStyleSheetService.USER_SHEET);
347 }
348
349 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor) 344 let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
350 .getInterface(Ci.nsIDOMWindowUtils); 345 .getInterface(Ci.nsIDOMWindowUtils);
351 try 346
347 let specificOnly = filter;
kzar 2016/10/07 09:30:21 I don't understand this line, isn't filter being g
Wladimir Palant 2016/10/07 09:37:49 There are two kinds of filters that we can get in
kzar 2016/10/07 09:53:31 Ah, I finally wrapped my head around it :). Well I
kzar 2016/10/07 10:15:29 (OK, I missed the final `return {enabled: true};`
Wladimir Palant 2016/10/07 10:53:05 Done.
348 if (!specificOnly)
352 { 349 {
353 utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET); 350 if (!this.sheet)
354 } 351 {
355 catch (e) 352 this.sheet = Utils.styleService.preloadSheet(this.styleURL,
356 { 353 Ci.nsIStyleSheetService.USER_SHEET);
357 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add 354 }
358 // the stylesheet multiple times to the same document (the observer 355
359 // will be notified twice for some documents). 356 try
360 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE) 357 {
361 throw e; 358 utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
359 }
360 catch (e)
361 {
362 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to ad d
363 // the stylesheet multiple times to the same document (the observer
364 // will be notified twice for some documents).
365 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
366 throw e;
367 }
362 } 368 }
363 369
364 let host = subject.location.hostname; 370 let host = subject.location.hostname;
365 if (host) 371 if (host)
366 { 372 {
367 try 373 try
368 { 374 {
369 utils.loadSheetUsingURIString(this.styleURL.spec + "=" + 375 let suffix = "=" + encodeURIComponent(host);
370 encodeURIComponent(host), Ci.nsIStyleSheetService.USER_SHEET); 376 if (specificOnly)
377 suffix += "&specificonly";
378 utils.loadSheetUsingURIString(this.styleURL.spec + suffix,
379 Ci.nsIStyleSheetService.USER_SHEET);
371 } 380 }
372 catch (e) 381 catch (e)
373 { 382 {
374 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to ad d 383 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to ad d
375 // the stylesheet multiple times to the same document (the observer 384 // the stylesheet multiple times to the same document (the observer
376 // will be notified twice for some documents). 385 // will be notified twice for some documents).
377 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE) 386 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
378 throw e; 387 throw e;
379 } 388 }
380 } 389 }
381 } 390 }
382 else if (filter) 391
392 if (filter)
383 { 393 {
384 RequestNotifier.addNodeData(window.document, window.top, { 394 RequestNotifier.addNodeData(window.document, window.top, {
385 contentType, docDomain, thirdParty, location, filter, filterType 395 contentType, docDomain, thirdParty, location, filter, filterType
386 }); 396 });
387 } 397 }
388 }); 398 });
389 } 399 }
390 }; 400 };
391 observer.init(); 401 observer.init();
OLDNEW
« no previous file with comments | « no previous file | lib/elemHideFF.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld