Bug 1255040 Add webidl for install/uninstall via AddonManager r=bz
☠☠ backed out by f60bd9567a05 ☠ ☠
authorAndrew Swan <aswan@mozilla.com>
Mon, 18 Apr 2016 13:51:41 -0700
changeset 317548 00bb04b8c9a0495fe026f609b18e09835e49c927
parent 317547 59fe5c482a5535f44775070b7ee56d9d15561b6b
child 317549 6741a3b28c55793fc1048afede74a305cc778165
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1255040
milestone48.0a1
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,21 +50,26 @@ 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);
@@ -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]);