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"); |
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 FilterStorage.addFilter(filter); | 186 var result = filterValidation.parseFilter(message.text); |
187 if (result.error) | |
188 sendMessage("app", "error", [result.error.toString()], sender.page); | |
189 else if (result.filter) | |
190 FilterStorage.addFilter(result.filter); | |
188 break; | 191 break; |
189 case "filters.blocked": | 192 case "filters.blocked": |
190 var filter = defaultMatcher.matchesAny(message.url, message.requestType, | 193 var filter = defaultMatcher.matchesAny(message.url, message.requestType, |
191 message.docDomain, message.thirdParty); | 194 message.docDomain, message.thirdParty); |
192 callback(filter instanceof BlockingFilter); | 195 callback(filter instanceof BlockingFilter); |
193 break; | 196 break; |
194 case "filters.get": | 197 case "filters.get": |
195 var subscription = Subscription.fromURL(message.subscriptionUrl); | 198 var subscription = Subscription.fromURL(message.subscriptionUrl); |
196 if (!subscription) | 199 if (!subscription) |
197 { | 200 { |
198 callback([]); | 201 callback([]); |
199 break; | 202 break; |
200 } | 203 } |
201 | 204 |
202 callback(subscription.filters.map(convertFilter)); | 205 callback(subscription.filters.map(convertFilter)); |
203 break; | 206 break; |
204 case "filters.importRaw": | 207 case "filters.importRaw": |
205 var result = parseFilters(message.text); | 208 var result = filterValidation.parseFilters(message.text); |
206 var errors = result.errors.filter(function(error) | 209 var errors = []; |
207 { | 210 for (var i = 0; i < result.errors.length; i++) |
208 return error.type != "unexpected-filter-list-header"; | 211 { |
209 }); | 212 var error = result.errors[i]; |
213 if (error.type != "unexpected-filter-list-header") | |
214 errors.push(error.toString()); | |
215 } | |
210 | 216 |
211 if (errors.length > 0) | 217 if (errors.length > 0) |
212 { | 218 { |
213 sendMessage("app", "error", errors, sender.page); | 219 sendMessage("app", "error", errors, sender.page); |
214 return; | 220 return; |
215 } | 221 } |
216 | 222 |
217 var seenFilter = Object.create(null); | 223 var seenFilter = Object.create(null); |
218 for (var i = 0; i < result.filters.length; i++) | 224 for (var i = 0; i < result.filters.length; i++) |
219 { | 225 { |
220 var filter = result.filters[i]; | 226 var filter = result.filters[i]; |
221 FilterStorage.addFilter(filter); | 227 FilterStorage.addFilter(filter); |
222 seenFilter[filter.text] = null; | 228 seenFilter[filter.text] = null; |
223 } | 229 } |
224 | 230 |
225 for (var i = 0; i < FilterStorage.subscriptions.length; i++) | 231 for (var i = 0; i < FilterStorage.subscriptions.length; i++) |
226 { | 232 { |
227 var subscription = FilterStorage.subscriptions[i]; | 233 var subscription = FilterStorage.subscriptions[i]; |
228 if (!(subscription instanceof SpecialSubscription)) | 234 if (!(subscription instanceof SpecialSubscription)) |
229 continue; | 235 continue; |
230 | 236 |
231 var filters = subscription.filters.slice(); | 237 for (var j = subscription.filters.length - 1; j >= 0; j--) |
232 for (var j = 0; j < filters.length; j++) | |
233 { | 238 { |
234 var filter = filters[j]; | 239 var filter = subscription.filters[j]; |
235 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) | 240 if (/^@@\|\|([^\/:]+)\^\$document$/.test(filter.text)) |
236 continue; | 241 continue; |
237 | 242 |
238 if (!(filter.text in seenFilter)) | 243 if (!(filter.text in seenFilter)) |
239 FilterStorage.removeFilter(filter); | 244 FilterStorage.removeFilter(filter); |
240 } | 245 } |
241 } | 246 } |
242 break; | 247 break; |
243 case "filters.listen": | 248 case "filters.listen": |
244 if (message.filter) | 249 if (message.filter) |
245 listenerFilters.filter = message.filter; | 250 listenerFilters.filter = message.filter; |
246 else | 251 else |
247 delete listenerFilters.filter; | 252 delete listenerFilters.filter; |
248 break; | |
249 case "filters.parse": | |
Sebastian Noack
2015/07/14 11:57:24
IMO this should be renamed to "filters.add", repla
saroyanm
2015/07/14 13:22:59
Done.
| |
250 var result = parseFilter(message.text); | |
251 if (result.error) | |
252 sendMessage("app", "error", [result.error.toString()], sender.page); | |
253 else | |
254 FilterStorage.addFilter(result.filter); | |
255 break; | 253 break; |
256 case "filters.remove": | 254 case "filters.remove": |
257 var filter = Filter.fromText(message.text); | 255 var filter = Filter.fromText(message.text); |
258 var subscription = null; | 256 var subscription = null; |
259 if (message.subscriptionUrl) | 257 if (message.subscriptionUrl) |
260 subscription = Subscription.fromURL(message.subscriptionUrl); | 258 subscription = Subscription.fromURL(message.subscriptionUrl); |
261 | 259 |
262 if (!subscription) | 260 if (!subscription) |
263 FilterStorage.removeFilter(filter); | 261 FilterStorage.removeFilter(filter); |
264 else | 262 else |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 subscription.title = message.title; | 317 subscription.title = message.title; |
320 subscription.homepage = message.homepage; | 318 subscription.homepage = message.homepage; |
321 FilterStorage.addSubscription(subscription); | 319 FilterStorage.addSubscription(subscription); |
322 if (!subscription.lastDownload) | 320 if (!subscription.lastDownload) |
323 Synchronizer.execute(subscription); | 321 Synchronizer.execute(subscription); |
324 } | 322 } |
325 break; | 323 break; |
326 } | 324 } |
327 }); | 325 }); |
328 })(this); | 326 })(this); |
LEFT | RIGHT |