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 |
| 38 var devtools = require("devtools"); |
| 39 var initDevToolsPanel = devtools ? devtools.initDevToolsPanel : function() {}; |
| 40 |
35 var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url",
"downloadStatus"]; | 41 var subscriptionKeys = ["disabled", "homepage", "lastSuccess", "title", "url",
"downloadStatus"]; |
36 function convertSubscription(subscription) | 42 function convertSubscription(subscription) |
37 { | 43 { |
38 var result = {}; | 44 var result = {}; |
39 for (var i = 0; i < subscriptionKeys.length; i++) | 45 for (var i = 0; i < subscriptionKeys.length; i++) |
40 result[subscriptionKeys[i]] = subscription[subscriptionKeys[i]] | 46 result[subscriptionKeys[i]] = subscription[subscriptionKeys[i]] |
41 return result; | 47 return result; |
42 } | 48 } |
43 | 49 |
44 var changeListeners = null; | 50 var changeListeners = null; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (s instanceof SpecialSubscription && message.special) | 138 if (s instanceof SpecialSubscription && message.special) |
133 return true; | 139 return true; |
134 return false; | 140 return false; |
135 }); | 141 }); |
136 callback(subscriptions.map(convertSubscription)); | 142 callback(subscriptions.map(convertSubscription)); |
137 break; | 143 break; |
138 case "filters.blocked": | 144 case "filters.blocked": |
139 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); |
140 callback(filter instanceof BlockingFilter); | 146 callback(filter instanceof BlockingFilter); |
141 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; |
142 case "subscriptions.toggle": | 154 case "subscriptions.toggle": |
143 var subscription = Subscription.fromURL(message.url); | 155 var subscription = Subscription.fromURL(message.url); |
144 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) | 156 if (subscription.url in FilterStorage.knownSubscriptions && !subscriptio
n.disabled) |
145 FilterStorage.removeSubscription(subscription); | 157 FilterStorage.removeSubscription(subscription); |
146 else | 158 else |
147 { | 159 { |
148 subscription.disabled = false; | 160 subscription.disabled = false; |
149 subscription.title = message.title; | 161 subscription.title = message.title; |
150 subscription.homepage = message.homepage; | 162 subscription.homepage = message.homepage; |
151 FilterStorage.addSubscription(subscription); | 163 FilterStorage.addSubscription(subscription); |
(...skipping 13 matching lines...) Expand all Loading... |
165 { | 177 { |
166 filters = Object.create(null); | 178 filters = Object.create(null); |
167 changeListeners.set(sender.page, filters); | 179 changeListeners.set(sender.page, filters); |
168 } | 180 } |
169 | 181 |
170 if (message.filter) | 182 if (message.filter) |
171 filters.subscription = message.filter; | 183 filters.subscription = message.filter; |
172 else | 184 else |
173 delete filters.subscription; | 185 delete filters.subscription; |
174 break; | 186 break; |
| 187 case "devtools.init": |
| 188 initDevToolsPanel(sender.page, message.inspectedTabId); |
| 189 break; |
175 } | 190 } |
176 }); | 191 }); |
177 })(this); | 192 })(this); |
OLD | NEW |