From 58ac4dd796fd8434463e1f1d5f203f41d5f44fec Mon Sep 17 00:00:00 2001 From: Haik Aftandilian Date: Tue, 3 Apr 2018 13:42:43 -0700 Subject: [PATCH] Bug 1448374 - Loading a .javascript file from a WebExtension's web_accessible_resources messing with macOS file associations r=jimm From content processes, on Mac, use ContentHandlerService::GetTypeFromExtension() instead of trying to query the OS directly for MIME information. Trying to get MIME information from the OS is blocked by content process sandboxing on Mac. MozReview-Commit-ID: KGJHDBklxvb --HG-- extra : rebase_source : ae46525eee622d64ffc6e263b19682aec033480a --- uriloader/exthandler/mac/nsOSHelperAppService.h | 4 +++ uriloader/exthandler/mac/nsOSHelperAppService.mm | 32 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/uriloader/exthandler/mac/nsOSHelperAppService.h b/uriloader/exthandler/mac/nsOSHelperAppService.h index 9c8b8c915859..eb068699d426 100644 --- a/uriloader/exthandler/mac/nsOSHelperAppService.h +++ b/uriloader/exthandler/mac/nsOSHelperAppService.h @@ -32,6 +32,10 @@ public: bool *found, nsIHandlerInfo **_retval) override; + // override so we can have a child process sandbox-friendly implementation + bool GetMIMETypeFromOSForExtension(const nsACString& aExtension, + nsACString& aMIMEType) override; + // GetFileTokenForPath must be implemented by each platform. // platformAppPath --> a platform specific path to an application that we got out of the // rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform diff --git a/uriloader/exthandler/mac/nsOSHelperAppService.mm b/uriloader/exthandler/mac/nsOSHelperAppService.mm index 763451071f47..09b2bafb4508 100644 --- a/uriloader/exthandler/mac/nsOSHelperAppService.mm +++ b/uriloader/exthandler/mac/nsOSHelperAppService.mm @@ -14,6 +14,7 @@ #include "nsTArray.h" #include "nsIURL.h" #include "nsIFile.h" +#include "nsIHandlerService.h" #include "nsILocalFileMac.h" #include "nsMimeTypes.h" #include "nsIStringBundle.h" @@ -573,3 +574,34 @@ nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme, return NS_OK; } +/* + * Override GetMIMETypeFromOSForExtension() so that we can proxy requests for + * the MIME type to the parent when we're executing in the child process. If + * we're in the parent process, query the OS directly. + */ +bool +nsOSHelperAppService::GetMIMETypeFromOSForExtension(const nsACString& aExtension, + nsACString& aMIMEType) +{ + if (XRE_IsParentProcess()) { + return nsExternalHelperAppService::GetMIMETypeFromOSForExtension(aExtension, + aMIMEType); + } + + nsCOMPtr handlerSvc = + do_GetService(NS_HANDLERSERVICE_CONTRACTID); + if (NS_WARN_IF(!handlerSvc)) { + return false; + } + + nsresult rv = handlerSvc->GetTypeFromExtension(aExtension, aMIMEType); + if (NS_WARN_IF(NS_FAILED(rv))) { + return false; + } + + if (aMIMEType.IsEmpty()) { + return false; + } + + return true; +} -- 2.11.4.GIT