| Index: adblockplus/Api.jsm |
| diff --git a/adblockplus/Api.jsm b/adblockplus/Api.jsm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..942e411034a1e551527a454c708ef5e823c168a5 |
| --- /dev/null |
| +++ b/adblockplus/Api.jsm |
| @@ -0,0 +1,98 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2015 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +var EXPORTED_SYMBOLS = ["AdblockPlusApi"]; |
| + |
| +const Cc = Components.classes; |
| +const Ci = Components.interfaces; |
| +const Cr = Components.results; |
| +const Cu = Components.utils; |
| + |
| +Cu.import("resource://gre/modules/Services.jsm"); |
| +Cu.import("resource://gre/modules/Messaging.jsm"); |
| + |
| +function require(module) |
| +{ |
| + let result = {}; |
| + result.wrappedJSObject = result; |
| + Services.obs.notifyObservers(result, "adblockplus-require", module); |
| + return result.exports; |
| +} |
| + |
| +let {FilterNotifier} = require("filterNotifier"); |
| +let {FilterStorage} = require("filterStorage"); |
| +let {Prefs} = require("prefs"); |
| +let {UI} = require("ui"); |
| + |
| +let {FilterNotifier} = require("filterNotifier"); |
| + |
| +var AdblockPlusApi = |
| +{ |
| + get filtersLoaded() |
| + { |
| + return filtersLoaded; |
| + }, |
| + get acceptableAdsEnabled() |
| + { |
| + return FilterStorage.subscriptions.some( |
| + (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); |
| + }, |
| + set acceptableAdsEnabled(acceptableAdsEnabled) |
| + { |
| + if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) |
| + UI.toggleAcceptableAds(); |
| + } |
| +}; |
| + |
| + |
| +FilterNotifier.addListener(function filterListener(action) |
| +{ |
| + if (action != "load") |
| + return; |
| + |
| + filtersLoaded = true; |
| + FilterNotifier.removeListener(filterListener); |
| +}); |
| + |
| +RequestService.addListener(function(data) |
| +{ |
| + if (!data) |
| + return {"success" : false, "error" : "misformed request"}; |
| + |
| + if (data["action"] == "query_ready_state") |
| + return {"success" : true, "value" : AdblockPlusApi.filtersLoaded}; |
| + |
| + if (!AdblockPlusApi.filtersLoaded) |
| + return {"success" : false, "error" : "filters not loaded"}; |
| + |
| + switch (data["action"]) |
| + { |
| + case "query_acceptable_ads_state": |
| + return {"success" : true, "value" : AdblockPlusApi.acceptableAdsEnabled}; |
| + case "change_acceptable_ads_state": |
| + if ("enable" in data) |
| + { |
| + AdblockPlusApi.acceptableAdsEnabled = !!data["enable"]; |
| + return {"success" : true}; |
| + } |
| + return {"success" : false, "error" : "misformed request"}; |
| + default: |
| + return {"success" : false, "error" : "unknown action '" + data["action"] + "'"}; |
| + } |
| + return {"success" : false, "error" : "misformed request"}; |
| +}, "AdblockPlus:Api"); |
| + |