| Index: adblockplus/Api.jsm |
| =================================================================== |
| --- a/adblockplus/Api.jsm |
| +++ b/adblockplus/Api.jsm |
| @@ -32,23 +32,76 @@ function require(module) |
| { |
| let result = {}; |
| result.wrappedJSObject = result; |
| Services.obs.notifyObservers(result, "adblockplus-require", module); |
| return result.exports; |
| } |
| let {Filter} = require("filterClasses"); |
| +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"; |
| + |
| +function initListeners() |
| +{ |
| + FilterNotifier.on("load", onLoad); |
| + FilterNotifier.on("save", onSave); |
| +} |
| + |
| +function onLoad() |
| +{ |
| + let {addonVersion} = require("info"); |
| + if (Prefs.currentVersion == addonVersion && !getBoolPref(subscriptionsSavedPref)) |
| + { |
| + UI.addSubscription(UI.currentWindow, Prefs.currentVersion); |
|
Felix Dahlke
2016/09/30 07:44:12
This'll solve the subscription issue I guess, but
diegocarloslima
2016/10/25 16:16:20
Actually firstRunActions is always performed. The
Felix Dahlke
2016/10/27 17:12:49
Acknowledged.
|
| + } |
| +} |
| + |
| +function onSave() |
| +{ |
| + if (FilterStorage.subscriptions.some((subscription) => subscription instanceof DownloadableSubscription && subscription.url != Prefs.subscriptions_exceptionsurl)) |
| + { |
| + setBoolPref(subscriptionsSavedPref, true); |
| + } |
| +} |
| + |
| +function getBoolPref(name) |
| +{ |
| + let branch = getPrefsBranch(); |
| + try |
| + { |
| + return branch.getBoolPref(name); |
| + } |
| + catch (e) |
| + { |
| + return null; |
|
anton
2016/09/30 06:39:04
LGTM in general if hiding exception with just `nul
Felix Dahlke
2016/09/30 07:44:12
That's alright, but because of type coercion, this
diegocarloslima
2016/10/25 16:16:20
I did that way to have a more flexible way of hand
|
| + } |
| +} |
| + |
| +function setBoolPref(name, value) |
| +{ |
| + let branch = getPrefsBranch(); |
| + branch.setBoolPref(name, value); |
| + Services.prefs.savePrefFile(null); |
| +} |
| + |
| +function getPrefsBranch() |
| +{ |
| + let {addonRoot, addonName} = require("info"); |
| + let branchName = "extensions." + addonName + "."; |
| + return Services.prefs.getBranch(branchName); |
| +} |
| + |
| function getWhitelistingFilter(url) |
| { |
| let uriObject = Services.io.newURI(url, null, null); |
| try |
| { |
| return defaultMatcher.whitelist.matchesAny( |
| uriObject.spec, "DOCUMENT", uriObject.host, false, null); |
| } |
| @@ -157,16 +210,18 @@ var AdblockPlusApi = |
| if (filter.subscriptions.length) |
| filter.disabled = true; |
| filter = getWhitelistingFilter(url); |
| } |
| } |
| }, |
| initCommunication: function() |
| { |
| + initListeners(); |
| + |
| Messaging.addListener((function(data) |
| { |
| if (!data) |
| return {"success": false, "error": "malformed request"}; |
| if (data["action"] == "getFiltersLoaded") |
| return {"success": true, "value": this.filtersLoaded}; |