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

Unified Diff: lib/whitelisting.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 5:06 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 | « lib/url.js ('k') | metadata.common » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/whitelisting.js
===================================================================
--- a/lib/whitelisting.js
+++ b/lib/whitelisting.js
@@ -17,30 +17,40 @@
let {defaultMatcher} = require("matcher");
let {WhitelistFilter} = require("filterClasses");
+let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = require("url");
let pagesWithKey = new ext.PageMap();
-function isWhitelisted(url, parentUrl, type, key)
+function isPageWhitelisted(page)
{
+ let url = page.url;
let filter = defaultMatcher.matchesAny(
- stripFragmentFromURL(url),
- type || "DOCUMENT",
- extractHostFromURL(parentUrl || url),
- false,
- key
+ stringifyURL(url), "DOCUMENT",
+ getDecodedHostname(url), false, null
);
return (filter instanceof WhitelistFilter ? filter : null);
}
-exports.isWhitelisted = isWhitelisted;
+exports.isPageWhitelisted = isPageWhitelisted;
function isFrameWhitelisted(page, frame, type)
{
- for (; frame != null; frame = frame.parent)
+ while (frame)
{
- let key = getKey(page, frame);
- if (isWhitelisted(frame.url, (frame.parent || {}).url, type, key))
+ let parent = frame.parent;
+ let url = frame.url;
+ let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
+
+ let filter = defaultMatcher.matchesAny(
+ stringifyURL(url), type || "DOCUMENT",
+ documentHost, isThirdParty(url, documentHost),
+ getKey(page, frame)
+ );
+
+ if (filter instanceof WhitelistFilter)
return true;
+
+ frame = parent;
}
return false;
@@ -55,8 +65,9 @@
for (; frame != null; frame = frame.parent)
{
- if (urlsWithKey[frame.url])
- return urlsWithKey[frame.url];
+ let key = urlsWithKey[stringifyURL(frame.url)];
+ if (key)
+ return key;
}
return null;
@@ -65,7 +76,6 @@
function verifyKey(key, signature, url)
{
- url = new URL(url);
let params = [
url.pathname + url.search, // REQUEST_URI
url.host, // HTTP_HOST
@@ -85,20 +95,18 @@
pagesWithKey.set(page, urlsWithKey);
}
- urlsWithKey[url] = key;
+ urlsWithKey[stringifyURL(url)] = key;
}
function processKey(token, page, frame)
{
- let url = stripFragmentFromURL(frame.url);
-
if (token.indexOf("_") < 0)
return;
let [key, signature] = token.split("_", 2);
key = key.replace(/=/g, "");
- if (verifyKey(key, signature, url))
- recordKey(page, url, key);
+ if (verifyKey(key, signature, frame.url))
+ recordKey(page, frame.url, key);
}
exports.processKey = processKey;
« no previous file with comments | « lib/url.js ('k') | metadata.common » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld