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

Side by Side Diff: messageResponder.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Patch Set: Removed unused import Created March 15, 2017, 3:16 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 | « lib/antiadblockInit.js ('k') | new-options.js » ('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 /* globals require */
19
18 "use strict"; 20 "use strict";
19 21
20 (function(global) 22 (function(global)
21 { 23 {
22 let ext = global.ext || require("ext_background"); 24 let ext = global.ext || require("ext_background");
23 25
24 const {port} = require("messaging"); 26 const {port} = require("messaging");
25 const {Prefs} = require("prefs"); 27 const {Prefs} = require("prefs");
26 const {Utils} = require("utils"); 28 const {Utils} = require("utils");
27 const {FilterStorage} = require("filterStorage"); 29 const {FilterStorage} = require("filterStorage");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 "lastDownload", "title", "url"], subscription); 73 "lastDownload", "title", "url"], subscription);
72 obj.isDownloading = Synchronizer.isExecuting(subscription.url); 74 obj.isDownloading = Synchronizer.isExecuting(subscription.url);
73 return obj; 75 return obj;
74 } 76 }
75 77
76 let convertFilter = convertObject.bind(null, ["text"]); 78 let convertFilter = convertObject.bind(null, ["text"]);
77 79
78 let changeListeners = new ext.PageMap(); 80 let changeListeners = new ext.PageMap();
79 let listenedPreferences = Object.create(null); 81 let listenedPreferences = Object.create(null);
80 let listenedFilterChanges = Object.create(null); 82 let listenedFilterChanges = Object.create(null);
81 let messageTypes = { 83 let messageTypes = new Map([
82 "app": "app.respond", 84 ["app", "app.respond"],
83 "filter": "filters.respond", 85 ["filter", "filters.respond"],
84 "pref": "prefs.respond", 86 ["pref", "prefs.respond"],
85 "subscription": "subscriptions.respond" 87 ["subscription", "subscriptions.respond"]
86 }; 88 ]);
87 89
88 function sendMessage(type, action) 90 function sendMessage(type, action, ...args)
89 { 91 {
90 let pages = changeListeners.keys(); 92 let pages = changeListeners.keys();
91 if (pages.length == 0) 93 if (pages.length == 0)
92 return; 94 return;
93 95
94 let args = []; 96 let convertedArgs = [];
95 for (let i = 2; i < arguments.length; i++) 97 for (let arg of args)
96 { 98 {
97 let arg = arguments[i];
98 if (arg instanceof Subscription) 99 if (arg instanceof Subscription)
99 args.push(convertSubscription(arg)); 100 convertedArgs.push(convertSubscription(arg));
100 else if (arg instanceof Filter) 101 else if (arg instanceof Filter)
101 args.push(convertFilter(arg)); 102 convertedArgs.push(convertFilter(arg));
102 else 103 else
103 args.push(arg); 104 convertedArgs.push(arg);
104 } 105 }
105 106
106 for (let page of pages) 107 for (let page of pages)
107 { 108 {
108 let filters = changeListeners.get(page); 109 let filters = changeListeners.get(page);
109 let actions = filters[type]; 110 let actions = filters[type];
110 if (actions && actions.indexOf(action) != -1) 111 if (actions && actions.indexOf(action) != -1)
111 { 112 {
112 page.sendMessage({ 113 page.sendMessage({
113 type: messageTypes[type], 114 type: messageTypes.get(type),
114 action: action, 115 action,
115 args: args 116 args: convertedArgs
116 }); 117 });
117 } 118 }
118 } 119 }
119 } 120 }
120 121
121 function addFilterListeners(type, actions) 122 function addFilterListeners(type, actions)
122 { 123 {
123 for (let action of actions) 124 for (let action of actions)
124 { 125 {
125 let name; 126 let name;
126 if (type == "filter" && action == "loaded") 127 if (type == "filter" && action == "loaded")
127 name = "load"; 128 name = "load";
128 else 129 else
129 name = type + "." + action; 130 name = type + "." + action;
130 131
131 if (!(name in listenedFilterChanges)) 132 if (!(name in listenedFilterChanges))
132 { 133 {
133 listenedFilterChanges[name] = null; 134 listenedFilterChanges[name] = null;
134 FilterNotifier.on(name, function() 135 FilterNotifier.on(name, (...args) =>
135 { 136 {
136 let args = [type, action]; 137 sendMessage(type, action, ...args);
137 for (let arg of arguments)
138 args.push(arg);
139 sendMessage.apply(null, args);
140 }); 138 });
141 } 139 }
142 } 140 }
143 } 141 }
144 142
145 function getListenerFilters(page) 143 function getListenerFilters(page)
146 { 144 {
147 let listenerFilters = changeListeners.get(page); 145 let listenerFilters = changeListeners.get(page);
148 if (!listenerFilters) 146 if (!listenerFilters)
149 { 147 {
150 listenerFilters = Object.create(null); 148 listenerFilters = Object.create(null);
151 changeListeners.set(page, listenerFilters); 149 changeListeners.set(page, listenerFilters);
152 } 150 }
153 return listenerFilters; 151 return listenerFilters;
154 } 152 }
155 153
156 port.on("app.get", (message, sender) => 154 port.on("app.get", (message, sender) =>
157 { 155 {
158 if (message.what == "issues") 156 if (message.what == "issues")
159 { 157 {
160 let subscriptionInit = tryRequire("subscriptionInit"); 158 let subscriptionInit = tryRequire("subscriptionInit");
161 return { 159 return {
162 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false 160 filterlistsReinitialized: subscriptionInit
161 ? subscriptionInit.reinitialized : false
163 }; 162 };
164 } 163 }
165 164
166 if (message.what == "doclink") 165 if (message.what == "doclink")
167 return Utils.getDocLink(message.link); 166 return Utils.getDocLink(message.link);
168 167
169 if (message.what == "localeInfo") 168 if (message.what == "localeInfo")
170 { 169 {
171 let bidiDir; 170 let bidiDir;
172 if ("chromeRegistry" in Utils) 171 if ("chromeRegistry" in Utils)
173 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; 172 {
173 let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus");
174 bidiDir = isRtl ? "rtl" : "ltr";
175 }
174 else 176 else
175 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 177 bidiDir = ext.i18n.getMessage("@@bidi_dir");
176 178
177 return {locale: Utils.appLocale, bidiDir: bidiDir}; 179 return {locale: Utils.appLocale, bidiDir};
178 } 180 }
179 181
180 if (message.what == "features") 182 if (message.what == "features")
181 { 183 {
182 return { 184 return {
183 devToolsPanel: info.platform == "chromium" 185 devToolsPanel: info.platform == "chromium"
184 }; 186 };
185 } 187 }
186 188
187 return info[message.what]; 189 return info[message.what];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 { 225 {
224 if (message.what == "elemhideemulation") 226 if (message.what == "elemhideemulation")
225 { 227 {
226 let filters = []; 228 let filters = [];
227 const {checkWhitelisted} = require("whitelisting"); 229 const {checkWhitelisted} = require("whitelisting");
228 230
229 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 231 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame,
230 RegExpFilter.typeMap.DOCUMENT | 232 RegExpFilter.typeMap.DOCUMENT |
231 RegExpFilter.typeMap.ELEMHIDE)) 233 RegExpFilter.typeMap.ELEMHIDE))
232 { 234 {
233 let hostname = sender.frame.url.hostname; 235 let {hostname} = sender.frame.url;
234 filters = ElemHideEmulation.getRulesForDomain(hostname); 236 filters = ElemHideEmulation.getRulesForDomain(hostname);
235 filters = filters.map(filter => 237 filters = filters.map((filter) =>
236 { 238 {
237 return { 239 return {
238 selector: filter.selector, 240 selector: filter.selector,
239 text: filter.text 241 text: filter.text
240 }; 242 };
241 }); 243 });
242 } 244 }
243 return filters; 245 return filters;
244 } 246 }
245 247
(...skipping 28 matching lines...) Expand all
274 return errors; 276 return errors;
275 277
276 for (let subscription of FilterStorage.subscriptions) 278 for (let subscription of FilterStorage.subscriptions)
277 { 279 {
278 if (!(subscription instanceof SpecialSubscription)) 280 if (!(subscription instanceof SpecialSubscription))
279 continue; 281 continue;
280 282
281 for (let j = subscription.filters.length - 1; j >= 0; j--) 283 for (let j = subscription.filters.length - 1; j >= 0; j--)
282 { 284 {
283 let filter = subscription.filters[j]; 285 let filter = subscription.filters[j];
284 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) 286 if (/^@@\|\|([^/:]+)\^\$document$/.test(filter.text))
285 continue; 287 continue;
286 288
287 if (!(filter.text in seenFilter)) 289 if (!(filter.text in seenFilter))
288 FilterStorage.removeFilter(filter); 290 FilterStorage.removeFilter(filter);
289 } 291 }
290 } 292 }
291 293
292 return errors; 294 return errors;
293 }); 295 });
294 296
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 ext.showOptions(() => 355 ext.showOptions(() =>
354 { 356 {
355 sendMessage("app", "addSubscription", subscription); 357 sendMessage("app", "addSubscription", subscription);
356 }); 358 });
357 } 359 }
358 else 360 else
359 { 361 {
360 subscription.disabled = false; 362 subscription.disabled = false;
361 FilterStorage.addSubscription(subscription); 363 FilterStorage.addSubscription(subscription);
362 364
363 if (subscription instanceof DownloadableSubscription && !subscription.last Download) 365 if (subscription instanceof DownloadableSubscription &&
366 !subscription.lastDownload)
364 Synchronizer.execute(subscription); 367 Synchronizer.execute(subscription);
365 } 368 }
366 }); 369 });
367 370
368 port.on("subscriptions.get", (message, sender) => 371 port.on("subscriptions.get", (message, sender) =>
369 { 372 {
370 let subscriptions = FilterStorage.subscriptions.filter(s => 373 let subscriptions = FilterStorage.subscriptions.filter((s) =>
371 { 374 {
372 if (message.ignoreDisabled && s.disabled) 375 if (message.ignoreDisabled && s.disabled)
373 return false; 376 return false;
374 if (s instanceof DownloadableSubscription && message.downloadable) 377 if (s instanceof DownloadableSubscription && message.downloadable)
375 return true; 378 return true;
376 if (s instanceof SpecialSubscription && message.special) 379 if (s instanceof SpecialSubscription && message.special)
377 return true; 380 return true;
378 return false; 381 return false;
379 }); 382 });
380 383
(...skipping 29 matching lines...) Expand all
410 subscription.title = message.title; 413 subscription.title = message.title;
411 subscription.homepage = message.homepage; 414 subscription.homepage = message.homepage;
412 FilterStorage.addSubscription(subscription); 415 FilterStorage.addSubscription(subscription);
413 if (!subscription.lastDownload) 416 if (!subscription.lastDownload)
414 Synchronizer.execute(subscription); 417 Synchronizer.execute(subscription);
415 } 418 }
416 }); 419 });
417 420
418 port.on("subscriptions.update", (message, sender) => 421 port.on("subscriptions.update", (message, sender) =>
419 { 422 {
420 let subscriptions = message.url ? [Subscription.fromURL(message.url)] : 423 let {subscriptions} = FilterStorage;
421 FilterStorage.subscriptions; 424 if (message.url)
425 subscriptions = [Subscription.fromURL(message.url)];
426
422 for (let subscription of subscriptions) 427 for (let subscription of subscriptions)
423 { 428 {
424 if (subscription instanceof DownloadableSubscription) 429 if (subscription instanceof DownloadableSubscription)
425 Synchronizer.execute(subscription, true); 430 Synchronizer.execute(subscription, true);
426 } 431 }
427 }); 432 });
428 })(this); 433 })(this);
OLDNEW
« no previous file with comments | « lib/antiadblockInit.js ('k') | new-options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld