Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: adblockplus/Api.jsm

Issue 29626577: Issue 6108 - No filter list is selected after a migration failure (Closed)
Patch Set: Small adjustments Created Dec. 5, 2017, 3:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | adblockplus/build.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 {
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
58 let {addonVersion} = require("info"); 65 let {addonVersion} = require("info");
59 if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPre f)) 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 79
66 function onFiltersSave() 80 function onFiltersSave()
67 { 81 {
68 if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsu rl)) 82 if (hasBlockSubscription())
69 { 83 {
70 setBoolPref(subscriptionsSavedPref, true); 84 setBoolPref(SUBSCRIPTIONS_SAVED_PREF, true);
71 } 85 }
72 Messaging.sendRequest({ type: "Abb:OnFiltersSave" }); 86 Messaging.sendRequest({ type: "Abb:OnFiltersSave" });
73 } 87 }
74 88
75 function getBoolPref(name) 89 function getBoolPref(name)
76 { 90 {
77 let branch = getPrefsBranch(); 91 let branch = getPrefsBranch();
78 try 92 try
79 { 93 {
80 return branch.getBoolPref(name); 94 return branch.getBoolPref(name);
(...skipping 11 matching lines...) Expand all
92 Services.prefs.savePrefFile(null); 106 Services.prefs.savePrefFile(null);
93 } 107 }
94 108
95 function getPrefsBranch() 109 function getPrefsBranch()
96 { 110 {
97 let {addonRoot, addonName} = require("info"); 111 let {addonRoot, addonName} = require("info");
98 let branchName = "extensions." + addonName + "."; 112 let branchName = "extensions." + addonName + ".";
99 return Services.prefs.getBranch(branchName); 113 return Services.prefs.getBranch(branchName);
100 } 114 }
101 115
116 function hasBlockSubscription()
117 {
118 return FilterStorage.subscriptions.some(
119 subscription => subscription instanceof DownloadableSubscription && subscrip tion.url != Prefs.subscriptions_exceptionsurl);
120 }
121
102 function getWhitelistingFilter(url) 122 function getWhitelistingFilter(url)
103 { 123 {
104 let uriObject = Services.io.newURI(url, null, null); 124 let uriObject = Services.io.newURI(url, null, null);
105 try 125 try
106 { 126 {
107 return defaultMatcher.whitelist.matchesAny( 127 return defaultMatcher.whitelist.matchesAny(
108 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null , false); 128 uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null , false);
109 } 129 }
110 catch (e) 130 catch (e)
111 { 131 {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 FilterStorage.addSubscription(subscriptionToAdd); 182 FilterStorage.addSubscription(subscriptionToAdd);
163 let subscription = FilterStorage.knownSubscriptions[url]; 183 let subscription = FilterStorage.knownSubscriptions[url];
164 if (subscription) 184 if (subscription)
165 { 185 {
166 subscription.disabled = false; 186 subscription.disabled = false;
167 if (!subscription.lastDownload) 187 if (!subscription.lastDownload)
168 { 188 {
169 Synchronizer.execute(subscription); 189 Synchronizer.execute(subscription);
170 } 190 }
171 } 191 }
192 if (url == Prefs.subscriptions_exceptionsurl)
193 {
194 setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, false);
195 }
196 else if (hasBlockSubscription())
197 {
198 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, false);
199 }
172 }, 200 },
173 removeSubscription: function(url) 201 removeSubscription: function(url)
174 { 202 {
175 FilterStorage.removeSubscription( 203 FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[url]);
176 FilterStorage.knownSubscriptions[url]); 204 if (url == Prefs.subscriptions_exceptionsurl)
205 {
206 setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, true);
207 }
208 else if (!hasBlockSubscription())
209 {
210 setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, true);
211 }
177 }, 212 },
178 getActiveSubscriptions: function() 213 getActiveSubscriptions: function()
179 { 214 {
180 let subscriptions = []; 215 let subscriptions = [];
181 for (let i = 0; i < FilterStorage.subscriptions.length; i++) 216 for (let i = 0; i < FilterStorage.subscriptions.length; i++)
182 { 217 {
183 let subscription = FilterStorage.subscriptions[i]; 218 let subscription = FilterStorage.subscriptions[i];
184 if (!subscription.disabled) 219 if (!subscription.disabled)
185 subscriptions.push({"title": subscription.title, "url": subscription.url }); 220 subscriptions.push({"title": subscription.title, "url": subscription.url });
186 } 221 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 { 330 {
296 this.whitelistSite(data["url"], data["whitelisted"]); 331 this.whitelistSite(data["url"], data["whitelisted"]);
297 return {"success": true}; 332 return {"success": true};
298 } 333 }
299 break; 334 break;
300 } 335 }
301 return {"success": false, "error": "malformed request"}; 336 return {"success": false, "error": "malformed request"};
302 }).bind(this), "AdblockPlus:Api"); 337 }).bind(this), "AdblockPlus:Api");
303 } 338 }
304 }; 339 };
OLDNEW
« no previous file with comments | « no previous file | adblockplus/build.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld