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: Created Oct. 27, 2015, 2:28 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 | 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
@@ -169,39 +169,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)
Thomas Greiner 2015/11/10 18:22:33 This function doesn't need to be inside `processNo
Wladimir Palant 2015/11/10 19:13:15 Given that this is a temporary solution I'd rather
+ {
+ 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, sitekey);
Thomas Greiner 2015/11/10 18:22:34 `sitekey` is the bottom window's sitekey so should
Wladimir Palant 2015/11/10 19:13:15 Yes, this should really be testSitekey - this was
Wladimir Palant 2015/11/11 07:54:20 Done.
+ 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,
@@ -224,37 +239,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