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

Side by Side Diff: lib/whitelisting.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Use chrome.runtime.onConnect directly Created Feb. 2, 2016, 11:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filterComposer.js ('k') | metadata.chrome » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /** @module whitelisting */ 18 /** @module whitelisting */
19 19
20 "use strict";
21
20 let {defaultMatcher} = require("matcher"); 22 let {defaultMatcher} = require("matcher");
21 let {RegExpFilter} = require("filterClasses"); 23 let {RegExpFilter} = require("filterClasses");
22 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 24 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
25 let devtools = require("devtools");
23 26
24 let pagesWithKey = new ext.PageMap(); 27 let pagesWithKey = new ext.PageMap();
25 28
29 function match(page, url, typeMask, docDomain, sitekey)
30 {
31 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
32 let urlString = stringifyURL(url);
33
34 if (!docDomain)
35 docDomain = getDecodedHostname(url);
36
37 let filter = defaultMatcher.whitelist.matchesAny(
38 urlString, typeMask, docDomain, thirdParty, sitekey
39 );
40
41 if (filter && devtools)
42 devtools.logWhitelistedDocument(
43 page, urlString, typeMask, docDomain, filter
44 );
45
46 return filter;
47 }
48
26 /** 49 /**
27 * Checks whether a page is whitelisted. 50 * Gets the active whitelisting filter for the document associated
51 * with the given page/frame, or null if it's not whitelisted.
28 * 52 *
29 * @param {Page} page 53 * @param {Page} page
30 * @return {WhitelistFilter} The active filter whitelisting this page or null 54 * @param {Frame} [frame]
55 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT]
56 * @return {WhitelistFilter?}
31 */ 57 */
32 exports.isPageWhitelisted = function(page) 58 exports.checkWhitelisted = function(page, frame, typeMask)
33 { 59 {
34 let url = page.url; 60 if (typeof typeMask == "undefined")
61 typeMask = RegExpFilter.typeMap.DOCUMENT;
35 62
36 return defaultMatcher.whitelist.matchesAny( 63 if (frame)
37 stringifyURL(url), RegExpFilter.typeMap.DOCUMENT, 64 {
38 getDecodedHostname(url), false, null 65 let filter = null;
39 ); 66
67 while (frame && !filter)
68 {
69 let parent = frame.parent;
70 let docDomain = extractHostFromFrame(parent);
71 let sitekey = getKey(page, frame);
72
73 filter = match(page, frame.url, typeMask, docDomain, sitekey);
74 frame = parent;
75 }
76
77 return filter;
78 }
79
80 return match(page, page.url, typeMask);
40 }; 81 };
41 82
42 /** 83 // Compatibility with adblockplusui, to be removed when updating the dependency
43 * Checks whether a frame is whitelisted. 84 exports.isFrameWhitelisted = exports.checkWhitelisted;
44 *
45 * @param {Page} page
46 * @param {Frame} frame
47 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
48 * @return {Boolean}
49 */
50 exports.isFrameWhitelisted = function(page, frame, typeMask)
51 {
52 while (frame)
53 {
54 let parent = frame.parent;
55 let url = frame.url;
56 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
57
58 let filter = defaultMatcher.whitelist.matchesAny(
59 stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
60 documentHost, isThirdParty(url, documentHost),
61 getKey(page, frame)
62 );
63
64 if (filter)
65 return true;
66
67 frame = parent;
68 }
69
70 return false;
71 };
72 85
73 let getKey = 86 let getKey =
74 /** 87 /**
75 * Gets the public key, previously recorded for the given page 88 * Gets the public key, previously recorded for the given page
76 * and frame, to be considered for the $sitekey filter option. 89 * and frame, to be considered for the $sitekey filter option.
77 * 90 *
78 * @param {Page} page 91 * @param {Page} page
79 * @param {Frame} frame 92 * @param {Frame} frame
80 * @return {string} 93 * @return {string}
81 */ 94 */
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 { 147 {
135 if (token.indexOf("_") < 0) 148 if (token.indexOf("_") < 0)
136 return; 149 return;
137 150
138 let [key, signature] = token.split("_", 2); 151 let [key, signature] = token.split("_", 2);
139 key = key.replace(/=/g, ""); 152 key = key.replace(/=/g, "");
140 153
141 if (verifyKey(key, signature, frame.url)) 154 if (verifyKey(key, signature, frame.url))
142 recordKey(page, frame.url, key); 155 recordKey(page, frame.url, key);
143 }; 156 };
OLDNEW
« 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