From bc7dfc9353e6108bf7e0e9ff5c754f513bc71cee Mon Sep 17 00:00:00 2001 From: Gian-Carlo Pascutto Date: Mon, 4 Sep 2017 21:48:59 +0200 Subject: [PATCH] Bug 1382323 - Remote OSProtocolHandlerExists. r=jld,smaug MozReview-Commit-ID: Gml7cjbgUvK --HG-- extra : rebase_source : 6ee7dfc8b5c05aec1ed268011fbec2ef64760554 --- ipc/ipdl/sync-messages.ini | 2 ++ .../exthandler/ContentHandlerService.cpp | 8 +++++ uriloader/exthandler/HandlerServiceParent.cpp | 17 +++++++++ uriloader/exthandler/HandlerServiceParent.h | 3 ++ uriloader/exthandler/PHandlerService.ipdl | 2 ++ .../exthandler/nsExternalHelperAppService.cpp | 20 +++++------ uriloader/exthandler/nsIHandlerService.idl | 10 ++++++ .../exthandler/unix/nsOSHelperAppService.cpp | 35 ++++++++----------- 8 files changed, 67 insertions(+), 30 deletions(-) diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini index 68b596905153..a263c0a0f20b 100644 --- a/ipc/ipdl/sync-messages.ini +++ b/ipc/ipdl/sync-messages.ini @@ -1051,6 +1051,8 @@ description = description = [PHandlerService::FillHandlerInfo] description = +[PHandlerService::ExistsForProtocol] +description = bug 1382323 [PHandlerService::Exists] description = [PHandlerService::GetTypeFromExtension] diff --git a/uriloader/exthandler/ContentHandlerService.cpp b/uriloader/exthandler/ContentHandlerService.cpp index e46ccdca0f3f..f3804dc02a82 100644 --- a/uriloader/exthandler/ContentHandlerService.cpp +++ b/uriloader/exthandler/ContentHandlerService.cpp @@ -154,6 +154,14 @@ NS_IMETHODIMP ContentHandlerService::Remove(nsIHandlerInfo *aHandlerInfo) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP +ContentHandlerService::ExistsForProtocol(const nsACString& aProtocolScheme, bool* aRetval) +{ + if (!mHandlerServiceChild->SendExistsForProtocol(nsCString(aProtocolScheme), aRetval)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} NS_IMETHODIMP ContentHandlerService::GetTypeFromExtension(const nsACString & aFileExtension, nsACString & _retval) { diff --git a/uriloader/exthandler/HandlerServiceParent.cpp b/uriloader/exthandler/HandlerServiceParent.cpp index 9cc0e4ab7d2d..384dc818850f 100644 --- a/uriloader/exthandler/HandlerServiceParent.cpp +++ b/uriloader/exthandler/HandlerServiceParent.cpp @@ -1,7 +1,11 @@ +#include "mozilla/Logging.h" #include "HandlerServiceParent.h" #include "nsIHandlerService.h" #include "nsIMIMEInfo.h" #include "ContentHandlerService.h" +#ifdef MOZ_WIDGET_GTK +#include "unix/nsGNOMERegistry.h" +#endif using mozilla::dom::HandlerInfo; using mozilla::dom::HandlerApp; @@ -259,6 +263,19 @@ HandlerServiceParent::RecvExists(const HandlerInfo& aHandlerInfo, return IPC_OK(); } +mozilla::ipc::IPCResult +HandlerServiceParent::RecvExistsForProtocol(const nsCString& aProtocolScheme, + bool* aHandlerExists) +{ +#ifdef MOZ_WIDGET_GTK + // Check the GNOME registry for a protocol handler + *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme.get()); +#else + *aHandlerExists = false; +#endif + return IPC_OK(); +} + mozilla::ipc::IPCResult HandlerServiceParent::RecvGetTypeFromExtension(const nsCString& aFileExtension, nsCString* type) diff --git a/uriloader/exthandler/HandlerServiceParent.h b/uriloader/exthandler/HandlerServiceParent.h index 6ed4c8a38687..8125758a2102 100644 --- a/uriloader/exthandler/HandlerServiceParent.h +++ b/uriloader/exthandler/HandlerServiceParent.h @@ -26,6 +26,9 @@ class HandlerServiceParent final : public mozilla::dom::PHandlerServiceParent virtual mozilla::ipc::IPCResult RecvGetTypeFromExtension(const nsCString& aFileExtension, nsCString* type) override; + virtual mozilla::ipc::IPCResult RecvExistsForProtocol(const nsCString& aProtocolScheme, + bool* aHandlerExists) override; + }; #endif diff --git a/uriloader/exthandler/PHandlerService.ipdl b/uriloader/exthandler/PHandlerService.ipdl index bcaab60ac3c0..b55bf3188433 100644 --- a/uriloader/exthandler/PHandlerService.ipdl +++ b/uriloader/exthandler/PHandlerService.ipdl @@ -30,6 +30,8 @@ parent: sync FillHandlerInfo(HandlerInfo aHandlerInfoData, nsCString aOverrideType) returns (HandlerInfo handlerInfoData); + sync ExistsForProtocol(nsCString aProtocolScheme) + returns (bool exists); sync Exists(HandlerInfo aHandlerInfo) returns (bool exists); sync GetTypeFromExtension(nsCString aFileExtension) diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index 2bf3e927f2ab..21b0e2ae8e3c 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -903,17 +903,17 @@ NS_IMETHODIMP nsExternalHelperAppService::ExternalProtocolHandlerExists(const ch nsCOMPtr handlerInfo; nsresult rv = GetProtocolHandlerInfo(nsDependentCString(aProtocolScheme), getter_AddRefs(handlerInfo)); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_SUCCEEDED(rv)) { + // See if we have any known possible handler apps for this + nsCOMPtr possibleHandlers; + handlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers)); - // See if we have any known possible handler apps for this - nsCOMPtr possibleHandlers; - handlerInfo->GetPossibleApplicationHandlers(getter_AddRefs(possibleHandlers)); - - uint32_t length; - possibleHandlers->GetLength(&length); - if (length) { - *aHandlerExists = true; - return NS_OK; + uint32_t length; + possibleHandlers->GetLength(&length); + if (length) { + *aHandlerExists = true; + return NS_OK; + } } // if not, fall back on an os-based handler diff --git a/uriloader/exthandler/nsIHandlerService.idl b/uriloader/exthandler/nsIHandlerService.idl index ecd396a8cadf..83c9f67b466b 100644 --- a/uriloader/exthandler/nsIHandlerService.idl +++ b/uriloader/exthandler/nsIHandlerService.idl @@ -120,4 +120,14 @@ interface nsIHandlerService : nsISupports * @returns the MIME type, if any; otherwise returns an empty string (""). */ ACString getTypeFromExtension(in ACString aFileExtension); + + /** + * Whether or not there is a handler known to the OS for the + * specified protocol type. + * + * @param aProtocolScheme scheme to check for support + * + * @returns whether or not a handler exists + */ + boolean existsForProtocol(in ACString aProtocolScheme); }; diff --git a/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/uriloader/exthandler/unix/nsOSHelperAppService.cpp index 721836982df5..226cc23fcec7 100644 --- a/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -7,11 +7,6 @@ #include #include -#if defined(MOZ_ENABLE_CONTENTACTION) -#include -#include -#endif - #include "nsOSHelperAppService.h" #include "nsMIMEInfoUnix.h" #ifdef MOZ_WIDGET_GTK @@ -32,6 +27,7 @@ #include "nsCRT.h" #include "nsDirectoryServiceDefs.h" #include "nsDirectoryServiceUtils.h" +#include "ContentHandlerService.h" #include "prenv.h" // for PR_GetEnv() #include "nsAutoPtr.h" #include "mozilla/Preferences.h" @@ -1132,25 +1128,24 @@ nsOSHelperAppService::GetHandlerAndDescriptionFromMailcapFile(const nsAString& a nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists) { - LOG(("-- nsOSHelperAppService::OSProtocolHandlerExists for '%s'\n", - aProtocolScheme)); - *aHandlerExists = false; - -#if defined(MOZ_ENABLE_CONTENTACTION) - // libcontentaction requires character ':' after scheme - ContentAction::Action action = - ContentAction::Action::defaultActionForScheme(QString(aProtocolScheme) + ':'); - - if (action.isValid()) - *aHandlerExists = true; -#endif + nsresult rv = NS_OK; + if (!XRE_IsContentProcess()) { #ifdef MOZ_WIDGET_GTK - // Check the GNOME registry for a protocol handler - *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme); + // Check the GNOME registry for a protocol handler + *aHandlerExists = nsGNOMERegistry::HandlerExists(aProtocolScheme); +#else + *aHandlerExists = false; #endif + } else { + *aHandlerExists = false; + nsCOMPtr handlerSvc = do_GetService(NS_HANDLERSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv) && handlerSvc) { + rv = handlerSvc->ExistsForProtocol(nsCString(aProtocolScheme), aHandlerExists); + } + } - return NS_OK; + return rv; } NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)