OLD | NEW |
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 Loading... |
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 {stringifyURL, 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 else if (details.initiator) // Chromium >=63 provides "intiator" which | 115 else if (details.initiator) // Chromium >=63 provides "intiator" which |
116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox | 116 url = details.initiator + "/*"; // is equivalent to "originUrl" on Firefox |
117 // except that its not a full URL but just | 117 // except that its not a full URL but just |
118 // an origin (proto + host). | 118 // an origin (proto + host). |
119 else | 119 else |
120 return Promise.resolve([]); | 120 return Promise.resolve([]); |
121 | 121 |
122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); | 122 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); |
123 } | 123 } |
124 | 124 |
125 function logRequest(tabIds, url, type, docDomain, thirdParty, | 125 function logRequest(tabIds, request, filter) |
126 sitekey, specificOnly, filter) | |
127 { | 126 { |
128 if (filter) | 127 if (filter) |
129 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 128 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); |
130 | 129 |
131 devtools.logRequest( | 130 hitLoggerLogRequest(tabIds, request, filter); |
132 tabIds, url, type, docDomain, | |
133 thirdParty, sitekey, | |
134 specificOnly, filter | |
135 ); | |
136 } | 131 } |
137 | 132 |
138 browser.webRequest.onBeforeRequest.addListener(details => | 133 browser.webRequest.onBeforeRequest.addListener(details => |
139 { | 134 { |
140 // Never block top-level documents. | 135 // Never block top-level documents. |
141 if (details.type == "main_frame") | 136 if (details.type == "main_frame") |
142 return; | 137 return; |
143 | 138 |
144 // Filter out requests from non web protocols. Ideally, we'd explicitly | 139 // Filter out requests from non web protocols. Ideally, we'd explicitly |
145 // specify the protocols we are interested in (i.e. http://, https://, | 140 // specify the protocols we are interested in (i.e. http://, https://, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 return; | 184 return; |
190 | 185 |
191 let type = resourceTypes.get(details.type) || "OTHER"; | 186 let type = resourceTypes.get(details.type) || "OTHER"; |
192 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, | 187 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame, |
193 originUrl); | 188 originUrl); |
194 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, | 189 let [filter, urlString, thirdParty] = matchRequest(url, type, docDomain, |
195 sitekey, specificOnly); | 190 sitekey, specificOnly); |
196 | 191 |
197 getRelatedTabIds(details).then(tabIds => | 192 getRelatedTabIds(details).then(tabIds => |
198 { | 193 { |
199 logRequest(tabIds, urlString, type, docDomain, | 194 logRequest( |
200 thirdParty, sitekey, specificOnly, filter); | 195 tabIds, |
| 196 {url: urlString, type, docDomain, thirdParty, sitekey, specificOnly}, |
| 197 filter |
| 198 ); |
201 }); | 199 }); |
202 | 200 |
203 if (filter instanceof BlockingFilter) | 201 if (filter instanceof BlockingFilter) |
204 return {cancel: true}; | 202 return {cancel: true}; |
205 }, {urls: ["<all_urls>"]}, ["blocking"]); | 203 }, {urls: ["<all_urls>"]}, ["blocking"]); |
206 | 204 |
207 port.on("filters.collapse", (message, sender) => | 205 port.on("filters.collapse", (message, sender) => |
208 { | 206 { |
209 let {page, frame} = sender; | 207 let {page, frame} = sender; |
210 | 208 |
(...skipping 25 matching lines...) Expand all Loading... |
236 let {page, frame} = sender; | 234 let {page, frame} = sender; |
237 | 235 |
238 if (checkWhitelisted(page, frame)) | 236 if (checkWhitelisted(page, frame)) |
239 return false; | 237 return false; |
240 | 238 |
241 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); | 239 let [docDomain, sitekey, specificOnly] = getDocumentInfo(page, frame); |
242 let [filter, url, thirdParty] = matchRequest(new URL(msg.url), | 240 let [filter, url, thirdParty] = matchRequest(new URL(msg.url), |
243 "WEBRTC", docDomain, | 241 "WEBRTC", docDomain, |
244 sitekey, specificOnly); | 242 sitekey, specificOnly); |
245 | 243 |
246 logRequest([sender.page.id], url, "WEBRTC", docDomain, | 244 logRequest( |
247 thirdParty, sitekey, specificOnly, filter); | 245 [sender.page.id], |
| 246 {url, type: "WEBRTC", docDomain, thirdParty, sitekey, specificOnly}, |
| 247 filter |
| 248 ); |
248 | 249 |
249 return filter instanceof BlockingFilter; | 250 return filter instanceof BlockingFilter; |
250 }); | 251 }); |
251 | 252 |
252 let ignoreFilterNotifications = false; | 253 let ignoreFilterNotifications = false; |
253 let handlerBehaviorChangedQuota = | 254 let handlerBehaviorChangedQuota = |
254 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; | 255 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; |
255 | 256 |
256 function propagateHandlerBehaviorChange() | 257 function propagateHandlerBehaviorChange() |
257 { | 258 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 310 } |
310 | 311 |
311 FilterNotifier.on("subscription.added", onFilterChange); | 312 FilterNotifier.on("subscription.added", onFilterChange); |
312 FilterNotifier.on("subscription.removed", onFilterChange); | 313 FilterNotifier.on("subscription.removed", onFilterChange); |
313 FilterNotifier.on("subscription.updated", onFilterChange); | 314 FilterNotifier.on("subscription.updated", onFilterChange); |
314 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 315 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
315 FilterNotifier.on("filter.added", onFilterChange); | 316 FilterNotifier.on("filter.added", onFilterChange); |
316 FilterNotifier.on("filter.removed", onFilterChange); | 317 FilterNotifier.on("filter.removed", onFilterChange); |
317 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 318 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
318 FilterNotifier.on("load", onFilterChange); | 319 FilterNotifier.on("load", onFilterChange); |
OLD | NEW |