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 |
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 {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 || |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // an origin (proto + host). | 115 // an origin (proto + host). |
116 else | 116 else |
117 return Promise.resolve([]); | 117 return Promise.resolve([]); |
118 | 118 |
119 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); | 119 return browser.tabs.query({url}).then(tabs => tabs.map(tab => tab.id)); |
120 } | 120 } |
121 | 121 |
122 function logRequest(tabIds, request, filter) | 122 function logRequest(tabIds, request, filter) |
123 { | 123 { |
124 if (filter) | 124 if (filter) |
125 FilterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); | 125 filterNotifier.emit("filter.hitCount", filter, 0, 0, tabIds); |
126 | 126 |
127 hitLoggerLogRequest(tabIds, request, filter); | 127 hitLoggerLogRequest(tabIds, request, filter); |
128 } | 128 } |
129 | 129 |
130 browser.webRequest.onBeforeRequest.addListener(details => | 130 browser.webRequest.onBeforeRequest.addListener(details => |
131 { | 131 { |
132 // Never block top-level documents. | 132 // Never block top-level documents. |
133 if (details.type == "main_frame") | 133 if (details.type == "main_frame") |
134 return; | 134 return; |
135 | 135 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 // Defer handlerBehaviorChanged() until navigation occurs. | 316 // Defer handlerBehaviorChanged() until navigation occurs. |
317 // There wouldn't be any visible effect when calling it earlier, | 317 // There wouldn't be any visible effect when calling it earlier, |
318 // but it's an expensive operation and that way we avoid to call | 318 // but it's an expensive operation and that way we avoid to call |
319 // it multiple times, if multiple filters are added/removed. | 319 // it multiple times, if multiple filters are added/removed. |
320 if (!browser.webNavigation.onBeforeNavigate | 320 if (!browser.webNavigation.onBeforeNavigate |
321 .hasListener(propagateHandlerBehaviorChange)) | 321 .hasListener(propagateHandlerBehaviorChange)) |
322 browser.webNavigation.onBeforeNavigate | 322 browser.webNavigation.onBeforeNavigate |
323 .addListener(propagateHandlerBehaviorChange); | 323 .addListener(propagateHandlerBehaviorChange); |
324 | 324 |
325 ignoreFilterNotifications = false; | 325 ignoreFilterNotifications = false; |
326 FilterNotifier.emit("filter.behaviorChanged"); | 326 filterNotifier.emit("filter.behaviorChanged"); |
327 }); | 327 }); |
328 } | 328 } |
329 | 329 |
330 FilterNotifier.on("subscription.added", onFilterChange); | 330 filterNotifier.on("subscription.added", onFilterChange); |
331 FilterNotifier.on("subscription.removed", onFilterChange); | 331 filterNotifier.on("subscription.removed", arg => onFilterChange(arg, false)); |
332 FilterNotifier.on("subscription.updated", onFilterChange); | 332 filterNotifier.on("subscription.updated", onFilterChange); |
333 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 333 filterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
334 FilterNotifier.on("filter.added", onFilterChange); | 334 filterNotifier.on("filter.added", onFilterChange); |
335 FilterNotifier.on("filter.removed", onFilterChange); | 335 filterNotifier.on("filter.removed", onFilterChange); |
336 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 336 filterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
337 FilterNotifier.on("load", onFilterChange); | 337 filterNotifier.on("load", onFilterChange); |
OLD | NEW |