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

Unified Diff: adblockplus/Api.jsm

Issue 29626577: Issue 6108 - No filter list is selected after a migration failure (Closed)
Patch Set: Adding USER_REMOVED_EXCEPTIONS_SUB_PREF Created Dec. 5, 2017, 9:42 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | adblockplus/build.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: adblockplus/Api.jsm
===================================================================
--- a/adblockplus/Api.jsm
+++ b/adblockplus/Api.jsm
@@ -40,39 +40,52 @@ let {Filter, RegExpFilter} = require("fi
let {FilterNotifier} = require("filterNotifier");
let {FilterStorage} = require("filterStorage");
let {defaultMatcher} = require("matcher");
let {Prefs} = require("prefs");
let {Subscription, SpecialSubscription, RegularSubscription, DownloadableSubscription, ExternalSubscription} = require("subscriptionClasses");
let {Synchronizer} = require("synchronizer");
let {UI} = require("ui");
-let subscriptionsSavedPref = "subscriptions_saved";
+const SUBSCRIPTIONS_SAVED_PREF = "subscriptions_saved";
+const USER_REMOVED_BLOCK_SUBS_PREF = "user_removed_block_subscriptions";
+const USER_REMOVED_EXCEPTIONS_SUB_PREF = "user_removed_exception_subscription";
function initFilterListeners()
{
FilterNotifier.on("load", onFiltersLoad);
FilterNotifier.on("save", onFiltersSave);
}
function onFiltersLoad()
{
let {addonVersion} = require("info");
- if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPref))
+ let detectedSubscriptionFailure = !hasBlockSubscription() &&
+ (!getBoolPref(SUBSCRIPTIONS_SAVED_PREF) || !getBoolPref(USER_REMOVED_BLOCK_SUBS_PREF) || FilterStorage.loadFromDiskFailed);
+
+ // We will only try to recover the default subscription settings if the addonVersion hasn't changed,
+ // otherwise it will be handled in firstRunActions(), inside ui.js
+ if (Prefs.currentVersion == addonVersion && detectedSubscriptionFailure)
{
- UI.addSubscription(UI.currentWindow, Prefs.currentVersion);
+ if (getBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF))
+ {
+ UI.addSubscription(UI.currentWindow, Prefs.currentVersion);
+ }
+ else
+ {
+ UI.addSubscription(UI.currentWindow, "0.0");
+ }
}
Messaging.sendRequest({ type: "Abb:OnFiltersLoad" });
}
-
function onFiltersSave()
{
- if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl))
+ if (hasBlockSubscription())
{
- setBoolPref(subscriptionsSavedPref, true);
+ setBoolPref(SUBSCRIPTIONS_SAVED_PREF, true);
}
Messaging.sendRequest({ type: "Abb:OnFiltersSave" });
}
function getBoolPref(name)
{
let branch = getPrefsBranch();
try
@@ -94,16 +107,22 @@ function setBoolPref(name, value)
function getPrefsBranch()
{
let {addonRoot, addonName} = require("info");
let branchName = "extensions." + addonName + ".";
return Services.prefs.getBranch(branchName);
}
+function hasBlockSubscription()
+{
+ return FilterStorage.subscriptions.some(
+ subscription => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl);
+}
+
function getWhitelistingFilter(url)
{
let uriObject = Services.io.newURI(url, null, null);
try
{
return defaultMatcher.whitelist.matchesAny(
uriObject.spec, RegExpFilter.typeMap.DOCUMENT, uriObject.host, false, null, false);
}
@@ -164,21 +183,36 @@ var AdblockPlusApi =
if (subscription)
{
subscription.disabled = false;
if (!subscription.lastDownload)
{
Synchronizer.execute(subscription);
}
}
+ if (url == Prefs.subscriptions_exceptionsurl)
+ {
+ setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, false);
+ }
+ else if (hasBlockSubscription())
+ {
+ setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, false);
+ }
},
removeSubscription: function(url)
{
- FilterStorage.removeSubscription(
- FilterStorage.knownSubscriptions[url]);
+ FilterStorage.removeSubscription(FilterStorage.knownSubscriptions[url]);
+ if (url == Prefs.subscriptions_exceptionsurl)
+ {
+ setBoolPref(USER_REMOVED_EXCEPTIONS_SUB_PREF, true);
+ }
+ else if (!hasBlockSubscription())
+ {
+ setBoolPref(USER_REMOVED_BLOCK_SUBS_PREF, true);
+ }
},
getActiveSubscriptions: function()
{
let subscriptions = [];
for (let i = 0; i < FilterStorage.subscriptions.length; i++)
{
let subscription = FilterStorage.subscriptions[i];
if (!subscription.disabled)
« 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