Bug 1255040 Add webidl for install/uninstall via AddonManager r=bz

MozReview-Commit-ID: 9eLMPbxostQ

--HG--
extra : rebase_source : 136dee769494ab175babda1bb492660c91c3df9a
This commit is contained in:
Andrew Swan 2016-04-18 13:51:41 -07:00
Родитель 825da3832b
Коммит b8835303a6
2 изменённых файлов: 45 добавлений и 4 удалений

Просмотреть файл

@ -3,8 +3,9 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* We need a JSImplementation but cannot get one without a contract ID. Since
This object is only ever created from JS we don't need a real contract ID. */
/* We need a JSImplementation but cannot get one without a contract ID.
Since Addon and AddonInstall are only ever created from JS they don't need
real contract IDs. */
[ChromeOnly, JSImplementation="dummy"]
interface Addon {
// The add-on's ID.
@ -23,6 +24,27 @@ interface Addon {
readonly attribute boolean isEnabled;
// If the add-on is currently active in the browser.
readonly attribute boolean isActive;
Promise<boolean> uninstall();
};
[ChromeOnly, JSImplementation="dummy"]
interface AddonInstall : EventTarget {
// One of the STATE_* symbols from AddonManager.jsm
readonly attribute DOMString state;
// One of the ERROR_* symbols from AddonManager.jsm, or null
readonly attribute DOMString? error;
// How many bytes have been downloaded
readonly attribute long long progress;
// How many total bytes will need to be downloaded or -1 if unknown
readonly attribute long long maxProgress;
Promise<void> install();
Promise<void> cancel();
};
dictionary addonInstallOptions {
required DOMString url;
};
[HeaderFile="mozilla/AddonManagerWebAPI.h",
@ -38,4 +60,13 @@ interface AddonManager {
* @return A promise. It will resolve to an Addon if the add-on is installed.
*/
Promise<Addon> getAddonByID(DOMString id);
/**
* Creates an AddonInstall object for a given URL.
*
* @param options
* Only one supported option: 'url', the URL of the addon to install.
* @return A promise that resolves to an instance of AddonInstall.
*/
Promise<AddonInstall> createInstall(optional addonInstallOptions options);
};

Просмотреть файл

@ -55,11 +55,16 @@ const APIBroker = {
APIBroker.init();
function Addon(properties) {
function Addon(win, properties) {
// We trust the webidl binding to broker access to our properties.
for (let key of Object.keys(properties)) {
this[key] = properties[key];
}
this.uninstall = function() {
let err = new win.Error("not yet implemented");
return win.Promise.reject(err);
};
}
/**
@ -97,9 +102,14 @@ WebAPI.prototype = {
getAddonByID: WebAPITask(function*(id) {
let addonInfo = yield APIBroker.sendRequest("getAddonByID", id);
return addonInfo ? new Addon(addonInfo) : null;
return addonInfo ? new Addon(this.window, addonInfo) : null;
}),
createInstall() {
let err = new this.window.Error("not yet implemented");
return this.window.Promise.reject(err);
},
classID: Components.ID("{8866d8e3-4ea5-48b7-a891-13ba0ac15235}"),
contractID: "@mozilla.org/addon-web-api/manager;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIDOMGlobalPropertyInitializer])