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: Created Jan. 11, 2017, 8:41 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 (global =>
Sebastian Noack 2017/01/11 16:29:08 Do we even need an IIFE with ES6? Wouldn't a simpl
kzar 2017/01/13 08:44:49 Good point, Done.
Sebastian Noack 2017/01/13 11:54:48 I just noticed, you'd also have to use strict mode
kzar 2017/01/16 04:41:49 Done.
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 port = require("messaging").port; 23 let port = require("messaging").port;
24 var Prefs = require("prefs").Prefs; 24 let Prefs = require("prefs").Prefs;
25 var Utils = require("utils").Utils; 25 let Utils = require("utils").Utils;
26 var FilterStorage = require("filterStorage").FilterStorage; 26 let FilterStorage = require("filterStorage").FilterStorage;
27 var FilterNotifier = require("filterNotifier").FilterNotifier; 27 let FilterNotifier = require("filterNotifier").FilterNotifier;
28 var defaultMatcher = require("matcher").defaultMatcher; 28 let defaultMatcher = require("matcher").defaultMatcher;
29 var ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation; 29 let ElemHideEmulation = require("elemHideEmulation").ElemHideEmulation;
30 var NotificationStorage = require("notification").Notification; 30 let NotificationStorage = require("notification").Notification;
31 31
32 var filterClasses = require("filterClasses"); 32 let filterClasses = require("filterClasses");
33 var Filter = filterClasses.Filter; 33 let Filter = filterClasses.Filter;
34 var BlockingFilter = filterClasses.BlockingFilter; 34 let BlockingFilter = filterClasses.BlockingFilter;
35 var RegExpFilter = filterClasses.RegExpFilter; 35 let RegExpFilter = filterClasses.RegExpFilter;
36 var Synchronizer = require("synchronizer").Synchronizer; 36 let Synchronizer = require("synchronizer").Synchronizer;
37 37
38 var info = require("info"); 38 let info = require("info");
39 var subscriptionClasses = require("subscriptionClasses"); 39 let subscriptionClasses = require("subscriptionClasses");
40 var Subscription = subscriptionClasses.Subscription; 40 let Subscription = subscriptionClasses.Subscription;
41 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; 41 let DownloadableSubscription = subscriptionClasses.DownloadableSubscription;
42 var SpecialSubscription = subscriptionClasses.SpecialSubscription; 42 let SpecialSubscription = subscriptionClasses.SpecialSubscription;
43 43
44 // Some modules doesn't exist on Firefox. Moreover, 44 // Some modules doesn't exist on Firefox. Moreover,
45 // require() throws an exception on Firefox in that case. 45 // require() throws an exception on Firefox in that case.
46 // However, try/catch causes the whole function to to be 46 // However, try/catch causes the whole function to to be
47 // deoptimized on V8. So we wrap it into another function. 47 // deoptimized on V8. So we wrap it into another function.
48 function tryRequire(module) 48 function tryRequire(module)
49 { 49 {
50 try 50 try
51 { 51 {
52 return require(module); 52 return require(module);
53 } 53 }
54 catch (e) 54 catch (e)
55 { 55 {
56 return null; 56 return null;
57 } 57 }
58 } 58 }
59 59
60 function convertObject(keys, obj) 60 function convertObject(keys, obj)
61 { 61 {
62 var result = {}; 62 let result = {};
63 for (var i = 0; i < keys.length; i++) 63 for (let key of keys)
64 {
65 var key = keys[i];
66 if (key in obj) 64 if (key in obj)
67 result[key] = obj[key]; 65 result[key] = obj[key];
68 }
69 return result; 66 return result;
70 } 67 }
71 68
72 function convertSubscription(subscription) 69 function convertSubscription(subscription)
73 { 70 {
74 var obj = convertObject(["disabled", "downloadStatus", "homepage", 71 let obj = convertObject(["disabled", "downloadStatus", "homepage",
75 "lastDownload", "title", "url"], subscription); 72 "lastDownload", "title", "url"], subscription);
76 obj.isDownloading = Synchronizer.isExecuting(subscription.url); 73 obj.isDownloading = Synchronizer.isExecuting(subscription.url);
77 return obj; 74 return obj;
78 } 75 }
79 76
80 var convertFilter = convertObject.bind(null, ["text"]); 77 let convertFilter = convertObject.bind(null, ["text"]);
81 78
82 var changeListeners = new global.ext.PageMap(); 79 let changeListeners = new global.ext.PageMap();
83 var listenedPreferences = Object.create(null); 80 let listenedPreferences = Object.create(null);
84 var listenedFilterChanges = Object.create(null); 81 let listenedFilterChanges = Object.create(null);
85 var messageTypes = { 82 let messageTypes = {
86 "app": "app.respond", 83 "app": "app.respond",
87 "filter": "filters.respond", 84 "filter": "filters.respond",
88 "pref": "prefs.respond", 85 "pref": "prefs.respond",
89 "subscription": "subscriptions.respond" 86 "subscription": "subscriptions.respond"
90 }; 87 };
91 88
92 function sendMessage(type, action) 89 function sendMessage(type, action)
93 { 90 {
94 var pages = changeListeners.keys(); 91 let pages = changeListeners.keys();
95 if (pages.length == 0) 92 if (pages.length == 0)
96 return; 93 return;
97 94
98 var args = []; 95 let args = [];
99 for (var i = 2; i < arguments.length; i++) 96 for (let i = 2; i < arguments.length; i++)
100 { 97 {
101 var arg = arguments[i]; 98 let arg = arguments[i];
102 if (arg instanceof Subscription) 99 if (arg instanceof Subscription)
103 args.push(convertSubscription(arg)); 100 args.push(convertSubscription(arg));
104 else if (arg instanceof Filter) 101 else if (arg instanceof Filter)
105 args.push(convertFilter(arg)); 102 args.push(convertFilter(arg));
106 else 103 else
107 args.push(arg); 104 args.push(arg);
108 } 105 }
109 106
110 for (var j = 0; j < pages.length; j++) 107 for (let page of pages)
111 { 108 {
112 var page = pages[j]; 109 let filters = changeListeners.get(page);
113 var filters = changeListeners.get(page); 110 let actions = filters[type];
114 var actions = filters[type];
115 if (actions && actions.indexOf(action) != -1) 111 if (actions && actions.indexOf(action) != -1)
116 { 112 {
117 page.sendMessage({ 113 page.sendMessage({
118 type: messageTypes[type], 114 type: messageTypes[type],
119 action: action, 115 action: action,
120 args: args 116 args: args
121 }); 117 });
122 } 118 }
123 } 119 }
124 } 120 }
125 121
126 function addFilterListeners(type, actions) 122 function addFilterListeners(type, actions)
127 { 123 {
128 actions.forEach(function(action) 124 actions.forEach(action =>
129 { 125 {
130 var name; 126 let name;
131 if (type == "filter" && action == "loaded") 127 if (type == "filter" && action == "loaded")
132 name = "load"; 128 name = "load";
133 else 129 else
134 name = type + "." + action; 130 name = type + "." + action;
135 131
136 if (!(name in listenedFilterChanges)) 132 if (!(name in listenedFilterChanges))
137 { 133 {
138 listenedFilterChanges[name] = null; 134 listenedFilterChanges[name] = null;
139 FilterNotifier.on(name, function() 135 FilterNotifier.on(name, function()
kzar 2017/01/11 08:50:44 (I originally used an arrow function here but that
140 { 136 {
141 var args = [type, action]; 137 let args = [type, action];
142 for (var i = 0; i < arguments.length; i++) 138 for (let arg of arguments)
143 args.push(arguments[i]); 139 args.push(arg);
144 sendMessage.apply(null, args); 140 sendMessage.apply(null, args);
145 }); 141 });
146 } 142 }
147 }); 143 });
148 } 144 }
149 145
150 function getListenerFilters(page) 146 function getListenerFilters(page)
151 { 147 {
152 var listenerFilters = changeListeners.get(page); 148 let listenerFilters = changeListeners.get(page);
153 if (!listenerFilters) 149 if (!listenerFilters)
154 { 150 {
155 listenerFilters = Object.create(null); 151 listenerFilters = Object.create(null);
156 changeListeners.set(page, listenerFilters); 152 changeListeners.set(page, listenerFilters);
157 } 153 }
158 return listenerFilters; 154 return listenerFilters;
159 } 155 }
160 156
161 port.on("app.get", (message, sender) => 157 port.on("app.get", (message, sender) =>
162 { 158 {
163 if (message.what == "issues") 159 if (message.what == "issues")
164 { 160 {
165 var subscriptionInit = tryRequire("subscriptionInit"); 161 let subscriptionInit = tryRequire("subscriptionInit");
166 return { 162 return {
167 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false, 163 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false,
168 legacySafariVersion: (info.platform == "safari" && ( 164 legacySafariVersion: (info.platform == "safari" && (
169 Services.vc.compare(info.platformVersion, "6.0") < 0 || // beforel oad breaks websites in Safari 5 165 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 166 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)) 167 Services.vc.compare(info.platformVersion, "7.0") == 0))
172 }; 168 };
173 } 169 }
174 170
175 if (message.what == "doclink") 171 if (message.what == "doclink")
176 return Utils.getDocLink(message.link); 172 return Utils.getDocLink(message.link);
177 173
178 if (message.what == "localeInfo") 174 if (message.what == "localeInfo")
179 { 175 {
180 var bidiDir; 176 let bidiDir;
181 if ("chromeRegistry" in Utils) 177 if ("chromeRegistry" in Utils)
182 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; 178 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr ";
183 else 179 else
184 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 180 bidiDir = ext.i18n.getMessage("@@bidi_dir");
185 181
186 return {locale: Utils.appLocale, bidiDir: bidiDir}; 182 return {locale: Utils.appLocale, bidiDir: bidiDir};
187 } 183 }
188 184
189 if (message.what == "features") 185 if (message.what == "features")
190 { 186 {
(...skipping 14 matching lines...) Expand all
205 }); 201 });
206 202
207 port.on("app.open", (message, sender) => 203 port.on("app.open", (message, sender) =>
208 { 204 {
209 if (message.what == "options") 205 if (message.what == "options")
210 ext.showOptions(); 206 ext.showOptions();
211 }); 207 });
212 208
213 port.on("filters.add", (message, sender) => 209 port.on("filters.add", (message, sender) =>
214 { 210 {
215 var result = require("filterValidation").parseFilter(message.text); 211 let result = require("filterValidation").parseFilter(message.text);
216 var errors = []; 212 let errors = [];
217 if (result.error) 213 if (result.error)
218 errors.push(result.error.toString()); 214 errors.push(result.error.toString());
219 else if (result.filter) 215 else if (result.filter)
220 FilterStorage.addFilter(result.filter); 216 FilterStorage.addFilter(result.filter);
221 217
222 return errors; 218 return errors;
223 }); 219 });
224 220
225 port.on("filters.blocked", (message, sender) => 221 port.on("filters.blocked", (message, sender) =>
226 { 222 {
227 var filter = defaultMatcher.matchesAny(message.url, 223 let filter = defaultMatcher.matchesAny(message.url,
228 RegExpFilter.typeMap[message.requestType], message.docDomain, 224 RegExpFilter.typeMap[message.requestType], message.docDomain,
229 message.thirdParty); 225 message.thirdParty);
230 226
231 return filter instanceof BlockingFilter; 227 return filter instanceof BlockingFilter;
232 }); 228 });
233 229
234 port.on("filters.get", (message, sender) => 230 port.on("filters.get", (message, sender) =>
235 { 231 {
236 if (message.what == "elemhideemulation") 232 if (message.what == "elemhideemulation")
237 { 233 {
238 var filters = []; 234 let filters = [];
239 var checkWhitelisted = require("whitelisting").checkWhitelisted; 235 let checkWhitelisted = require("whitelisting").checkWhitelisted;
240 236
241 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 237 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame,
242 RegExpFilter.typeMap.DOCUMENT | 238 RegExpFilter.typeMap.DOCUMENT |
243 RegExpFilter.typeMap.ELEMHIDE)) 239 RegExpFilter.typeMap.ELEMHIDE))
244 { 240 {
245 var hostname = sender.frame.url.hostname; 241 let hostname = sender.frame.url.hostname;
246 filters = ElemHideEmulation.getRulesForDomain(hostname); 242 filters = ElemHideEmulation.getRulesForDomain(hostname);
247 filters = filters.map(function(filter) 243 filters = filters.map(filter =>
248 { 244 {
249 return { 245 return {
250 selector: filter.selector, 246 selector: filter.selector,
251 text: filter.text 247 text: filter.text
252 }; 248 };
253 }); 249 });
254 } 250 }
255 return filters; 251 return filters;
256 } 252 }
257 253
258 var subscription = Subscription.fromURL(message.subscriptionUrl); 254 let subscription = Subscription.fromURL(message.subscriptionUrl);
259 if (!subscription) 255 if (!subscription)
260 return []; 256 return [];
261 257
262 return subscription.filters.map(convertFilter); 258 return subscription.filters.map(convertFilter);
263 }); 259 });
264 260
265 port.on("filters.importRaw", (message, sender) => 261 port.on("filters.importRaw", (message, sender) =>
266 { 262 {
267 var result = require("filterValidation").parseFilters(message.text); 263 let result = require("filterValidation").parseFilters(message.text);
268 var errors = []; 264 let errors = [];
269 for (var i = 0; i < result.errors.length; i++) 265 for (let error of result.errors)
270 {
271 var error = result.errors[i];
272 if (error.type != "unexpected-filter-list-header") 266 if (error.type != "unexpected-filter-list-header")
273 errors.push(error.toString()); 267 errors.push(error.toString());
274 }
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 message.filter.forEach(preference =>
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 {
439 var subscription = subscriptions[i];
440 if (subscription instanceof DownloadableSubscription) 429 if (subscription instanceof DownloadableSubscription)
441 Synchronizer.execute(subscription, true); 430 Synchronizer.execute(subscription, true);
442 }
443 }); 431 });
444 })(this); 432 })(this);
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