From 547763099f0e639c84dc767f9e3cac12ec049e7c Mon Sep 17 00:00:00 2001 From: "edward.lee@engineering.uiuc.edu" Date: Mon, 25 Feb 2008 13:38:54 -0800 Subject: [PATCH] Bug 401316 - Open-with downloads are readonly. r=biesi, sr=biesi, a1.9=damons --- .../exthandler/nsExternalHelperAppService.cpp | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index c05b7f6e907..8746767cbda 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -2068,8 +2068,25 @@ nsresult nsExternalAppHandler::OpenWithApplication() // if a stop request was already issued then proceed with launching the application. if (mStopRequestIssued) { + PRBool deleteTempFileOnExit; + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (!prefs || NS_FAILED(prefs->GetBoolPref( + "browser.helperApps.deleteTempFileOnExit", &deleteTempFileOnExit))) { + // No prefservice or no pref set; use default value +#if !defined(XP_MACOSX) + // Mac users have been very verbal about temp files being deleted on + // app exit - they don't like it - but we'll continue to do this on + // other platforms for now. + deleteTempFileOnExit = PR_TRUE; +#else + deleteTempFileOnExit = PR_FALSE; +#endif + } + // make the tmp file readonly so users won't edit it and lose the changes - mFinalFileDestination->SetPermissions(0400); + // only if we're going to delete the file + if (deleteTempFileOnExit) + mFinalFileDestination->SetPermissions(0400); rv = mMimeInfo->LaunchWithFile(mFinalFileDestination); if (NS_FAILED(rv)) @@ -2080,30 +2097,9 @@ nsresult nsExternalAppHandler::OpenWithApplication() SendStatusChange(kLaunchError, rv, nsnull, path); Cancel(rv); // Cancel, and clean up temp file. } - else - { - PRBool deleteTempFileOnExit; - nsresult result = NS_ERROR_NOT_AVAILABLE; // don't return this! - nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefs) { - result = prefs->GetBoolPref("browser.helperApps.deleteTempFileOnExit", - &deleteTempFileOnExit); - } - if (NS_FAILED(result)) { - // No pref set; use default value -#if !defined(XP_MACOSX) - // Mac users have been very verbal about temp files being deleted on - // app exit - they don't like it - but we'll continue to do this on - // other platforms for now. - deleteTempFileOnExit = PR_TRUE; -#else - deleteTempFileOnExit = PR_FALSE; -#endif - } - if (deleteTempFileOnExit) { - NS_ASSERTION(gExtProtSvc, "Service gone away!?"); - gExtProtSvc->DeleteTemporaryFileOnExit(mFinalFileDestination); - } + else if (deleteTempFileOnExit) { + NS_ASSERTION(gExtProtSvc, "Service gone away!?"); + gExtProtSvc->DeleteTemporaryFileOnExit(mFinalFileDestination); } }