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

Delta Between Two Patch Sets: lib/requestBlocker.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
Left Patch Set: Addressed Sebastian's feedback Created May 3, 2018, 3:55 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/popupBlocker.js ('k') | lib/whitelisting.js » ('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 requestBlocker */ 18 /** @module requestBlocker */
19 19
20 "use strict"; 20 "use strict";
21 21
22 const {Filter, RegExpFilter, BlockingFilter} = 22 const {Filter, RegExpFilter, BlockingFilter} =
23 require("../adblockpluscore/lib/filterClasses"); 23 require("../adblockpluscore/lib/filterClasses");
24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses"); 24 const {Subscription} = require("../adblockpluscore/lib/subscriptionClasses");
25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher"); 25 const {defaultMatcher} = require("../adblockpluscore/lib/matcher");
26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier"); 26 const {FilterNotifier} = require("../adblockpluscore/lib/filterNotifier");
27 const {Prefs} = require("./prefs"); 27 const {Prefs} = require("./prefs");
28 const {checkWhitelisted, getKey} = require("./whitelisting"); 28 const {checkWhitelisted, getKey} = require("./whitelisting");
29 const {stringifyURL, extractHostFromFrame, isThirdParty} = require("./url"); 29 const {extractHostFromFrame, isThirdParty} = require("./url");
30 const {port} = require("./messaging"); 30 const {port} = require("./messaging");
31 const {logRequest: hitLoggerLogRequest} = require("./hitLogger"); 31 const {logRequest: hitLoggerLogRequest} = require("./hitLogger");
32 32
33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol; 33 const extensionProtocol = new URL(browser.extension.getURL("")).protocol;
34 34
35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests. 35 // Chrome can't distinguish between OBJECT_SUBREQUEST and OBJECT requests.
36 if (!browser.webRequest.ResourceType || 36 if (!browser.webRequest.ResourceType ||
37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType)) 37 !("OBJECT_SUBREQUEST" in browser.webRequest.ResourceType))
38 { 38 {
39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT; 39 RegExpFilter.typeMap.OBJECT_SUBREQUEST = RegExpFilter.typeMap.OBJECT;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return [ 81 return [
82 extractHostFromFrame(frame, originUrl), 82 extractHostFromFrame(frame, originUrl),
83 getKey(page, frame, originUrl), 83 getKey(page, frame, originUrl),
84 !!checkWhitelisted(page, frame, originUrl, 84 !!checkWhitelisted(page, frame, originUrl,
85 RegExpFilter.typeMap.GENERICBLOCK) 85 RegExpFilter.typeMap.GENERICBLOCK)
86 ]; 86 ];
87 } 87 }
88 88
89 function matchRequest(url, type, docDomain, sitekey, specificOnly) 89 function matchRequest(url, type, docDomain, sitekey, specificOnly)
90 { 90 {
91 let urlString = stringifyURL(url);
92 let thirdParty = isThirdParty(url, docDomain); 91 let thirdParty = isThirdParty(url, docDomain);
93 92 let filter = defaultMatcher.matchesAny(url.href, RegExpFilter.typeMap[type],
94 return [ 93 docDomain, thirdParty,
95 defaultMatcher.matchesAny(urlString, RegExpFilter.typeMap[type], 94 sitekey, specificOnly);
96 docDomain, thirdParty, sitekey, specificOnly), 95 return [filter, thirdParty];
97 urlString,
98 thirdParty
99 ];
100 } 96 }
101 97
102 function getRelatedTabIds(details) 98 function getRelatedTabIds(details)
103 { 99 {
104 // This is the common case, the request is associated with a single tab. 100 // This is the common case, the request is associated with a single tab.
105 // If tabId is -1, its not (e.g. the request was sent by 101 // If tabId is -1, its not (e.g. the request was sent by
106 // a Service/Shared Worker) and we have to identify the related tabs. 102 // a Service/Shared Worker) and we have to identify the related tabs.
107 if (details.tabId != -1) 103 if (details.tabId != -1)
108 return Promise.resolve([details.tabId]); 104 return Promise.resolve([details.tabId]);
109 105
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // this can also indicate a request sent by a Shared/Service Worker). 175 // this can also indicate a request sent by a Shared/Service Worker).
180 if (!frame && !originUrl) 176 if (!frame && !originUrl)
181 return; 177 return;
182 178
183 if (checkWhitelisted(page, frame, originUrl)) 179 if (checkWhitelisted(page, frame, originUrl))
184 return; 180 return;
185 181
186 let type = resourceTypes.get(details.type) || "OTHER"; 182 let type = resourceTypes.get(details.type) || "OTHER";
187 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 183 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
188 originUrl); 184 originUrl);
189 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, 185 let [filter, thirdParty] = matchRequest(url, type, docDomain,
190 sitekey, specificOnly); 186 sitekey, specificOnly);
191 187
192 getRelatedTabIds(details).then(tabIds => 188 getRelatedTabIds(details).then(tabIds =>
193 { 189 {
194 logRequest( 190 logRequest(
195 tabIds, 191 tabIds,
196 {url: urlString, type, docDomain, thirdParty, sitekey, specificOnly}, 192 {url: details.url, type, docDomain, thirdParty, sitekey, specificOnly},
197 filter 193 filter
198 ); 194 );
199 }); 195 });
200 196
201 if (filter instanceof BlockingFilter) 197 if (filter instanceof BlockingFilter)
202 return {cancel: true}; 198 return {cancel: true};
203 }, {urls: ["<all_urls>"]}, ["blocking"]); 199 }, {urls: ["<all_urls>"]}, ["blocking"]);
204 200
205 port.on("filters.collapse", (message, sender) => 201 port.on("filters.collapse", (message, sender) =>
206 { 202 {
(...skipping 22 matching lines...) Expand all
229 return blocked && Prefs.hidePlaceholders; 225 return blocked && Prefs.hidePlaceholders;
230 }); 226 });
231 227
232 port.on("request.blockedByRTCWrapper", (msg, sender) => 228 port.on("request.blockedByRTCWrapper", (msg, sender) =>
233 { 229 {
234 let {page, frame} = sender; 230 let {page, frame} = sender;
235 231
236 if (checkWhitelisted(page, frame)) 232 if (checkWhitelisted(page, frame))
237 return false; 233 return false;
238 234
235 let {url} = msg;
239 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); 236 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
240 let [filter, url, thirdParty] = matchRequest(new URL(msg.url), 237 let [filter, thirdParty] = matchRequest(new URL(url), "WEBRTC", docDomain,
241 "WEBRTC", docDomain, 238 sitekey, specificOnly);
242 sitekey, specificOnly);
243
244 logRequest( 239 logRequest(
245 [sender.page.id], 240 [sender.page.id],
246 {url, type: "WEBRTC", docDomain, thirdParty, sitekey, specificOnly}, 241 {url, type: "WEBRTC", docDomain, thirdParty, sitekey, specificOnly},
247 filter 242 filter
248 ); 243 );
249 244
250 return filter instanceof BlockingFilter; 245 return filter instanceof BlockingFilter;
251 }); 246 });
252 247
253 let ignoreFilterNotifications = false; 248 let ignoreFilterNotifications = false;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 305 }
311 306
312 FilterNotifier.on("subscription.added", onFilterChange); 307 FilterNotifier.on("subscription.added", onFilterChange);
313 FilterNotifier.on("subscription.removed", onFilterChange); 308 FilterNotifier.on("subscription.removed", onFilterChange);
314 FilterNotifier.on("subscription.updated", onFilterChange); 309 FilterNotifier.on("subscription.updated", onFilterChange);
315 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 310 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
316 FilterNotifier.on("filter.added", onFilterChange); 311 FilterNotifier.on("filter.added", onFilterChange);
317 FilterNotifier.on("filter.removed", onFilterChange); 312 FilterNotifier.on("filter.removed", onFilterChange);
318 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 313 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
319 FilterNotifier.on("load", onFilterChange); 314 FilterNotifier.on("load", onFilterChange);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld