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

Side by Side Diff: messageResponder.js

Issue 29370999: Issue 4783 - Use modern JavaScript syntax for the messageResponder (Closed)
Patch Set: Use destructuring + const, fix typo Created Jan. 18, 2017, 5:48 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 | « no previous file | no next file » | 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 "use strict";
19
19 { 20 {
20 if (!global.ext) 21 var ext = ext || require("ext_background");
21 global.ext = require("ext_background");
22 22
23 var port = require("messaging").port; 23 const {port} = require("messaging");
24 var Prefs = require("prefs").Prefs; 24 const {Prefs} = require("prefs");
25 var Utils = require("utils").Utils; 25 const {Utils} = require("utils");
26 var FilterStorage = require("filterStorage").FilterStorage; 26 const {FilterStorage} = require("filterStorage");
27 var FilterNotifier = require("filterNotifier").FilterNotifier; 27 const {FilterNotifier} = require("filterNotifier");
28 var defaultMatcher = require("matcher").defaultMatcher; 28 const {defaultMatcher} = require("matcher");
29 var ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation; 29 const {ElemHideEmulation} = require("elemHideEmulation");
30 var NotificationStorage = require("notification").Notification; 30 const {NotificationStorage} = require("notification");
Thomas Greiner 2017/01/18 11:40:09 This doesn't work. What you'd want to do is: cons
kzar 2017/01/18 11:54:41 Done.
31 31
32 var filterClasses = require("filterClasses"); 32 const {Filter, BlockingFilter, RegExpFilter} = require("filterClasses");
33 var Filter = filterClasses.Filter; 33 const {Synchronizer} = require("synchronizer");
34 var BlockingFilter = filterClasses.BlockingFilter;
35 var RegExpFilter = filterClasses.RegExpFilter;
36 var Synchronizer = require("synchronizer").Synchronizer;
37 34
38 var info = require("info"); 35 const info = require("info");
39 var subscriptionClasses = require("subscriptionClasses"); 36 const {Subscription,
40 var Subscription = subscriptionClasses.Subscription; 37 DownloadableSubscription,
41 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 38 SpecialSubscription} = require("subscriptionClasses");
42 var 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);
53 } 49 }
54 catch (e) 50 catch (e)
55 { 51 {
56 return null; 52 return null;
57 } 53 }
58 } 54 }
59 55
60 function convertObject(keys, obj) 56 function convertObject(keys, obj)
61 { 57 {
62 var result = {}; 58 let result = {};
63 for (var i = 0; i < keys.length; i++) 59 for (let key of keys)
64 { 60 {
65 var key = keys[i];
66 if (key in obj) 61 if (key in obj)
67 result[key] = obj[key]; 62 result[key] = obj[key];
68 } 63 }
69 return result; 64 return result;
70 } 65 }
71 66
72 function convertSubscription(subscription) 67 function convertSubscription(subscription)
73 { 68 {
74 var obj = convertObject(["disabled", "downloadStatus", "homepage", 69 let obj = convertObject(["disabled", "downloadStatus", "homepage",
75 "lastDownload", "title", "url"], subscription); 70 "lastDownload", "title", "url"], subscription);
76 obj.isDownloading = Synchronizer.isExecuting(subscription.url); 71 obj.isDownloading = Synchronizer.isExecuting(subscription.url);
77 return obj; 72 return obj;
78 } 73 }
79 74
80 var convertFilter = convertObject.bind(null, ["text"]); 75 let convertFilter = convertObject.bind(null, ["text"]);
81 76
82 var changeListeners = new global.ext.PageMap(); 77 let changeListeners = new ext.PageMap();
83 var listenedPreferences = Object.create(null); 78 let listenedPreferences = Object.create(null);
84 var listenedFilterChanges = Object.create(null); 79 let listenedFilterChanges = Object.create(null);
85 var messageTypes = { 80 let messageTypes = {
86 "app": "app.respond", 81 "app": "app.respond",
87 "filter": "filters.respond", 82 "filter": "filters.respond",
88 "pref": "prefs.respond", 83 "pref": "prefs.respond",
89 "subscription": "subscriptions.respond" 84 "subscription": "subscriptions.respond"
90 }; 85 };
91 86
92 function sendMessage(type, action) 87 function sendMessage(type, action)
93 { 88 {
94 var pages = changeListeners.keys(); 89 let pages = changeListeners.keys();
95 if (pages.length == 0) 90 if (pages.length == 0)
96 return; 91 return;
97 92
98 var args = []; 93 let args = [];
99 for (var i = 2; i < arguments.length; i++) 94 for (let i = 2; i < arguments.length; i++)
100 { 95 {
101 var arg = arguments[i]; 96 let arg = arguments[i];
102 if (arg instanceof Subscription) 97 if (arg instanceof Subscription)
103 args.push(convertSubscription(arg)); 98 args.push(convertSubscription(arg));
104 else if (arg instanceof Filter) 99 else if (arg instanceof Filter)
105 args.push(convertFilter(arg)); 100 args.push(convertFilter(arg));
106 else 101 else
107 args.push(arg); 102 args.push(arg);
108 } 103 }
109 104
110 for (var j = 0; j < pages.length; j++) 105 for (let page of pages)
111 { 106 {
112 var page = pages[j]; 107 let filters = changeListeners.get(page);
113 var filters = changeListeners.get(page); 108 let actions = filters[type];
114 var actions = filters[type];
115 if (actions && actions.indexOf(action) != -1) 109 if (actions && actions.indexOf(action) != -1)
116 { 110 {
117 page.sendMessage({ 111 page.sendMessage({
118 type: messageTypes[type], 112 type: messageTypes[type],
119 action: action, 113 action: action,
120 args: args 114 args: args
121 }); 115 });
122 } 116 }
123 } 117 }
124 } 118 }
125 119
126 function addFilterListeners(type, actions) 120 function addFilterListeners(type, actions)
127 { 121 {
128 actions.forEach(function(action) 122 for (let action of actions)
129 { 123 {
130 var name; 124 let name;
131 if (type == "filter" && action == "loaded") 125 if (type == "filter" && action == "loaded")
132 name = "load"; 126 name = "load";
133 else 127 else
134 name = type + "." + action; 128 name = type + "." + action;
135 129
136 if (!(name in listenedFilterChanges)) 130 if (!(name in listenedFilterChanges))
137 { 131 {
138 listenedFilterChanges[name] = null; 132 listenedFilterChanges[name] = null;
139 FilterNotifier.on(name, function() 133 FilterNotifier.on(name, function()
140 { 134 {
141 var args = [type, action]; 135 let args = [type, action];
142 for (var i = 0; i < arguments.length; i++) 136 for (let arg of arguments)
143 args.push(arguments[i]); 137 args.push(arg);
144 sendMessage.apply(null, args); 138 sendMessage.apply(null, args);
145 }); 139 });
146 } 140 }
147 }); 141 };
Thomas Greiner 2017/01/18 11:40:09 Detail: This semicolon is still left over from you
kzar 2017/01/18 11:54:41 Whoops, Done.
148 } 142 }
149 143
150 function getListenerFilters(page) 144 function getListenerFilters(page)
151 { 145 {
152 var listenerFilters = changeListeners.get(page); 146 let listenerFilters = changeListeners.get(page);
153 if (!listenerFilters) 147 if (!listenerFilters)
154 { 148 {
155 listenerFilters = Object.create(null); 149 listenerFilters = Object.create(null);
156 changeListeners.set(page, listenerFilters); 150 changeListeners.set(page, listenerFilters);
157 } 151 }
158 return listenerFilters; 152 return listenerFilters;
159 } 153 }
160 154
161 port.on("app.get", (message, sender) => 155 port.on("app.get", (message, sender) =>
162 { 156 {
163 if (message.what == "issues") 157 if (message.what == "issues")
164 { 158 {
165 var subscriptionInit = tryRequire("subscriptionInit"); 159 let subscriptionInit = tryRequire("subscriptionInit");
166 return { 160 return {
167 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false, 161 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false,
168 legacySafariVersion: (info.platform == "safari" && ( 162 legacySafariVersion: (info.platform == "safari" && (
169 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforel oad breaks websites in Safari 5 163 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforel oad breaks websites in Safari 5
170 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensi ons are broken in 6.1 and 7.0 164 Services.vc.compare(info.platformVersion, "6.1") == 0 || // extensi ons are broken in 6.1 and 7.0
171 Services.vc.compare(info.platformVersion, "7.0") == 0)) 165 Services.vc.compare(info.platformVersion, "7.0") == 0))
172 }; 166 };
173 } 167 }
174 168
175 if (message.what == "doclink") 169 if (message.what == "doclink")
176 return Utils.getDocLink(message.link); 170 return Utils.getDocLink(message.link);
177 171
178 if (message.what == "localeInfo") 172 if (message.what == "localeInfo")
179 { 173 {
180 var bidiDir; 174 let bidiDir;
181 if ("chromeRegistry" in Utils) 175 if ("chromeRegistry" in Utils)
182 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; 176 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr ";
183 else 177 else
184 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 178 bidiDir = ext.i18n.getMessage("@@bidi_dir");
185 179
186 return {locale: Utils.appLocale, bidiDir: bidiDir}; 180 return {locale: Utils.appLocale, bidiDir: bidiDir};
187 } 181 }
188 182
189 if (message.what == "features") 183 if (message.what == "features")
190 { 184 {
(...skipping 14 matching lines...) Expand all
205 }); 199 });
206 200
207 port.on("app.open", (message, sender) => 201 port.on("app.open", (message, sender) =>
208 { 202 {
209 if (message.what == "options") 203 if (message.what == "options")
210 ext.showOptions(); 204 ext.showOptions();
211 }); 205 });
212 206
213 port.on("filters.add", (message, sender) => 207 port.on("filters.add", (message, sender) =>
214 { 208 {
215 var result = require("filterValidation").parseFilter(message.text); 209 let result = require("filterValidation").parseFilter(message.text);
216 var errors = []; 210 let errors = [];
217 if (result.error) 211 if (result.error)
218 errors.push(result.error.toString()); 212 errors.push(result.error.toString());
219 else if (result.filter) 213 else if (result.filter)
220 FilterStorage.addFilter(result.filter); 214 FilterStorage.addFilter(result.filter);
221 215
222 return errors; 216 return errors;
223 }); 217 });
224 218
225 port.on("filters.blocked", (message, sender) => 219 port.on("filters.blocked", (message, sender) =>
226 { 220 {
227 var filter = defaultMatcher.matchesAny(message.url, 221 let filter = defaultMatcher.matchesAny(message.url,
228 RegExpFilter.typeMap[message.requestType], message.docDomain, 222 RegExpFilter.typeMap[message.requestType], message.docDomain,
229 message.thirdParty); 223 message.thirdParty);
230 224
231 return filter instanceof BlockingFilter; 225 return filter instanceof BlockingFilter;
232 }); 226 });
233 227
234 port.on("filters.get", (message, sender) => 228 port.on("filters.get", (message, sender) =>
235 { 229 {
236 if (message.what == "elemhideemulation") 230 if (message.what == "elemhideemulation")
237 { 231 {
238 var filters = []; 232 let filters = [];
239 var checkWhitelisted = require("whitelisting").checkWhitelisted; 233 const {checkWhitelisted} = require("whitelisting");
240 234
241 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 235 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame,
242 RegExpFilter.typeMap.DOCUMENT | 236 RegExpFilter.typeMap.DOCUMENT |
243 RegExpFilter.typeMap.ELEMHIDE)) 237 RegExpFilter.typeMap.ELEMHIDE))
244 { 238 {
245 var hostname = sender.frame.url.hostname; 239 const hostname = sender.frame.url.hostname;
Thomas Greiner 2017/01/18 11:40:09 Detail: I don't see a compelling enough use-case f
kzar 2017/01/18 11:54:41 Done.
246 filters = ElemHideEmulation.getRulesForDomain(hostname); 240 filters = ElemHideEmulation.getRulesForDomain(hostname);
247 filters = filters.map(function(filter) 241 filters = filters.map(filter =>
248 { 242 {
249 return { 243 return {
250 selector: filter.selector, 244 selector: filter.selector,
251 text: filter.text 245 text: filter.text
252 }; 246 };
253 }); 247 });
254 } 248 }
255 return filters; 249 return filters;
256 } 250 }
257 251
258 var subscription = Subscription.fromURL(message.subscriptionUrl); 252 let subscription = Subscription.fromURL(message.subscriptionUrl);
259 if (!subscription) 253 if (!subscription)
260 return []; 254 return [];
261 255
262 return subscription.filters.map(convertFilter); 256 return subscription.filters.map(convertFilter);
263 }); 257 });
264 258
265 port.on("filters.importRaw", (message, sender) => 259 port.on("filters.importRaw", (message, sender) =>
266 { 260 {
267 var result = require("filterValidation").parseFilters(message.text); 261 let result = require("filterValidation").parseFilters(message.text);
268 var errors = []; 262 let errors = [];
269 for (var i = 0; i < result.errors.length; i++) 263 for (let error of result.errors)
270 { 264 {
271 var error = result.errors[i];
272 if (error.type != "unexpected-filter-list-header") 265 if (error.type != "unexpected-filter-list-header")
273 errors.push(error.toString()); 266 errors.push(error.toString());
274 } 267 }
275 268
276 if (errors.length > 0) 269 if (errors.length > 0)
277 return errors; 270 return errors;
278 271
279 var seenFilter = Object.create(null); 272 let seenFilter = Object.create(null);
280 for (var i = 0; i < result.filters.length; i++) 273 for (let filter of result.filters)
281 { 274 {
282 var filter = result.filters[i];
283 FilterStorage.addFilter(filter); 275 FilterStorage.addFilter(filter);
284 seenFilter[filter.text] = null; 276 seenFilter[filter.text] = null;
285 } 277 }
286 278
287 if (!message.removeExisting) 279 if (!message.removeExisting)
288 return errors; 280 return errors;
289 281
290 for (var i = 0; i < FilterStorage.subscriptions.length; i++) 282 for (let subscription of FilterStorage.subscriptions)
291 { 283 {
292 var subscription = FilterStorage.subscriptions[i];
293 if (!(subscription instanceof SpecialSubscription)) 284 if (!(subscription instanceof SpecialSubscription))
294 continue; 285 continue;
295 286
296 for (var j = subscription.filters.length - 1; j >= 0; j--) 287 for (let j = subscription.filters.length - 1; j >= 0; j--)
297 { 288 {
298 var filter = subscription.filters[j]; 289 let filter = subscription.filters[j];
299 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) 290 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text))
300 continue; 291 continue;
301 292
302 if (!(filter.text in seenFilter)) 293 if (!(filter.text in seenFilter))
303 FilterStorage.removeFilter(filter); 294 FilterStorage.removeFilter(filter);
304 } 295 }
305 } 296 }
306 297
307 return errors; 298 return errors;
308 }); 299 });
309 300
310 port.on("filters.listen", (message, sender) => 301 port.on("filters.listen", (message, sender) =>
311 { 302 {
312 getListenerFilters(sender.page).filter = message.filter; 303 getListenerFilters(sender.page).filter = message.filter;
313 addFilterListeners("filter", message.filter); 304 addFilterListeners("filter", message.filter);
314 }); 305 });
315 306
316 port.on("filters.remove", (message, sender) => 307 port.on("filters.remove", (message, sender) =>
317 { 308 {
318 var filter = Filter.fromText(message.text); 309 let filter = Filter.fromText(message.text);
319 var subscription = null; 310 let subscription = null;
320 if (message.subscriptionUrl) 311 if (message.subscriptionUrl)
321 subscription = Subscription.fromURL(message.subscriptionUrl); 312 subscription = Subscription.fromURL(message.subscriptionUrl);
322 313
323 if (!subscription) 314 if (!subscription)
324 FilterStorage.removeFilter(filter); 315 FilterStorage.removeFilter(filter);
325 else 316 else
326 FilterStorage.removeFilter(filter, subscription, message.index); 317 FilterStorage.removeFilter(filter, subscription, message.index);
327 }); 318 });
328 319
329 port.on("prefs.get", (message, sender) => 320 port.on("prefs.get", (message, sender) =>
330 { 321 {
331 return Prefs[message.key]; 322 return Prefs[message.key];
332 }); 323 });
333 324
334 port.on("prefs.listen", (message, sender) => 325 port.on("prefs.listen", (message, sender) =>
335 { 326 {
336 getListenerFilters(sender.page).pref = message.filter; 327 getListenerFilters(sender.page).pref = message.filter;
337 message.filter.forEach(function(preference) 328 for (let preference of message.filter)
338 { 329 {
339 if (!(preference in listenedPreferences)) 330 if (!(preference in listenedPreferences))
340 { 331 {
341 listenedPreferences[preference] = null; 332 listenedPreferences[preference] = null;
342 Prefs.on(preference, function() 333 Prefs.on(preference, () =>
343 { 334 {
344 sendMessage("pref", preference, Prefs[preference]); 335 sendMessage("pref", preference, Prefs[preference]);
345 }); 336 });
346 } 337 }
347 }); 338 }
348 }); 339 });
349 340
350 port.on("prefs.toggle", (message, sender) => 341 port.on("prefs.toggle", (message, sender) =>
351 { 342 {
352 if (message.key == "notifications_ignoredcategories") 343 if (message.key == "notifications_ignoredcategories")
353 NotificationStorage.toggleIgnoreCategory("*"); 344 NotificationStorage.toggleIgnoreCategory("*");
354 else 345 else
355 Prefs[message.key] = !Prefs[message.key]; 346 Prefs[message.key] = !Prefs[message.key];
356 }); 347 });
357 348
358 port.on("subscriptions.add", (message, sender) => 349 port.on("subscriptions.add", (message, sender) =>
359 { 350 {
360 var subscription = Subscription.fromURL(message.url); 351 let subscription = Subscription.fromURL(message.url);
361 if ("title" in message) 352 if ("title" in message)
362 subscription.title = message.title; 353 subscription.title = message.title;
363 if ("homepage" in message) 354 if ("homepage" in message)
364 subscription.homepage = message.homepage; 355 subscription.homepage = message.homepage;
365 356
366 if (message.confirm) 357 if (message.confirm)
367 { 358 {
368 ext.showOptions(function() 359 ext.showOptions(() =>
369 { 360 {
370 sendMessage("app", "addSubscription", subscription); 361 sendMessage("app", "addSubscription", subscription);
371 }); 362 });
372 } 363 }
373 else 364 else
374 { 365 {
375 subscription.disabled = false; 366 subscription.disabled = false;
376 FilterStorage.addSubscription(subscription); 367 FilterStorage.addSubscription(subscription);
377 368
378 if (subscription instanceof DownloadableSubscription && !subscription.last Download) 369 if (subscription instanceof DownloadableSubscription && !subscription.last Download)
379 Synchronizer.execute(subscription); 370 Synchronizer.execute(subscription);
380 } 371 }
381 }); 372 });
382 373
383 port.on("subscriptions.get", (message, sender) => 374 port.on("subscriptions.get", (message, sender) =>
384 { 375 {
385 var subscriptions = FilterStorage.subscriptions.filter(function(s) 376 let subscriptions = FilterStorage.subscriptions.filter(s =>
386 { 377 {
387 if (message.ignoreDisabled && s.disabled) 378 if (message.ignoreDisabled && s.disabled)
388 return false; 379 return false;
389 if (s instanceof DownloadableSubscription && message.downloadable) 380 if (s instanceof DownloadableSubscription && message.downloadable)
390 return true; 381 return true;
391 if (s instanceof SpecialSubscription && message.special) 382 if (s instanceof SpecialSubscription && message.special)
392 return true; 383 return true;
393 return false; 384 return false;
394 }); 385 });
395 386
396 return subscriptions.map(convertSubscription); 387 return subscriptions.map(convertSubscription);
397 }); 388 });
398 389
399 port.on("subscriptions.listen", (message, sender) => 390 port.on("subscriptions.listen", (message, sender) =>
400 { 391 {
401 getListenerFilters(sender.page).subscription = message.filter; 392 getListenerFilters(sender.page).subscription = message.filter;
402 addFilterListeners("subscription", message.filter); 393 addFilterListeners("subscription", message.filter);
403 }); 394 });
404 395
405 port.on("subscriptions.remove", (message, sender) => 396 port.on("subscriptions.remove", (message, sender) =>
406 { 397 {
407 var subscription = Subscription.fromURL(message.url); 398 let subscription = Subscription.fromURL(message.url);
408 if (subscription.url in FilterStorage.knownSubscriptions) 399 if (subscription.url in FilterStorage.knownSubscriptions)
409 FilterStorage.removeSubscription(subscription); 400 FilterStorage.removeSubscription(subscription);
410 }); 401 });
411 402
412 port.on("subscriptions.toggle", (message, sender) => 403 port.on("subscriptions.toggle", (message, sender) =>
413 { 404 {
414 var subscription = Subscription.fromURL(message.url); 405 let subscription = Subscription.fromURL(message.url);
415 if (subscription.url in FilterStorage.knownSubscriptions) 406 if (subscription.url in FilterStorage.knownSubscriptions)
416 { 407 {
417 if (subscription.disabled || message.keepInstalled) 408 if (subscription.disabled || message.keepInstalled)
418 subscription.disabled = !subscription.disabled; 409 subscription.disabled = !subscription.disabled;
419 else 410 else
420 FilterStorage.removeSubscription(subscription); 411 FilterStorage.removeSubscription(subscription);
421 } 412 }
422 else 413 else
423 { 414 {
424 subscription.disabled = false; 415 subscription.disabled = false;
425 subscription.title = message.title; 416 subscription.title = message.title;
426 subscription.homepage = message.homepage; 417 subscription.homepage = message.homepage;
427 FilterStorage.addSubscription(subscription); 418 FilterStorage.addSubscription(subscription);
428 if (!subscription.lastDownload) 419 if (!subscription.lastDownload)
429 Synchronizer.execute(subscription); 420 Synchronizer.execute(subscription);
430 } 421 }
431 }); 422 });
432 423
433 port.on("subscriptions.update", (message, sender) => 424 port.on("subscriptions.update", (message, sender) =>
434 { 425 {
435 var subscriptions = message.url ? [Subscription.fromURL(message.url)] : 426 let subscriptions = message.url ? [Subscription.fromURL(message.url)] :
436 FilterStorage.subscriptions; 427 FilterStorage.subscriptions;
437 for (var i = 0; i < subscriptions.length; i++) 428 for (let subscription of subscriptions)
438 { 429 {
439 var subscription = subscriptions[i];
440 if (subscription instanceof DownloadableSubscription) 430 if (subscription instanceof DownloadableSubscription)
441 Synchronizer.execute(subscription, true); 431 Synchronizer.execute(subscription, true);
442 } 432 }
443 }); 433 });
444 })(this); 434 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld