Left: | ||
Right: |
OLD | NEW |
---|---|
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 10 matching lines...) Expand all Loading... | |
21 global.ext = require("ext_background"); | 21 global.ext = require("ext_background"); |
22 | 22 |
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 WhitelistFilter = filterClasses.WhitelistFilter | |
31 var BlockingFilter = filterClasses.BlockingFilter; | 32 var BlockingFilter = filterClasses.BlockingFilter; |
32 var Synchronizer = require("synchronizer").Synchronizer; | 33 var Synchronizer = require("synchronizer").Synchronizer; |
34 var parseFilters = require("filterValidation").parseFilters; | |
35 var parseFilter = require("filterValidation").parseFilter; | |
33 | 36 |
34 var subscriptionClasses = require("subscriptionClasses"); | 37 var subscriptionClasses = require("subscriptionClasses"); |
35 var Subscription = subscriptionClasses.Subscription; | 38 var Subscription = subscriptionClasses.Subscription; |
36 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; | 39 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; |
37 var SpecialSubscription = subscriptionClasses.SpecialSubscription; | 40 var SpecialSubscription = subscriptionClasses.SpecialSubscription; |
38 | 41 |
39 function convertObject(keys, obj) | 42 function convertObject(keys, obj) |
40 { | 43 { |
41 var result = {}; | 44 var result = {}; |
42 for (var i = 0; i < keys.length; i++) | 45 for (var i = 0; i < keys.length; i++) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 case "filters.get": | 191 case "filters.get": |
189 var subscription = Subscription.fromURL(message.subscriptionUrl); | 192 var subscription = Subscription.fromURL(message.subscriptionUrl); |
190 if (!subscription) | 193 if (!subscription) |
191 { | 194 { |
192 callback([]); | 195 callback([]); |
193 break; | 196 break; |
194 } | 197 } |
195 | 198 |
196 callback(subscription.filters.map(convertFilter)); | 199 callback(subscription.filters.map(convertFilter)); |
197 break; | 200 break; |
201 case "filters.importRaw": | |
202 var result = parseFilters(message.text); | |
203 var errors = result.errors.filter(function(error) | |
204 { | |
205 return error.type != "unexpected-filter-list-header"; | |
206 }); | |
207 | |
208 if (errors.length > 0) | |
209 { | |
210 alert(errors.join("\n")); | |
211 return; | |
212 } | |
213 | |
214 var seenFilter = Object.create(null); | |
215 for (var i = 0; i < result.filters.length; i++) | |
216 { | |
217 var filter = result.filters[i]; | |
218 FilterStorage.addFilter(filter); | |
219 seenFilter[filter.text] = null; | |
220 } | |
221 | |
222 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | |
223 { | |
224 var subscription = FilterStorage.subscriptions[i]; | |
225 if (!(subscription instanceof SpecialSubscription)) | |
226 continue; | |
227 | |
228 var filters = subscription.filters.slice(); | |
229 for (var j = 0; j < filters.length; j++) | |
230 { | |
231 var filter = filters[j]; | |
232 if (filter instanceof WhitelistFilter && | |
233 /^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | |
234 continue; | |
235 | |
236 if (!(filter.text in seenFilter)) | |
237 FilterStorage.removeFilter(filter); | |
238 } | |
239 } | |
240 break; | |
198 case "filters.listen": | 241 case "filters.listen": |
199 if (message.filter) | 242 if (message.filter) |
200 listenerFilters.filter = message.filter; | 243 listenerFilters.filter = message.filter; |
201 else | 244 else |
202 delete listenerFilters.filter; | 245 delete listenerFilters.filter; |
203 break; | 246 break; |
247 case "filters.parse": | |
248 var result = parseFilter(message.text); | |
249 if (result.error) | |
250 alert(result.error); | |
Sebastian Noack
2015/07/10 07:31:01
Please no alert() or similar calls in the backgrou
Thomas Greiner
2015/07/10 12:38:53
Unfortunately, this didn't make it into the initia
| |
251 else | |
252 FilterStorage.addFilter(result.filter); | |
253 break; | |
204 case "filters.remove": | 254 case "filters.remove": |
205 var filter = Filter.fromText(message.text); | 255 var filter = Filter.fromText(message.text); |
206 var subscription = null; | 256 var subscription = null; |
207 if (message.subscriptionUrl) | 257 if (message.subscriptionUrl) |
208 subscription = Subscription.fromURL(message.subscriptionUrl); | 258 subscription = Subscription.fromURL(message.subscriptionUrl); |
209 | 259 |
210 if (!subscription) | 260 if (!subscription) |
211 FilterStorage.removeFilter(filter); | 261 FilterStorage.removeFilter(filter); |
212 else | 262 else |
213 FilterStorage.removeFilter(filter, subscription, message.index); | 263 FilterStorage.removeFilter(filter, subscription, message.index); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 subscription.title = message.title; | 317 subscription.title = message.title; |
268 subscription.homepage = message.homepage; | 318 subscription.homepage = message.homepage; |
269 FilterStorage.addSubscription(subscription); | 319 FilterStorage.addSubscription(subscription); |
270 if (!subscription.lastDownload) | 320 if (!subscription.lastDownload) |
271 Synchronizer.execute(subscription); | 321 Synchronizer.execute(subscription); |
272 } | 322 } |
273 break; | 323 break; |
274 } | 324 } |
275 }); | 325 }); |
276 })(this); | 326 })(this); |
OLD | NEW |