Bug 566020 - Add support for custom confirmation UI [r=dtownsend]
authorMark Finkle <mfinkle@mozilla.com>
Tue, 18 May 2010 23:16:50 -0400
changeset 42444 6108e2debf9ecc17529790100896f35ff33ccc89
parent 42443 f2c78e370b4377d77ebfb3cc2ee1e8dba4c3f6fd
child 42445 bb8801a4ac33ecf3f143f1cff9807c85fc5bbd79
push idunknown
push userunknown
push dateunknown
reviewersdtownsend
bugs566020
milestone1.9.3a5pre
Bug 566020 - Add support for custom confirmation UI [r=dtownsend]
toolkit/mozapps/extensions/amIWebInstallListener.idl
toolkit/mozapps/extensions/amWebInstallListener.js
--- a/toolkit/mozapps/extensions/amIWebInstallListener.idl
+++ b/toolkit/mozapps/extensions/amIWebInstallListener.idl
@@ -98,8 +98,33 @@ interface amIWebInstallListener : nsISup
    * @param  aCount
    *         The number of AddonInstalls
    * @return true if the caller should start the installs
    */
   boolean onWebInstallRequested(in nsIDOMWindowInternal aWindow, in nsIURI aUri,
                                 [array, size_is(aCount)] in nsIVariant aInstalls,
                                 [optional] in PRUint32 aCount);
 };
+
+/**
+ * amIWebInstallPrompt is used, if available, by the default implementation of 
+ * amIWebInstallInfo to display a confirmation UI to the user before running
+ * installs.
+ */
+[scriptable, uuid(c5529918-4291-4b56-bd46-e9268900f2a3)]
+interface amIWebInstallPrompt : nsISupports
+{
+  /**
+   * Get a confirmation that the user wants to start the installs.
+   *
+   * @param  aWindow
+   *         The window that triggered the installs
+   * @param  aUri
+   *         The URI of the site that triggered the installs
+   * @param  aInstalls
+   *         The AddonInstalls that were requested
+   * @param  aCount
+   *         The number of AddonInstalls
+   */
+  void confirm(in nsIDOMWindowInternal aWindow, in nsIURI aUri,
+               [array, size_is(aCount)] in nsIVariant aInstalls,
+               [optional] in PRUint32 aCount);
+};
--- a/toolkit/mozapps/extensions/amWebInstallListener.js
+++ b/toolkit/mozapps/extensions/amWebInstallListener.js
@@ -106,16 +106,26 @@ Installer.prototype = {
   checkAllDownloaded: function() {
     if (--this.count > 0)
       return;
 
     // Maybe none of the downloads were sucessful
     if (this.installs.length == 0)
       return;
 
+    if ("@mozilla.org/addons/web-install-prompt;1" in Cc) {
+      try {
+        let prompt = Cc["@mozilla.org/addons/web-install-prompt;1"].
+                     getService(Ci.amIWebInstallPrompt);
+        prompt.confirm(this.window, this.url, this.installs, this.installs.length);
+        return;
+      }
+      catch (e) {}
+    }
+
     let args = {};
     args.url = this.url;
     args.installs = this.installs;
     args.wrappedJSObject = args;
 
     Services.ww.openWindow(this.window, "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul",
                            null, "chrome,modal,centerscreen", args);
   },