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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 function require(module) | 31 function require(module) |
32 { | 32 { |
33 let result = {}; | 33 let result = {}; |
34 result.wrappedJSObject = result; | 34 result.wrappedJSObject = result; |
35 Services.obs.notifyObservers(result, "adblockplus-require", module); | 35 Services.obs.notifyObservers(result, "adblockplus-require", module); |
36 return result.exports; | 36 return result.exports; |
37 } | 37 } |
38 | 38 |
39 let {Filter} = require("filterClasses"); | 39 let {Filter} = require("filterClasses"); |
| 40 let {FilterNotifier} = require("filterNotifier"); |
40 let {FilterStorage} = require("filterStorage"); | 41 let {FilterStorage} = require("filterStorage"); |
41 let {defaultMatcher} = require("matcher"); | 42 let {defaultMatcher} = require("matcher"); |
42 let {Prefs} = require("prefs"); | 43 let {Prefs} = require("prefs"); |
43 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri
ption, ExternalSubscription} = require("subscriptionClasses"); | 44 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri
ption, ExternalSubscription} = require("subscriptionClasses"); |
44 let {Synchronizer} = require("synchronizer"); | 45 let {Synchronizer} = require("synchronizer"); |
45 let {UI} = require("ui"); | 46 let {UI} = require("ui"); |
46 | 47 |
| 48 function initFilterListeners() |
| 49 { |
| 50 FilterNotifier.on("load", onFiltersLoad); |
| 51 FilterNotifier.on("save", onFiltersSave); |
| 52 } |
| 53 |
| 54 function onFiltersLoad() |
| 55 { |
| 56 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
| 57 } |
| 58 |
| 59 function onFiltersSave() |
| 60 { |
| 61 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
| 62 } |
| 63 |
47 function getWhitelistingFilter(url) | 64 function getWhitelistingFilter(url) |
48 { | 65 { |
49 let uriObject = Services.io.newURI(url, null, null); | 66 let uriObject = Services.io.newURI(url, null, null); |
50 try | 67 try |
51 { | 68 { |
52 return defaultMatcher.whitelist.matchesAny( | 69 return defaultMatcher.whitelist.matchesAny( |
53 uriObject.spec, "DOCUMENT", uriObject.host, false, null); | 70 uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
54 } | 71 } |
55 catch (e) | 72 catch (e) |
56 { | 73 { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 { | 172 { |
156 FilterStorage.removeFilter(filter); | 173 FilterStorage.removeFilter(filter); |
157 if (filter.subscriptions.length) | 174 if (filter.subscriptions.length) |
158 filter.disabled = true; | 175 filter.disabled = true; |
159 filter = getWhitelistingFilter(url); | 176 filter = getWhitelistingFilter(url); |
160 } | 177 } |
161 } | 178 } |
162 }, | 179 }, |
163 initCommunication: function() | 180 initCommunication: function() |
164 { | 181 { |
| 182 initFilterListeners(); |
| 183 |
165 Messaging.addListener((function(data) | 184 Messaging.addListener((function(data) |
166 { | 185 { |
167 if (!data) | 186 if (!data) |
168 return {"success": false, "error": "malformed request"}; | 187 return {"success": false, "error": "malformed request"}; |
169 | 188 |
170 if (data["action"] == "getFiltersLoaded") | |
171 return {"success": true, "value": this.filtersLoaded}; | |
172 | |
173 if (!this.filtersLoaded) | 189 if (!this.filtersLoaded) |
174 return {"success": false, "error": "filters not loaded"}; | 190 return {"success": false, "error": "filters not loaded"}; |
175 | 191 |
176 switch (data["action"]) | 192 switch (data["action"]) |
177 { | 193 { |
178 case "getAcceptableAdsEnabled": | 194 case "getAcceptableAdsEnabled": |
179 return {"success": true, "value": this.acceptableAdsEnabled}; | 195 return {"success": true, "value": this.acceptableAdsEnabled}; |
180 case "setAcceptableAdsEnabled": | 196 case "setAcceptableAdsEnabled": |
181 if ("enable" in data) | 197 if ("enable" in data) |
182 { | 198 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 { | 240 { |
225 this.whitelistSite(data["url"], data["whitelisted"]); | 241 this.whitelistSite(data["url"], data["whitelisted"]); |
226 return {"success": true}; | 242 return {"success": true}; |
227 } | 243 } |
228 break; | 244 break; |
229 } | 245 } |
230 return {"success": false, "error": "malformed request"}; | 246 return {"success": false, "error": "malformed request"}; |
231 }).bind(this), "AdblockPlus:Api"); | 247 }).bind(this), "AdblockPlus:Api"); |
232 } | 248 } |
233 }; | 249 }; |
OLD | NEW |