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

Unified Diff: messageResponder.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Patch Set: Added show_devtools_panel preference Created March 15, 2016, 3:32 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 | « locale/en-US/options.json ('k') | options.html » ('j') | options.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: messageResponder.js
===================================================================
--- a/messageResponder.js
+++ b/messageResponder.js
@@ -26,6 +26,7 @@
var FilterNotifier = require("filterNotifier").FilterNotifier;
var defaultMatcher = require("matcher").defaultMatcher;
var CSSRules = require("cssRules").CSSRules;
+ var NotificationStorage = require("notification").Notification;
var filterClasses = require("filterClasses");
var Filter = filterClasses.Filter;
@@ -33,6 +34,7 @@
var RegExpFilter = filterClasses.RegExpFilter;
var Synchronizer = require("synchronizer").Synchronizer;
+ var info = require("info");
var subscriptionClasses = require("subscriptionClasses");
var Subscription = subscriptionClasses.Subscription;
var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
@@ -54,6 +56,7 @@
var messageTypes = {
"app": "app.listen",
"filter": "filters.listen",
+ "pref": "prefs.listen",
"subscription": "subscriptions.listen"
};
@@ -107,27 +110,29 @@
sendMessage(type, action, args);
}
+ function onPrefChange(name)
+ {
+ sendMessage("pref", name, [Prefs[name]]);
+ }
+
global.ext.onMessage.addListener(function(message, sender, callback)
{
var listenerFilters = null;
- switch (message.type)
+ if (/\.listen$/.test(message.type))
{
- case "app.listen":
- case "filters.listen":
- case "subscriptions.listen":
- if (!changeListeners)
- {
- changeListeners = new global.ext.PageMap();
- FilterNotifier.addListener(onFilterChange);
- }
+ if (!changeListeners)
+ {
+ changeListeners = new global.ext.PageMap();
+ FilterNotifier.addListener(onFilterChange);
+ Prefs.onChanged.addListener(onPrefChange);
+ }
- listenerFilters = changeListeners.get(sender.page);
- if (!listenerFilters)
- {
- listenerFilters = Object.create(null);
- changeListeners.set(sender.page, listenerFilters);
- }
- break;
+ listenerFilters = changeListeners.get(sender.page);
+ if (!listenerFilters)
+ {
+ listenerFilters = Object.create(null);
+ changeListeners.set(sender.page, listenerFilters);
+ }
}
switch (message.type)
@@ -144,7 +149,6 @@
if (message.what == "issues")
{
var subscriptionInit = require("subscriptionInit");
- var info = require("info");
callback({
filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitialized : false,
legacySafariVersion: (info.platform == "safari" && (
@@ -167,7 +171,16 @@
}
else if (message.what == "addonVersion")
{
- callback(require("info").addonVersion);
+ callback(info.addonVersion);
+ }
+ else if (message.what == "features")
+ {
+ callback({
+ devToolsPanel: info.platform == "chromium",
+ safariContentBlocker: "safari" in global
+ && "extension" in global.safari
+ && "setContentBlocker" in global.safari.extension
+ });
}
else
callback(null);
@@ -289,6 +302,18 @@
case "prefs.get":
callback(Prefs[message.key]);
break;
+ case "prefs.listen":
+ if (message.filter)
+ listenerFilters.pref = message.filter;
+ else
+ delete listenerFilters.pref;
+ break;
+ case "prefs.toggle":
+ if (message.key == "notifications_ignoredcategories")
+ NotificationStorage.toggleIgnoreCategory("*");
+ else
+ Prefs[message.key] = !Prefs[message.key];
+ break;
case "subscriptions.add":
if (message.url in FilterStorage.knownSubscriptions)
return;
« no previous file with comments | « locale/en-US/options.json ('k') | options.html » ('j') | options.js » ('J')

Powered by Google App Engine
This is Rietveld