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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | lib/elemHideFF.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/child/elemHide.js
===================================================================
--- a/lib/child/elemHide.js
+++ b/lib/child/elemHide.js
@@ -89,21 +89,21 @@ let AboutHandler =
},
newChannel: function(uri, loadInfo)
{
let match = /\?hit(\d+)$/.exec(uri.path);
if (match)
return new HitRegistrationChannel(uri, loadInfo, match[1]);
- match = /\?css(?:=(.*?))?$/.exec(uri.path);
+ match = /\?css(?:=(.*?))?(&specificonly)?$/.exec(uri.path);
if (match)
{
return new StyleDataChannel(uri, loadInfo,
- match[1] ? decodeURIComponent(match[1]) : null);
+ match[1] ? decodeURIComponent(match[1]) : null, !!match[2]);
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
};
AboutHandler.init();
@@ -208,37 +208,38 @@ BaseChannel.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest])
};
/**
* Channel returning CSS data for the global as well as site-specific stylesheet.
* @constructor
*/
-function StyleDataChannel(uri, loadInfo, domain)
+function StyleDataChannel(uri, loadInfo, domain, specificOnly)
{
BaseChannel.call(this, uri, loadInfo);
this._domain = domain;
+ this._specificOnly = specificOnly;
}
StyleDataChannel.prototype = {
__proto__: BaseChannel.prototype,
contentType: "text/css",
_domain: null,
_getResponse: function()
{
function escapeChar(match)
{
return "\\" + match.charCodeAt(0).toString(16) + " ";
}
// Would be great to avoid sync messaging here but nsIStyleSheetService
// insists on opening channels synchronously.
let [selectors, keys] = (this._domain ?
- port.emitSync("getSelectorsForDomain", this._domain) :
+ port.emitSync("getSelectorsForDomain", [this._domain, this._specificOnly]) :
port.emitSync("getUnconditionalSelectors"));
let cssPrefix = "{-moz-binding: url(about:abp-elemhide?hit";
let cssSuffix = "#dummy) !important;}\n";
let result = [];
for (let i = 0; i < selectors.length; i++)
{
@@ -335,56 +336,67 @@ let observer = {
if (Cu.isDeadWrapper(window))
{
// We are too late, the window is gone already.
return;
}
if (enabled)
{
- if (!this.sheet)
- {
- this.sheet = Utils.styleService.preloadSheet(this.styleURL,
- Ci.nsIStyleSheetService.USER_SHEET);
- }
-
let utils = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
- try
+
+ // If we have a filter hit at this point then it must be a $generichide
+ // filter - apply only specific element hiding filters.
+ let specificOnly = !!filter;
+ if (!specificOnly)
{
- utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
- }
- catch (e)
- {
- // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add
- // the stylesheet multiple times to the same document (the observer
- // will be notified twice for some documents).
- if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
- throw e;
+ if (!this.sheet)
+ {
+ this.sheet = Utils.styleService.preloadSheet(this.styleURL,
+ Ci.nsIStyleSheetService.USER_SHEET);
+ }
+
+ try
+ {
+ utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
+ }
+ catch (e)
+ {
+ // Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add
+ // the stylesheet multiple times to the same document (the observer
+ // will be notified twice for some documents).
+ if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
+ throw e;
+ }
}
let host = subject.location.hostname;
if (host)
{
try
{
- utils.loadSheetUsingURIString(this.styleURL.spec + "=" +
- encodeURIComponent(host), Ci.nsIStyleSheetService.USER_SHEET);
+ let suffix = "=" + encodeURIComponent(host);
+ if (specificOnly)
+ suffix += "&specificonly";
+ utils.loadSheetUsingURIString(this.styleURL.spec + suffix,
+ Ci.nsIStyleSheetService.USER_SHEET);
}
catch (e)
{
// Ignore NS_ERROR_ILLEGAL_VALUE - it will be thrown if we try to add
// the stylesheet multiple times to the same document (the observer
// will be notified twice for some documents).
if (e.result != Cr.NS_ERROR_ILLEGAL_VALUE)
throw e;
}
}
}
- else if (filter)
+
+ if (filter)
{
RequestNotifier.addNodeData(window.document, window.top, {
contentType, docDomain, thirdParty, location, filter, filterType
});
}
});
}
};
« 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