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 = |