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: Created March 16, 2016, 11:13 a.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
37 var info = require("info");
36 var subscriptionClasses = require("subscriptionClasses"); 38 var subscriptionClasses = require("subscriptionClasses");
37 var Subscription = subscriptionClasses.Subscription; 39 var Subscription = subscriptionClasses.Subscription;
38 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 40 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
39 var SpecialSubscription = subscriptionClasses.SpecialSubscription; 41 var SpecialSubscription = subscriptionClasses.SpecialSubscription;
40 42
41 function convertObject(keys, obj) 43 function convertObject(keys, obj)
42 { 44 {
43 var result = {}; 45 var result = {};
44 for (var i = 0; i < keys.length; i++) 46 for (var i = 0; i < keys.length; i++)
45 result[keys[i]] = obj[keys[i]]; 47 result[keys[i]] = obj[keys[i]];
46 return result; 48 return result;
47 } 49 }
48 50
49 var convertSubscription = convertObject.bind(null, ["disabled", 51 var convertSubscription = convertObject.bind(null, ["disabled",
50 "downloadStatus", "homepage", "lastDownload", "title", "url"]); 52 "downloadStatus", "homepage", "lastDownload", "title", "url"]);
51 var convertFilter = convertObject.bind(null, ["text"]); 53 var convertFilter = convertObject.bind(null, ["text"]);
52 54
53 var changeListeners = null; 55 var changeListeners = null;
54 var messageTypes = { 56 var messageTypes = {
55 "app": "app.listen", 57 "app": "app.listen",
56 "filter": "filters.listen", 58 "filter": "filters.listen",
59 "pref": "prefs.listen",
57 "subscription": "subscriptions.listen" 60 "subscription": "subscriptions.listen"
58 }; 61 };
59 62
60 function sendMessage(type, action, args, page) 63 function sendMessage(type, action, args, page)
61 { 64 {
62 var pages = page ? [page] : changeListeners.keys(); 65 var pages = page ? [page] : changeListeners.keys();
63 for (var i = 0; i < pages.length; i++) 66 for (var i = 0; i < pages.length; i++)
64 { 67 {
65 var filters = changeListeners.get(pages[i]); 68 var filters = changeListeners.get(pages[i]);
66 if (filters[type] && filters[type].indexOf(action) >= 0) 69 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) 103 if (arg instanceof Subscription)
101 return convertSubscription(arg); 104 return convertSubscription(arg);
102 else if (arg instanceof Filter) 105 else if (arg instanceof Filter)
103 return convertFilter(arg); 106 return convertFilter(arg);
104 else 107 else
105 return arg; 108 return arg;
106 }); 109 });
107 sendMessage(type, action, args); 110 sendMessage(type, action, args);
108 } 111 }
109 112
113 function onPrefChange(name)
114 {
115 sendMessage("pref", name, [Prefs[name]]);
116 }
117
110 global.ext.onMessage.addListener(function(message, sender, callback) 118 global.ext.onMessage.addListener(function(message, sender, callback)
111 { 119 {
112 var listenerFilters = null; 120 var listenerFilters = null;
113 switch (message.type) 121 if (/\.listen$/.test(message.type))
114 { 122 {
115 case "app.listen": 123 if (!changeListeners)
116 case "filters.listen": 124 {
117 case "subscriptions.listen": 125 changeListeners = new global.ext.PageMap();
118 if (!changeListeners) 126 FilterNotifier.addListener(onFilterChange);
119 { 127 Prefs.onChanged.addListener(onPrefChange);
120 changeListeners = new global.ext.PageMap(); 128 }
121 FilterNotifier.addListener(onFilterChange);
122 }
123 129
124 listenerFilters = changeListeners.get(sender.page); 130 listenerFilters = changeListeners.get(sender.page);
125 if (!listenerFilters) 131 if (!listenerFilters)
126 { 132 {
127 listenerFilters = Object.create(null); 133 listenerFilters = Object.create(null);
128 changeListeners.set(sender.page, listenerFilters); 134 changeListeners.set(sender.page, listenerFilters);
129 } 135 }
130 break;
131 } 136 }
132 137
133 switch (message.type) 138 switch (message.type)
134 { 139 {
135 case "add-subscription": 140 case "add-subscription":
136 ext.showOptions(function() 141 ext.showOptions(function()
137 { 142 {
138 var subscription = Subscription.fromURL(message.url); 143 var subscription = Subscription.fromURL(message.url);
139 subscription.title = message.title; 144 subscription.title = message.title;
140 onFilterChange("addSubscription", subscription); 145 onFilterChange("addSubscription", subscription);
141 }); 146 });
142 break; 147 break;
143 case "app.get": 148 case "app.get":
144 if (message.what == "issues") 149 if (message.what == "issues")
145 { 150 {
146 var subscriptionInit = require("subscriptionInit"); 151 var subscriptionInit = require("subscriptionInit");
147 var info = require("info");
148 callback({ 152 callback({
149 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinit ialized : false, 153 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinit ialized : false,
150 legacySafariVersion: (info.platform == "safari" && ( 154 legacySafariVersion: (info.platform == "safari" && (
151 Services.vc.compare(info.platformVersion, "6.0") < 0 || // bef oreload breaks websites in Safari 5 155 Services.vc.compare(info.platformVersion, "6.0") < 0 || // bef oreload breaks websites in Safari 5
152 Services.vc.compare(info.platformVersion, "6.1") == 0 || // ext ensions are broken in 6.1 and 7.0 156 Services.vc.compare(info.platformVersion, "6.1") == 0 || // ext ensions are broken in 6.1 and 7.0
153 Services.vc.compare(info.platformVersion, "7.0") == 0)) 157 Services.vc.compare(info.platformVersion, "7.0") == 0))
154 }); 158 });
155 } 159 }
156 else if (message.what == "doclink") 160 else if (message.what == "doclink")
157 callback(Utils.getDocLink(message.link)); 161 callback(Utils.getDocLink(message.link));
158 else if (message.what == "localeInfo") 162 else if (message.what == "localeInfo")
159 { 163 {
160 var bidiDir; 164 var bidiDir;
161 if ("chromeRegistry" in Utils) 165 if ("chromeRegistry" in Utils)
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(info.addonVersion);
175 }
176 else if (message.what == "features")
177 {
178 callback({
179 devToolsPanel: info.platform == "chromium",
180 safariContentBlocker: "safari" in global
181 && "extension" in global.safari
182 && "setContentBlocker" in global.safari.extension
183 });
171 } 184 }
172 else 185 else
173 callback(null); 186 callback(null);
174 break; 187 break;
175 case "app.listen": 188 case "app.listen":
176 if (message.filter) 189 if (message.filter)
177 listenerFilters.app = message.filter; 190 listenerFilters.app = message.filter;
178 else 191 else
179 delete listenerFilters.app; 192 delete listenerFilters.app;
180 break; 193 break;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 subscription = Subscription.fromURL(message.subscriptionUrl); 295 subscription = Subscription.fromURL(message.subscriptionUrl);
283 296
284 if (!subscription) 297 if (!subscription)
285 FilterStorage.removeFilter(filter); 298 FilterStorage.removeFilter(filter);
286 else 299 else
287 FilterStorage.removeFilter(filter, subscription, message.index); 300 FilterStorage.removeFilter(filter, subscription, message.index);
288 break; 301 break;
289 case "prefs.get": 302 case "prefs.get":
290 callback(Prefs[message.key]); 303 callback(Prefs[message.key]);
291 break; 304 break;
305 case "prefs.listen":
306 if (message.filter)
307 listenerFilters.pref = message.filter;
308 else
309 delete listenerFilters.pref;
310 break;
311 case "prefs.toggle":
312 if (message.key == "notifications_ignoredcategories")
313 NotificationStorage.toggleIgnoreCategory("*");
314 else
315 Prefs[message.key] = !Prefs[message.key];
316 break;
292 case "subscriptions.add": 317 case "subscriptions.add":
293 if (message.url in FilterStorage.knownSubscriptions) 318 if (message.url in FilterStorage.knownSubscriptions)
294 return; 319 return;
295 320
296 var subscription = Subscription.fromURL(message.url); 321 var subscription = Subscription.fromURL(message.url);
297 if (!subscription) 322 if (!subscription)
298 return; 323 return;
299 324
300 subscription.disabled = false; 325 subscription.disabled = false;
301 if ("title" in message) 326 if ("title" in message)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 if (subscription instanceof DownloadableSubscription) 388 if (subscription instanceof DownloadableSubscription)
364 Synchronizer.execute(subscription, true); 389 Synchronizer.execute(subscription, true);
365 } 390 }
366 break; 391 break;
367 case "subscriptions.isDownloading": 392 case "subscriptions.isDownloading":
368 callback(Synchronizer.isExecuting(message.url)); 393 callback(Synchronizer.isExecuting(message.url));
369 break; 394 break;
370 } 395 }
371 }); 396 });
372 })(this); 397 })(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