[Pkg-mozext-commits] [adblock-plus] 12/98: Issue 3969 - Hits are not counted for custom CSS property rules

David Prévot taffit at moszumanska.debian.org
Tue Oct 24 01:30:13 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 bc12cbdf58b5c5b8b9f3d050fd789a0004943518
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Apr 27 20:15:08 2016 +0200

    Issue 3969 - Hits are not counted for custom CSS property rules
---
 chrome/content/ui/sidebar.js |  2 +-
 lib/child/cssProperties.js   | 33 +++++++++++++++++++++++++++++++--
 lib/cssProperties.js         | 28 ++++++++++++++++++++++++++++
 lib/main.js                  |  1 +
 4 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/chrome/content/ui/sidebar.js b/chrome/content/ui/sidebar.js
index fcb2c96..c4447c0 100644
--- a/chrome/content/ui/sidebar.js
+++ b/chrome/content/ui/sidebar.js
@@ -989,7 +989,7 @@ var treeView = {
           state = "state-whitelisted";
         else if (filter instanceof BlockingFilter)
           state = "state-filtered";
-        else if (filter instanceof ElemHideFilter)
+        else if (filter instanceof ElemHideFilter || filter instanceof CSSPropertyFilter)
           state = "state-hidden";
         else if (filter instanceof ElemHideException)
           state = "state-hiddenexception";
diff --git a/lib/child/cssProperties.js b/lib/child/cssProperties.js
index 3c9a0fa..279a900 100644
--- a/lib/child/cssProperties.js
+++ b/lib/child/cssProperties.js
@@ -22,7 +22,8 @@
   let {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
 
   let {port} = require("messaging");
-  let {getFrames} = require("child/utils");
+  let {getFrames, isPrivate} = require("child/utils");
+  let {RequestNotifier} = require("child/requestNotifier");
 
   function getFilters(window, callback)
   {
@@ -60,7 +61,7 @@
       {
         subject.removeEventListener("load", onReady);
         let handler = new scope.CSSPropertyFilters(
-          subject, getFilters.bind(null, subject), selectors =>
+          subject, getFilters.bind(null, subject), (selectors, filters) =>
           {
             if (selectors.length == 0)
               return;
@@ -68,6 +69,34 @@
             addUserCSS(subject, selectors.map(
               selector => selector + "{display: none !important;}"
             ).join("\n"));
+
+            if (!isPrivate(subject))
+              port.emit("addHits", filters);
+
+            let docDomain = null;
+            try
+            {
+              // We are calling getFrames() here because it will consider
+              // "inheritance" for about:blank and data: frames.
+              docDomain = new URL(getFrames(subject)[0].location).hostname;
+            }
+            catch (e)
+            {
+              // Invalid URL?
+            }
+
+            for (let filter of filters)
+            {
+              RequestNotifier.addNodeData(subject.document, subject.top, {
+                contentType: "ELEMHIDE",
+                docDomain: docDomain,
+                thirdParty: false,
+                // TODO: Show the actual matching selector here?
+                location: filter.replace(/^.*?##/, ""),
+                filter: filter,
+                filterType: "cssproperty"
+              });
+            }
           }
         );
 
diff --git a/lib/cssProperties.js b/lib/cssProperties.js
new file mode 100644
index 0000000..aa3d993
--- /dev/null
+++ b/lib/cssProperties.js
@@ -0,0 +1,28 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-2016 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+"use strict";
+
+let {port} = require("messaging");
+let {Filter} = require("filterClasses");
+let {FilterStorage} = require("filterStorage");
+
+port.on("addHits", filters =>
+{
+  for (let text of filters)
+    FilterStorage.increaseHitCount(Filter.fromText(text));
+});
diff --git a/lib/main.js b/lib/main.js
index 742a9fb..dadca3a 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -32,6 +32,7 @@ require("sync");
 require("messageResponder");
 require("ui");
 require("objectTabs");
+require("cssProperties");
 
 function bootstrapChildProcesses()
 {

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