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

Side by Side Diff: lib/requestBlocker.js

Issue 29705719: Issue 6402 - Split filter hit / request logging out into own API (Closed)
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:
View unified diff | Download patch
« no previous file with comments | « lib/popupBlocker.js ('k') | lib/whitelisting.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-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
(...skipping 10 matching lines...) Expand all
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 {extractHostFromFrame, isThirdParty} = require("./url"); 29 const {extractHostFromFrame, isThirdParty} = require("./url");
30 const {port} = require("./messaging"); 30 const {port} = require("./messaging");
31 const devtools = require("./devtools"); 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;
40 } 40 }
41 41
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 else if (details.initiator) // Chromium >=63 provides "intiator" which 111 else if (details.initiator) // Chromium >=63 provides "intiator" which
112 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox 112 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox
113 // except that its not a full URL but just 113 // except that its not a full URL but just
114 // an origin (proto + host). 114 // an origin (proto + host).
115 else 115 else
116 return Promise.resolve([]); 116 return Promise.resolve([]);
117 117
118 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); 118 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id));
119 } 119 }
120 120
121 function logRequest(tabIds, url, type, docDomain, thirdParty, 121 function logRequest(tabIds, request, filter)
122 sitekey, specificOnly, filter)
123 { 122 {
124 if (filter) 123 if (filter)
125 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); 124 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds);
126 125
127 devtools.logRequest( 126 hitLoggerLogRequest(tabIds, request, filter);
128 tabIds, url, type, docDomain,
129 thirdParty, sitekey,
130 specificOnly, filter
131 );
132 } 127 }
133 128
134 browser.webRequest.onBeforeRequest.addListener(details => 129 browser.webRequest.onBeforeRequest.addListener(details =>
135 { 130 {
136 // Never block top-level documents. 131 // Never block top-level documents.
137 if (details.type == "main_frame") 132 if (details.type == "main_frame")
138 return; 133 return;
139 134
140 // Filter out requests from non web protocols. Ideally, we'd explicitly 135 // Filter out requests from non web protocols. Ideally, we'd explicitly
141 // specify the protocols we are interested in (i.e. http://, https://, 136 // specify the protocols we are interested in (i.e. http://, https://,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return; 180 return;
186 181
187 let type = resourceTypes.get(details.type) || "OTHER"; 182 let type = resourceTypes.get(details.type) || "OTHER";
188 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, 183 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame,
189 originUrl); 184 originUrl);
190 let [filter, thirdParty] = matchRequest(url, type, docDomain, 185 let [filter, thirdParty] = matchRequest(url, type, docDomain,
191 sitekey, specificOnly); 186 sitekey, specificOnly);
192 187
193 getRelatedTabIds(details).then(tabIds => 188 getRelatedTabIds(details).then(tabIds =>
194 { 189 {
195 logRequest(tabIds, details.url, type, docDomain, 190 logRequest(
196 thirdParty, sitekey, specificOnly, filter); 191 tabIds,
192 {url: details.url, type, docDomain, thirdParty, sitekey, specificOnly},
193 filter
194 );
197 }); 195 });
198 196
199 if (filter instanceof BlockingFilter) 197 if (filter instanceof BlockingFilter)
200 return {cancel: true}; 198 return {cancel: true};
201 }, {urls: ["<all_urls>"]}, ["blocking"]); 199 }, {urls: ["<all_urls>"]}, ["blocking"]);
202 200
203 port.on("filters.collapse", (message, sender) => 201 port.on("filters.collapse", (message, sender) =>
204 { 202 {
205 let {page, frame} = sender; 203 let {page, frame} = sender;
206 204
(...skipping 20 matching lines...) Expand all
227 return blocked && Prefs.hidePlaceholders; 225 return blocked && Prefs.hidePlaceholders;
228 }); 226 });
229 227
230 port.on("request.blockedByRTCWrapper", (msg, sender) => 228 port.on("request.blockedByRTCWrapper", (msg, sender) =>
231 { 229 {
232 let {page, frame} = sender; 230 let {page, frame} = sender;
233 231
234 if (checkWhitelisted(page, frame)) 232 if (checkWhitelisted(page, frame))
235 return false; 233 return false;
236 234
235 let {url} = msg;
237 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); 236 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame);
238 let [filter, thirdParty] = matchRequest(new URL(msg.url), 237 let [filter, thirdParty] = matchRequest(new URL(url), "WEBRTC", docDomain,
239 "WEBRTC", docDomain,
240 sitekey, specificOnly); 238 sitekey, specificOnly);
241 239 logRequest(
242 logRequest([sender.page.id], msg.url, "WEBRTC", docDomain, 240 [sender.page.id],
243 thirdParty, sitekey, specificOnly, filter); 241 {url, type: "WEBRTC", docDomain, thirdParty, sitekey, specificOnly},
242 filter
243 );
244 244
245 return filter instanceof BlockingFilter; 245 return filter instanceof BlockingFilter;
246 }); 246 });
247 247
248 let ignoreFilterNotifications = false; 248 let ignoreFilterNotifications = false;
249 let handlerBehaviorChangedQuota = 249 let handlerBehaviorChangedQuota =
250 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; 250 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES;
251 251
252 function propagateHandlerBehaviorChange() 252 function propagateHandlerBehaviorChange()
253 { 253 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 305 }
306 306
307 FilterNotifier.on("subscription.added", onFilterChange); 307 FilterNotifier.on("subscription.added", onFilterChange);
308 FilterNotifier.on("subscription.removed", onFilterChange); 308 FilterNotifier.on("subscription.removed", onFilterChange);
309 FilterNotifier.on("subscription.updated", onFilterChange); 309 FilterNotifier.on("subscription.updated", onFilterChange);
310 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); 310 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true));
311 FilterNotifier.on("filter.added", onFilterChange); 311 FilterNotifier.on("filter.added", onFilterChange);
312 FilterNotifier.on("filter.removed", onFilterChange); 312 FilterNotifier.on("filter.removed", onFilterChange);
313 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); 313 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true));
314 FilterNotifier.on("load", onFilterChange); 314 FilterNotifier.on("load", onFilterChange);
OLDNEW
« no previous file with comments | « lib/popupBlocker.js ('k') | lib/whitelisting.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld