OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ |
| 17 |
| 18 var EXPORTED_SYMBOLS = ["AdblockPlusApi"]; |
| 19 |
| 20 const Cc = Components.classes; |
| 21 const Ci = Components.interfaces; |
| 22 const Cr = Components.results; |
| 23 const Cu = Components.utils; |
| 24 |
| 25 Cu.import("resource://gre/modules/Services.jsm"); |
| 26 Cu.import("resource://gre/modules/Messaging.jsm"); |
| 27 |
| 28 function require(module) |
| 29 { |
| 30 let result = {}; |
| 31 result.wrappedJSObject = result; |
| 32 Services.obs.notifyObservers(result, "adblockplus-require", module); |
| 33 return result.exports; |
| 34 } |
| 35 |
| 36 let {FilterNotifier} = require("filterNotifier"); |
| 37 let {FilterStorage} = require("filterStorage"); |
| 38 let {Prefs} = require("prefs"); |
| 39 let {UI} = require("ui"); |
| 40 |
| 41 let {FilterNotifier} = require("filterNotifier"); |
| 42 |
| 43 var AdblockPlusApi = |
| 44 { |
| 45 get filtersLoaded() |
| 46 { |
| 47 return filtersLoaded; |
| 48 }, |
| 49 get acceptableAdsEnabled() |
| 50 { |
| 51 return FilterStorage.subscriptions.some( |
| 52 (subscription) => subscription.url == Prefs.subscriptions_exceptionsurl); |
| 53 }, |
| 54 set acceptableAdsEnabled(acceptableAdsEnabled) |
| 55 { |
| 56 if (acceptableAdsEnabled != AdblockPlusApi.acceptableAdsEnabled) |
| 57 UI.toggleAcceptableAds(); |
| 58 } |
| 59 }; |
| 60 |
| 61 |
| 62 FilterNotifier.addListener(function filterListener(action) |
| 63 { |
| 64 if (action != "load") |
| 65 return; |
| 66 |
| 67 filtersLoaded = true; |
| 68 FilterNotifier.removeListener(filterListener); |
| 69 }); |
| 70 |
| 71 RequestService.addListener(function(data) |
| 72 { |
| 73 if (!data) |
| 74 return {"success" : false, "error" : "misformed request"}; |
| 75 |
| 76 if (data["action"] == "query_ready_state") |
| 77 return {"success" : true, "value" : AdblockPlusApi.filtersLoaded}; |
| 78 |
| 79 if (!AdblockPlusApi.filtersLoaded) |
| 80 return {"success" : false, "error" : "filters not loaded"}; |
| 81 |
| 82 switch (data["action"]) |
| 83 { |
| 84 case "query_acceptable_ads_state": |
| 85 return {"success" : true, "value" : AdblockPlusApi.acceptableAdsEnabled}; |
| 86 case "change_acceptable_ads_state": |
| 87 if ("enable" in data) |
| 88 { |
| 89 AdblockPlusApi.acceptableAdsEnabled = !!data["enable"]; |
| 90 return {"success" : true}; |
| 91 } |
| 92 return {"success" : false, "error" : "misformed request"}; |
| 93 default: |
| 94 return {"success" : false, "error" : "unknown action '" + data["action"] +
"'"}; |
| 95 } |
| 96 return {"success" : false, "error" : "misformed request"}; |
| 97 }, "AdblockPlus:Api"); |
| 98 |
OLD | NEW |