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