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

Unified Diff: lib/whitelisting.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Fixed a typo, updated dependency, tidied up some code Created Feb. 2, 2016, 1:21 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
« lib/devtools.js ('K') | « lib/filterComposer.js ('k') | metadata.chrome » ('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,57 +17,67 @@
/** @module whitelisting */
+"use strict";
+
let {defaultMatcher} = require("matcher");
let {RegExpFilter} = require("filterClasses");
let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = require("url");
+let devtools = require("devtools");
let pagesWithKey = new ext.PageMap();
-/**
- * Checks whether a page is whitelisted.
- *
- * @param {Page} page
- * @return {WhitelistFilter} The active filter whitelisting this page or null
- */
-exports.isPageWhitelisted = function(page)
+function match(page, url, typeMask, docDomain, sitekey)
{
- let url = page.url;
+ let thirdParty = !!docDomain && isThirdParty(url, docDomain);
+ let urlString = stringifyURL(url);
- return defaultMatcher.whitelist.matchesAny(
- stringifyURL(url), RegExpFilter.typeMap.DOCUMENT,
- getDecodedHostname(url), false, null
+ if (!docDomain)
+ docDomain = getDecodedHostname(url);
+
+ let filter = defaultMatcher.whitelist.matchesAny(
+ urlString, typeMask, docDomain, thirdParty, sitekey
);
-};
+
+ if (filter && devtools)
+ devtools.logWhitelistedDocument(
+ page, urlString, typeMask, docDomain, filter
+ );
+
+ return filter;
+}
/**
- * Checks whether a frame is whitelisted.
+ * 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 {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
- * @return {Boolean}
+ * @param {Frame} [frame]
+ * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
+ * @return {?WhitelistFilter}
*/
-exports.isFrameWhitelisted = function(page, frame, typeMask)
+exports.checkWhitelisted = function(page, frame, typeMask)
{
- while (frame)
+ if (typeof typeMask == "undefined")
+ typeMask = RegExpFilter.typeMap.DOCUMENT;
+
+ if (frame)
{
- let parent = frame.parent;
- let url = frame.url;
- let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
+ let filter = null;
- let filter = defaultMatcher.whitelist.matchesAny(
- stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
- documentHost, isThirdParty(url, documentHost),
- getKey(page, frame)
- );
+ while (frame && !filter)
+ {
+ let parent = frame.parent;
+ let docDomain = extractHostFromFrame(parent);
+ let sitekey = getKey(page, frame);
- if (filter)
- return true;
+ filter = match(page, frame.url, typeMask, docDomain, sitekey);
+ frame = parent;
+ }
- frame = parent;
+ return filter;
}
- return false;
+ return match(page, page.url, typeMask);
};
let getKey =
« lib/devtools.js ('K') | « lib/filterComposer.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld