diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 09:03:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-17 09:03:13 +0000 |
commit | 0681b3ac9a6ab4879ca2fbfcf8aa9d00a67b8365 (patch) | |
tree | 1437375a1c16af40bb2982577c25eb9608e17566 /uriloader/exthandler/nsExternalProtocolHandler.cpp | |
parent | Adding debian version 115.11.0esr-1~deb12u1. (diff) | |
download | firefox-esr-0681b3ac9a6ab4879ca2fbfcf8aa9d00a67b8365.tar.xz firefox-esr-0681b3ac9a6ab4879ca2fbfcf8aa9d00a67b8365.zip |
Merging upstream version 115.12.0esr.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'uriloader/exthandler/nsExternalProtocolHandler.cpp')
-rw-r--r-- | uriloader/exthandler/nsExternalProtocolHandler.cpp | 43 |
1 files changed, 10 insertions, 33 deletions
diff --git a/uriloader/exthandler/nsExternalProtocolHandler.cpp b/uriloader/exthandler/nsExternalProtocolHandler.cpp index 4e93977b8f..f969cb2d66 100644 --- a/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -7,6 +7,7 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/BasePrincipal.h" +#include "mozilla/ScopeExit.h" #include "nsIURI.h" #include "nsExternalProtocolHandler.h" #include "nsString.h" @@ -148,22 +149,25 @@ nsresult nsExtProtocolChannel::OpenURL() { nsCOMPtr<nsIExternalProtocolService> extProtService( do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); + auto cleanup = mozilla::MakeScopeExit([&] { + mCallbacks = nullptr; + mListener = nullptr; + }); + if (extProtService) { -#ifdef DEBUG nsAutoCString urlScheme; mUrl->GetScheme(urlScheme); bool haveHandler = false; extProtService->ExternalProtocolHandlerExists(urlScheme.get(), &haveHandler); - NS_ASSERTION(haveHandler, - "Why do we have a channel for this url if we don't support " - "the protocol?"); -#endif + if (!haveHandler) { + return NS_ERROR_UNKNOWN_PROTOCOL; + } RefPtr<mozilla::dom::BrowsingContext> ctx; rv = mLoadInfo->GetTargetBrowsingContext(getter_AddRefs(ctx)); if (NS_FAILED(rv)) { - goto finish; + return rv; } RefPtr<nsIPrincipal> triggeringPrincipal = mLoadInfo->TriggeringPrincipal(); @@ -189,9 +193,6 @@ nsresult nsExtProtocolChannel::OpenURL() { } } -finish: - mCallbacks = nullptr; - mListener = nullptr; return rv; } @@ -497,22 +498,6 @@ nsExternalProtocolHandler::AllowPort(int32_t port, const char* scheme, *_retval = false; return NS_OK; } -// returns TRUE if the OS can handle this protocol scheme and false otherwise. -bool nsExternalProtocolHandler::HaveExternalProtocolHandler(nsIURI* aURI) { - MOZ_ASSERT(aURI); - nsAutoCString scheme; - aURI->GetScheme(scheme); - - nsCOMPtr<nsIExternalProtocolService> extProtSvc( - do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); - if (!extProtSvc) { - return false; - } - - bool haveHandler = false; - extProtSvc->ExternalProtocolHandlerExists(scheme.get(), &haveHandler); - return haveHandler; -} NS_IMETHODIMP nsExternalProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, @@ -520,14 +505,6 @@ nsExternalProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, NS_ENSURE_TRUE(aURI, NS_ERROR_UNKNOWN_PROTOCOL); NS_ENSURE_TRUE(aRetval, NS_ERROR_UNKNOWN_PROTOCOL); - // Only try to return a channel if we have a protocol handler for the url. - // nsOSHelperAppService::LoadUriInternal relies on this to check trustedness - // for some platforms at least. (win uses ::ShellExecute and unix uses - // gnome_url_show.) - if (!HaveExternalProtocolHandler(aURI)) { - return NS_ERROR_UNKNOWN_PROTOCOL; - } - nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel(aURI, aLoadInfo); channel.forget(aRetval); return NS_OK; |