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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 let {Filter, RegExpFilter} = require("filterClasses"); | 39 let {Filter, RegExpFilter} = require("filterClasses"); |
40 let {FilterNotifier} = require("filterNotifier"); | 40 let {FilterNotifier} = require("filterNotifier"); |
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 subscriptionsSavedPref = "subscriptions_saved"; | 48 const SUBSCRIPTIONS_SAVED_PREF = "subscriptions_saved"; |
| 49 const USER_REMOVED_BLOCK_SUBS_PREF = "user_removed_block_subscriptions"; |
| 50 const USER_REMOVED_EXCEPTIONS_SUB_PREF = "user_removed_exception_subscription"; |
49 | 51 |
50 function initFilterListeners() | 52 function initFilterListeners() |
51 { | 53 { |
52 FilterNotifier.on("load", onFiltersLoad); | 54 FilterNotifier.on("load", onFiltersLoad); |
53 FilterNotifier.on("save", onFiltersSave); | 55 FilterNotifier.on("save", onFiltersSave); |
54 } | 56 } |
55 | 57 |
56 function onFiltersLoad() | 58 function onFiltersLoad() |
57 { | 59 { |
58 let {addonVersion} = require("info"); | 60 let {addonVersion} = require("info"); |
59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre
f)) | 61 let detectedSubscriptionFailure = !hasBlockSubscription() && |
| 62 (!getBoolPref(SUBSCRIPTIONS_SAVED_PREF) || !getBoolPref(USER_REMOVED_BLOCK_S
UBS_PREF) || FilterStorage.loadFromDiskFailed); |
| 63 |
| 64 // We will only try to recover the default subscription settings if the addonV
ersion hasn't changed, |
| 65 // otherwise it will be handled in firstRunActions(), inside ui.js |
| 66 if (Prefs.currentVersion == addonVersion && detectedSubscriptionFailure) |
60 { | 67 { |
61 UI.addSubscription(UI.currentWindow, Prefs.currentVersion); | 68 if (getBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF)) |
| 69 { |
| 70 UI.addSubscription(UI.currentWindow, Prefs.currentVersion); |
| 71 } |
| 72 else |
| 73 { |
| 74 UI.addSubscription(UI.currentWindow, "0.0"); |
| 75 } |
62 } | 76 } |
63 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); | 77 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
64 } | 78 } |
65 | |
66 function onFiltersSave() | 79 function onFiltersSave() |
67 { | 80 { |
68 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof
DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu
rl)) | 81 if (hasBlockSubscription()) |
69 { | 82 { |
70 setBoolPref(subscriptionsSavedPref, true); | 83 setBoolPref(SUBSCRIPTIONS_SAVED_PREF, true); |
71 } | 84 } |
72 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); | 85 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
73 } | 86 } |
74 | 87 |
75 function getBoolPref(name) | 88 function getBoolPref(name) |
76 { | 89 { |
77 let branch = getPrefsBranch(); | 90 let branch = getPrefsBranch(); |
78 try | 91 try |
79 { | 92 { |
80 return branch.getBoolPref(name); | 93 return branch.getBoolPref(name); |
(...skipping 11 matching lines...) Expand all Loading... |
92 Services.prefs.savePrefFile(null); | 105 Services.prefs.savePrefFile(null); |
93 } | 106 } |
94 | 107 |
95 function getPrefsBranch() | 108 function getPrefsBranch() |
96 { | 109 { |
97 let {addonRoot, addonName} = require("info"); | 110 let {addonRoot, addonName} = require("info"); |
98 let branchName = "extensions." + addonName + "."; | 111 let branchName = "extensions." + addonName + "."; |
99 return Services.prefs.getBranch(branchName); | 112 return Services.prefs.getBranch(branchName); |
100 } | 113 } |
101 | 114 |
| 115 function hasBlockSubscription() |
| 116 { |
| 117 return FilterStorage.subscriptions.some( |
| 118 subscription => subscription instanceof DownloadableSubscription && subscrip
tion.url != Prefs.subscriptions_exceptionsurl); |
| 119 } |
| 120 |
102 function getWhitelistingFilter(url) | 121 function getWhitelistingFilter(url) |
103 { | 122 { |
104 let uriObject = Services.io.newURI(url, null, null); | 123 let uriObject = Services.io.newURI(url, null, null); |
105 try | 124 try |
106 { | 125 { |
107 return defaultMatcher.whitelist.matchesAny( | 126 return defaultMatcher.whitelist.matchesAny( |
108 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null
, false); | 127 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null
, false); |
109 } | 128 } |
110 catch (e) | 129 catch (e) |
111 { | 130 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 FilterStorage.addSubscription(subscriptionToAdd); | 181 FilterStorage.addSubscription(subscriptionToAdd); |
163 let subscription = FilterStorage.knownSubscriptions[url]; | 182 let subscription = FilterStorage.knownSubscriptions[url]; |
164 if (subscription) | 183 if (subscription) |
165 { | 184 { |
166 subscription.disabled = false; | 185 subscription.disabled = false; |
167 if (!subscription.lastDownload) | 186 if (!subscription.lastDownload) |
168 { | 187 { |
169 Synchronizer.execute(subscription); | 188 Synchronizer.execute(subscription); |
170 } | 189 } |
171 } | 190 } |
| 191 if (url == Prefs.subscriptions_exceptionsurl) |
| 192 { |
| 193 setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, false); |
| 194 } |
| 195 else if (hasBlockSubscription()) |
| 196 { |
| 197 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, false); |
| 198 } |
172 }, | 199 }, |
173 removeSubscription: function(url) | 200 removeSubscription: function(url) |
174 { | 201 { |
175 FilterStorage.removeSubscription( | 202 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[url]); |
176 FilterStorage.knownSubscriptions[url]); | 203 if (url == Prefs.subscriptions_exceptionsurl) |
| 204 { |
| 205 setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, true); |
| 206 } |
| 207 else if (!hasBlockSubscription()) |
| 208 { |
| 209 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, true); |
| 210 } |
177 }, | 211 }, |
178 getActiveSubscriptions: function() | 212 getActiveSubscriptions: function() |
179 { | 213 { |
180 let subscriptions = []; | 214 let subscriptions = []; |
181 for (let i = 0; i < FilterStorage.subscriptions.length; i++) | 215 for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
182 { | 216 { |
183 let subscription = FilterStorage.subscriptions[i]; | 217 let subscription = FilterStorage.subscriptions[i]; |
184 if (!subscription.disabled) | 218 if (!subscription.disabled) |
185 subscriptions.push({"title": subscription.title, "url": subscription.url
}); | 219 subscriptions.push({"title": subscription.title, "url": subscription.url
}); |
186 } | 220 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 { | 329 { |
296 this.whitelistSite(data["url"], data["whitelisted"]); | 330 this.whitelistSite(data["url"], data["whitelisted"]); |
297 return {"success": true}; | 331 return {"success": true}; |
298 } | 332 } |
299 break; | 333 break; |
300 } | 334 } |
301 return {"success": false, "error": "malformed request"}; | 335 return {"success": false, "error": "malformed request"}; |
302 }).bind(this), "AdblockPlus:Api"); | 336 }).bind(this), "AdblockPlus:Api"); |
303 } | 337 } |
304 }; | 338 }; |
OLD | NEW |