diff --git a/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp b/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp index b0e829d2187..969d08c2de7 100644 --- a/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/mozilla/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -2031,10 +2031,6 @@ nsDownload::SetState(DownloadState aState) PRInt16 oldState = mDownloadState; mDownloadState = aState; - nsresult rv; - - nsCOMPtr pref = do_GetService(NS_PREFSERVICE_CONTRACTID); - // We don't want to lose access to our member variables nsRefPtr kungFuDeathGrip = this; @@ -2066,11 +2062,19 @@ nsDownload::SetState(DownloadState aState) case nsIDownloadManager::DOWNLOAD_FINISHED: { // Do what exthandler would have done if necessary - (void)ExecuteDesiredAction(); + nsresult rv = ExecuteDesiredAction(); + if (NS_FAILED(rv)) { + // We've failed to execute the desired action. As a result, we should + // fail the download so the user can try again. + (void)FailDownload(rv, nsnull); + return rv; + } // Now that we're done with handling the download, clean it up Finalize(); + nsCOMPtr pref(do_GetService(NS_PREFSERVICE_CONTRACTID)); + // Master pref to control this function. PRBool showTaskbarAlert = PR_TRUE; if (pref) @@ -2156,7 +2160,7 @@ nsDownload::SetState(DownloadState aState) // Before notifying the listener, we must update the database so that calls // to it work out properly. - rv = UpdateDB(); + nsresult rv = UpdateDB(); NS_ENSURE_SUCCESS(rv, rv); mDownloadManager->NotifyListenersOnDownloadStateChange(oldState, this); diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp index 3cbc5b9f724..b91f2e91649 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -1805,6 +1805,19 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction() if (NS_SUCCEEDED(rv)) rv = OpenWithApplication(); } + else + { + // Cancel the download and report an error. We do not want to end up in + // a state where it appears that we have a normal download that is + // pointing to a file that we did not actually create. + nsAutoString path; + mTempFile->GetPath(path); + SendStatusChange(kWriteError, rv, nsnull, path); + Cancel(rv); + + // We still need to notify if we have a progress listener, so we cannot + // return at this point. + } } else // Various unknown actions go here too { @@ -1817,7 +1830,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction() gExtProtSvc->FixFilePermissions(destfile); } } - + // Notify dialog that download is complete. // By waiting till this point, it ensures that the progress dialog doesn't indicate // success until we're really done. @@ -1833,7 +1846,7 @@ nsresult nsExternalAppHandler::ExecuteDesiredAction() nsIWebProgressListener::STATE_IS_NETWORK, NS_OK); } } - + return rv; }