Fix 191977 (File not saved if progress dialog is the last open window) by landing bz's changes from bug 181374 (Downloads lost when using Progress dialog...).

The changes are slightly different here as the changes bz posted were for the trunk, and unfrtuantely the trunk nsDownloadManager.cpp and the Firebird Browser version have diverged significantly. I don't have time to bring them in sync now, just landing these components so we can get Fb 0.6 out the door.
This commit is contained in:
ben%netscape.com 2003-04-22 10:16:31 +00:00
parent 9a0d217546
commit 45b04c898e

View File

@ -543,12 +543,17 @@ nsDownloadManager::CancelDownload(const PRUnichar* aPath)
if (!mCurrDownloads.Exists(&key))
return RemoveDownload(aPath); // XXXBlake for now, to provide a workaround for stuck downloads
nsCOMPtr<nsIDownload> download;
nsDownload* internalDownload = NS_STATIC_CAST(nsDownload*, mCurrDownloads.Get(&key));
internalDownload->QueryInterface(NS_GET_IID(nsIDownload), (void**) getter_AddRefs(download));
nsCOMPtr<nsIDownload> download;
CallQueryInterface(internalDownload, NS_STATIC_CAST(nsIDownload**,
getter_AddRefs(download)));
if (!download)
return NS_ERROR_FAILURE;
// Don't cancel if download is already finished
if (internalDownload->mDownloadState == FINISHED)
return NS_OK;
internalDownload->SetDownloadState(CANCELED);
// if a persist was provided, we can do the cancel ourselves.
@ -1016,9 +1021,9 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
if (mListener)
mListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
if (mDialogListener)
mDialogListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
// We need to update mDownloadState before updating the dialog, because
// that will close and call CancelDownload if it was the last open window.
nsresult rv = NS_OK;
if (aStateFlags & STATE_STOP) {
if (mDownloadState == DOWNLOADING || mDownloadState == NOTSTARTED) {
mDownloadState = FINISHED;
@ -1031,10 +1036,11 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
gObserverService->NotifyObservers(NS_STATIC_CAST(nsIDownload *, this), "dl-done", nsnull);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
mDownloadManager->DownloadEnded(path.get(), nsnull);
rv = mTarget->GetPath(path);
// can't do an early return; have to break reference cycle below
if (NS_SUCCEEDED(rv)) {
mDownloadManager->DownloadEnded(path.get(), nsnull);
}
}
// break the cycle we created in AddDownload
@ -1042,7 +1048,10 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
mPersist->SetProgressListener(nsnull);
}
return NS_OK;
if (mDialogListener)
mDialogListener->OnStateChange(aWebProgress, aRequest, aStateFlags, aStatus);
return rv;
}
NS_IMETHODIMP