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

Delta Between Two Patch Sets: lib/whitelisting.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Left Patch Set: Created Jan. 25, 2015, 1:18 p.m.
Right Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/url.js ('k') | metadata.common » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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"); 19 let {WhitelistFilter} = require("filterClasses");
20 let {stringifyURL, getDecodedHostname, isThirdParty} = require("url"); 20 let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = req uire("url");
Wladimir Palant 2015/02/09 12:54:29 Shouldn't this import extractHostFromFrame as well
Sebastian Noack 2015/02/11 10:55:51 You are right. It works though, since extractHostF
21 21
22 let pagesWithKey = new ext.PageMap(); 22 let pagesWithKey = new ext.PageMap();
23 23
24 function isPageWhitelisted(page) 24 function isPageWhitelisted(page)
25 { 25 {
26 let url = page.url; 26 let url = page.url;
27 let filter = defaultMatcher.matchesAny( 27 let filter = defaultMatcher.matchesAny(
28 stringifyURL(url), "DOCUMENT", 28 stringifyURL(url), "DOCUMENT",
29 getDecodedHostname(url), false 29 getDecodedHostname(url), false, null
Wladimir Palant 2015/02/09 12:54:29 Please provide a sitekey parameter (null).
Sebastian Noack 2015/02/11 10:55:51 Done.
30 ); 30 );
31 31
32 return (filter instanceof WhitelistFilter ? filter : null); 32 return (filter instanceof WhitelistFilter ? filter : null);
33 } 33 }
34 exports.isPageWhitelisted = isPageWhitelisted; 34 exports.isPageWhitelisted = isPageWhitelisted;
35 35
36 function isFrameWhitelisted(page, frame, type) 36 function isFrameWhitelisted(page, frame, type)
37 { 37 {
38 while (frame) 38 while (frame)
39 { 39 {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 return verifySignature(key, signature, params.join("\0")); 85 return verifySignature(key, signature, params.join("\0"));
86 } 86 }
87 87
88 function recordKey(page, url, key) 88 function recordKey(page, url, key)
89 { 89 {
90 let urlsWithKey = pagesWithKey.get(page); 90 let urlsWithKey = pagesWithKey.get(page);
91 91
92 if (!urlsWithKey) 92 if (!urlsWithKey)
93 { 93 {
94 urlsWithKey = {__proto__: null}; 94 urlsWithKey = Object.create(null);
95 pagesWithKey.set(page, urlsWithKey); 95 pagesWithKey.set(page, urlsWithKey);
96 } 96 }
97 97
98 urlsWithKey[stringifyURL(url)] = key; 98 urlsWithKey[stringifyURL(url)] = key;
99 } 99 }
100 100
101 function processKey(token, page, frame) 101 function processKey(token, page, frame)
102 { 102 {
103 if (token.indexOf("_") < 0) 103 if (token.indexOf("_") < 0)
104 return; 104 return;
105 105
106 let [key, signature] = token.split("_", 2); 106 let [key, signature] = token.split("_", 2);
107 key = key.replace(/=/g, ""); 107 key = key.replace(/=/g, "");
108 108
109 if (verifyKey(key, signature, frame.url)) 109 if (verifyKey(key, signature, frame.url))
110 recordKey(page, frame.url, key); 110 recordKey(page, frame.url, key);
111 } 111 }
112 exports.processKey = processKey; 112 exports.processKey = processKey;
LEFTRIGHT

Powered by Google App Engine
This is Rietveld