Bug 810208 - Show the private download manager UI when clicking on the notification alert after a private download finishes; r=mak sr=gavin
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 29 Dec 2012 20:01:34 -0500
changeset 117358 7ff599b28e1130ad6d29cd5cb8d1fa030fdd7f7e
parent 117357 2e65e2a8077592ed395ff3d152674287d9b70bfb
child 117359 a38c72b27bf75bab9b085b29a87c42d900f73b63
push id20474
push usereakhgari@mozilla.com
push dateWed, 02 Jan 2013 22:14:31 +0000
treeherdermozilla-inbound@7ff599b28e11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, gavin
bugs810208
milestone20.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 810208 - Show the private download manager UI when clicking on the notification alert after a private download finishes; r=mak sr=gavin
browser/components/downloads/src/DownloadsUI.js
mobile/android/components/DownloadManagerUI.js
mobile/xul/components/DownloadManagerUI.js
toolkit/components/downloads/nsDownloadManager.cpp
toolkit/components/downloads/nsDownloadManagerUI.js
toolkit/components/downloads/nsDownloadProxy.h
toolkit/components/downloads/nsIDownloadManagerUI.idl
uriloader/exthandler/tests/unit_ipc/test_encoding.js
--- 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)
+  show: function DUI_show(aWindowContext, aID, aReason, aUsePrivateUI)
   {
     if (DownloadsCommon.useToolkitUI) {
-      this._toolkitUI.show(aWindowContext, aID, aReason);
+      this._toolkitUI.show(aWindowContext, aID, 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);
+        this._showDownloadManagerUI(aWindowContext, aID, aReason, 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);
+            this._showDownloadManagerUI(aWindowContext, aID, aReason, aUsePrivateUI);
           }
         }.bind(this));
       }
     } else {
-      this._showDownloadManagerUI(aWindowContext, aID, aReason);
+      this._showDownloadManagerUI(aWindowContext, aID, aReason, 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,23 +107,23 @@ DownloadsUI.prototype = {
       this._toolkitUI.getAttention();
     }
   },
 
   /**
    * Helper function that opens the download manager UI.
    */
   _showDownloadManagerUI:
-  function DUI_showDownloadManagerUI(aWindowContext, aID, aReason)
+  function DUI_showDownloadManagerUI(aWindowContext, aID, aReason, 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();
+      parentWindow = RecentWindow.getMostRecentBrowserWindow({ private: !!aUsePrivateUI });
       if (!parentWindow) {
         Components.utils.reportError(
           "Couldn't find a browser window to open the Places Downloads View " +
           "from.");
         return;
       }
     }
 
--- a/mobile/android/components/DownloadManagerUI.js
+++ b/mobile/android/components/DownloadManagerUI.js
@@ -11,17 +11,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) {
+  show: function show(aWindowContext, aID, aReason, aUsePrivateUI) {
     if (!aReason)
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
 
     let browser = Services.wm.getMostRecentWindow("navigator:browser");
     if (browser)
       browser.showDownloadManager(aWindowContext, aID, aReason);
   },
 
--- a/mobile/xul/components/DownloadManagerUI.js
+++ b/mobile/xul/components/DownloadManagerUI.js
@@ -11,17 +11,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) {
+  show: function show(aWindowContext, aID, aReason, aUsePrivateUI) {
     if (!aReason)
       aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
 
     let browser = Services.wm.getMostRecentWindow("navigator:browser");
     if (browser)
       browser.showDownloadManager(aWindowContext, aID, aReason);
   },
 
--- a/toolkit/components/downloads/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/nsDownloadManager.cpp
@@ -2474,22 +2474,21 @@ nsDownloadManager::Observe(nsISupports *
     (void)PauseAllDownloads(true);
   }
   else if (strcmp(aTopic, NS_IOSERVICE_OFFLINE_STATUS_TOPIC) == 0 &&
            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) {
-    //TODO: This doens't make sense when clicking a notification related to
-    //      private downloads when per-window mode is enabled. (bug 810208)
     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, 0, 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;
     nsCOMPtr<nsIPrefBranch> pref = do_GetService(NS_PREFSERVICE_CONTRACTID);
@@ -2771,18 +2770,19 @@ nsDownload::SetState(DownloadState aStat
                 mDownloadManager->GetRetentionBehavior() == 0;
 
               // If downloads are automatically removed per the user's
               // retention policy, there's no reason to make the text clickable
               // because if it is, they'll click open the download manager and
               // the items they downloaded will have been removed.
               alerts->ShowAlertNotification(
                   NS_LITERAL_STRING(DOWNLOAD_MANAGER_ALERT_ICON), title,
-                  message, !removeWhenDone, EmptyString(), mDownloadManager,
-                  EmptyString());
+                  message, !removeWhenDone,
+                  mPrivate ? NS_LITERAL_STRING("private") : NS_LITERAL_STRING("non-private"),
+                  mDownloadManager, EmptyString());
             }
         }
       }
 
 #if defined(XP_WIN) || defined(XP_MACOSX) || defined(MOZ_WIDGET_ANDROID) || defined(MOZ_WIDGET_GTK2)
       nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mTarget);
       nsCOMPtr<nsIFile> file;
       nsAutoString path;
--- 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)
+  show: function show(aWindowContext, aID, 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();
--- a/toolkit/components/downloads/nsDownloadProxy.h
+++ b/toolkit/components/downloads/nsDownloadProxy.h
@@ -65,17 +65,17 @@ public:
 
       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);
+      return dmui->Show(nullptr, id, 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,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/. */
 
 #include "nsISupports.idl"
 interface nsIInterfaceRequestor;
 
-[scriptable, uuid(ca7663d5-69e3-4c4a-b754-f462bd36b05f)]
+[scriptable, uuid(bc54ef90-5215-11e2-bcfd-0800200c9a66)]
 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;
 
   /**
@@ -25,20 +25,24 @@ interface nsIDownloadManagerUI : nsISupp
   * @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] 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 short aReason);
+            [optional] in short aReason,
+            [optional] in boolean aUsePrivateUI);
 
  /**
   * Indicates if the UI is visible or not.
   */
   readonly attribute boolean visible;
 
  /**
   * Brings attention to the UI if it is already visible
--- a/uriloader/exthandler/tests/unit_ipc/test_encoding.js
+++ b/uriloader/exthandler/tests/unit_ipc/test_encoding.js
@@ -53,17 +53,17 @@ let DownloadListener = {
   }
 }
 DownloadListener.init();
 
 function HelperAppDlg() { }
 HelperAppDlg.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIHelperAppLauncherDialog]),
   contractID: "@mozilla.org/helperapplauncherdialog;1",
-  show: function (launcher, ctx, reason) {
+  show: function (launcher, ctx, reason, usePrivateUI) {
     launcher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToFile;
     launcher.launchWithApplication(null, false);
   },
 
   promptForSaveToFile: function (launcher, ctx, defaultFile, suggestedExtension, forcePrompt) { }
 }
 
 // Stolen from XPCOMUtils, since this handy function is not public there