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

Unified Diff: lib/contentPolicy.js

Issue 5840485868371968: Issue 616 - Add $generichide + $genericblock filter options and enforce them. (Closed)
Patch Set: Addressed Thomas' feedback Created Sept. 3, 2015, 12:35 p.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/filterClasses.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/contentPolicy.js
diff --git a/lib/contentPolicy.js b/lib/contentPolicy.js
index b0498da6ec3bf66b35e35d8d8114e99ad3477707..e88ba5f15786c6cbf575d9dcb4a42650ac497a47 100644
--- a/lib/contentPolicy.js
+++ b/lib/contentPolicy.js
@@ -162,6 +162,9 @@ let Policy = exports.Policy =
let docDomain = getHostname(wndLocation);
let match = null;
let [sitekey, sitekeyWnd] = getSitekey(wnd);
+ let genericblock = null;
+ let generichide = null;
Wladimir Palant 2015/09/03 13:09:42 It's either a blocking rule or hiding rule - so at
kzar 2015/09/05 14:39:58 Done.
+
if (!match && Prefs.enabled)
{
let testWnd = wnd;
@@ -181,6 +184,24 @@ let Policy = exports.Policy =
return true;
}
+ if (contentType != Policy.type.ELEMHIDE)
+ {
+ let parentDocDomain = getHostname(parentWndLocation);
+ let genericblockMatch = defaultMatcher.matchesAny(
+ testWndLocation, RegExpFilter.typeMap.GENERICBLOCK,
+ parentDocDomain, false, testSitekey
+ );
+ if (genericblockMatch instanceof WhitelistFilter)
+ {
+ genericblock = {
+ match: genericblockMatch,
+ parentDocDomain: parentDocDomain,
+ testWnd: testWnd,
+ testWndLocation: testWndLocation
+ };
+ }
+ }
+
if (testWnd.parent == testWnd)
break;
@@ -208,7 +229,9 @@ let Policy = exports.Policy =
let testWndLocation = parentWndLocation;
parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWindowLocation(testWnd.parent));
let parentDocDomain = getHostname(parentWndLocation);
+
match = defaultMatcher.matchesAny(testWndLocation, RegExpFilter.typeMap.ELEMHIDE, parentDocDomain, false, sitekey);
+
if (match instanceof WhitelistFilter)
{
FilterStorage.increaseHitCount(match, wnd);
@@ -216,6 +239,20 @@ let Policy = exports.Policy =
return true;
}
+ let generichideMatch = defaultMatcher.matchesAny(
+ testWndLocation, RegExpFilter.typeMap.GENERICHIDE,
+ parentDocDomain, false, sitekey
+ );
+ if (generichideMatch instanceof WhitelistFilter)
+ {
+ generichide = {
+ match: generichideMatch,
+ parentDocDomain: parentDocDomain,
+ testWnd: testWnd,
+ testWndLocation: testWndLocation
+ };
+ }
Wladimir Palant 2015/09/03 13:09:42 This is simply duplicating the logic from above. I
kzar 2015/09/05 14:39:58 Done.
+
if (testWnd.parent == testWnd)
break;
else
@@ -236,6 +273,19 @@ let Policy = exports.Policy =
RequestNotifier.addNodeData(node, topWnd, contentType, docDomain, false, locationText, exception);
return true;
}
+
+ if (generichide && match && match.isGeneric())
+ {
+ FilterStorage.increaseHitCount(generichide.match, wnd);
+ RequestNotifier.addNodeData(
+ generichide.testWnd.document,
+ topWnd, contentType,
+ generichide.parentDocDomain,
+ false, generichide.testWndLocation,
+ generichide.match
+ );
+ return true;
+ }
}
let thirdParty = (contentType == Policy.type.ELEMHIDE ? false : isThirdParty(location, docDomain));
@@ -243,11 +293,27 @@ let Policy = exports.Policy =
if (!match && Prefs.enabled && contentType in Policy.typeMask)
{
match = defaultMatcher.matchesAny(locationText, Policy.typeMask[contentType], docDomain, thirdParty, sitekey);
- if (match instanceof BlockingFilter && node.ownerDocument && !(contentType in Policy.nonVisual))
+ if (match instanceof BlockingFilter)
{
- let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fastcollapse);
- if (collapse || prefCollapse)
- schedulePostProcess(node);
+ if (genericblock && match.isGeneric())
Wladimir Palant 2015/09/03 13:09:43 What if there are multiple filters potentially mat
kzar 2015/09/04 15:49:10 Hmm good point, any suggestions? In the other revi
Wladimir Palant 2015/09/04 16:16:23 Why another search? Just pass specificOnly and be
kzar 2015/09/05 14:39:58 Oh, of course! Done.
+ {
+ FilterStorage.increaseHitCount(genericblock.match, wnd);
+ RequestNotifier.addNodeData(
+ genericblock.testWnd.document,
+ topWnd, contentType,
+ genericblock.parentDocDomain,
+ false, genericblock.testWndLocation,
+ genericblock.match
+ );
+ return true;
+ }
+
+ if (node.ownerDocument && !(contentType in Policy.nonVisual))
+ {
+ let prefCollapse = (match.collapse != null ? match.collapse : !Prefs.fastcollapse);
+ if (collapse || prefCollapse)
+ schedulePostProcess(node);
+ }
}
// Track mouse events for objects
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld