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 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"); | |
anton
2016/09/30 06:51:03
Please make sure it does not interfere with https:
diegocarloslima
2016/10/26 13:48:04
Yes, they don't conflict to each other, altough th
| |
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 let shouldSaveFiltersPref = "should_save_filters"; | |
49 | |
50 function initListeners() | |
51 { | |
52 FilterNotifier.on("filter.added", onFiltersChanged); | |
53 FilterNotifier.on("filter.removed", onFiltersChanged); | |
54 FilterNotifier.on("subscription.added", onFiltersChanged); | |
55 FilterNotifier.on("subscription.removed", onFiltersChanged); | |
56 FilterNotifier.on("save", onSave); | |
57 } | |
58 | |
59 function onFiltersChanged() | |
60 { | |
61 setBoolPref(shouldSaveFiltersPref, true); | |
62 } | |
63 | |
64 function onSave() | |
65 { | |
66 setBoolPref(shouldSaveFiltersPref, false); | |
67 } | |
68 | |
69 function getBoolPref(name) | |
70 { | |
71 let branch = getPrefsBranch(); | |
72 try | |
73 { | |
74 return branch.getBoolPref(name); | |
75 } | |
76 catch (e) | |
77 { | |
78 return null; | |
79 } | |
80 } | |
81 | |
82 function setBoolPref(name, value) | |
83 { | |
84 let branch = getPrefsBranch(); | |
85 branch.setBoolPref(name, value); | |
86 Services.prefs.savePrefFile(null); | |
87 } | |
88 | |
89 function getPrefsBranch() | |
90 { | |
91 let {addonRoot, addonName} = require("info"); | |
92 let branchName = "extensions." + addonName + "."; | |
93 return Services.prefs.getBranch(branchName); | |
94 } | |
95 | |
47 function getWhitelistingFilter(url) | 96 function getWhitelistingFilter(url) |
48 { | 97 { |
49 let uriObject = Services.io.newURI(url, null, null); | 98 let uriObject = Services.io.newURI(url, null, null); |
50 try | 99 try |
51 { | 100 { |
52 return defaultMatcher.whitelist.matchesAny( | 101 return defaultMatcher.whitelist.matchesAny( |
53 uriObject.spec, "DOCUMENT", uriObject.host, false, null); | 102 uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
54 } | 103 } |
55 catch (e) | 104 catch (e) |
56 { | 105 { |
57 return null; | 106 return null; |
58 } | 107 } |
59 } | 108 } |
60 | 109 |
61 var AdblockPlusApi = | 110 var AdblockPlusApi = |
62 { | 111 { |
63 get filtersLoaded() | 112 get filtersLoaded() |
64 { | 113 { |
65 return !FilterStorage._loading; | 114 return !FilterStorage._loading; |
66 }, | 115 }, |
116 get requestsSaved() | |
117 { | |
118 return !getBoolPref(shouldSaveFiltersPref) && !FilterStorage._saving && !Fil terStorage._needsSave; | |
119 }, | |
67 get acceptableAdsEnabled() | 120 get acceptableAdsEnabled() |
68 { | 121 { |
69 return FilterStorage.subscriptions.some( | 122 return FilterStorage.subscriptions.some( |
70 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); | 123 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); |
71 }, | 124 }, |
72 set acceptableAdsEnabled(acceptableAdsEnabled) | 125 set acceptableAdsEnabled(acceptableAdsEnabled) |
73 { | 126 { |
74 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) | 127 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) |
75 UI.toggleAcceptableAds(); | 128 UI.toggleAcceptableAds(); |
76 }, | 129 }, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 { | 208 { |
156 FilterStorage.removeFilter(filter); | 209 FilterStorage.removeFilter(filter); |
157 if (filter.subscriptions.length) | 210 if (filter.subscriptions.length) |
158 filter.disabled = true; | 211 filter.disabled = true; |
159 filter = getWhitelistingFilter(url); | 212 filter = getWhitelistingFilter(url); |
160 } | 213 } |
161 } | 214 } |
162 }, | 215 }, |
163 initCommunication: function() | 216 initCommunication: function() |
164 { | 217 { |
218 initListeners(); | |
219 | |
165 Messaging.addListener((function(data) | 220 Messaging.addListener((function(data) |
166 { | 221 { |
167 if (!data) | 222 if (!data) |
168 return {"success": false, "error": "malformed request"}; | 223 return {"success": false, "error": "malformed request"}; |
169 | 224 |
170 if (data["action"] == "getFiltersLoaded") | 225 if (data["action"] == "getFiltersLoaded") |
171 return {"success": true, "value": this.filtersLoaded}; | 226 return {"success": true, "value": this.filtersLoaded}; |
172 | 227 |
173 if (!this.filtersLoaded) | 228 if (!this.filtersLoaded) |
174 return {"success": false, "error": "filters not loaded"}; | 229 return {"success": false, "error": "filters not loaded"}; |
175 | 230 |
176 switch (data["action"]) | 231 switch (data["action"]) |
177 { | 232 { |
233 case "getRequestsSaved": | |
234 return {"success": true, "value": this.requestsSaved}; | |
178 case "getAcceptableAdsEnabled": | 235 case "getAcceptableAdsEnabled": |
179 return {"success": true, "value": this.acceptableAdsEnabled}; | 236 return {"success": true, "value": this.acceptableAdsEnabled}; |
180 case "setAcceptableAdsEnabled": | 237 case "setAcceptableAdsEnabled": |
181 if ("enable" in data) | 238 if ("enable" in data) |
182 { | 239 { |
183 this.acceptableAdsEnabled = !!data["enable"]; | 240 this.acceptableAdsEnabled = !!data["enable"]; |
184 return {"success": true}; | 241 return {"success": true}; |
185 } | 242 } |
186 break; | 243 break; |
187 case "getSubscriptionsXml": | 244 case "getSubscriptionsXml": |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 { | 281 { |
225 this.whitelistSite(data["url"], data["whitelisted"]); | 282 this.whitelistSite(data["url"], data["whitelisted"]); |
226 return {"success": true}; | 283 return {"success": true}; |
227 } | 284 } |
228 break; | 285 break; |
229 } | 286 } |
230 return {"success": false, "error": "malformed request"}; | 287 return {"success": false, "error": "malformed request"}; |
231 }).bind(this), "AdblockPlus:Api"); | 288 }).bind(this), "AdblockPlus:Api"); |
232 } | 289 } |
233 }; | 290 }; |
OLD | NEW |