[Pkg-mozext-commits] [adblock-plus] 35/98: Issue 524 - Stop using @-moz-document
David Prévot
taffit at moszumanska.debian.org
Tue Oct 24 01:30:16 UTC 2017
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository adblock-plus.
commit a706af4885fd469999211d31d7f6a3b4c1ba34ca
Author: Wladimir Palant <trev at adblockplus.org>
Date: Thu Oct 6 14:22:55 2016 +0200
Issue 524 - Stop using @-moz-document
---
dependencies | 2 +-
lib/child/elemHide.js | 99 ++++++++++++++++++++++++++-------------------------
lib/contentPolicy.js | 27 +++-----------
lib/elemHideFF.js | 59 ++++++++++++++++++++----------
4 files changed, 96 insertions(+), 91 deletions(-)
diff --git a/dependencies b/dependencies
index adfd338..044ccf2 100644
--- a/dependencies
+++ b/dependencies
@@ -1,5 +1,5 @@
_root = hg:https://hg.adblockplus.org/ git:https://github.com/adblockplus/
_self = buildtools/ensure_dependencies.py
buildtools = buildtools hg:822863fb5df6 git:a0cd489
-adblockpluscore = adblockpluscore hg:d0d7a9d27bf7 git:b2333b7
+adblockpluscore = adblockpluscore hg:cc214664f060 git:0335b67
adblockplusui = adblockplusui hg:feea7a2cc0f5 git:c1e08b3
diff --git a/lib/child/elemHide.js b/lib/child/elemHide.js
index bc55810..34884c7 100644
--- a/lib/child/elemHide.js
+++ b/lib/child/elemHide.js
@@ -16,7 +16,7 @@
*/
/**
- * @fileOverview Hit counts for element hiding.
+ * @fileOverview Serves CSS for element hiding and processes hits.
*/
try
@@ -41,12 +41,6 @@ let {RequestNotifier} = require("child/requestNotifier");
let {port} = require("messaging");
let {Utils} = require("utils");
-// The allowXBL binding below won't have any effect on the element. For elements
-// that should be hidden however we don't return any binding at all, this makes
-// Gecko stop constructing the node - it cannot be shown.
-const allowXBL = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dummy' bindToUntrustedContent='true'/></bindings>";
-const hideXBL = "<bindings xmlns='http://www.mozilla.org/xbl'/>";
-
const notImplemented = () => Cr.NS_ERROR_NOT_IMPLEMENTED;
/**
@@ -96,14 +90,18 @@ let AboutHandler =
newChannel: function(uri, loadInfo)
{
- let match = /\?(?:hit(\d+)|css)$/.exec(uri.path);
- if (!match)
- throw Cr.NS_ERROR_FAILURE;
-
- if (match[1])
+ let match = /\?hit(\d+)$/.exec(uri.path);
+ if (match)
return new HitRegistrationChannel(uri, loadInfo, match[1]);
- else
- return new StyleDataChannel(uri, loadInfo);
+
+ match = /\?css(?:=(.*?))?$/.exec(uri.path);
+ if (match)
+ {
+ return new StyleDataChannel(uri, loadInfo,
+ match[1] ? decodeURIComponent(match[1]) : null);
+ }
+
+ throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule])
@@ -212,16 +210,18 @@ BaseChannel.prototype = {
};
/**
- * Channel returning CSS data for the global stylesheet.
+ * Channel returning CSS data for the global as well as site-specific stylesheet.
* @constructor
*/
-function StyleDataChannel(uri, loadInfo)
+function StyleDataChannel(uri, loadInfo, domain)
{
BaseChannel.call(this, uri, loadInfo);
+ this._domain = domain;
}
StyleDataChannel.prototype = {
__proto__: BaseChannel.prototype,
contentType: "text/css",
+ _domain: null,
_getResponse: function()
{
@@ -232,38 +232,20 @@ StyleDataChannel.prototype = {
// Would be great to avoid sync messaging here but nsIStyleSheetService
// insists on opening channels synchronously.
- let domains = port.emitSync("getSelectors");
+ let [selectors, keys] = (this._domain ?
+ port.emitSync("getSelectorsForDomain", this._domain) :
+ port.emitSync("getUnconditionalSelectors"));
let cssPrefix = "{-moz-binding: url(about:abp-elemhide?hit";
let cssSuffix = "#dummy) !important;}\n";
let result = [];
- for (let [domain, selectors] of domains)
+ for (let i = 0; i < selectors.length; i++)
{
- if (domain)
- {
- result.push('@-moz-document domain("',
- domain.replace(/[^\x01-\x7F]/g, escapeChar)
- .split(",").join('"),domain("'),
- '"){\n');
- }
- else
- {
- // Only allow unqualified rules on a few protocols to prevent them
- // from blocking chrome content
- result.push('@-moz-document url-prefix("http://"),',
- 'url-prefix("https://"),url-prefix("mailbox://"),',
- 'url-prefix("imap://"),url-prefix("news://"),',
- 'url-prefix("snews://"){\n');
- }
-
- for (let [selector, key] of selectors)
- {
- result.push(selector.replace(/[^\x01-\x7F]/g, escapeChar),
- cssPrefix, key, cssSuffix);
- }
-
- result.push("}\n");
+ let selector = selectors[i];
+ let key = keys[i];
+ result.push(selector.replace(/[^\x01-\x7F]/g, escapeChar),
+ cssPrefix, key, cssSuffix);
}
return result.join("");
@@ -286,14 +268,17 @@ HitRegistrationChannel.prototype = {
_getResponse: function()
{
- return new Promise((resolve, reject) =>
+ let window = Utils.getRequestWindow(this);
+ port.emitWithResponse("registerElemHideHit", {
+ key: this.key,
+ frames: getFrames(window),
+ isPrivate: isPrivate(window)
+ }).then(hit =>
{
- let window = Utils.getRequestWindow(this);
- shouldAllowAsync(window, window.document, "ELEMHIDE", this.key, allow =>
- {
- resolve(allow ? allowXBL : hideXBL);
- });
+ if (hit)
+ RequestNotifier.addNodeData(window.document, window.top, hit);
});
+ return "<bindings xmlns='http://www.mozilla.org/xbl'/>";
}
};
@@ -375,6 +360,24 @@ let observer = {
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);
+ }
+ 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)
{
diff --git a/lib/contentPolicy.js b/lib/contentPolicy.js
index 4318b00..c8bce20 100644
--- a/lib/contentPolicy.js
+++ b/lib/contentPolicy.js
@@ -30,7 +30,6 @@ let {Prefs} = require("prefs");
let {FilterStorage} = require("filterStorage");
let {BlockingFilter, WhitelistFilter, RegExpFilter} = require("filterClasses");
let {defaultMatcher} = require("matcher");
-let {ElemHide} = require("elemHide");
/**
* Public policy checking functions and auxiliary objects
@@ -113,7 +112,7 @@ var Policy = exports.Policy =
* Checks whether a node should be blocked, hides it if necessary
* @param {Object} data request data
* @param {String} data.contentType
- * @param {String} data.location location of the request, filter key if contentType is ELEMHIDE
+ * @param {String} data.location location of the request
* @param {Object[]} data.frames
* @param {Boolean} data.isPrivate true if the request belongs to a private browsing window
* @return {Object} An object containing properties allow, collapse and hits
@@ -150,12 +149,12 @@ var Policy = exports.Policy =
if (Prefs.enabled)
{
let whitelistHit =
- this.isFrameWhitelisted(frames, contentType == "ELEMHIDE");
+ this.isFrameWhitelisted(frames, false);
if (whitelistHit)
{
let [frameIndex, matchType, docDomain, thirdParty, location, filter] = whitelistHit;
addHit(frameIndex, matchType, docDomain, thirdParty, location, filter);
- if (matchType == "DOCUMENT" || matchType == "ELEMHIDE")
+ if (matchType == "DOCUMENT")
return response(true, false);
else
nogeneric = true;
@@ -166,26 +165,8 @@ var Policy = exports.Policy =
let wndLocation = frames[0].location;
let docDomain = getHostname(wndLocation);
let [sitekey, sitekeyFrame] = getSitekey(frames);
- if (contentType == "ELEMHIDE")
- {
- match = ElemHide.getFilterByKey(location);
- location = match.text.replace(/^.*?#/, '#');
-
- if (!match.isActiveOnDomain(docDomain))
- return response(true, false);
-
- let exception = ElemHide.getException(match, docDomain);
- if (exception)
- {
- addHit(null, contentType, docDomain, false, location, exception);
- return response(true, false);
- }
-
- if (nogeneric && match.isGeneric())
- return response(true, false);
- }
- let thirdParty = (contentType == "ELEMHIDE" ? false : isThirdParty(location, docDomain));
+ let thirdParty = isThirdParty(location, docDomain);
let collapse = false;
if (!match && Prefs.enabled && RegExpFilter.typeMap.hasOwnProperty(contentType))
{
diff --git a/lib/elemHideFF.js b/lib/elemHideFF.js
index ef3902c..2e5c5e0 100644
--- a/lib/elemHideFF.js
+++ b/lib/elemHideFF.js
@@ -41,27 +41,19 @@ FilterNotifier.on("elemhideupdate", () =>
}
});
-let translateMap = map => map;
-if (Services.vc.compare(Utils.platformVersion, "40.0") <= 0)
+port.on("getUnconditionalSelectors", () =>
{
- translateMap = map =>
- {
- // We cannot send Map objects with Gecko 40 and below, "translate" them
- // into nested arrays. This isn't very efficient but that should be ok as
- // long as only outdated Firefox versions are affected.
- let translated = [];
- for (let [key, value] of map)
- {
- if (value instanceof Map)
- translated.push([key, translateMap(value)]);
- else
- translated.push([key, value]);
- }
- return translated;
- };
-}
+ return [
+ ElemHide.getUnconditionalSelectors(),
+ ElemHide.getUnconditionalFilterKeys()
+ ];
+});
-port.on("getSelectors", () => translateMap(ElemHide.getSelectors()));
+port.on("getSelectorsForDomain", domain =>
+{
+ return ElemHide.getSelectorsForDomain(domain, ElemHide.NO_UNCONDITIONAL,
+ true);
+});
port.on("elemhideEnabled", ({frames, isPrivate}) =>
{
@@ -86,3 +78,32 @@ port.on("elemhideEnabled", ({frames, isPrivate}) =>
return {enabled: true};
});
+
+port.on("registerElemHideHit", ({key, frames, isPrivate}) =>
+{
+ let filter = ElemHide.getFilterByKey(key);
+ if (!filter)
+ return null;
+
+ if (!isPrivate)
+ FilterStorage.increaseHitCount(filter);
+
+ let docDomain;
+ try
+ {
+ docDomain = Utils.unwrapURL(frames[0].location).host;
+ }
+ catch(e)
+ {
+ docDomain = null;
+ }
+
+ return {
+ contentType: "ELEMHIDE",
+ docDomain,
+ thirdParty: false,
+ location: filter.text.replace(/^.*?#/, '#'),
+ filter: filter.text,
+ filterType: filter.type
+ };
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus.git
More information about the Pkg-mozext-commits
mailing list