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

Delta Between Two Patch Sets: messageResponder.js

Issue 29522650: Issue 5316 - Adds dynamic filter types to devtools panel (Closed)
Left Patch Set: Created Aug. 21, 2017, 3:24 p.m.
Right Patch Set: Created Sept. 12, 2017, 12:10 p.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 | « devtools-panel.js ('k') | skin/devtools-panel.css » ('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-2017 eyeo GmbH 3 * Copyright (C) 2006-present 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 *
(...skipping 15 matching lines...) Expand all
29 const {FilterStorage} = require("filterStorage"); 29 const {FilterStorage} = require("filterStorage");
30 const {FilterNotifier} = require("filterNotifier"); 30 const {FilterNotifier} = require("filterNotifier");
31 const {defaultMatcher} = require("matcher"); 31 const {defaultMatcher} = require("matcher");
32 const {ElemHideEmulation} = require("elemHideEmulation"); 32 const {ElemHideEmulation} = require("elemHideEmulation");
33 const {Notification: NotificationStorage} = require("notification"); 33 const {Notification: NotificationStorage} = require("notification");
34 34
35 const {Filter, BlockingFilter, RegExpFilter} = require("filterClasses"); 35 const {Filter, BlockingFilter, RegExpFilter} = require("filterClasses");
36 const {Synchronizer} = require("synchronizer"); 36 const {Synchronizer} = require("synchronizer");
37 37
38 const info = require("info"); 38 const info = require("info");
39 const {Subscription, 39 const {
40 DownloadableSubscription, 40 Subscription,
41 SpecialSubscription} = require("subscriptionClasses"); 41 DownloadableSubscription,
42 42 SpecialSubscription
43 // Some resource types are not available on Chrome 43 } = require("subscriptionClasses");
Jon Sonesen 2017/08/21 15:31:07 This comment probably needs to be improved
Thomas Greiner 2017/08/22 11:21:47 Indeed… what are you trying to express here?
Jon Sonesen 2017/08/24 11:29:06 Yeah I dunno, I thought it would make sense to exp
Thomas Greiner 2017/08/25 17:11:35 Agreed, I don't think it adds value to add a comme
44 port.on("request.getTypes", (message, sender) => 44
45 Array.from(require("requestBlocker").filterTypes)); 45 port.on("types.get", (message, sender) =>
Thomas Greiner 2017/08/22 11:21:47 Why did you decide to make `filterTypes` a `Set` i
Sebastian Noack 2017/08/22 11:38:28 The way filter types are accumulated in adblockplu
Thomas Greiner 2017/08/25 17:11:35 Ok, not great either way then, I guess. Thanks for
46 {
47 let filterTypes = Array.from(require("requestBlocker").filterTypes);
48 filterTypes.push(...filterTypes.splice(filterTypes.indexOf("OTHER"), 1));
49 return filterTypes;
50 });
46 51
47 // Some modules doesn't exist on Firefox. Moreover, 52 // Some modules doesn't exist on Firefox. Moreover,
48 // require() throws an exception on Firefox in that case. 53 // require() throws an exception on Firefox in that case.
49 // However, try/catch causes the whole function to to be 54 // However, try/catch causes the whole function to to be
50 // deoptimized on V8. So we wrap it into another function. 55 // deoptimized on V8. So we wrap it into another function.
51 function tryRequire(module) 56 function tryRequire(module)
52 { 57 {
53 try 58 try
54 { 59 {
55 return require(module); 60 return require(module);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 176
172 if (message.what == "localeInfo") 177 if (message.what == "localeInfo")
173 { 178 {
174 let bidiDir; 179 let bidiDir;
175 if ("chromeRegistry" in Utils) 180 if ("chromeRegistry" in Utils)
176 { 181 {
177 let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus"); 182 let isRtl = Utils.chromeRegistry.isLocaleRTL("adblockplus");
178 bidiDir = isRtl ? "rtl" : "ltr"; 183 bidiDir = isRtl ? "rtl" : "ltr";
179 } 184 }
180 else 185 else
181 bidiDir = ext.i18n.getMessage("@@bidi_dir"); 186 bidiDir = Utils.readingDirection;
182 187
183 return {locale: Utils.appLocale, bidiDir}; 188 return {locale: Utils.appLocale, bidiDir};
184 } 189 }
185 190
186 if (message.what == "features") 191 if (message.what == "features")
187 { 192 {
188 return { 193 return {
189 devToolsPanel: info.platform == "chromium" 194 devToolsPanel: info.platform == "chromium"
190 }; 195 };
191 } 196 }
192 197
193 return info[message.what]; 198 return info[message.what];
194 }); 199 });
195 200
196 port.on("app.listen", (message, sender) => 201 port.on("app.listen", (message, sender) =>
197 { 202 {
198 getListenerFilters(sender.page).app = message.filter; 203 getListenerFilters(sender.page).app = message.filter;
199 }); 204 });
200 205
201 port.on("app.open", (message, sender) => 206 port.on("app.open", (message, sender) =>
202 { 207 {
203 if (message.what == "options") 208 if (message.what == "options")
204 ext.showOptions(); 209 {
210 ext.showOptions(() =>
211 {
212 if (!message.action)
213 return;
214
215 sendMessage("app", message.action, ...message.args);
216 });
217 }
205 }); 218 });
206 219
207 port.on("filters.add", (message, sender) => 220 port.on("filters.add", (message, sender) =>
208 { 221 {
209 let result = require("filterValidation").parseFilter(message.text); 222 let result = require("filterValidation").parseFilter(message.text);
210 let errors = []; 223 let errors = [];
211 if (result.error) 224 if (result.error)
212 errors.push(result.error.toString()); 225 errors.push(result.error.toString());
213 else if (result.filter) 226 else if (result.filter)
214 FilterStorage.addFilter(result.filter); 227 FilterStorage.addFilter(result.filter);
(...skipping 10 matching lines...) Expand all
225 return filter instanceof BlockingFilter; 238 return filter instanceof BlockingFilter;
226 }); 239 });
227 240
228 port.on("filters.get", (message, sender) => 241 port.on("filters.get", (message, sender) =>
229 { 242 {
230 if (message.what == "elemhideemulation") 243 if (message.what == "elemhideemulation")
231 { 244 {
232 let filters = []; 245 let filters = [];
233 const {checkWhitelisted} = require("whitelisting"); 246 const {checkWhitelisted} = require("whitelisting");
234 247
235 if (Prefs.enabled && !checkWhitelisted(sender.page, sender.frame, 248 let isWhitelisted = checkWhitelisted(sender.page, sender.frame,
236 RegExpFilter.typeMap.DOCUMENT | 249 RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE);
237 RegExpFilter.typeMap.ELEMHIDE)) 250 if (Prefs.enabled && !isWhitelisted)
238 { 251 {
239 let {hostname} = sender.frame.url; 252 let {hostname} = sender.frame.url;
240 filters = ElemHideEmulation.getRulesForDomain(hostname); 253 filters = ElemHideEmulation.getRulesForDomain(hostname);
241 filters = filters.map((filter) => 254 filters = filters.map((filter) =>
242 { 255 {
243 return { 256 return {
244 selector: filter.selector, 257 selector: filter.selector,
245 text: filter.text 258 text: filter.text
246 }; 259 };
247 }); 260 });
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 let {subscriptions} = FilterStorage; 440 let {subscriptions} = FilterStorage;
428 if (message.url) 441 if (message.url)
429 subscriptions = [Subscription.fromURL(message.url)]; 442 subscriptions = [Subscription.fromURL(message.url)];
430 443
431 for (let subscription of subscriptions) 444 for (let subscription of subscriptions)
432 { 445 {
433 if (subscription instanceof DownloadableSubscription) 446 if (subscription instanceof DownloadableSubscription)
434 Synchronizer.execute(subscription, true); 447 Synchronizer.execute(subscription, true);
435 } 448 }
436 }); 449 });
437
438 port.on("request.getTypes", (message, sender) =>
439 Array.from(require("requestBlocker").filterTypes));
Thomas Greiner 2017/08/22 11:21:47 This is exactly the same code as the one above so
Jon Sonesen 2017/08/24 11:29:06 Acknowledged.
440 })(this); 450 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld