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: Created Feb. 25, 2016, 5:50 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
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;
@@ -54,6 +55,7 @@
var messageTypes = {
"app": "app.listen",
"filter": "filters.listen",
+ "pref": "prefs.listen",
"subscription": "subscriptions.listen"
};
@@ -107,27 +109,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.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)
@@ -169,6 +173,14 @@
{
callback(require("info").addonVersion);
}
+ else if (message.what == "features")
+ {
+ callback({
+ safariContentBlocker: "safari" in global
+ && "extension" in global.safari
+ && "setContentBlocker" in global.safari.extension
+ });
+ }
else
callback(null);
break;
@@ -289,6 +301,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];
saroyanm 2016/02/29 14:34:38 Shouldn't we also trigger the listener ? The list
Thomas Greiner 2016/02/29 17:32:43 Done. The listener is automatically triggered by
+ break;
case "subscriptions.add":
if (message.url in FilterStorage.knownSubscriptions)
return;

Powered by Google App Engine
This is Rietveld