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

Unified Diff: lib/whitelisting.js

Issue 29739594: Issue 6543 - Match requests without tabId/frameId in their originating context (Closed)
Patch Set: Use URL patterns to find tabs for initiator Created April 4, 2018, 1:01 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
« lib/requestBlocker.js ('K') | « lib/url.js ('k') | no next file » | 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
@@ -43,7 +43,7 @@
urlString, typeMask, docDomain, thirdParty, sitekey
);
- if (filter)
+ if (filter && page)
logWhitelistedDocument(page.id, urlString, typeMask, docDomain, filter);
return filter;
@@ -54,34 +54,35 @@
* Gets the active whitelisting filter for the document associated
* with the given page/frame, or null if it's not whitelisted.
*
- * @param {Page} page
- * @param {Frame} [frame]
+ * @param {?Page} page
+ * @param {?Frame} [frame]
+ * @param {?URL} [originUrl]
* @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
* @return {?WhitelistFilter}
*/
-exports.checkWhitelisted = (page, frame, typeMask) =>
+exports.checkWhitelisted = (page, frame, originUrl,
+ typeMask = RegExpFilter.typeMap.DOCUMENT) =>
{
- if (typeof typeMask == "undefined")
- typeMask = RegExpFilter.typeMap.DOCUMENT;
-
- if (frame)
+ if (frame || originUrl)
{
- let filter = null;
-
- while (frame && !filter)
+ while (frame)
{
- let {parent} = frame;
- let docDomain = extractHostFromFrame(parent);
- let sitekey = getKey(page, frame);
+ let parentFrame = frame.parent;
+ let filter = match(page, frame.url, typeMask,
+ extractHostFromFrame(parentFrame, originUrl),
+ getKey(page, frame, originUrl));
- filter = match(page, frame.url, typeMask, docDomain, sitekey);
- frame = parent;
+ if (filter)
+ return filter;
+
+ frame = parentFrame;
}
- return filter;
+ return originUrl && match(page, originUrl, typeMask, null,
+ getKey(null, null, originUrl));
}
- return match(page, page.url, typeMask);
+ return page && match(page, page.url, typeMask);
};
port.on("filters.isWhitelisted", message =>
@@ -143,21 +144,35 @@
* Gets the public key, previously recorded for the given page
* and frame, to be considered for the $sitekey filter option.
*
- * @param {Page} page
- * @param {Frame} frame
+ * @param {?Page} page
+ * @param {?Frame} frame
+ * @param {URL} [originUrl]
* @return {string}
*/
-exports.getKey = (page, frame) =>
+exports.getKey = (page, frame, originUrl) =>
{
- let keys = sitekeys.get(page);
- if (!keys)
- return null;
+ if (page)
+ {
+ let keys = sitekeys.get(page);
+ if (keys)
+ {
+ for (; frame; frame = frame.parent)
+ {
+ let key = keys.get(stringifyURL(frame.url));
+ if (key)
+ return key;
+ }
+ }
+ }
- for (; frame != null; frame = frame.parent)
+ if (originUrl)
{
- let key = keys.get(stringifyURL(frame.url));
- if (key)
- return key;
+ for (let keys of sitekeys._map.values())
+ {
+ let key = keys.get(stringifyURL(originUrl));
+ if (key)
+ return key;
+ }
}
return null;
« lib/requestBlocker.js ('K') | « lib/url.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld