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: Avoid violating operator-linebreak rule Created March 15, 2017, 4:43 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 let result = subscriptionInit ? subscriptionInit.reinitialized : false;
162 filterlistsReinitialized: subscriptionInit ? subscriptionInit.reinitiali zed : false 160 return {filterlistsReinitialized: result};
163 };
164 } 161 }
165 162
166 if (message.what == "doclink") 163 if (message.what == "doclink")
167 return Utils.getDocLink(message.link); 164 return Utils.getDocLink(message.link);
168 165
169 if (message.what == "localeInfo") 166 if (message.what == "localeInfo")
170 { 167 {
171 let bidiDir; 168 let bidiDir;
172 if ("chromeRegistry" in Utils) 169 if ("chromeRegistry" in Utils)
173 bidiDir = Utils.chromeRegistry.isLocaleRTL("adblockplus") ? "rtl" : "ltr "; 170 {
171 let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus");
172 bidiDir = isRtl ? "rtl" : "ltr";
173 }
174 else 174 else
175 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 175 bidiDir = ext.i18n.getMessage("@@bidi_dir");
176 176
177 return {locale: Utils.appLocale, bidiDir: bidiDir}; 177 return {locale: Utils.appLocale, bidiDir};
178 } 178 }
179 179
180 if (message.what == "features") 180 if (message.what == "features")
181 { 181 {
182 return { 182 return {
183 devToolsPanel: info.platform == "chromium" 183 devToolsPanel: info.platform == "chromium"
184 }; 184 };
185 } 185 }
186 186
187 return info[message.what]; 187 return info[message.what];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 { 223 {
224 if (message.what == "elemhideemulation") 224 if (message.what == "elemhideemulation")
225 { 225 {
226 let filters = []; 226 let filters = [];
227 const {checkWhitelisted} = require("whitelisting"); 227 const {checkWhitelisted} = require("whitelisting");
228 228
229 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 229 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame,
230 RegExpFilter.typeMap.DOCUMENT | 230 RegExpFilter.typeMap.DOCUMENT |
231 RegExpFilter.typeMap.ELEMHIDE)) 231 RegExpFilter.typeMap.ELEMHIDE))
232 { 232 {
233 let hostname = sender.frame.url.hostname; 233 let {hostname} = sender.frame.url;
234 filters = ElemHideEmulation.getRulesForDomain(hostname); 234 filters = ElemHideEmulation.getRulesForDomain(hostname);
235 filters = filters.map(filter => 235 filters = filters.map((filter) =>
236 { 236 {
237 return { 237 return {
238 selector: filter.selector, 238 selector: filter.selector,
239 text: filter.text 239 text: filter.text
240 }; 240 };
241 }); 241 });
242 } 242 }
243 return filters; 243 return filters;
244 } 244 }
245 245
(...skipping 28 matching lines...) Expand all
274 return errors; 274 return errors;
275 275
276 for (let subscription of FilterStorage.subscriptions) 276 for (let subscription of FilterStorage.subscriptions)
277 { 277 {
278 if (!(subscription instanceof SpecialSubscription)) 278 if (!(subscription instanceof SpecialSubscription))
279 continue; 279 continue;
280 280
281 for (let j = subscription.filters.length - 1; j >= 0; j--) 281 for (let j = subscription.filters.length - 1; j >= 0; j--)
282 { 282 {
283 let filter = subscription.filters[j]; 283 let filter = subscription.filters[j];
284 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) 284 if (/^@@\|\|([^/:]+)\^\$document$/.test(filter.text))
285 continue; 285 continue;
286 286
287 if (!(filter.text in seenFilter)) 287 if (!(filter.text in seenFilter))
288 FilterStorage.removeFilter(filter); 288 FilterStorage.removeFilter(filter);
289 } 289 }
290 } 290 }
291 291
292 return errors; 292 return errors;
293 }); 293 });
294 294
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 ext.showOptions(() => 353 ext.showOptions(() =>
354 { 354 {
355 sendMessage("app", "addSubscription", subscription); 355 sendMessage("app", "addSubscription", subscription);
356 }); 356 });
357 } 357 }
358 else 358 else
359 { 359 {
360 subscription.disabled = false; 360 subscription.disabled = false;
361 FilterStorage.addSubscription(subscription); 361 FilterStorage.addSubscription(subscription);
362 362
363 if (subscription instanceof DownloadableSubscription && !subscription.last Download) 363 if (subscription instanceof DownloadableSubscription &&
364 !subscription.lastDownload)
364 Synchronizer.execute(subscription); 365 Synchronizer.execute(subscription);
365 } 366 }
366 }); 367 });
367 368
368 port.on("subscriptions.get", (message, sender) => 369 port.on("subscriptions.get", (message, sender) =>
369 { 370 {
370 let subscriptions = FilterStorage.subscriptions.filter(s => 371 let subscriptions = FilterStorage.subscriptions.filter((s) =>
371 { 372 {
372 if (message.ignoreDisabled && s.disabled) 373 if (message.ignoreDisabled && s.disabled)
373 return false; 374 return false;
374 if (s instanceof DownloadableSubscription && message.downloadable) 375 if (s instanceof DownloadableSubscription && message.downloadable)
375 return true; 376 return true;
376 if (s instanceof SpecialSubscription && message.special) 377 if (s instanceof SpecialSubscription && message.special)
377 return true; 378 return true;
378 return false; 379 return false;
379 }); 380 });
380 381
(...skipping 29 matching lines...) Expand all
410 subscription.title = message.title; 411 subscription.title = message.title;
411 subscription.homepage = message.homepage; 412 subscription.homepage = message.homepage;
412 FilterStorage.addSubscription(subscription); 413 FilterStorage.addSubscription(subscription);
413 if (!subscription.lastDownload) 414 if (!subscription.lastDownload)
414 Synchronizer.execute(subscription); 415 Synchronizer.execute(subscription);
415 } 416 }
416 }); 417 });
417 418
418 port.on("subscriptions.update", (message, sender) => 419 port.on("subscriptions.update", (message, sender) =>
419 { 420 {
420 let subscriptions = message.url ? [Subscription.fromURL(message.url)] : 421 let {subscriptions} = FilterStorage;
421 FilterStorage.subscriptions; 422 if (message.url)
423 subscriptions = [Subscription.fromURL(message.url)];
424
422 for (let subscription of subscriptions) 425 for (let subscription of subscriptions)
423 { 426 {
424 if (subscription instanceof DownloadableSubscription) 427 if (subscription instanceof DownloadableSubscription)
425 Synchronizer.execute(subscription, true); 428 Synchronizer.execute(subscription, true);
426 } 429 }
427 }); 430 });
428 })(this); 431 })(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