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: Addressed comments, fixed popup blocking detection, log whitelisted documents Created Feb. 2, 2016, 10:38 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
« no previous file with comments | « 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,58 +17,71 @@
/** @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();
+function match(page, url, typeMask, docDomain, sitekey)
+{
+ let thirdParty = !!docDomain && isThirdParty(url, docDomain);
+ let urlString = stringifyURL(url);
+
+ 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 page 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
- * @return {WhitelistFilter} The active filter whitelisting this page or null
+ * @param {Page} page
+ * @param {Frame} [frame]
+ * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
+ * @return {WhitelistFilter?}
*/
-exports.isPageWhitelisted = function(page)
+exports.checkWhitelisted = function(page, frame, typeMask)
{
- let url = page.url;
+ if (typeof typeMask == "undefined")
+ typeMask = RegExpFilter.typeMap.DOCUMENT;
- return defaultMatcher.whitelist.matchesAny(
- stringifyURL(url), RegExpFilter.typeMap.DOCUMENT,
- getDecodedHostname(url), false, null
- );
+ if (frame)
+ {
+ let filter = null;
+
+ while (frame && !filter)
+ {
+ let parent = frame.parent;
+ let docDomain = extractHostFromFrame(parent);
+ let sitekey = getKey(page, frame);
+
+ filter = match(page, frame.url, typeMask, docDomain, sitekey);
+ frame = parent;
+ }
+
+ return filter;
+ }
+
+ return match(page, page.url, typeMask);
};
-/**
- * Checks whether a frame is whitelisted.
- *
- * @param {Page} page
- * @param {Frame} frame
- * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
- * @return {Boolean}
- */
-exports.isFrameWhitelisted = function(page, frame, typeMask)
-{
- while (frame)
- {
- let parent = frame.parent;
- let url = frame.url;
- let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
-
- let filter = defaultMatcher.whitelist.matchesAny(
- stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
- documentHost, isThirdParty(url, documentHost),
- getKey(page, frame)
- );
-
- if (filter)
- return true;
-
- frame = parent;
- }
-
- return false;
-};
+// Compatibility with adblockplusui, to be removed when updating the dependency
Sebastian Noack 2016/02/02 10:39:54 I am going to update adblockplusui and remove that
+exports.isFrameWhitelisted = exports.checkWhitelisted;
let getKey =
/**
« no previous file with comments | « lib/filterComposer.js ('k') | metadata.chrome » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld