Bug 830271 - Make download UI notification take an nsIDownload. r=mak sr=mossop
authorJosh Matthews <josh@joshmatthews.net>
Mon, 21 Jan 2013 16:11:45 +0000
changeset 119429 f57f7c12b6dc379233f42533c66dde5e523fc5ee
parent 119428 c3072e256623294f1ebcab922a64413b6cb04ab2
child 119430 1aa6bf0a46a2fb1598ef427e77edfb31628d677a
push id24204
push usereakhgari@mozilla.com
push dateTue, 22 Jan 2013 17:50:00 +0000
treeherdermozilla-central@8962a7fabc33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, mossop
bugs830271
milestone21.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 830271 - Make download UI notification take an nsIDownload. r=mak sr=mossop
browser/components/downloads/src/DownloadsUI.js
mobile/android/components/DownloadManagerUI.js
toolkit/components/downloads/nsDownloadManager.cpp
toolkit/components/downloads/nsDownloadManagerUI.js
toolkit/components/downloads/nsDownloadProxy.h
toolkit/components/downloads/nsIDownloadManagerUI.idl
--- a/browser/components/downloads/src/DownloadsUI.js
+++ b/browser/components/downloads/src/DownloadsUI.js
@@ -55,45 +55,45 @@ DownloadsUI.prototype = {
   //////////////////////////////////////////////////////////////////////////////
   //// nsISupports
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDownloadManagerUI]),
 
   //////////////////////////////////////////////////////////////////////////////
   //// nsIDownloadManagerUI
 
-  show: function DUI_show(aWindowContext, aID, aReason, aUsePrivateUI)
+  show: function DUI_show(aWindowContext, aDownload, aReason, aUsePrivateUI)
   {
     if (DownloadsCommon.useToolkitUI) {
-      this._toolkitUI.show(aWindowContext, aID, aReason, aUsePrivateUI);
+      this._toolkitUI.show(aWindowContext, aDownload, aReason, aUsePrivateUI);
       return;
     }
 
     if (!aReason) {
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
     }
 
     if (aReason == Ci.nsIDownloadManagerUI.REASON_NEW_DOWNLOAD) {
       const kMinimized = Ci.nsIDOMChromeWindow.STATE_MINIMIZED;
       let browserWin = gBrowserGlue.getMostRecentBrowserWindow();
 
       if (!browserWin || browserWin.windowState == kMinimized) {
-        this._showDownloadManagerUI(aWindowContext, aID, aReason, aUsePrivateUI);
+        this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
       }
       else {
         // If the indicator is visible, then new download notifications are
         // already handled by the panel service.
         browserWin.DownloadsButton.checkIsVisible(function(isVisible) {
           if (!isVisible) {
-            this._showDownloadManagerUI(aWindowContext, aID, aReason, aUsePrivateUI);
+            this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
           }
         }.bind(this));
       }
     } else {
-      this._showDownloadManagerUI(aWindowContext, aID, aReason, aUsePrivateUI);
+      this._showDownloadManagerUI(aWindowContext, aUsePrivateUI);
     }
   },
 
   get visible()
   {
     // If we're still using the toolkit downloads manager, delegate the call
     // to it. Otherwise, return true for now, until we decide on how we want
     // to indicate that a new download has started if a browser window is
@@ -107,17 +107,17 @@ DownloadsUI.prototype = {
       this._toolkitUI.getAttention();
     }
   },
 
   /**
    * Helper function that opens the download manager UI.
    */
   _showDownloadManagerUI:
-  function DUI_showDownloadManagerUI(aWindowContext, aID, aReason, aUsePrivateUI)
+  function DUI_showDownloadManagerUI(aWindowContext, aUsePrivateUI)
   {
     // If we weren't given a window context, try to find a browser window
     // to use as our parent - and if that doesn't work, error out and give up.
     let parentWindow = aWindowContext;
     if (!parentWindow) {
       parentWindow = RecentWindow.getMostRecentBrowserWindow({ private: !!aUsePrivateUI });
       if (!parentWindow) {
         Components.utils.reportError(
--- a/mobile/android/components/DownloadManagerUI.js
+++ b/mobile/android/components/DownloadManagerUI.js
@@ -12,17 +12,17 @@ Components.utils.import("resource://gre/
 // Download Manager UI
 // -----------------------------------------------------------------------
 
 function DownloadManagerUI() { }
 
 DownloadManagerUI.prototype = {
   classID: Components.ID("{93db15b1-b408-453e-9a2b-6619e168324a}"),
 
-  show: function show(aWindowContext, aID, aReason, aUsePrivateUI) {
+  show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI) {
     if (!aReason)
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
 
     this._getBrowserApp().selectOrOpenTab("about:downloads");
   },
 
   get visible() {
     let browserApp = this._getBrowserApp();
--- a/toolkit/components/downloads/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/nsDownloadManager.cpp
@@ -2477,17 +2477,17 @@ nsDownloadManager::Observe(nsISupports *
            nsDependentString(aData).EqualsLiteral(NS_IOSERVICE_ONLINE)) {
     // We can now resume all downloads that are supposed to auto-resume.
     (void)ResumeAllDownloads(false);
   }
   else if (strcmp(aTopic, "alertclickcallback") == 0) {
     nsCOMPtr<nsIDownloadManagerUI> dmui =
       do_GetService("@mozilla.org/download-manager-ui;1", &rv);
     NS_ENSURE_SUCCESS(rv, rv);
-    return dmui->Show(nullptr, 0, nsIDownloadManagerUI::REASON_USER_INTERACTED,
+    return dmui->Show(nullptr, nullptr, nsIDownloadManagerUI::REASON_USER_INTERACTED,
                       aData && NS_strcmp(aData, NS_LITERAL_STRING("private").get()) == 0);
   } else if (strcmp(aTopic, "sleep_notification") == 0 ||
              strcmp(aTopic, "suspend_process_notification") == 0) {
     // Pause downloads if we're sleeping, and mark the downloads as auto-resume
     (void)PauseAllDownloads(true);
   } else if (strcmp(aTopic, "wake_notification") == 0 ||
              strcmp(aTopic, "resume_process_notification") == 0) {
     int32_t resumeOnWakeDelay = 10000;
--- a/toolkit/components/downloads/nsDownloadManagerUI.js
+++ b/toolkit/components/downloads/nsDownloadManagerUI.js
@@ -19,17 +19,17 @@ const PREF_FLASH_COUNT = "browser.downlo
 function nsDownloadManagerUI() {}
 
 nsDownloadManagerUI.prototype = {
   classID: Components.ID("7dfdf0d1-aff6-4a34-bad1-d0fe74601642"),
 
   //////////////////////////////////////////////////////////////////////////////
   //// nsIDownloadManagerUI
 
-  show: function show(aWindowContext, aID, aReason, aUsePrivateUI)
+  show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI)
   {
     if (!aReason)
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
 
     // First we see if it is already visible
     let window = this.recentWindow;
     if (window) {
       window.focus();
@@ -47,25 +47,17 @@ nsDownloadManagerUI.prototype = {
     // browser.download.manager.closeWhenDone is set to true.
     try {
       if (aWindowContext)
         parent = aWindowContext.getInterface(Ci.nsIDOMWindow);
     } catch (e) { /* it's OK to not have a parent window */ }
 
     // We pass the download manager and the nsIDownload we want selected (if any)
     var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
-
-    // Don't fail if our passed in ID is invalid
-    var download = null;
-    try {
-      let dm = Cc["@mozilla.org/download-manager;1"].
-               getService(Ci.nsIDownloadManager);
-      download = dm.getDownload(aID);
-    } catch (ex) {}
-    params.appendElement(download, false);
+    params.appendElement(aDownload, false);
 
     // Pass in the reason as well
     let reason = Cc["@mozilla.org/supports-PRInt16;1"].
                  createInstance(Ci.nsISupportsPRInt16);
     reason.data = aReason;
     params.appendElement(reason, false);
 
     var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
--- a/toolkit/components/downloads/nsDownloadProxy.h
+++ b/toolkit/components/downloads/nsDownloadProxy.h
@@ -47,35 +47,32 @@ public:
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr<nsIPrefBranch> branch = do_QueryInterface(prefs);
 
     bool showDM = true;
     if (branch)
       branch->GetBoolPref(PREF_BDM_SHOWWHENSTARTING, &showDM);
 
     if (showDM) {
-      uint32_t id;
-      mInner->GetId(&id);
-
       nsCOMPtr<nsIDownloadManagerUI> dmui =
         do_GetService("@mozilla.org/download-manager-ui;1", &rv);
       NS_ENSURE_SUCCESS(rv, rv);
 
       bool visible;
       rv = dmui->GetVisible(&visible);
       NS_ENSURE_SUCCESS(rv, rv);
 
       bool focusWhenStarting = true;
       if (branch)
         (void)branch->GetBoolPref(PREF_BDM_FOCUSWHENSTARTING, &focusWhenStarting);
 
       if (visible && !focusWhenStarting)
         return NS_OK;
 
-      return dmui->Show(nullptr, id, nsIDownloadManagerUI::REASON_NEW_DOWNLOAD, aIsPrivate);
+      return dmui->Show(nullptr, mInner, nsIDownloadManagerUI::REASON_NEW_DOWNLOAD, aIsPrivate);
     }
     return rv;
   }
 
   NS_IMETHODIMP OnStateChange(nsIWebProgress* aWebProgress,
                               nsIRequest* aRequest, uint32_t aStateFlags,
                               nsresult aStatus)
   {
--- a/toolkit/components/downloads/nsIDownloadManagerUI.idl
+++ b/toolkit/components/downloads/nsIDownloadManagerUI.idl
@@ -1,16 +1,17 @@
 /* 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/. */
 
 #include "nsISupports.idl"
 interface nsIInterfaceRequestor;
+interface nsIDownload;
 
-[scriptable, uuid(bc54ef90-5215-11e2-bcfd-0800200c9a66)]
+[scriptable, uuid(0c76d4cf-0b06-4c1a-9bea-520c7bbdba99)]
 interface nsIDownloadManagerUI : nsISupports {
   /**
    * The reason that should be passed when the user requests to show the
    * download manager's UI.
    */
   const short REASON_USER_INTERACTED = 0;
 
   /**
@@ -19,28 +20,28 @@ interface nsIDownloadManagerUI : nsISupp
    */
   const short REASON_NEW_DOWNLOAD = 1;
 
  /**
   * Shows the Download Manager's UI to the user.
   *
   * @param [optional] aWindowContext
   *        The parent window context to show the UI.
-  * @param [optional] aID
-  *        The id of the download to be preselected upon opening.
+  * @param [optional] aDownload
+  *        The download to be preselected upon opening.
   * @param [optional] aReason
   *        The reason to show the download manager's UI.  This defaults to
   *        REASON_USER_INTERACTED, and should be one of the previously listed
   *        constants.
   * @param [optional] aUsePrivateUI
   *        Pass true as this argument to hint to the implementation that it
   *        should only display private downloads in the UI, if possible.
   */
   void show([optional] in nsIInterfaceRequestor aWindowContext,
-            [optional] in unsigned long aID,
+            [optional] in nsIDownload aDownload,
             [optional] in short aReason,
             [optional] in boolean aUsePrivateUI);
 
  /**
   * Indicates if the UI is visible or not.
   */
   readonly attribute boolean visible;