| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 "WEBRTC", docDomain, | 249 "WEBRTC", docDomain, |
| 250 sitekey, specificOnly); | 250 sitekey, specificOnly); |
| 251 | 251 |
| 252 logRequest([sender.page.id], url, "WEBRTC", docDomain, | 252 logRequest([sender.page.id], url, "WEBRTC", docDomain, |
| 253 thirdParty, sitekey, specificOnly, filter); | 253 thirdParty, sitekey, specificOnly, filter); |
| 254 | 254 |
| 255 return filter instanceof BlockingFilter; | 255 return filter instanceof BlockingFilter; |
| 256 }); | 256 }); |
| 257 | 257 |
| 258 let ignoreFilterNotifications = false; | 258 let ignoreFilterNotifications = false; |
| 259 let handlerBehaviorChangedQuota = |
| 260 browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES; |
| 261 |
| 262 function propagateHandlerBehaviorChange() |
| 263 { |
| 264 // Make sure to not call handlerBehaviorChanged() more often than allowed |
| 265 // by browser.webRequest.MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES. |
| 266 // Otherwise Chrome notifies the user that this extension is causing issues. |
| 267 if (handlerBehaviorChangedQuota > 0) |
| 268 { |
| 269 browser.webNavigation.onBeforeNavigate.removeListener( |
| 270 propagateHandlerBehaviorChange |
| 271 ); |
| 272 browser.webRequest.handlerBehaviorChanged(); |
| 273 handlerBehaviorChangedQuota--; |
| 274 setTimeout(() => { handlerBehaviorChangedQuota++; }, 600000); |
| 275 } |
| 276 } |
| 259 | 277 |
| 260 function onFilterChange(arg, isDisabledAction) | 278 function onFilterChange(arg, isDisabledAction) |
| 261 { | 279 { |
| 262 // Avoid triggering filters.behaviorChanged multiple times | 280 // Avoid triggering filters.behaviorChanged multiple times |
| 263 // when multiple filter hanges happen at the same time. | 281 // when multiple filter hanges happen at the same time. |
| 264 if (ignoreFilterNotifications) | 282 if (ignoreFilterNotifications) |
| 265 return; | 283 return; |
| 266 | 284 |
| 267 // Ignore disabled subscriptions and filters, unless they just got | 285 // Ignore disabled subscriptions and filters, unless they just got |
| 268 // disabled, otherwise they have no effect on the handler behavior. | 286 // disabled, otherwise they have no effect on the handler behavior. |
| 269 if (arg && arg.disabled && !isDisabledAction) | 287 if (arg && arg.disabled && !isDisabledAction) |
| 270 return; | 288 return; |
| 271 | 289 |
| 272 // Ignore empty subscriptions. This includes subscriptions | 290 // Ignore empty subscriptions. This includes subscriptions |
| 273 // that have just been added, but not downloaded yet. | 291 // that have just been added, but not downloaded yet. |
| 274 if (arg instanceof Subscription && arg.filters.length == 0) | 292 if (arg instanceof Subscription && arg.filters.length == 0) |
| 275 return; | 293 return; |
| 276 | 294 |
| 277 // Ignore all types of filters but request filters, | 295 // Ignore all types of filters but request filters, |
| 278 // only these have an effect on the handler behavior. | 296 // only these have an effect on the handler behavior. |
| 279 if (arg instanceof Filter && !(arg instanceof RegExpFilter)) | 297 if (arg instanceof Filter && !(arg instanceof RegExpFilter)) |
| 280 return; | 298 return; |
| 281 | 299 |
| 282 ignoreFilterNotifications = true; | 300 ignoreFilterNotifications = true; |
| 283 setTimeout(() => | 301 setTimeout(() => |
| 284 { | 302 { |
| 303 // Defer handlerBehaviorChanged() until navigation occurs. |
| 304 // There wouldn't be any visible effect when calling it earlier, |
| 305 // but it's an expensive operation and that way we avoid to call |
| 306 // it multiple times, if multiple filters are added/removed. |
| 307 if (!browser.webNavigation.onBeforeNavigate |
| 308 .hasListener(propagateHandlerBehaviorChange)) |
| 309 browser.webNavigation.onBeforeNavigate |
| 310 .addListener(propagateHandlerBehaviorChange); |
| 311 |
| 285 ignoreFilterNotifications = false; | 312 ignoreFilterNotifications = false; |
| 286 ext.webRequest.handlerBehaviorChanged(); | |
| 287 FilterNotifier.emit("filter.behaviorChanged"); | 313 FilterNotifier.emit("filter.behaviorChanged"); |
| 288 }); | 314 }); |
| 289 } | 315 } |
| 290 | 316 |
| 291 FilterNotifier.on("subscription.added", onFilterChange); | 317 FilterNotifier.on("subscription.added", onFilterChange); |
| 292 FilterNotifier.on("subscription.removed", onFilterChange); | 318 FilterNotifier.on("subscription.removed", onFilterChange); |
| 293 FilterNotifier.on("subscription.updated", onFilterChange); | 319 FilterNotifier.on("subscription.updated", onFilterChange); |
| 294 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); | 320 FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
| 295 FilterNotifier.on("filter.added", onFilterChange); | 321 FilterNotifier.on("filter.added", onFilterChange); |
| 296 FilterNotifier.on("filter.removed", onFilterChange); | 322 FilterNotifier.on("filter.removed", onFilterChange); |
| 297 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); | 323 FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
| 298 FilterNotifier.on("load", onFilterChange); | 324 FilterNotifier.on("load", onFilterChange); |
| OLD | NEW |