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

Delta Between Two Patch Sets: messageResponder.js

Issue 29375899: Issue 4871 - Start using ESLint for adblockplusui (Closed)
Left Patch Set: Fix regressions with the new options page Created March 1, 2017, 8:25 a.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/antiadblockInit.js ('k') | new-options.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
22 (function(global)
20 { 23 {
21 if (typeof ext == "undefined") 24 let ext = global.ext || require("ext_background");
kzar 2017/03/08 14:15:54 I'm a bit confused by the discussion in https://co
22 window.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");
28 const {FilterNotifier} = require("filterNotifier"); 30 const {FilterNotifier} = require("filterNotifier");
29 const {defaultMatcher} = require("matcher"); 31 const {defaultMatcher} = require("matcher");
30 const {ElemHideEmulation} = require("elemHideEmulation"); 32 const {ElemHideEmulation} = require("elemHideEmulation");
31 const {Notification: NotificationStorage} = require("notification"); 33 const {Notification: NotificationStorage} = require("notification");
32 34
(...skipping 38 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, ...args) 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 convertedArgs = []; 96 let convertedArgs = [];
95 for (let arg of args) 97 for (let arg of args)
96 { 98 {
97 if (arg instanceof Subscription) 99 if (arg instanceof Subscription)
98 convertedArgs.push(convertSubscription(arg)); 100 convertedArgs.push(convertSubscription(arg));
99 else if (arg instanceof Filter) 101 else if (arg instanceof Filter)
100 convertedArgs.push(convertFilter(arg)); 102 convertedArgs.push(convertFilter(arg));
101 else 103 else
102 convertedArgs.push(arg); 104 convertedArgs.push(arg);
103 } 105 }
104 106
105 for (let page of pages) 107 for (let page of pages)
106 { 108 {
107 let filters = changeListeners.get(page); 109 let filters = changeListeners.get(page);
108 let actions = filters[type]; 110 let actions = filters[type];
109 if (actions && actions.indexOf(action) != -1) 111 if (actions && actions.indexOf(action) != -1)
110 { 112 {
111 page.sendMessage({ 113 page.sendMessage({
112 type: messageTypes[type], 114 type: messageTypes.get(type),
113 action, 115 action,
114 args: convertedArgs 116 args: convertedArgs
115 }); 117 });
116 } 118 }
117 } 119 }
118 } 120 }
119 121
120 function addFilterListeners(type, actions) 122 function addFilterListeners(type, actions)
121 { 123 {
122 for (let action of actions) 124 for (let action of actions)
(...skipping 24 matching lines...) Expand all
147 changeListeners.set(page, listenerFilters); 149 changeListeners.set(page, listenerFilters);
148 } 150 }
149 return listenerFilters; 151 return listenerFilters;
150 } 152 }
151 153
152 port.on("app.get", (message, sender) => 154 port.on("app.get", (message, sender) =>
153 { 155 {
154 if (message.what == "issues") 156 if (message.what == "issues")
155 { 157 {
156 let subscriptionInit = tryRequire("subscriptionInit"); 158 let subscriptionInit = tryRequire("subscriptionInit");
157 return { 159 let result = subscriptionInit ? subscriptionInit.reinitialized : false;
158 filterlistsReinitialized: subscriptionInit 160 return {filterlistsReinitialized: result};
159 ? subscriptionInit.reinitialized : false
160 };
161 } 161 }
162 162
163 if (message.what == "doclink") 163 if (message.what == "doclink")
164 return Utils.getDocLink(message.link); 164 return Utils.getDocLink(message.link);
165 165
166 if (message.what == "localeInfo") 166 if (message.what == "localeInfo")
167 { 167 {
168 let bidiDir; 168 let bidiDir;
169 if ("chromeRegistry" in Utils) 169 if ("chromeRegistry" in Utils)
170 { 170 {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 FilterStorage.addSubscription(subscription); 361 FilterStorage.addSubscription(subscription);
362 362
363 if (subscription instanceof DownloadableSubscription && 363 if (subscription instanceof DownloadableSubscription &&
364 !subscription.lastDownload) 364 !subscription.lastDownload)
365 Synchronizer.execute(subscription); 365 Synchronizer.execute(subscription);
366 } 366 }
367 }); 367 });
368 368
369 port.on("subscriptions.get", (message, sender) => 369 port.on("subscriptions.get", (message, sender) =>
370 { 370 {
371 let subscriptions = FilterStorage.subscriptions.filter(s => 371 let subscriptions = FilterStorage.subscriptions.filter((s) =>
372 { 372 {
373 if (message.ignoreDisabled && s.disabled) 373 if (message.ignoreDisabled && s.disabled)
374 return false; 374 return false;
375 if (s instanceof DownloadableSubscription && message.downloadable) 375 if (s instanceof DownloadableSubscription && message.downloadable)
376 return true; 376 return true;
377 if (s instanceof SpecialSubscription && message.special) 377 if (s instanceof SpecialSubscription && message.special)
378 return true; 378 return true;
379 return false; 379 return false;
380 }); 380 });
381 381
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 let {subscriptions} = FilterStorage; 421 let {subscriptions} = FilterStorage;
422 if (message.url) 422 if (message.url)
423 subscriptions = [Subscription.fromURL(message.url)]; 423 subscriptions = [Subscription.fromURL(message.url)];
424 424
425 for (let subscription of subscriptions) 425 for (let subscription of subscriptions)
426 { 426 {
427 if (subscription instanceof DownloadableSubscription) 427 if (subscription instanceof DownloadableSubscription)
428 Synchronizer.execute(subscription, true); 428 Synchronizer.execute(subscription, true);
429 } 429 }
430 }); 430 });
431 } 431 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld