Bug 397935 - Download Manager ("Downloads") window doesn't stay open when clicking on download-complete alert notification with auto-close pref ("close when done"). r=Mardak, sr=mconnor

git-svn-id: svn://10.0.0.236/trunk@249029 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sdwilsh%shawnwilsher.com
2008-04-03 03:05:22 +00:00
parent a12d928259
commit 9378af0c9a
6 changed files with 52 additions and 16 deletions

View File

@@ -37,18 +37,35 @@
#include "nsISupports.idl"
interface nsIInterfaceRequestor;
[scriptable, uuid(67796ac0-effe-4cb0-91d4-229176956164)]
[scriptable, uuid(ca7663d5-69e3-4c4a-b754-f462bd36b05f)]
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;
/**
* The reason that should be passed to the show method when we are displaying
* the UI because a new download is being added to it.
*/
const short REASON_NEW_DOWNLOAD = 1;
/**
* Shows the Download Manager's UI to the user.
*
* @param aWindowContext
* @param [optional] aWindowContext
* The parent window context to show the UI.
* @param aID
* @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.
*/
void show([optional] in nsIInterfaceRequestor aWindowContext,
[optional] in unsigned long aID);
[optional] in unsigned long aID,
[optional] in short aReason);
/**
* Indicates if the UI is visible or not.

View File

@@ -1806,7 +1806,7 @@ nsDownloadManager::Observe(nsISupports *aSubject,
nsCOMPtr<nsIDownloadManagerUI> dmui =
do_GetService("@mozilla.org/download-manager-ui;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
return dmui->Show(nsnull, 0);
return dmui->Show(nsnull, 0, nsIDownloadManagerUI::REASON_USER_INTERACTED);
} else if (strcmp(aTopic, "sleep_notification") == 0) {
// Pause downloads if we're sleeping, and mark the downloads as auto-resume
(void)PauseAllDownloads(PR_TRUE);

View File

@@ -58,39 +58,53 @@ nsDownloadManagerUI.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// nsIDownloadManagerUI
show: function show(aWindowContext, aID)
show: function show(aWindowContext, aID, aReason)
{
if (!aReason)
aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
// First we see if it is already visible
if (this.recentWindow) {
this.recentWindow.focus();
let window = this.recentWindow;
if (window) {
window.focus();
// If we are being asked to show again, with a user interaction reason,
// set the appropriate variable.
if (aReason == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED)
window.gUserInteracted = true;
return;
}
let parent = null;
// We try to get a window to use as the parent here. If we don't have one,
// the download manager will close immediately after opening if the pref
// browser.download.manager.closeWhenDone is set to true.
var window = null;
try {
if (aWindowContext)
window = aWindowContext.getInterface(Ci.nsIDOMWindow);
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);
var dm = Cc["@mozilla.org/download-manager;1"].
getService(Ci.nsIDownloadManager);
params.appendElement(dm, false);
// 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);
// 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"].
getService(Ci.nsIWindowWatcher);
ww.openWindow(window,
ww.openWindow(parent,
DOWNLOAD_MANAGER_URL,
"Download:Manager",
"chrome,dialog=no,resizable",

View File

@@ -106,7 +106,7 @@ public:
if (visible && !focus)
return dmui->GetAttention();
return dmui->Show(nsnull, id);
return dmui->Show(nsnull, id, nsIDownloadManagerUI::REASON_NEW_DOWNLOAD);
}
return rv;
}

View File

@@ -401,6 +401,11 @@ function Startup()
gDownloadListener = new DownloadProgressListener();
gDownloadManager.addListener(gDownloadListener);
// If the UI was displayed because the user interacted, we need to make sure
// we update gUserInteracted accordingly.
if (window.arguments[1] == Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED)
gUserInteracted = true;
// downloads can finish before Startup() does, so check if the window should
// close and act accordingly
if (!autoRemoveAndClose())

View File

@@ -74,7 +74,7 @@ function test()
// Make sure the window stays open
let dmui = Cc["@mozilla.org/download-manager-ui;1"].
getService(Ci.nsIDownloadManagerUI);
// TODO bug 397935 ok(dmui.visible, "Download Manager stays open on alert click");
ok(dmui.visible, "Download Manager stays open on alert click");
setClose(false);
finish();