AddonManager.webidl (4207B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 /* We need a JSImplementation but cannot get one without a contract ID. 7 Since Addon and AddonInstall are only ever created from JS they don't need 8 real contract IDs. */ 9 [ChromeOnly, JSImplementation="dummy", 10 Exposed=Window] 11 interface Addon { 12 // The add-on's ID. 13 readonly attribute DOMString id; 14 // The add-on's version. 15 readonly attribute DOMString version; 16 // The add-on's type (extension, theme, etc.). 17 readonly attribute DOMString type; 18 // The add-on's name in the current locale. 19 readonly attribute DOMString name; 20 // The add-on's description in the current locale. 21 readonly attribute DOMString description; 22 // If the user has enabled this add-on, note that it still may not be running 23 // depending on whether enabling requires a restart or if the add-on is 24 // incompatible in some way. 25 readonly attribute boolean isEnabled; 26 // If the add-on is currently active in the browser. 27 readonly attribute boolean isActive; 28 // If the add-on may be uninstalled 29 readonly attribute boolean canUninstall; 30 31 Promise<boolean> uninstall(); 32 Promise<undefined> setEnabled(boolean value); 33 }; 34 35 [ChromeOnly, JSImplementation="dummy", 36 Exposed=Window] 37 interface AddonInstall : EventTarget { 38 // One of the STATE_* symbols from AddonManager.sys.mjs 39 readonly attribute DOMString state; 40 // One of the ERROR_* symbols from AddonManager.sys.mjs, or null 41 readonly attribute DOMString? error; 42 // How many bytes have been downloaded 43 readonly attribute long long progress; 44 // How many total bytes will need to be downloaded or -1 if unknown 45 readonly attribute long long maxProgress; 46 47 Promise<undefined> install(); 48 Promise<undefined> cancel(); 49 }; 50 51 dictionary addonInstallOptions { 52 required DOMString url; 53 // If a non-empty string is passed for "hash", it is used to verify the 54 // checksum of the downloaded XPI before installing. If is omitted or if 55 // it is null or empty string, no checksum verification is performed. 56 DOMString? hash = null; 57 }; 58 59 dictionary sendAbuseReportOptions { 60 // This should be an Authorization HTTP header value. 61 DOMString? authorization = null; 62 }; 63 64 [HeaderFile="mozilla/AddonManagerWebAPI.h", 65 Func="mozilla::AddonManagerWebAPI::IsAPIEnabled", 66 JSImplementation="@mozilla.org/addon-web-api/manager;1", 67 WantsEventListenerHooks, 68 Exposed=Window] 69 interface AddonManager : EventTarget { 70 /** 71 * Gets information about an add-on 72 * 73 * @param id 74 * The ID of the add-on to test for. 75 * @return A promise. It will resolve to an Addon if the add-on is installed. 76 */ 77 Promise<Addon> getAddonByID(DOMString id); 78 79 /** 80 * Creates an AddonInstall object for a given URL. 81 * 82 * @param options 83 * Only one supported option: 'url', the URL of the addon to install. 84 * @return A promise that resolves to an instance of AddonInstall. 85 */ 86 Promise<AddonInstall> createInstall(optional addonInstallOptions options = {}); 87 88 /** 89 * Sends an abuse report to the AMO API. 90 * 91 * NOTE: The type for `data` and for the return value are loose because both 92 * the AMO API might change its response and the caller (AMO frontend) might 93 * also want to pass slightly different data in the future. 94 * 95 * @param addonId 96 * The ID of the add-on to report. 97 * @param data 98 * The caller passes the data to be sent to the AMO API. 99 * @param options 100 * Optional - A set of options. It currently only supports 101 * `authorization`, which is expected to be the value of an 102 * Authorization HTTP header when provided. 103 * @return A promise that resolves to the AMO API response, or an error when 104 * something went wrong. 105 */ 106 [NewObject] Promise<any> sendAbuseReport( 107 DOMString addonId, 108 record<DOMString, DOMString?> data, 109 optional sendAbuseReportOptions options = {} 110 ); 111 }; 112 113 [ChromeOnly,Exposed=Window,HeaderFile="mozilla/AddonManagerWebAPI.h"] 114 namespace AddonManagerPermissions { 115 boolean isHostPermitted(DOMString host); 116 };