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

Side by Side Diff: lib/whitelisting.js

Issue 29321504: Issue 2738 - Pass bit masks to matching functions (Closed)
Patch Set: Updated to match adblockplus changes and addressed feedback Created July 12, 2015, 2:25 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 let {defaultMatcher} = require("matcher"); 20 let {defaultMatcher} = require("matcher");
21 let {RegExpFilter} = require("filterClasses");
21 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 22 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
22 23
23 let pagesWithKey = new ext.PageMap(); 24 let pagesWithKey = new ext.PageMap();
24 25
25 /** 26 /**
26 * Checks whether a page is whitelisted. 27 * Checks whether a page is whitelisted.
27 * 28 *
28 * @param {Page} page 29 * @param {Page} page
30 * @param {Number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
29 * @return {WhitelistFilter} The active filter whitelisting this page or null 31 * @return {WhitelistFilter} The active filter whitelisting this page or null
30 */ 32 */
31 exports.isPageWhitelisted = function(page) 33 exports.isPageWhitelisted = function(page, typeMask)
Sebastian Noack 2015/07/13 16:41:50 Sorry if my previous comment was misleading. But s
kzar 2015/07/14 09:22:24 Done.
32 { 34 {
33 let url = page.url; 35 let url = page.url;
34 36
35 return defaultMatcher.whitelist.matchesAny( 37 return defaultMatcher.whitelist.matchesAny(
36 stringifyURL(url), "DOCUMENT", 38 stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
37 getDecodedHostname(url), false, null 39 getDecodedHostname(url), false, null
38 ); 40 );
39 }; 41 };
40 42
41 /** 43 /**
42 * Checks whether a frame is whitelisted. 44 * Checks whether a frame is whitelisted.
43 * 45 *
44 * @param {Page} page 46 * @param {Page} page
45 * @param {Frame} frame 47 * @param {Frame} frame
46 * @param {string} [type=DOCUMENT] The request type to check whether 48 * @param {Number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
Sebastian Noack 2015/07/13 16:41:50 Nit: Please use lowercase when referring to primit
kzar 2015/07/14 09:22:24 Done.
47 * the frame is whitelisted for.
48 * @return {Boolean} 49 * @return {Boolean}
49 */ 50 */
50 exports.isFrameWhitelisted = function(page, frame, type) 51 exports.isFrameWhitelisted = function(page, frame, typeMask)
51 { 52 {
52 while (frame) 53 while (frame)
53 { 54 {
54 let parent = frame.parent; 55 let parent = frame.parent;
55 let url = frame.url; 56 let url = frame.url;
56 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); 57 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
57 58
58 let filter = defaultMatcher.whitelist.matchesAny( 59 let filter = defaultMatcher.whitelist.matchesAny(
59 stringifyURL(url), type || "DOCUMENT", 60 stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
60 documentHost, isThirdParty(url, documentHost), 61 documentHost, isThirdParty(url, documentHost),
61 getKey(page, frame) 62 getKey(page, frame)
62 ); 63 );
63 64
64 if (filter) 65 if (filter)
65 return true; 66 return true;
66 67
67 frame = parent; 68 frame = parent;
68 } 69 }
69 70
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 134 {
134 if (token.indexOf("_") < 0) 135 if (token.indexOf("_") < 0)
135 return; 136 return;
136 137
137 let [key, signature] = token.split("_", 2); 138 let [key, signature] = token.split("_", 2);
138 key = key.replace(/=/g, ""); 139 key = key.replace(/=/g, "");
139 140
140 if (verifyKey(key, signature, frame.url)) 141 if (verifyKey(key, signature, frame.url))
141 recordKey(page, frame.url, key); 142 recordKey(page, frame.url, key);
142 }; 143 };
OLDNEW
« lib/filterComposer.js ('K') | « lib/filterComposer.js ('k') | popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld