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

Delta Between Two Patch Sets: lib/whitelisting.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Left Patch Set: Nightmarish rebase Created April 13, 2018, 3:20 p.m.
Right Patch Set: Addressed Manish's feedback Created May 9, 2018, 5:53 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/requestBlocker.js ('k') | metadata.chrome » ('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-present eyeo GmbH 3 * Copyright (C) 2006-present 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"; 20 "use strict";
21 21
22 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 22 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
23 const {Filter, RegExpFilter} = require("../adblockpluscore/lib/filterClasses"); 23 const {Filter, RegExpFilter} = require("../adblockpluscore/lib/filterClasses");
24 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 24 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage"); 25 const {FilterStorage} = require("../adblockpluscore/lib/filterStorage");
26 const {stringifyURL, getDecodedHostname, 26 const {extractHostFromFrame, isThirdParty} = require("./url");
27 extractHostFromFrame, isThirdParty} = require("./url");
28 const {port} = require("./messaging"); 27 const {port} = require("./messaging");
29 const {logWhitelistedDocument} = require("./hitLogger"); 28 const {logWhitelistedDocument} = require("./hitLogger");
30 const {verifySignature} = require("../adblockpluscore/lib/rsa"); 29 const {verifySignature} = require("../adblockpluscore/lib/rsa");
31 30
32 let sitekeys = new ext.PageMap(); 31 let sitekeys = new ext.PageMap();
33 32
34 function match(page, url, typeMask, docDomain, sitekey) 33 function match(page, url, typeMask, docDomain, sitekey)
35 { 34 {
36 let thirdParty = !!docDomain && isThirdParty(url, docDomain); 35 let thirdParty = !!docDomain && isThirdParty(url, docDomain);
37 let urlString = stringifyURL(url);
38 36
39 if (!docDomain) 37 if (!docDomain)
40 docDomain = getDecodedHostname(url); 38 docDomain = url.hostname;
41 39
42 let filter = defaultMatcher.whitelist.matchesAny( 40 let filter = defaultMatcher.whitelist.matchesAny(
43 urlString, typeMask, docDomain, thirdParty, sitekey 41 url.href, typeMask, docDomain, thirdParty, sitekey
44 ); 42 );
45 43
46 if (filter && page) 44 if (filter && page)
47 logWhitelistedDocument(page.id, urlString, typeMask, docDomain, filter); 45 logWhitelistedDocument(page.id, url.href, typeMask, docDomain, filter);
48 46
49 return filter; 47 return filter;
50 } 48 }
51 49
52 let checkWhitelisted = 50 let checkWhitelisted =
53 /** 51 /**
54 * Gets the active whitelisting filter for the document associated 52 * Gets the active whitelisting filter for the document associated
55 * with the given page/frame, or null if it's not whitelisted. 53 * with the given page/frame, or null if it's not whitelisted.
56 * 54 *
57 * @param {?Page} page 55 * @param {?Page} page
(...skipping 28 matching lines...) Expand all
86 }; 84 };
87 85
88 port.on("filters.isWhitelisted", message => 86 port.on("filters.isWhitelisted", message =>
89 { 87 {
90 return !!checkWhitelisted(new ext.Page(message.tab)); 88 return !!checkWhitelisted(new ext.Page(message.tab));
91 }); 89 });
92 90
93 port.on("filters.whitelist", message => 91 port.on("filters.whitelist", message =>
94 { 92 {
95 let page = new ext.Page(message.tab); 93 let page = new ext.Page(message.tab);
96 let host = getDecodedHostname(page.url).replace(/^www\./, ""); 94 let host = page.url.hostname.replace(/^www\./, "");
97 let filter = Filter.fromText("@@||" + host + "^$document"); 95 let filter = Filter.fromText("@@||" + host + "^$document");
98 if (filter.subscriptions.length && filter.disabled) 96 if (filter.subscriptions.length && filter.disabled)
99 { 97 {
100 filter.disabled = false; 98 filter.disabled = false;
101 } 99 }
102 else 100 else
103 { 101 {
104 filter.disabled = false; 102 filter.disabled = false;
105 FilterStorage.addFilter(filter); 103 FilterStorage.addFilter(filter);
106 } 104 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 */ 149 */
152 exports.getKey = (page, frame, originUrl) => 150 exports.getKey = (page, frame, originUrl) =>
153 { 151 {
154 if (page) 152 if (page)
155 { 153 {
156 let keys = sitekeys.get(page); 154 let keys = sitekeys.get(page);
157 if (keys) 155 if (keys)
158 { 156 {
159 for (; frame; frame = frame.parent) 157 for (; frame; frame = frame.parent)
160 { 158 {
161 let key = keys.get(stringifyURL(frame.url)); 159 let key = keys.get(frame.url.href);
162 if (key) 160 if (key)
163 return key; 161 return key;
164 } 162 }
165 } 163 }
166 } 164 }
167 165
168 if (originUrl) 166 if (originUrl)
169 { 167 {
170 for (let keys of sitekeys._map.values()) 168 for (let keys of sitekeys._map.values())
171 { 169 {
172 let key = keys.get(stringifyURL(originUrl)); 170 let key = keys.get(originUrl.href);
173 if (key) 171 if (key)
174 return key; 172 return key;
175 } 173 }
176 } 174 }
177 175
178 return null; 176 return null;
179 }; 177 };
180 178
181 function checkKey(token, url) 179 function checkKey(token, url)
182 { 180 {
(...skipping 13 matching lines...) Expand all
196 } 194 }
197 195
198 function recordKey(key, page, url) 196 function recordKey(key, page, url)
199 { 197 {
200 let keys = sitekeys.get(page); 198 let keys = sitekeys.get(page);
201 if (!keys) 199 if (!keys)
202 { 200 {
203 keys = new Map(); 201 keys = new Map();
204 sitekeys.set(page, keys); 202 sitekeys.set(page, keys);
205 } 203 }
206 keys.set(stringifyURL(url), key); 204 keys.set(url.href, key);
207 } 205 }
208 206
209 port.on("filters.addKey", (message, sender) => 207 port.on("filters.addKey", (message, sender) =>
210 { 208 {
211 let key = checkKey(message.token, sender.frame.url); 209 let key = checkKey(message.token, sender.frame.url);
212 if (key) 210 if (key)
213 recordKey(key, sender.page, sender.frame.url); 211 recordKey(key, sender.page, sender.frame.url);
214 }); 212 });
215 213
216 function onHeadersReceived(details) 214 function onHeadersReceived(details)
(...skipping 19 matching lines...) Expand all
236 { 234 {
237 browser.webRequest.onHeadersReceived.addListener( 235 browser.webRequest.onHeadersReceived.addListener(
238 onHeadersReceived, 236 onHeadersReceived,
239 { 237 {
240 urls: ["http://*/*", "https://*/*"], 238 urls: ["http://*/*", "https://*/*"],
241 types: ["main_frame", "sub_frame"] 239 types: ["main_frame", "sub_frame"]
242 }, 240 },
243 ["responseHeaders"] 241 ["responseHeaders"]
244 ); 242 );
245 } 243 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld