Bug 830271 - Make download UI notification take an nsIDownload. r=mak sr=mossop

This commit is contained in:
Josh Matthews 2013-01-21 16:11:45 +00:00
parent 8a38786008
commit 3a496e0b5b
6 changed files with 16 additions and 26 deletions

View File

@ -60,10 +60,10 @@ DownloadsUI.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// 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;
}
@ -76,19 +76,19 @@ DownloadsUI.prototype = {
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);
}
},
@ -112,7 +112,7 @@ DownloadsUI.prototype = {
* 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.

View File

@ -17,7 +17,7 @@ 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;

View File

@ -2482,7 +2482,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(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) {

View File

@ -24,7 +24,7 @@ nsDownloadManagerUI.prototype = {
//////////////////////////////////////////////////////////////////////////////
//// nsIDownloadManagerUI
show: function show(aWindowContext, aID, aReason, aUsePrivateUI)
show: function show(aWindowContext, aDownload, aReason, aUsePrivateUI)
{
if (!aReason)
aReason = Ci.nsIDownloadManagerUI.REASON_USER_INTERACTED;
@ -52,15 +52,7 @@ nsDownloadManagerUI.prototype = {
// 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"].

View File

@ -52,9 +52,6 @@ public:
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);
@ -70,7 +67,7 @@ public:
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;
}

View File

@ -4,8 +4,9 @@
#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
@ -24,8 +25,8 @@ interface nsIDownloadManagerUI : nsISupports {
*
* @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
@ -35,7 +36,7 @@ interface nsIDownloadManagerUI : nsISupports {
* 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);