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