[Pkg-mozext-commits] [adblock-plus] 37/98: Issue 4499 - Consider $generichide exceptions when applying element hiding rules

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 1b5cb52db820989d9b40da9aee3094981a82270b
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Fri Oct 7 12:50:58 2016 +0200

    Issue 4499 - Consider $generichide exceptions when applying element hiding rules
---
 lib/child/elemHide.js | 58 +++++++++++++++++++++++++++++++--------------------
 lib/elemHideFF.js     | 23 +++++++++-----------
 2 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/lib/child/elemHide.js b/lib/child/elemHide.js
index 34884c7..63c639d 100644
--- a/lib/child/elemHide.js
+++ b/lib/child/elemHide.js
@@ -94,11 +94,11 @@ let AboutHandler =
     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;
@@ -213,10 +213,11 @@ BaseChannel.prototype = {
  * 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,
@@ -233,7 +234,7 @@ StyleDataChannel.prototype = {
     // 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";
@@ -340,25 +341,32 @@ let observer = {
 
       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
-        {
-          utils.addSheet(this.sheet, Ci.nsIStyleSheetService.USER_SHEET);
-        }
-        catch (e)
+
+        // 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)
         {
-          // 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;
@@ -366,8 +374,11 @@ let observer = {
         {
           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)
           {
@@ -379,7 +390,8 @@ let observer = {
           }
         }
       }
-      else if (filter)
+
+      if (filter)
       {
         RequestNotifier.addNodeData(window.document, window.top, {
           contentType, docDomain, thirdParty, location, filter, filterType
diff --git a/lib/elemHideFF.js b/lib/elemHideFF.js
index 2e5c5e0..b9a00b8 100644
--- a/lib/elemHideFF.js
+++ b/lib/elemHideFF.js
@@ -49,10 +49,10 @@ port.on("getUnconditionalSelectors", () =>
   ];
 });
 
-port.on("getSelectorsForDomain", domain =>
+port.on("getSelectorsForDomain", ([domain, specificOnly]) =>
 {
-  return ElemHide.getSelectorsForDomain(domain, ElemHide.NO_UNCONDITIONAL,
-    true);
+  let type = specificOnly ? ElemHide.SPECIFIC_ONLY : ElemHide.NO_UNCONDITIONAL;
+  return ElemHide.getSelectorsForDomain(domain, type, true);
 });
 
 port.on("elemhideEnabled", ({frames, isPrivate}) =>
@@ -64,16 +64,13 @@ port.on("elemhideEnabled", ({frames, isPrivate}) =>
   if (hit)
   {
     let [frameIndex, contentType, docDomain, thirdParty, location, filter] = hit;
-    if (contentType != "GENERICHIDE")
-    {
-      if (!isPrivate)
-        FilterStorage.increaseHitCount(filter);
-      return {
-        enabled: false,
-        contentType, docDomain, thirdParty, location,
-        filter: filter.text, filterType: filter.type
-      };
-    }
+    if (!isPrivate)
+      FilterStorage.increaseHitCount(filter);
+    return {
+      enabled: contentType == "GENERICHIDE",
+      contentType, docDomain, thirdParty, location,
+      filter: filter.text, filterType: filter.type
+    };
   }
 
   return {enabled: true};

-- 
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