Index: lib/whitelisting.js |
=================================================================== |
--- a/lib/whitelisting.js |
+++ b/lib/whitelisting.js |
@@ -21,6 +21,7 @@ |
let {defaultMatcher} = require("matcher"); |
let {RegExpFilter} = require("filterClasses"); |
+let {FilterNotifier} = require("filterNotifier"); |
let {stringifyURL, getDecodedHostname, extractHostFromFrame, isThirdParty} = require("url"); |
let {port} = require("messaging"); |
let devtools = require("devtools"); |
@@ -81,6 +82,45 @@ |
return match(page, page.url, typeMask); |
}; |
+function revalidateWhitelistingState(page) |
+{ |
+ FilterNotifier.triggerListeners( |
+ "page.WhitelistingStateRevalidate", page, |
+ match(page, page.url, RegExpFilter.typeMap.DOCUMENT) |
+ ); |
+} |
+ |
+let expectsSave = false; |
+FilterNotifier.addListener((action, filter) => |
+{ |
+ switch (action) |
+ { |
+ case "subscription.added": // On subscription changes, defer |
+ case "subscription.removed": // revalidation until the changes |
+ case "subscription.disabled": // are saved to avoid revalidating the |
+ case "subscription.updated": // whitelisting state unnecessarily often. |
+ expectsSave = true; |
+ break; |
+ |
+ case "save": |
+ if (!expectsSave) |
+ break; |
+ expectsSave = false; |
+ |
+ case "load": |
+ case "filter.added": // On filter changes, revalidate imediatelly |
+ case "filter.removed": // to avoid visible delays when the user |
+ case "filter.disabled": // disables/enables the extension for a website. |
+ ext.pages.query({}, pages => |
+ { |
+ for (let page of pages) |
+ revalidateWhitelistingState(page); |
+ }); |
+ } |
+}); |
+ |
+ext.pages.onLoading.addListener(revalidateWhitelistingState); |
+ |
let getKey = |
/** |
* Gets the public key, previously recorded for the given page |