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: Added comment to explain the logic Created Oct. 7, 2016, 10:52 a.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 // If we have a filter hit at this point then it must be a $generichide
348 // filter - apply only specific element hiding filters.
349 let specificOnly = !!filter;
350 if (!specificOnly)
352 { 351 {
353 utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET); 352 if (!this.sheet)
354 } 353 {
355 catch (e) 354 this.sheet = Utils.styleService.preloadSheet(this.styleURL,
356 { 355 Ci.nsIStyleSheetService.USER_SHEET);
357 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add 356 }
358 // the stylesheet multiple times to the same document (the observer 357
359 // will be notified twice for some documents). 358 try
360 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE) 359 {
361 throw e; 360 utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
361 }
362 catch (e)
363 {
364 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to ad d
365 // the stylesheet multiple times to the same document (the observer
366 // will be notified twice for some documents).
367 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
368 throw e;
369 }
362 } 370 }
363 371
364 let host = subject.location.hostname; 372 let host = subject.location.hostname;
365 if (host) 373 if (host)
366 { 374 {
367 try 375 try
368 { 376 {
369 utils.loadSheetUsingURIString(this.styleURL.spec + "=" + 377 let suffix = "=" + encodeURIComponent(host);
370 encodeURIComponent(host), Ci.nsIStyleSheetService.USER_SHEET); 378 if (specificOnly)
379 suffix += "&specificonly";
380 utils.loadSheetUsingURIString(this.styleURL.spec + suffix,
381 Ci.nsIStyleSheetService.USER_SHEET);
371 } 382 }
372 catch (e) 383 catch (e)
373 { 384 {
374 // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to ad d 385 // 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 386 // the stylesheet multiple times to the same document (the observer
376 // will be notified twice for some documents). 387 // will be notified twice for some documents).
377 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE) 388 if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
378 throw e; 389 throw e;
379 } 390 }
380 } 391 }
381 } 392 }
382 else if (filter) 393
394 if (filter)
383 { 395 {
384 RequestNotifier.addNodeData(window.document, window.top, { 396 RequestNotifier.addNodeData(window.document, window.top, {
385 contentType, docDomain, thirdParty, location, filter, filterType 397 contentType, docDomain, thirdParty, location, filter, filterType
386 }); 398 });
387 } 399 }
388 }); 400 });
389 } 401 }
390 }; 402 };
391 observer.init(); 403 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