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

Unified Diff: lib/contentPolicy.js

Issue 29329419: Issue 3208 - Unify handling of $document and $elemhide exceptions and improve performance (Closed)
Patch Set: Fixed sitekey parameter Created Nov. 11, 2015, 7:53 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/contentPolicy.js
===================================================================
--- a/lib/contentPolicy.js
+++ b/lib/contentPolicy.js
@@ -171,39 +171,54 @@ var Policy = exports.Policy =
let originWindow = Utils.getOriginWindow(wnd);
let wndLocation = originWindow.location.href;
let docDomain = getHostname(wndLocation);
let match = null;
let [sitekey, sitekeyWnd] = getSitekey(wnd);
let nogeneric = false;
+ function cleanWindowLocation(wnd)
+ {
+ let url = getWindowLocation(wnd);
+ let index = url.indexOf("#");
+ if (index >= 0)
+ url = url.substring(0, index);
+
+ return url;
+ }
+
if (!match && Prefs.enabled)
{
let testWnd = wnd;
let testSitekey = sitekey;
let testSitekeyWnd = sitekeyWnd;
- let parentWndLocation = getWindowLocation(testWnd);
+ let parentWndLocation = cleanWindowLocation(testWnd);
while (true)
{
let testWndLocation = parentWndLocation;
- parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : getWindowLocation(testWnd.parent));
- match = Policy.isWhitelisted(testWndLocation, parentWndLocation, testSitekey);
+ parentWndLocation = (testWnd == testWnd.parent ? testWndLocation : cleanWindowLocation(testWnd.parent));
+ let parentDocDomain = getHostname(parentWndLocation);
- if (match instanceof WhitelistFilter)
+ let typeMap = RegExpFilter.typeMap.DOCUMENT;
+ if (contentType == Policy.type.ELEMHIDE)
+ typeMap = typeMap | RegExpFilter.typeMap.ELEMHIDE;
+ let whitelistMatch = defaultMatcher.matchesAny(testWndLocation, typeMap, parentDocDomain, false, testSitekey);
+ if (whitelistMatch instanceof WhitelistFilter)
{
- FilterStorage.increaseHitCount(match, wnd);
- RequestNotifier.addNodeData(testWnd.document, topWnd, Policy.type.DOCUMENT, getHostname(parentWndLocation), false, testWndLocation, match);
+ FilterStorage.increaseHitCount(whitelistMatch, wnd);
+ RequestNotifier.addNodeData(testWnd.document, topWnd,
+ (whitelistMatch.contentType & RegExpFilter.typeMap.DOCUMENT) ? Policy.type.DOCUMENT : Policy.type.ELEMHIDE,
+ parentDocDomain, false, testWndLocation, whitelistMatch);
return true;
}
let genericType = (contentType == Policy.type.ELEMHIDE ?
Policy.type.GENERICHIDE :
Policy.type.GENERICBLOCK);
- let parentDocDomain = getHostname(parentWndLocation);
let nogenericMatch = defaultMatcher.matchesAny(testWndLocation,
Policy.typeMask[genericType], parentDocDomain, false, testSitekey);
if (nogenericMatch instanceof WhitelistFilter)
{
nogeneric = true;
FilterStorage.increaseHitCount(nogenericMatch, wnd);
RequestNotifier.addNodeData(testWnd.document, topWnd, genericType,
@@ -226,37 +241,16 @@ var Policy = exports.Policy =
// Fix type for objects misrepresented as frames or images
if (contentType != Policy.type.OBJECT && (node instanceof Ci.nsIDOMHTMLObjectElement || node instanceof Ci.nsIDOMHTMLEmbedElement))
contentType = Policy.type.OBJECT;
let locationText = location.spec;
if (!match && contentType == Policy.type.ELEMHIDE)
{
- let testWnd = wnd;
- let parentWndLocation = getWindowLocation(testWnd);
- while (true)
- {
- 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);
- RequestNotifier.addNodeData(testWnd.document, topWnd, contentType, parentDocDomain, false, testWndLocation, match);
- return true;
- }
-
- if (testWnd.parent == testWnd)
- break;
- else
- testWnd = testWnd.parent;
- }
-
match = location;
locationText = match.text.replace(/^.*?#/, '#');
location = locationText;
if (!match.isActiveOnDomain(docDomain))
return true;
let exception = ElemHide.getException(match, docDomain);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld