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

Side by Side Diff: lib/whitelisting.js

Issue 5733398375038976: Issue 2132 - Only match exception rules when checking whether a page/frame is whitelisted (Closed)
Patch Set: Created March 12, 2015, 7:33 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') | no next file » | 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 let {defaultMatcher} = require("matcher"); 18 let {defaultMatcher} = require("matcher");
19 let {WhitelistFilter} = require("filterClasses");
20 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url"); 19 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
21 20
22 let pagesWithKey = new ext.PageMap(); 21 let pagesWithKey = new ext.PageMap();
23 22
24 /** 23 /**
25 * Checks whether a page is whitelisted. 24 * Checks whether a page is whitelisted.
26 * 25 *
27 * @param {Page} page 26 * @param {Page} page
28 * @return {WhitelistFilter} The active filter whitelisting this page or null 27 * @return {WhitelistFilter} The active filter whitelisting this page or null
29 */ 28 */
30 function isPageWhitelisted(page) 29 function isPageWhitelisted(page)
31 { 30 {
32 let url = page.url; 31 let url = page.url;
33 let filter = defaultMatcher.matchesAny( 32
33 return defaultMatcher.whitelist.matchesAny(
34 stringifyURL(url), "DOCUMENT", 34 stringifyURL(url), "DOCUMENT",
35 getDecodedHostname(url), false, null 35 getDecodedHostname(url), false, null
36 ); 36 );
37
38 return (filter instanceof WhitelistFilter ? filter : null);
39 } 37 }
40 exports.isPageWhitelisted = isPageWhitelisted; 38 exports.isPageWhitelisted = isPageWhitelisted;
41 39
42 /** 40 /**
43 * Checks whether a frame is whitelisted. 41 * Checks whether a frame is whitelisted.
44 * 42 *
45 * @param {Page} page 43 * @param {Page} page
46 * @param {Frame} frame 44 * @param {Frame} frame
47 * @param {string} [type=DOCUMENT] The request type to check whether 45 * @param {string} [type=DOCUMENT] The request type to check whether
48 * the frame is whitelisted for. 46 * the frame is whitelisted for.
49 * @return {Boolean} 47 * @return {Boolean}
50 */ 48 */
51 function isFrameWhitelisted(page, frame, type) 49 function isFrameWhitelisted(page, frame, type)
52 { 50 {
53 while (frame) 51 while (frame)
54 { 52 {
55 let parent = frame.parent; 53 let parent = frame.parent;
56 let url = frame.url; 54 let url = frame.url;
57 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url); 55 let documentHost = extractHostFromFrame(parent) || getDecodedHostname(url);
58 56
59 let filter = defaultMatcher.matchesAny( 57 let filter = defaultMatcher.whitelist.matchesAny(
60 stringifyURL(url), type || "DOCUMENT", 58 stringifyURL(url), type || "DOCUMENT",
61 documentHost, isThirdParty(url, documentHost), 59 documentHost, isThirdParty(url, documentHost),
62 getKey(page, frame) 60 getKey(page, frame)
63 ); 61 );
64 62
65 if (filter instanceof WhitelistFilter) 63 if (filter)
66 return true; 64 return true;
67 65
68 frame = parent; 66 frame = parent;
69 } 67 }
70 68
71 return false; 69 return false;
72 } 70 }
73 exports.isFrameWhitelisted = isFrameWhitelisted; 71 exports.isFrameWhitelisted = isFrameWhitelisted;
74 72
75 /** 73 /**
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (token.indexOf("_") < 0) 135 if (token.indexOf("_") < 0)
138 return; 136 return;
139 137
140 let [key, signature] = token.split("_", 2); 138 let [key, signature] = token.split("_", 2);
141 key = key.replace(/=/g, ""); 139 key = key.replace(/=/g, "");
142 140
143 if (verifyKey(key, signature, frame.url)) 141 if (verifyKey(key, signature, frame.url))
144 recordKey(page, frame.url, key); 142 recordKey(page, frame.url, key);
145 } 143 }
146 exports.processKey = processKey; 144 exports.processKey = processKey;
OLDNEW
« no previous file with comments | « lib/filterComposer.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld