Bug 1255040 - Add webidl for install/uninstall via AddonManager. r=bz
authorAndrew Swan <aswan@mozilla.com>
Wed, 20 Apr 2016 09:42:38 -0700
changeset 331981 71e2c45790dc01e3cc7ffd00f35bca771da21b84
parent 331980 baa84a5b4465238deaf0eb1ba28ec7fd38154ef6
child 331982 a035f41ef23754a8dea677ab52b562e759c4cf50
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1255040
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1255040 - Add webidl for install/uninstall via AddonManager. r=bz MozReview-Commit-ID: 9eLMPbxostQ
dom/webidl/AddonManager.webidl
toolkit/mozapps/extensions/amWebAPI.js
--- a/dom/webidl/AddonManager.webidl
+++ b/dom/webidl/AddonManager.webidl
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * 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.
   readonly attribute DOMString id;
   // The add-on's version.
   readonly attribute DOMString version;
   // The add-on's type (extension, theme, etc.).
   readonly attribute DOMString type;
@@ -18,24 +19,54 @@ interface Addon {
   // The add-on's description in the current locale.
   readonly attribute DOMString description;
   // If the user has enabled this add-on, note that it still may not be running
   // depending on whether enabling requires a restart or if the add-on is
   // incompatible in some way.
   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",
  Func="mozilla::AddonManagerWebAPI::IsAPIEnabled",
  NavigatorProperty="mozAddonManager",
  JSImplementation="@mozilla.org/addon-web-api/manager;1"]
 interface AddonManager {
   /**
    * Gets information about an add-on
    *
    * @param  id
    *         The ID of the add-on to test for.
    * @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);
 };
--- a/toolkit/mozapps/extensions/amWebAPI.js
+++ b/toolkit/mozapps/extensions/amWebAPI.js
@@ -50,31 +50,36 @@ const APIBroker = {
       this._promises.set(callbackID, { resolve, reject });
       Services.cpmm.sendAsyncMessage(MSG_PROMISE_REQUEST, { type, callbackID, args });
     });
   },
 };
 
 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);
+  };
 }
 
 /**
  * API methods should return promises from the page, this is a simple wrapper
  * to make sure of that. It also automatically wraps objects when necessary.
  */
 function WebAPITask(generator) {
-  let task = Task.async(generator);
+  return function(...args) {
+    let task = Task.async(generator.bind(this));
 
-  return function(...args) {
     let win = this.window;
 
     let wrapForContent = (obj) => {
       if (obj instanceof Addon) {
         return win.Addon._create(win, obj);
       }
 
       return obj;
@@ -92,17 +97,22 @@ function WebAPI() {
 
 WebAPI.prototype = {
   init(window) {
     this.window = window;
   },
 
   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])
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([WebAPI]);