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-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"; | |
49 | 50 |
50 function initFilterListeners() | 51 function initFilterListeners() |
51 { | 52 { |
52 FilterNotifier.on("load", onFiltersLoad); | 53 FilterNotifier.on("load", onFiltersLoad); |
53 FilterNotifier.on("save", onFiltersSave); | 54 FilterNotifier.on("save", onFiltersSave); |
54 } | 55 } |
55 | 56 |
56 function onFiltersLoad() | 57 function onFiltersLoad() |
57 { | 58 { |
58 let {addonVersion} = require("info"); | 59 let {addonVersion} = require("info"); |
59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre f)) | 60 let detectedSubscriptionFailure = !hasBlockSubscription() && |
61 (!getBoolPref(SUBSCRIPTIONS_SAVED_PREF) || !getBoolPref(USER_REMOVED_BLOCK_S UBS_PREF) || FilterStorage.loadFromDiskFailed); | |
62 | |
63 // We will only try to recover the default subscription settings if the addonV ersion hasn't changed, | |
64 // otherwise it will be handled in firstRunActions(), inside ui.js | |
65 if(Prefs.currentVersion == addonVersion && detectedSubscriptionFailure) | |
anton
2017/12/04 14:00:46
space is needed here
diegocarloslima
2017/12/05 09:44:10
Acknowledged.
| |
60 { | 66 { |
61 UI.addSubscription(UI.currentWindow, Prefs.currentVersion); | 67 UI.addSubscription(UI.currentWindow, "0.0"); |
62 } | 68 } |
63 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); | 69 Messaging.sendRequest({ type: "Abb:OnFiltersLoad" }); |
64 } | 70 } |
65 | |
66 function onFiltersSave() | 71 function onFiltersSave() |
67 { | 72 { |
68 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu rl)) | 73 if (hasBlockSubscription()) |
69 { | 74 { |
70 setBoolPref(subscriptionsSavedPref, true); | 75 setBoolPref(SUBSCRIPTIONS_SAVED_PREF, true); |
71 } | 76 } |
72 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); | 77 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); |
73 } | 78 } |
74 | 79 |
75 function getBoolPref(name) | 80 function getBoolPref(name) |
76 { | 81 { |
77 let branch = getPrefsBranch(); | 82 let branch = getPrefsBranch(); |
78 try | 83 try |
79 { | 84 { |
80 return branch.getBoolPref(name); | 85 return branch.getBoolPref(name); |
(...skipping 11 matching lines...) Expand all Loading... | |
92 Services.prefs.savePrefFile(null); | 97 Services.prefs.savePrefFile(null); |
93 } | 98 } |
94 | 99 |
95 function getPrefsBranch() | 100 function getPrefsBranch() |
96 { | 101 { |
97 let {addonRoot, addonName} = require("info"); | 102 let {addonRoot, addonName} = require("info"); |
98 let branchName = "extensions." + addonName + "."; | 103 let branchName = "extensions." + addonName + "."; |
99 return Services.prefs.getBranch(branchName); | 104 return Services.prefs.getBranch(branchName); |
100 } | 105 } |
101 | 106 |
107 function hasBlockSubscription() | |
108 { | |
109 return FilterStorage.subscriptions.some( | |
110 (subscription) => subscription instanceof DownloadableSubscription && subscr iption.url != Prefs.subscriptions_exceptionsurl); | |
jens
2017/12/04 11:00:30
Do we need parentheses when there's only one param
diegocarloslima
2017/12/05 09:44:09
Acknowledged.
| |
111 } | |
112 | |
102 function getWhitelistingFilter(url) | 113 function getWhitelistingFilter(url) |
103 { | 114 { |
104 let uriObject = Services.io.newURI(url, null, null); | 115 let uriObject = Services.io.newURI(url, null, null); |
105 try | 116 try |
106 { | 117 { |
107 return defaultMatcher.whitelist.matchesAny( | 118 return defaultMatcher.whitelist.matchesAny( |
108 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null , false); | 119 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null , false); |
109 } | 120 } |
110 catch (e) | 121 catch (e) |
111 { | 122 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 FilterStorage.addSubscription(subscriptionToAdd); | 173 FilterStorage.addSubscription(subscriptionToAdd); |
163 let subscription = FilterStorage.knownSubscriptions[url]; | 174 let subscription = FilterStorage.knownSubscriptions[url]; |
164 if (subscription) | 175 if (subscription) |
165 { | 176 { |
166 subscription.disabled = false; | 177 subscription.disabled = false; |
167 if (!subscription.lastDownload) | 178 if (!subscription.lastDownload) |
168 { | 179 { |
169 Synchronizer.execute(subscription); | 180 Synchronizer.execute(subscription); |
170 } | 181 } |
171 } | 182 } |
183 if (hasBlockSubscription()) | |
184 { | |
185 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, false); | |
186 } | |
172 }, | 187 }, |
173 removeSubscription: function(url) | 188 removeSubscription: function(url) |
174 { | 189 { |
175 FilterStorage.removeSubscription( | 190 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[url]); |
176 FilterStorage.knownSubscriptions[url]); | 191 if (!hasBlockSubscription()) |
192 { | |
193 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, true); | |
194 } | |
177 }, | 195 }, |
178 getActiveSubscriptions: function() | 196 getActiveSubscriptions: function() |
179 { | 197 { |
180 let subscriptions = []; | 198 let subscriptions = []; |
181 for (let i = 0; i < FilterStorage.subscriptions.length; i++) | 199 for (let i = 0; i < FilterStorage.subscriptions.length; i++) |
182 { | 200 { |
183 let subscription = FilterStorage.subscriptions[i]; | 201 let subscription = FilterStorage.subscriptions[i]; |
184 if (!subscription.disabled) | 202 if (!subscription.disabled) |
185 subscriptions.push({"title": subscription.title, "url": subscription.url }); | 203 subscriptions.push({"title": subscription.title, "url": subscription.url }); |
186 } | 204 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 { | 313 { |
296 this.whitelistSite(data["url"], data["whitelisted"]); | 314 this.whitelistSite(data["url"], data["whitelisted"]); |
297 return {"success": true}; | 315 return {"success": true}; |
298 } | 316 } |
299 break; | 317 break; |
300 } | 318 } |
301 return {"success": false, "error": "malformed request"}; | 319 return {"success": false, "error": "malformed request"}; |
302 }).bind(this), "AdblockPlus:Api"); | 320 }).bind(this), "AdblockPlus:Api"); |
303 } | 321 } |
304 }; | 322 }; |
OLD | NEW |