From 59d264251bd9d5f50c77926e7a726e8b9532c137 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sat, 29 Dec 2012 20:01:34 -0500 Subject: [PATCH] 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 | 14 +++++++------- mobile/android/components/DownloadManagerUI.js | 2 +- mobile/xul/components/DownloadManagerUI.js | 2 +- toolkit/components/downloads/nsDownloadManager.cpp | 10 +++++----- .../components/downloads/nsDownloadManagerUI.js | 2 +- toolkit/components/downloads/nsDownloadProxy.h | 2 +- .../components/downloads/nsIDownloadManagerUI.idl | 8 ++++++-- .../exthandler/tests/unit_ipc/test_encoding.js | 2 +- 8 files changed, 23 insertions(+), 19 deletions(-) diff --git a/browser/components/downloads/src/DownloadsUI.js b/browser/components/downloads/src/DownloadsUI.js index e6725a8f0fa8..baa732f7ec73 100644 --- a/browser/components/downloads/src/DownloadsUI.js +++ b/browser/components/downloads/src/DownloadsUI.js @@ -60,10 +60,10 @@ DownloadsUI.prototype = { ////////////////////////////////////////////////////////////////////////////// //// 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; } @@ -76,19 +76,19 @@ DownloadsUI.prototype = { 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); } }, @@ -112,13 +112,13 @@ DownloadsUI.prototype = { * 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 " + diff --git a/mobile/android/components/DownloadManagerUI.js b/mobile/android/components/DownloadManagerUI.js index befb28d06728..19023d9e19ac 100644 --- a/mobile/android/components/DownloadManagerUI.js +++ b/mobile/android/components/DownloadManagerUI.js @@ -16,7 +16,7 @@ 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; diff --git a/mobile/xul/components/DownloadManagerUI.js b/mobile/xul/components/DownloadManagerUI.js index befb28d06728..19023d9e19ac 100644 --- a/mobile/xul/components/DownloadManagerUI.js +++ b/mobile/xul/components/DownloadManagerUI.js @@ -16,7 +16,7 @@ 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; diff --git a/toolkit/components/downloads/nsDownloadManager.cpp b/toolkit/components/downloads/nsDownloadManager.cpp index ac7da5230fdb..9ea6e7fdd592 100644 --- a/toolkit/components/downloads/nsDownloadManager.cpp +++ b/toolkit/components/downloads/nsDownloadManager.cpp @@ -2479,12 +2479,11 @@ nsDownloadManager::Observe(nsISupports *aSubject, (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 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, + 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 @@ -2776,8 +2775,9 @@ nsDownload::SetState(DownloadState aState) // 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()); } } } diff --git a/toolkit/components/downloads/nsDownloadManagerUI.js b/toolkit/components/downloads/nsDownloadManagerUI.js index 29021756111a..bf3eff72de0b 100644 --- a/toolkit/components/downloads/nsDownloadManagerUI.js +++ b/toolkit/components/downloads/nsDownloadManagerUI.js @@ -24,7 +24,7 @@ nsDownloadManagerUI.prototype = { ////////////////////////////////////////////////////////////////////////////// //// nsIDownloadManagerUI - show: function show(aWindowContext, aID, aReason) + show: function show(aWindowContext, aID, aReason, aUsePrivateUI) { if (!aReason) aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED; diff --git a/toolkit/components/downloads/nsDownloadProxy.h b/toolkit/components/downloads/nsDownloadProxy.h index 87b12270f6d0..54d4c250e06d 100644 --- a/toolkit/components/downloads/nsDownloadProxy.h +++ b/toolkit/components/downloads/nsDownloadProxy.h @@ -70,7 +70,7 @@ public: 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; } diff --git a/toolkit/components/downloads/nsIDownloadManagerUI.idl b/toolkit/components/downloads/nsIDownloadManagerUI.idl index 066ec6263526..d9e69fe8f9ee 100644 --- a/toolkit/components/downloads/nsIDownloadManagerUI.idl +++ b/toolkit/components/downloads/nsIDownloadManagerUI.idl @@ -5,7 +5,7 @@ #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 @@ -30,10 +30,14 @@ interface nsIDownloadManagerUI : nsISupports { * 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. diff --git a/uriloader/exthandler/tests/unit_ipc/test_encoding.js b/uriloader/exthandler/tests/unit_ipc/test_encoding.js index 0e3c26de1f88..10a8f1cab10a 100644 --- a/uriloader/exthandler/tests/unit_ipc/test_encoding.js +++ b/uriloader/exthandler/tests/unit_ipc/test_encoding.js @@ -58,7 +58,7 @@ 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); },