Index: lib/requestBlocker.js |
=================================================================== |
--- a/lib/requestBlocker.js |
+++ b/lib/requestBlocker.js |
@@ -19,7 +19,8 @@ |
"use strict"; |
-let {RegExpFilter, BlockingFilter} = require("filterClasses"); |
+let {Filter, RegExpFilter, BlockingFilter} = require("filterClasses"); |
+let {Subscription} = require("subscriptionClasses"); |
let {defaultMatcher} = require("matcher"); |
let {FilterNotifier} = require("filterNotifier"); |
let {Prefs} = require("prefs"); |
@@ -39,7 +40,7 @@ |
specificOnly, filter) |
{ |
if (filter) |
- FilterNotifier.triggerListeners("filter.hitCount", filter, 0, 0, page); |
+ FilterNotifier.emit("filter.hitCount", filter, 0, 0, page); |
if (devtools) |
devtools.logRequest( |
@@ -113,56 +114,43 @@ |
}); |
let ignoreFilterNotifications = false; |
-FilterNotifier.addListener((action, arg) => |
+ |
+function onFilterChange(arg, isDisabledAction) |
{ |
// Avoid triggering filters.behaviorChanged multiple times |
// when multiple filter hanges happen at the same time. |
if (ignoreFilterNotifications) |
return; |
- if (action != "load") |
- { |
- let parts = action.split("."); |
- let [category, event] = parts; |
- if (category == "subscription") |
- { |
- if (event != "added" && |
- event != "removed" && |
- event != "updated" && |
- event != "disabled") |
- return; |
+ // Ignore disabled subscriptions and filters, unless they just got |
+ // disabled, otherwise they have no effect on the handler behavior. |
+ if (arg && arg.disabled && !isDisabledAction) |
+ return; |
- // Ignore empty subscriptions. This includes subscriptions |
- // that have just been added, but not downloaded yet. |
- if (arg.filters.length == 0) |
- return; |
- } |
- else if (category == "filter") |
- { |
- if (event != "added" && |
- event != "removed" && |
- event != "disabled") |
- return; |
+ // Ignore empty subscriptions. This includes subscriptions |
+ // that have just been added, but not downloaded yet. |
+ if (arg instanceof Subscription && arg.filters.length == 0) |
+ return; |
- // Ignore all types of filters but request filters, |
- // only these have an effect on the handler behavior. |
- if (!(arg instanceof RegExpFilter)) |
- return; |
- } |
- else |
- return; |
- |
- // Ignore disabled subscriptions and filters, unless they just got |
- // disabled, otherwise they have no effect on the handler behavior. |
- if (arg.disabled && event != "disabled") |
- return; |
- } |
+ // Ignore all types of filters but request filters, |
+ // only these have an effect on the handler behavior. |
+ if (arg instanceof Filter && !(arg instanceof RegExpFilter)) |
+ return; |
ignoreFilterNotifications = true; |
setTimeout(() => |
{ |
ignoreFilterNotifications = false; |
ext.webRequest.handlerBehaviorChanged(); |
- FilterNotifier.triggerListeners("filter.behaviorChanged"); |
+ FilterNotifier.emit("filter.behaviorChanged"); |
}); |
-}); |
+} |
+ |
+FilterNotifier.on("subscription.added", onFilterChange) |
+FilterNotifier.on("subscription.removed", onFilterChange); |
+FilterNotifier.on("subscription.updated", onFilterChange); |
+FilterNotifier.on("subscription.disabled", arg => onFilterChange(arg, true)); |
+FilterNotifier.on("filter.added", onFilterChange); |
+FilterNotifier.on("filter.removed", onFilterChange); |
+FilterNotifier.on("filter.disabled", arg => onFilterChange(arg, true)); |
+FilterNotifier.on("load", onFilterChange); |