Index: adblockplus/Api.jsm |
=================================================================== |
--- a/adblockplus/Api.jsm |
+++ b/adblockplus/Api.jsm |
@@ -40,39 +40,53 @@ 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 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 |
let {addonVersion} = require("info"); |
- if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPref)) |
+ 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 +108,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 +184,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) |