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

Delta Between Two Patch Sets: messageResponder.js

Issue 29370999: Issue 4783 - Use modern JavaScript syntax for the messageResponder (Closed)
Left Patch Set: Addressed feedback Created Jan. 17, 2017, 11:27 a.m.
Right Patch Set: Addressed further feedback Created Jan. 18, 2017, 11:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "use strict"; 18 "use strict";
19 19
20 { 20 {
21 var ext = ext || require("ext_background"); 21 var ext = ext || require("ext_background");
22 22
23 let port = require("messaging").port; 23 const {port} = require("messaging");
Sebastian Noack 2017/01/17 17:30:16 Also what is about using destructing here?
kzar 2017/01/18 05:50:32 Done.
24 let Prefs = require("prefs").Prefs; 24 const {Prefs} = require("prefs");
25 let Utils = require("utils").Utils; 25 const {Utils} = require("utils");
26 let FilterStorage = require("filterStorage").FilterStorage; 26 const {FilterStorage} = require("filterStorage");
27 let FilterNotifier = require("filterNotifier").FilterNotifier; 27 const {FilterNotifier} = require("filterNotifier");
28 let defaultMatcher = require("matcher").defaultMatcher; 28 const {defaultMatcher} = require("matcher");
29 let ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation; 29 const {ElemHideEmulation} = require("elemHideEmulation");
30 let NotificationStorage = require("notification").Notification; 30 const {Notification: NotificationStorage} = require("notification");
31 31
32 let filterClasses = require("filterClasses"); 32 const {Filter, BlockingFilter, RegExpFilter} = require("filterClasses");
33 let Filter = filterClasses.Filter; 33 const {Synchronizer} = require("synchronizer");
34 let BlockingFilter = filterClasses.BlockingFilter; 34
35 let RegExpFilter = filterClasses.RegExpFilter; 35 const info = require("info");
36 let Synchronizer = require("synchronizer").Synchronizer; 36 const {Subscription,
37 37 DownloadableSubscription,
38 let info = require("info"); 38 SpecialSubscription} = require("subscriptionClasses");
39 let subscriptionClasses = require("subscriptionClasses");
40 let Subscription = subscriptionClasses.Subscription;
41 let DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
42 let SpecialSubscription = subscriptionClasses.SpecialSubscription;
43 39
44 // Some modules doesn't exist on Firefox. Moreover, 40 // Some modules doesn't exist on Firefox. Moreover,
45 // require() throws an exception on Firefox in that case. 41 // require() throws an exception on Firefox in that case.
46 // However, try/catch causes the whole function to to be 42 // However, try/catch causes the whole function to to be
47 // deoptimized on V8. So we wrap it into another function. 43 // deoptimized on V8. So we wrap it into another function.
48 function tryRequire(module) 44 function tryRequire(module)
49 { 45 {
50 try 46 try
51 { 47 {
52 return require(module); 48 return require(module);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 { 131 {
136 listenedFilterChanges[name] = null; 132 listenedFilterChanges[name] = null;
137 FilterNotifier.on(name, function() 133 FilterNotifier.on(name, function()
138 { 134 {
139 let args = [type, action]; 135 let args = [type, action];
140 for (let arg of arguments) 136 for (let arg of arguments)
141 args.push(arg); 137 args.push(arg);
142 sendMessage.apply(null, args); 138 sendMessage.apply(null, args);
143 }); 139 });
144 } 140 }
145 }; 141 }
146 } 142 }
147 143
148 function getListenerFilters(page) 144 function getListenerFilters(page)
149 { 145 {
150 let listenerFilters = changeListeners.get(page); 146 let listenerFilters = changeListeners.get(page);
151 if (!listenerFilters) 147 if (!listenerFilters)
152 { 148 {
153 listenerFilters = Object.create(null); 149 listenerFilters = Object.create(null);
154 changeListeners.set(page, listenerFilters); 150 changeListeners.set(page, listenerFilters);
155 } 151 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 message.thirdParty); 223 message.thirdParty);
228 224
229 return filter instanceof BlockingFilter; 225 return filter instanceof BlockingFilter;
230 }); 226 });
231 227
232 port.on("filters.get", (message, sender) => 228 port.on("filters.get", (message, sender) =>
233 { 229 {
234 if (message.what == "elemhideemulation") 230 if (message.what == "elemhideemulation")
235 { 231 {
236 let filters = []; 232 let filters = [];
237 let checkWhitelisted = require("whitelisting").checkWhitelisted; 233 const {checkWhitelisted} = require("whitelisting");
238 234
239 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 235 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame,
240 RegExpFilter.typeMap.DOCUMENT | 236 RegExpFilter.typeMap.DOCUMENT |
241 RegExpFilter.typeMap.ELEMHIDE)) 237 RegExpFilter.typeMap.ELEMHIDE))
242 { 238 {
243 let hostname = sender.frame.url.hostname; 239 let hostname = sender.frame.url.hostname;
244 filters = ElemHideEmulation.getRulesForDomain(hostname); 240 filters = ElemHideEmulation.getRulesForDomain(hostname);
245 filters = filters.map(filter => 241 filters = filters.map(filter =>
246 { 242 {
247 return { 243 return {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 for (let preference of message.filter) 328 for (let preference of message.filter)
333 { 329 {
334 if (!(preference in listenedPreferences)) 330 if (!(preference in listenedPreferences))
335 { 331 {
336 listenedPreferences[preference] = null; 332 listenedPreferences[preference] = null;
337 Prefs.on(preference, () => 333 Prefs.on(preference, () =>
338 { 334 {
339 sendMessage("pref", preference, Prefs[preference]); 335 sendMessage("pref", preference, Prefs[preference]);
340 }); 336 });
341 } 337 }
342 }); 338 }
343 }); 339 });
344 340
345 port.on("prefs.toggle", (message, sender) => 341 port.on("prefs.toggle", (message, sender) =>
346 { 342 {
347 if (message.key == "notifications_ignoredcategories") 343 if (message.key == "notifications_ignoredcategories")
348 NotificationStorage.toggleIgnoreCategory("*"); 344 NotificationStorage.toggleIgnoreCategory("*");
349 else 345 else
350 Prefs[message.key] = !Prefs[message.key]; 346 Prefs[message.key] = !Prefs[message.key];
351 }); 347 });
352 348
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 { 425 {
430 let subscriptions = message.url ? [Subscription.fromURL(message.url)] : 426 let subscriptions = message.url ? [Subscription.fromURL(message.url)] :
431 FilterStorage.subscriptions; 427 FilterStorage.subscriptions;
432 for (let subscription of subscriptions) 428 for (let subscription of subscriptions)
433 { 429 {
434 if (subscription instanceof DownloadableSubscription) 430 if (subscription instanceof DownloadableSubscription)
435 Synchronizer.execute(subscription, true); 431 Synchronizer.execute(subscription, true);
436 } 432 }
437 }); 433 });
438 } 434 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld