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

Side by Side Diff: messageResponder.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Patch Set: Rebased to 0e4b41190cf5 Created March 15, 2016, 2:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « locale/en-US/options.json ('k') | options.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 (function(global) 18 (function(global)
19 { 19 {
20 if (!global.ext) 20 if (!global.ext)
21 global.ext = require("ext_background"); 21 global.ext = require("ext_background");
22 22
23 var Prefs = require("prefs").Prefs; 23 var Prefs = require("prefs").Prefs;
24 var Utils = require("utils").Utils; 24 var Utils = require("utils").Utils;
25 var FilterStorage = require("filterStorage").FilterStorage; 25 var FilterStorage = require("filterStorage").FilterStorage;
26 var FilterNotifier = require("filterNotifier").FilterNotifier; 26 var FilterNotifier = require("filterNotifier").FilterNotifier;
27 var defaultMatcher = require("matcher").defaultMatcher; 27 var defaultMatcher = require("matcher").defaultMatcher;
28 var CSSRules = require("cssRules").CSSRules; 28 var CSSRules = require("cssRules").CSSRules;
29 var NotificationStorage = require("notification").Notification;
29 30
30 var filterClasses = require("filterClasses"); 31 var filterClasses = require("filterClasses");
31 var Filter = filterClasses.Filter; 32 var Filter = filterClasses.Filter;
32 var BlockingFilter = filterClasses.BlockingFilter; 33 var BlockingFilter = filterClasses.BlockingFilter;
33 var RegExpFilter = filterClasses.RegExpFilter; 34 var RegExpFilter = filterClasses.RegExpFilter;
34 var Synchronizer = require("synchronizer").Synchronizer; 35 var Synchronizer = require("synchronizer").Synchronizer;
35 36
36 var subscriptionClasses = require("subscriptionClasses"); 37 var subscriptionClasses = require("subscriptionClasses");
37 var Subscription = subscriptionClasses.Subscription; 38 var Subscription = subscriptionClasses.Subscription;
38 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 39 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
39 var SpecialSubscription = subscriptionClasses.SpecialSubscription; 40 var SpecialSubscription = subscriptionClasses.SpecialSubscription;
40 41
41 function convertObject(keys, obj) 42 function convertObject(keys, obj)
42 { 43 {
43 var result = {}; 44 var result = {};
44 for (var i = 0; i < keys.length; i++) 45 for (var i = 0; i < keys.length; i++)
45 result[keys[i]] = obj[keys[i]]; 46 result[keys[i]] = obj[keys[i]];
46 return result; 47 return result;
47 } 48 }
48 49
49 var convertSubscription = convertObject.bind(null, ["disabled", 50 var convertSubscription = convertObject.bind(null, ["disabled",
50 "downloadStatus", "homepage", "lastDownload", "title", "url"]); 51 "downloadStatus", "homepage", "lastDownload", "title", "url"]);
51 var convertFilter = convertObject.bind(null, ["text"]); 52 var convertFilter = convertObject.bind(null, ["text"]);
52 53
53 var changeListeners = null; 54 var changeListeners = null;
54 var messageTypes = { 55 var messageTypes = {
55 "app": "app.listen", 56 "app": "app.listen",
56 "filter": "filters.listen", 57 "filter": "filters.listen",
58 "pref": "prefs.listen",
57 "subscription": "subscriptions.listen" 59 "subscription": "subscriptions.listen"
58 }; 60 };
59 61
60 function sendMessage(type, action, args, page) 62 function sendMessage(type, action, args, page)
61 { 63 {
62 var pages = page ? [page] : changeListeners.keys(); 64 var pages = page ? [page] : changeListeners.keys();
63 for (var i = 0; i < pages.length; i++) 65 for (var i = 0; i < pages.length; i++)
64 { 66 {
65 var filters = changeListeners.get(pages[i]); 67 var filters = changeListeners.get(pages[i]);
66 if (filters[type] && filters[type].indexOf(action) >= 0) 68 if (filters[type] && filters[type].indexOf(action) >= 0)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (arg instanceof Subscription) 102 if (arg instanceof Subscription)
101 return convertSubscription(arg); 103 return convertSubscription(arg);
102 else if (arg instanceof Filter) 104 else if (arg instanceof Filter)
103 return convertFilter(arg); 105 return convertFilter(arg);
104 else 106 else
105 return arg; 107 return arg;
106 }); 108 });
107 sendMessage(type, action, args); 109 sendMessage(type, action, args);
108 } 110 }
109 111
112 function onPrefChange(name)
113 {
114 sendMessage("pref", name, [Prefs[name]]);
115 }
116
110 global.ext.onMessage.addListener(function(message, sender, callback) 117 global.ext.onMessage.addListener(function(message, sender, callback)
111 { 118 {
112 var listenerFilters = null; 119 var listenerFilters = null;
113 switch (message.type) 120 if (/\.listen$/.test(message.type))
114 { 121 {
115 case "app.listen": 122 if (!changeListeners)
116 case "filters.listen": 123 {
117 case "subscriptions.listen": 124 changeListeners = new global.ext.PageMap();
118 if (!changeListeners) 125 FilterNotifier.addListener(onFilterChange);
119 { 126 Prefs.onChanged.addListener(onPrefChange);
120 changeListeners = new global.ext.PageMap(); 127 }
121 FilterNotifier.addListener(onFilterChange);
122 }
123 128
124 listenerFilters = changeListeners.get(sender.page); 129 listenerFilters = changeListeners.get(sender.page);
125 if (!listenerFilters) 130 if (!listenerFilters)
126 { 131 {
127 listenerFilters = Object.create(null); 132 listenerFilters = Object.create(null);
128 changeListeners.set(sender.page, listenerFilters); 133 changeListeners.set(sender.page, listenerFilters);
129 } 134 }
130 break;
131 } 135 }
132 136
133 switch (message.type) 137 switch (message.type)
134 { 138 {
135 case "add-subscription": 139 case "add-subscription":
136 ext.showOptions(function() 140 ext.showOptions(function()
137 { 141 {
138 var subscription = Subscription.fromURL(message.url); 142 var subscription = Subscription.fromURL(message.url);
139 subscription.title = message.title; 143 subscription.title = message.title;
140 onFilterChange("addSubscription", subscription); 144 onFilterChange("addSubscription", subscription);
(...skipping 21 matching lines...) Expand all
162 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr"; 166 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr";
163 else 167 else
164 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 168 bidiDir = ext.i18n.getMessage("@@bidi_dir");
165 169
166 callback({locale: Utils.appLocale, bidiDir: bidiDir}); 170 callback({locale: Utils.appLocale, bidiDir: bidiDir});
167 } 171 }
168 else if (message.what == "addonVersion") 172 else if (message.what == "addonVersion")
169 { 173 {
170 callback(require("info").addonVersion); 174 callback(require("info").addonVersion);
171 } 175 }
176 else if (message.what == "features")
177 {
178 callback({
179 safariContentBlocker: "safari" in global
180 && "extension" in global.safari
181 && "setContentBlocker" in global.safari.extension
182 });
183 }
172 else 184 else
173 callback(null); 185 callback(null);
174 break; 186 break;
175 case "app.listen": 187 case "app.listen":
176 if (message.filter) 188 if (message.filter)
177 listenerFilters.app = message.filter; 189 listenerFilters.app = message.filter;
178 else 190 else
179 delete listenerFilters.app; 191 delete listenerFilters.app;
180 break; 192 break;
181 case "app.open": 193 case "app.open":
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 subscription = Subscription.fromURL(message.subscriptionUrl); 294 subscription = Subscription.fromURL(message.subscriptionUrl);
283 295
284 if (!subscription) 296 if (!subscription)
285 FilterStorage.removeFilter(filter); 297 FilterStorage.removeFilter(filter);
286 else 298 else
287 FilterStorage.removeFilter(filter, subscription, message.index); 299 FilterStorage.removeFilter(filter, subscription, message.index);
288 break; 300 break;
289 case "prefs.get": 301 case "prefs.get":
290 callback(Prefs[message.key]); 302 callback(Prefs[message.key]);
291 break; 303 break;
304 case "prefs.listen":
305 if (message.filter)
306 listenerFilters.pref = message.filter;
307 else
308 delete listenerFilters.pref;
309 break;
310 case "prefs.toggle":
311 if (message.key == "notifications_ignoredcategories")
312 NotificationStorage.toggleIgnoreCategory("*");
313 else
314 Prefs[message.key] = !Prefs[message.key];
315 break;
292 case "subscriptions.add": 316 case "subscriptions.add":
293 if (message.url in FilterStorage.knownSubscriptions) 317 if (message.url in FilterStorage.knownSubscriptions)
294 return; 318 return;
295 319
296 var subscription = Subscription.fromURL(message.url); 320 var subscription = Subscription.fromURL(message.url);
297 if (!subscription) 321 if (!subscription)
298 return; 322 return;
299 323
300 subscription.disabled = false; 324 subscription.disabled = false;
301 if ("title" in message) 325 if ("title" in message)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (subscription instanceof DownloadableSubscription) 387 if (subscription instanceof DownloadableSubscription)
364 Synchronizer.execute(subscription, true); 388 Synchronizer.execute(subscription, true);
365 } 389 }
366 break; 390 break;
367 case "subscriptions.isDownloading": 391 case "subscriptions.isDownloading":
368 callback(Synchronizer.isExecuting(message.url)); 392 callback(Synchronizer.isExecuting(message.url));
369 break; 393 break;
370 } 394 }
371 }); 395 });
372 })(this); 396 })(this);
OLDNEW
« no previous file with comments | « locale/en-US/options.json ('k') | options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld