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 adblockplus dependency Created July 14, 2015, 2:45 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
« no previous file with comments | « lib/filterComposer.js ('k') | popupBlocker.js » ('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-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
29 * @return {WhitelistFilter} The active filter whitelisting this page or null 30 * @return {WhitelistFilter} The active filter whitelisting this page or null
30 */ 31 */
31 exports.isPageWhitelisted = function(page) 32 exports.isPageWhitelisted = function(page)
32 { 33 {
33 let url = page.url; 34 let url = page.url;
34 35
35 return defaultMatcher.whitelist.matchesAny( 36 return defaultMatcher.whitelist.matchesAny(
36 stringifyURL(url), "DOCUMENT", 37 stringifyURL(url), RegExpFilter.typeMap.DOCUMENT,
37 getDecodedHostname(url), false, null 38 getDecodedHostname(url), false, null
38 ); 39 );
39 }; 40 };
40 41
41 /** 42 /**
42 * Checks whether a frame is whitelisted. 43 * Checks whether a frame is whitelisted.
43 * 44 *
44 * @param {Page} page 45 * @param {Page} page
45 * @param {Frame} frame 46 * @param {Frame} frame
46 * @param {string} [type=DOCUMENT] The request type to check whether 47 * @param {number} [typeMask=RegExpFilter.typeMap.DOCUMENT] Bit mask of request / content types to match
47 * the frame is whitelisted for.
48 * @return {Boolean} 48 * @return {Boolean}
49 */ 49 */
50 exports.isFrameWhitelisted = function(page, frame, type) 50 exports.isFrameWhitelisted = function(page, frame, typeMask)
51 { 51 {
52 while (frame) 52 while (frame)
53 { 53 {
54 let parent = frame.parent; 54 let parent = frame.parent;
55 let url = frame.url; 55 let url = frame.url;
56 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); 56 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
57 57
58 let filter = defaultMatcher.whitelist.matchesAny( 58 let filter = defaultMatcher.whitelist.matchesAny(
59 stringifyURL(url), type || "DOCUMENT", 59 stringifyURL(url), typeMask || RegExpFilter.typeMap.DOCUMENT,
60 documentHost, isThirdParty(url, documentHost), 60 documentHost, isThirdParty(url, documentHost),
61 getKey(page, frame) 61 getKey(page, frame)
62 ); 62 );
63 63
64 if (filter) 64 if (filter)
65 return true; 65 return true;
66 66
67 frame = parent; 67 frame = parent;
68 } 68 }
69 69
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 if (token.indexOf("_") < 0) 134 if (token.indexOf("_") < 0)
135 return; 135 return;
136 136
137 let [key, signature] = token.split("_", 2); 137 let [key, signature] = token.split("_", 2);
138 key = key.replace(/=/g, ""); 138 key = key.replace(/=/g, "");
139 139
140 if (verifyKey(key, signature, frame.url)) 140 if (verifyKey(key, signature, frame.url))
141 recordKey(page, frame.url, key); 141 recordKey(page, frame.url, key);
142 }; 142 };
OLDNEW
« no previous file with comments | « lib/filterComposer.js ('k') | popupBlocker.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld