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.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) |
@@ -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]; |
+ break; |
case "subscriptions.add": |
if (message.url in FilterStorage.knownSubscriptions) |
return; |