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 |
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 (function(global) | 18 (function(global) |
19 { | 19 { |
20 if (!global.ext) | 20 if (!global.ext) |
21 global.ext = require("ext_background"); | 21 global.ext = require("ext_background"); |
22 | 22 |
23 var Utils = require("utils").Utils; | 23 var Utils = require("utils").Utils; |
24 var FilterStorage = require("filterStorage").FilterStorage; | 24 var FilterStorage = require("filterStorage").FilterStorage; |
25 var FilterNotifier = require("filterNotifier").FilterNotifier; | 25 var FilterNotifier = require("filterNotifier").FilterNotifier; |
26 var defaultMatcher = require("matcher").defaultMatcher; | 26 var defaultMatcher = require("matcher").defaultMatcher; |
27 var BlockingFilter = require("filterClasses").BlockingFilter; | |
28 var Synchronizer = require("synchronizer").Synchronizer; | 27 var Synchronizer = require("synchronizer").Synchronizer; |
29 | 28 |
30 var subscriptionClasses = require("subscriptionClasses"); | 29 var subscriptionClasses = require("subscriptionClasses"); |
31 var Subscription = subscriptionClasses.Subscription; | 30 var Subscription = subscriptionClasses.Subscription; |
32 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; | 31 var DownloadableSubscription = subscriptionClasses.DownloadableSubscription; |
33 var SpecialSubscription = subscriptionClasses.SpecialSubscription; | 32 var SpecialSubscription = subscriptionClasses.SpecialSubscription; |
34 | 33 |
| 34 var filterClasses = require("filterClasses"); |
| 35 var Filter = filterClasses.Filter; |
| 36 var BlockingFilter = filterClasses.BlockingFilter; |
| 37 |
35 var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url",
"downloadStatus"]; | 38 var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url",
"downloadStatus"]; |
36 function convertSubscription(subscription) | 39 function convertSubscription(subscription) |
37 { | 40 { |
38 var result = {}; | 41 var result = {}; |
39 for (var i = 0; i < subscriptionKeys.length; i++) | 42 for (var i = 0; i < subscriptionKeys.length; i++) |
40 result[subscriptionKeys[i]] = subscription[subscriptionKeys[i]] | 43 result[subscriptionKeys[i]] = subscription[subscriptionKeys[i]] |
41 return result; | 44 return result; |
42 } | 45 } |
43 | 46 |
44 var changeListeners = null; | 47 var changeListeners = null; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (s instanceof SpecialSubscription && message.special) | 138 if (s instanceof SpecialSubscription && message.special) |
136 return true; | 139 return true; |
137 return false; | 140 return false; |
138 }); | 141 }); |
139 callback(subscriptions.map(convertSubscription)); | 142 callback(subscriptions.map(convertSubscription)); |
140 break; | 143 break; |
141 case "filters.blocked": | 144 case "filters.blocked": |
142 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
message.docDomain, message.thirdParty); | 145 var filter = defaultMatcher.matchesAny(message.url, message.requestType,
message.docDomain, message.thirdParty); |
143 callback(filter instanceof BlockingFilter); | 146 callback(filter instanceof BlockingFilter); |
144 break; | 147 break; |
| 148 case "filters.add": |
| 149 FilterStorage.addFilter(Filter.fromText(message.filter)); |
| 150 break; |
| 151 case "filters.remove": |
| 152 FilterStorage.removeFilter(Filter.fromText(message.filter)); |
| 153 break; |
145 case "subscriptions.toggle": | 154 case "subscriptions.toggle": |
146 var subscription = Subscription.fromURL(message.url); | 155 var subscription = Subscription.fromURL(message.url); |
147 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) | 156 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) |
148 FilterStorage.removeSubscription(subscription); | 157 FilterStorage.removeSubscription(subscription); |
149 else | 158 else |
150 { | 159 { |
151 subscription.disabled = false; | 160 subscription.disabled = false; |
152 subscription.title = message.title; | 161 subscription.title = message.title; |
153 subscription.homepage = message.homepage; | 162 subscription.homepage = message.homepage; |
154 FilterStorage.addSubscription(subscription); | 163 FilterStorage.addSubscription(subscription); |
(...skipping 16 matching lines...) Expand all Loading... |
171 } | 180 } |
172 | 181 |
173 if (message.filter) | 182 if (message.filter) |
174 filters.subscription = message.filter; | 183 filters.subscription = message.filter; |
175 else | 184 else |
176 delete filters.subscription; | 185 delete filters.subscription; |
177 break; | 186 break; |
178 } | 187 } |
179 }); | 188 }); |
180 })(this); | 189 })(this); |
OLD | NEW |