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

Unified Diff: background.js

Issue 29338764: Issue 3842 - Split up the logic updating the icon and context menu (Closed)
Patch Set: Rebased Created March 21, 2016, 10:07 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 | « no previous file | lib/filterComposer.js » ('j') | popup.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -33,56 +33,14 @@
this.extractHostFromFrame = extractHostFromFrame;
}
var FilterStorage = require("filterStorage").FilterStorage;
-var FilterNotifier = require("filterNotifier").FilterNotifier;
var SpecialSubscription = require("subscriptionClasses").SpecialSubscription;
var ElemHide = require("elemHide").ElemHide;
var defaultMatcher = require("matcher").defaultMatcher;
var Prefs = require("prefs").Prefs;
-var updateIcon = require("icon").updateIcon;
var showNextNotificationForUrl = require("notificationHelper").showNextNotificationForUrl;
var port = require("messaging").port;
var devtools = require("devtools");
-var htmlPages = new ext.PageMap();
-
-var contextMenuItem = {
- title: ext.i18n.getMessage("block_element"),
- contexts: ["image", "video", "audio"],
- onclick: function(page)
- {
- page.sendMessage({type: "composer.content.contextMenuClicked"});
- }
-};
-
-// Adds or removes browser action icon according to options.
-function refreshIconAndContextMenu(page)
-{
- var whitelisted = !!checkWhitelisted(page);
- updateIcon(page, whitelisted);
-
- // show or hide the context menu entry dependent on whether
- // adblocking is active on that page
- page.contextMenus.remove(contextMenuItem);
- if (Prefs.shouldShowBlockElementMenu && !whitelisted && htmlPages.has(page))
- page.contextMenus.create(contextMenuItem);
-}
-
-function refreshIconAndContextMenuForAllPages()
-{
- ext.pages.query({}, function(pages)
- {
- pages.forEach(refreshIconAndContextMenu);
- });
-}
-
-FilterNotifier.addListener(function(action)
-{
- if (action == "load" || action == "save")
- refreshIconAndContextMenuForAllPages();
-});
-
-Prefs.on("shouldShowBlockElementMenu", refreshIconAndContextMenuForAllPages);
-
// This is a hack to speedup loading of the options page on Safari.
// Once we replaced the background page proxy with message passing
// this global function should removed.
@@ -191,6 +149,5 @@
ext.pages.onLoading.addListener(function(page)
{
page.sendMessage({type: "composer.content.finished"});
- refreshIconAndContextMenu(page);
showNextNotificationForUrl(page.url);
});
« no previous file with comments | « no previous file | lib/filterComposer.js » ('j') | popup.js » ('J')

Powered by Google App Engine
This is Rietveld