Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
(...skipping 12 matching lines...) Expand all Loading... | |
23 var Prefs = require("prefs").Prefs; | 23 var Prefs = require("prefs").Prefs; |
24 var Utils = require("utils").Utils; | 24 var Utils = require("utils").Utils; |
25 var FilterStorage = require("filterStorage").FilterStorage; | 25 var FilterStorage = require("filterStorage").FilterStorage; |
26 var FilterNotifier = require("filterNotifier").FilterNotifier; | 26 var FilterNotifier = require("filterNotifier").FilterNotifier; |
27 var defaultMatcher = require("matcher").defaultMatcher; | 27 var defaultMatcher = require("matcher").defaultMatcher; |
28 | 28 |
29 var filterClasses = require("filterClasses"); | 29 var filterClasses = require("filterClasses"); |
30 var Filter = filterClasses.Filter; | 30 var Filter = filterClasses.Filter; |
31 var BlockingFilter = filterClasses.BlockingFilter; | 31 var BlockingFilter = filterClasses.BlockingFilter; |
32 var Synchronizer = require("synchronizer").Synchronizer; | 32 var Synchronizer = require("synchronizer").Synchronizer; |
33 var parseFilters = require("filterValidation").parseFilters; | 33 var filterValidation = require("filterValidation"); |
Sebastian Noack
2015/07/14 13:36:31
You might want to cache the module into a variable
saroyanm
2015/07/14 13:53:29
Good point, done.
| |
34 var parseFilter = require("filterValidation").parseFilter; | |
35 | 34 |
36 var subscriptionClasses = require("subscriptionClasses"); | 35 var subscriptionClasses = require("subscriptionClasses"); |
37 var Subscription = subscriptionClasses.Subscription; | 36 var Subscription = subscriptionClasses.Subscription; |
38 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; | 37 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; |
39 var SpecialSubscription = subscriptionClasses.SpecialSubscription; | 38 var SpecialSubscription = subscriptionClasses.SpecialSubscription; |
40 | 39 |
41 function convertObject(keys, obj) | 40 function convertObject(keys, obj) |
42 { | 41 { |
43 var result = {}; | 42 var result = {}; |
44 for (var i = 0; i < keys.length; i++) | 43 for (var i = 0; i < keys.length; i++) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 listenerFilters.app = message.filter; | 176 listenerFilters.app = message.filter; |
178 else | 177 else |
179 delete listenerFilters.app; | 178 delete listenerFilters.app; |
180 break; | 179 break; |
181 case "app.open": | 180 case "app.open": |
182 if (message.what == "options") | 181 if (message.what == "options") |
183 ext.showOptions(); | 182 ext.showOptions(); |
184 break; | 183 break; |
185 case "filters.add": | 184 case "filters.add": |
186 var filter = Filter.fromText(message.text); | 185 var filter = Filter.fromText(message.text); |
187 var result = parseFilter(message.text); | 186 var result = filterValidation.parseFilter(message.text); |
188 if (result.error) | 187 if (result.error) |
189 sendMessage("app", "error", [result.error.toString()], sender.page); | 188 sendMessage("app", "error", [result.error.toString()], sender.page); |
190 else | 189 else if (result.filter) |
191 FilterStorage.addFilter(result.filter); | 190 FilterStorage.addFilter(result.filter); |
192 break; | 191 break; |
193 case "filters.blocked": | 192 case "filters.blocked": |
194 var filter = defaultMatcher.matchesAny(message.url, message.requestType, | 193 var filter = defaultMatcher.matchesAny(message.url, message.requestType, |
195 message.docDomain, message.thirdParty); | 194 message.docDomain, message.thirdParty); |
196 callback(filter instanceof BlockingFilter); | 195 callback(filter instanceof BlockingFilter); |
197 break; | 196 break; |
198 case "filters.get": | 197 case "filters.get": |
199 var subscription = Subscription.fromURL(message.subscriptionUrl); | 198 var subscription = Subscription.fromURL(message.subscriptionUrl); |
200 if (!subscription) | 199 if (!subscription) |
201 { | 200 { |
202 callback([]); | 201 callback([]); |
203 break; | 202 break; |
204 } | 203 } |
205 | 204 |
206 callback(subscription.filters.map(convertFilter)); | 205 callback(subscription.filters.map(convertFilter)); |
207 break; | 206 break; |
208 case "filters.importRaw": | 207 case "filters.importRaw": |
209 var result = parseFilters(message.text); | 208 var result = filterValidation.parseFilters(message.text); |
210 var errors = result.errors.filter(function(error) | 209 var errors = []; |
Sebastian Noack
2015/07/14 13:36:31
I'd rather go with for-loop, rather than chaining
saroyanm
2015/07/14 13:53:28
Good point, done.
| |
211 { | 210 for (var i = 0; i < result.errors.length; i++) |
212 return error.type != "unexpected-filter-list-header"; | 211 { |
213 }).map(function(error) | 212 var error = result.errors[i]; |
214 { | 213 if (error.type != "unexpected-filter-list-header") |
215 return error.toString(); | 214 errors.push(error.toString()); |
216 }); | 215 } |
217 | 216 |
218 if (errors.length > 0) | 217 if (errors.length > 0) |
219 { | 218 { |
220 sendMessage("app", "error", errors, sender.page); | 219 sendMessage("app", "error", errors, sender.page); |
221 return; | 220 return; |
222 } | 221 } |
223 | 222 |
224 var seenFilter = Object.create(null); | 223 var seenFilter = Object.create(null); |
225 for (var i = 0; i < result.filters.length; i++) | 224 for (var i = 0; i < result.filters.length; i++) |
226 { | 225 { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 subscription.title = message.title; | 317 subscription.title = message.title; |
319 subscription.homepage = message.homepage; | 318 subscription.homepage = message.homepage; |
320 FilterStorage.addSubscription(subscription); | 319 FilterStorage.addSubscription(subscription); |
321 if (!subscription.lastDownload) | 320 if (!subscription.lastDownload) |
322 Synchronizer.execute(subscription); | 321 Synchronizer.execute(subscription); |
323 } | 322 } |
324 break; | 323 break; |
325 } | 324 } |
326 }); | 325 }); |
327 })(this); | 326 })(this); |
LEFT | RIGHT |