Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/whitelisting.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Patch Set: Prevent visible delays Created March 21, 2016, 10:10 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/icon.js ('k') | popup.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « lib/icon.js ('k') | popup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld