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

Unified Diff: lib/filterComposer.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Patch Set: Created March 19, 2016, 8:33 p.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 | « background.js ('k') | lib/icon.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterComposer.js
===================================================================
--- a/lib/filterComposer.js
+++ b/lib/filterComposer.js
@@ -19,12 +19,27 @@
"use strict";
+let {defaultMatcher} = require("matcher");
+let {RegExpFilter} = require("filterClasses");
+let {FilterNotifier} = require("filterNotifier");
+let {Prefs} = require("prefs");
let {extractHostFromFrame, stringifyURL, isThirdParty} = require("url");
let {getKey, checkWhitelisted} = require("whitelisting");
-let {defaultMatcher} = require("matcher");
-let {RegExpFilter} = require("filterClasses");
let {port} = require("messaging");
+let readyPages = new ext.PageMap();
+
+/**
+ * Checks whether the given page is ready to use the filter composer
+ *
+ * @param {Page} page
+ * @return {boolean}
+ */
+exports.isPageReady = function(page)
+{
+ return readyPages.has(page);
+};
+
function isValidString(s) {
return s && s.indexOf("\0") == -1;
}
@@ -138,10 +153,44 @@
return {filters: filters, selectors: selectors};
}
+let contextMenuItem = {
+ title: ext.i18n.getMessage("block_element"),
+ contexts: ["image", "video", "audio"],
+ onclick: page =>
+ {
+ page.sendMessage({type: "composer.content.contextMenuClicked"});
+ }
+};
+
+function updateContextMenu(page, filter)
+{
+ page.contextMenus.remove(contextMenuItem);
+
+ if (typeof filter == "undefined")
+ filter = checkWhitelisted(page);
+ if (!filter && Prefs.shouldShowBlockElementMenu && readyPages.has(page))
kzar 2016/03/20 12:51:06 (Maybe we should first check the preference before
Sebastian Noack 2016/03/20 15:12:01 As you said, that micro optimization would make th
+ page.contextMenus.create(contextMenuItem);
+}
+
+FilterNotifier.addListener((action, page, filter) =>
+{
+ if (action == "page.WhitelistingStateRevalidate")
+ updateContextMenu(page, filter);
+});
+
+Prefs.on("shouldShowBlockElementMenu", () =>
+{
+ ext.pages.query({}, pages =>
+ {
+ for (let page of pages)
+ updateContextMenu(page);
+ });
+});
+
port.on("composer.ready", (message, sender) =>
{
- htmlPages.set(sender.page, null);
- refreshIconAndContextMenu(sender.page);
+ readyPages.set(sender.page, null);
+ updateContextMenu(sender.page);
});
port.on("composer.openDialog", (message, sender) =>
« no previous file with comments | « background.js ('k') | lib/icon.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld