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"); | |
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 subscriptionsSavedPref = "subscriptions_saved"; | |
49 | |
50 function initListeners() | |
51 { | |
52 FilterNotifier.on("load", onLoad); | |
53 FilterNotifier.on("save", onSave); | |
54 } | |
55 | |
56 function onLoad() | |
57 { | |
58 let {addonVersion} = require("info"); | |
59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre f)) | |
60 { | |
61 UI.addSubscription(UI.currentWindow, Prefs.currentVersion); | |
Felix Dahlke
2016/09/30 07:44:12
This'll solve the subscription issue I guess, but
diegocarloslima
2016/10/25 16:16:20
Actually firstRunActions is always performed. The
Felix Dahlke
2016/10/27 17:12:49
Acknowledged.
| |
62 } | |
63 } | |
64 | |
65 function onSave() | |
66 { | |
67 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu rl)) | |
68 { | |
69 setBoolPref(subscriptionsSavedPref, true); | |
70 } | |
71 } | |
72 | |
73 function getBoolPref(name) | |
74 { | |
75 let branch = getPrefsBranch(); | |
76 try | |
77 { | |
78 return branch.getBoolPref(name); | |
79 } | |
80 catch (e) | |
81 { | |
82 return null; | |
anton
2016/09/30 06:39:04
LGTM in general if hiding exception with just `nul
Felix Dahlke
2016/09/30 07:44:12
That's alright, but because of type coercion, this
diegocarloslima
2016/10/25 16:16:20
I did that way to have a more flexible way of hand
| |
83 } | |
84 } | |
85 | |
86 function setBoolPref(name, value) | |
87 { | |
88 let branch = getPrefsBranch(); | |
89 branch.setBoolPref(name, value); | |
90 Services.prefs.savePrefFile(null); | |
91 } | |
92 | |
93 function getPrefsBranch() | |
94 { | |
95 let {addonRoot, addonName} = require("info"); | |
96 let branchName = "extensions." + addonName + "."; | |
97 return Services.prefs.getBranch(branchName); | |
98 } | |
99 | |
47 function getWhitelistingFilter(url) | 100 function getWhitelistingFilter(url) |
48 { | 101 { |
49 let uriObject = Services.io.newURI(url, null, null); | 102 let uriObject = Services.io.newURI(url, null, null); |
50 try | 103 try |
51 { | 104 { |
52 return defaultMatcher.whitelist.matchesAny( | 105 return defaultMatcher.whitelist.matchesAny( |
53 uriObject.spec, "DOCUMENT", uriObject.host, false, null); | 106 uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
54 } | 107 } |
55 catch (e) | 108 catch (e) |
56 { | 109 { |
(...skipping 98 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"}; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 { | 279 { |
225 this.whitelistSite(data["url"], data["whitelisted"]); | 280 this.whitelistSite(data["url"], data["whitelisted"]); |
226 return {"success": true}; | 281 return {"success": true}; |
227 } | 282 } |
228 break; | 283 break; |
229 } | 284 } |
230 return {"success": false, "error": "malformed request"}; | 285 return {"success": false, "error": "malformed request"}; |
231 }).bind(this), "AdblockPlus:Api"); | 286 }).bind(this), "AdblockPlus:Api"); |
232 } | 287 } |
233 }; | 288 }; |
OLD | NEW |