From cb8d3c752f121807b92a807caff9107a02d31cdc Mon Sep 17 00:00:00 2001 From: Jan Horak Date: Thu, 19 Jul 2018 15:46:26 +0200 Subject: [PATCH] Bug 1463809 - Don't lookup mimeinfo of application/octet-stream; r=Paolo Mimeinfo returned for the generic application/octet-stream content type is usually irrelevant to the file extension, getting mimeinfo from extension itself is more reliable. Also prefer file extension over application/octet-stream content tyope when lookup in extras. MozReview-Commit-ID: A9Q2NFAwQ7b --HG-- extra : rebase_source : 4206cbfd898fb12b2415ef751a74d1bdeee26a2d --- uriloader/exthandler/nsExternalHelperAppService.cpp | 13 ++++--------- uriloader/exthandler/unix/nsOSHelperAppService.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index f69a078a4eb6..4ae754d14bf8 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -2595,16 +2595,11 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(const nsACStri // (3) No match yet. Ask extras. if (!found) { rv = NS_ERROR_FAILURE; -#ifdef XP_WIN - /* XXX Gross hack to wallpaper over the most common Win32 - * extension issues caused by the fix for bug 116938. See bug - * 120327, comment 271 for why this is needed. Not even sure we - * want to remove this once we have fixed all this stuff to work - * right; any info we get from extras on this type is pretty much - * useless.... - */ + // Getting info for application/octet-stream content-type from extras + // does not make a sense because this tends to open all octet-streams + // as Binary file with exe, com or bin extension regardless the real + // extension. if (!typeToUse.Equals(APPLICATION_OCTET_STREAM, nsCaseInsensitiveCStringComparator())) -#endif rv = FillMIMEInfoForMimeTypeFromExtras(typeToUse, *_retval); LOG(("Searched extras (by type), rv 0x%08" PRIX32 "\n", static_cast(rv))); // If that didn't work out, try file extension from extras diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp index 31bc54e0834e..1dd37e22972c 100644 --- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -31,6 +31,7 @@ #include "prenv.h" // for PR_GetEnv() #include "nsAutoPtr.h" #include "mozilla/Preferences.h" +#include "nsMimeTypes.h" using namespace mozilla; @@ -1450,7 +1451,12 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType, const nsACString& aFileExt, bool *aFound) { *aFound = true; - RefPtr retval = GetFromType(PromiseFlatCString(aType)); + RefPtr retval; + // Fallback to lookup by extension when generic 'application/octet-stream' + // content type is received. + if (!aType.EqualsLiteral(APPLICATION_OCTET_STREAM)) { + retval = GetFromType(PromiseFlatCString(aType)); + } bool hasDefault = false; if (retval) retval->GetHasDefaultHandler(&hasDefault);