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 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 {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
| |
41 let {FilterStorage} = require("filterStorage"); | 41 let {FilterStorage} = require("filterStorage"); |
42 let {defaultMatcher} = require("matcher"); | 42 let {defaultMatcher} = require("matcher"); |
43 let {Prefs} = require("prefs"); | 43 let {Prefs} = require("prefs"); |
44 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri ption, ExternalSubscription} = require("subscriptionClasses"); | 44 let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscri ption, ExternalSubscription} = require("subscriptionClasses"); |
45 let {Synchronizer} = require("synchronizer"); | 45 let {Synchronizer} = require("synchronizer"); |
46 let {UI} = require("ui"); | 46 let {UI} = require("ui"); |
47 | 47 |
48 let shouldSaveFiltersPref = "should_save_filters"; | 48 function initFilterListeners() |
49 | 49 { |
50 function initListeners() | 50 FilterNotifier.on("load", onFiltersLoad); |
51 { | 51 FilterNotifier.on("save", onFiltersSave); |
52 FilterNotifier.on("filter.added", onFiltersChanged); | 52 } |
53 FilterNotifier.on("filter.removed", onFiltersChanged); | 53 |
54 FilterNotifier.on("subscription.added", onFiltersChanged); | 54 function onFiltersLoad() |
55 FilterNotifier.on("subscription.removed", onFiltersChanged); | 55 { |
56 FilterNotifier.on("save", onSave); | 56 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
57 } | 57 } |
58 | 58 |
59 function onFiltersChanged() | 59 function onFiltersSave() |
60 { | 60 { |
61 setBoolPref(shouldSaveFiltersPref, true); | 61 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
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 } | 62 } |
95 | 63 |
96 function getWhitelistingFilter(url) | 64 function getWhitelistingFilter(url) |
97 { | 65 { |
98 let uriObject = Services.io.newURI(url, null, null); | 66 let uriObject = Services.io.newURI(url, null, null); |
99 try | 67 try |
100 { | 68 { |
101 return defaultMatcher.whitelist.matchesAny( | 69 return defaultMatcher.whitelist.matchesAny( |
102 uriObject.spec, "DOCUMENT", uriObject.host, false, null); | 70 uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
103 } | 71 } |
104 catch (e) | 72 catch (e) |
105 { | 73 { |
106 return null; | 74 return null; |
107 } | 75 } |
108 } | 76 } |
109 | 77 |
110 var AdblockPlusApi = | 78 var AdblockPlusApi = |
111 { | 79 { |
112 get filtersLoaded() | 80 get filtersLoaded() |
113 { | 81 { |
114 return !FilterStorage._loading; | 82 return !FilterStorage._loading; |
115 }, | |
116 get requestsSaved() | |
117 { | |
118 return !getBoolPref(shouldSaveFiltersPref) && !FilterStorage._saving && !Fil terStorage._needsSave; | |
119 }, | 83 }, |
120 get acceptableAdsEnabled() | 84 get acceptableAdsEnabled() |
121 { | 85 { |
122 return FilterStorage.subscriptions.some( | 86 return FilterStorage.subscriptions.some( |
123 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); | 87 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); |
124 }, | 88 }, |
125 set acceptableAdsEnabled(acceptableAdsEnabled) | 89 set acceptableAdsEnabled(acceptableAdsEnabled) |
126 { | 90 { |
127 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) | 91 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) |
128 UI.toggleAcceptableAds(); | 92 UI.toggleAcceptableAds(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 { | 172 { |
209 FilterStorage.removeFilter(filter); | 173 FilterStorage.removeFilter(filter); |
210 if (filter.subscriptions.length) | 174 if (filter.subscriptions.length) |
211 filter.disabled = true; | 175 filter.disabled = true; |
212 filter = getWhitelistingFilter(url); | 176 filter = getWhitelistingFilter(url); |
213 } | 177 } |
214 } | 178 } |
215 }, | 179 }, |
216 initCommunication: function() | 180 initCommunication: function() |
217 { | 181 { |
218 initListeners(); | 182 initFilterListeners(); |
219 | 183 |
220 Messaging.addListener((function(data) | 184 Messaging.addListener((function(data) |
221 { | 185 { |
222 if (!data) | 186 if (!data) |
223 return {"success": false, "error": "malformed request"}; | 187 return {"success": false, "error": "malformed request"}; |
224 | 188 |
225 if (data["action"] == "getFiltersLoaded") | |
226 return {"success": true, "value": this.filtersLoaded}; | |
227 | |
228 if (!this.filtersLoaded) | 189 if (!this.filtersLoaded) |
229 return {"success": false, "error": "filters not loaded"}; | 190 return {"success": false, "error": "filters not loaded"}; |
230 | 191 |
231 switch (data["action"]) | 192 switch (data["action"]) |
232 { | 193 { |
233 case "getRequestsSaved": | |
234 return {"success": true, "value": this.requestsSaved}; | |
235 case "getAcceptableAdsEnabled": | 194 case "getAcceptableAdsEnabled": |
236 return {"success": true, "value": this.acceptableAdsEnabled}; | 195 return {"success": true, "value": this.acceptableAdsEnabled}; |
237 case "setAcceptableAdsEnabled": | 196 case "setAcceptableAdsEnabled": |
238 if ("enable" in data) | 197 if ("enable" in data) |
239 { | 198 { |
240 this.acceptableAdsEnabled = !!data["enable"]; | 199 this.acceptableAdsEnabled = !!data["enable"]; |
241 return {"success": true}; | 200 return {"success": true}; |
242 } | 201 } |
243 break; | 202 break; |
244 case "getSubscriptionsXml": | 203 case "getSubscriptionsXml": |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 { | 240 { |
282 this.whitelistSite(data["url"], data["whitelisted"]); | 241 this.whitelistSite(data["url"], data["whitelisted"]); |
283 return {"success": true}; | 242 return {"success": true}; |
284 } | 243 } |
285 break; | 244 break; |
286 } | 245 } |
287 return {"success": false, "error": "malformed request"}; | 246 return {"success": false, "error": "malformed request"}; |
288 }).bind(this), "AdblockPlus:Api"); | 247 }).bind(this), "AdblockPlus:Api"); |
289 } | 248 } |
290 }; | 249 }; |
LEFT | RIGHT |