diff --git a/mozilla/toolkit/components/downloads/public/nsIDownloadManagerUI.idl b/mozilla/toolkit/components/downloads/public/nsIDownloadManagerUI.idl index b037e6fbd01..5332a78abce 100644 --- a/mozilla/toolkit/components/downloads/public/nsIDownloadManagerUI.idl +++ b/mozilla/toolkit/components/downloads/public/nsIDownloadManagerUI.idl @@ -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. diff --git a/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp b/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp index 294de1b71bf..4e6b41312cc 100644 --- a/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -1806,7 +1806,7 @@ nsDownloadManager::Observe(nsISupports *aSubject, nsCOMPtr 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); diff --git a/mozilla/toolkit/components/downloads/src/nsDownloadManagerUI.js b/mozilla/toolkit/components/downloads/src/nsDownloadManagerUI.js index 12a4eba1aaf..48f85f2383e 100644 --- a/mozilla/toolkit/components/downloads/src/nsDownloadManagerUI.js +++ b/mozilla/toolkit/components/downloads/src/nsDownloadManagerUI.js @@ -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", diff --git a/mozilla/toolkit/components/downloads/src/nsDownloadProxy.h b/mozilla/toolkit/components/downloads/src/nsDownloadProxy.h index 7527b362a91..270f1b99ca4 100644 --- a/mozilla/toolkit/components/downloads/src/nsDownloadProxy.h +++ b/mozilla/toolkit/components/downloads/src/nsDownloadProxy.h @@ -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; } diff --git a/mozilla/toolkit/mozapps/downloads/content/downloads.js b/mozilla/toolkit/mozapps/downloads/content/downloads.js index 9a004707cc6..9a6ad8a38b7 100644 --- a/mozilla/toolkit/mozapps/downloads/content/downloads.js +++ b/mozilla/toolkit/mozapps/downloads/content/downloads.js @@ -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()) diff --git a/mozilla/toolkit/mozapps/downloads/tests/browser/browser_bug_397935.js b/mozilla/toolkit/mozapps/downloads/tests/browser/browser_bug_397935.js index 20a59f8affd..d3e30e91d15 100644 --- a/mozilla/toolkit/mozapps/downloads/tests/browser/browser_bug_397935.js +++ b/mozilla/toolkit/mozapps/downloads/tests/browser/browser_bug_397935.js @@ -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();