Loading devtools/shared/DevToolsUtils.js +22 −13 Original line number Diff line number Diff line Loading @@ -730,7 +730,11 @@ function mainThreadFetch( * @param {Object} options - The options object passed to @method fetch. * @return {nsIChannel} - The newly created channel. Throws on failure. */ function newChannelForURL(url, { policy, window, principal }) { function newChannelForURL( url, { policy, window, principal }, recursing = false ) { const securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL; Loading Loading @@ -774,19 +778,24 @@ function newChannelForURL(url, { policy, window, principal }) { channelOptions.loadingPrincipal = prin; } // In xpcshell tests on Windows, opening the channel try { return NetUtil.newChannel(channelOptions); } catch (e) { // Don't infinitely recurse if newChannel keeps throwing. if (recursing) { throw e; } // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel() // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't // supported by Windows, so we also need to handle that case here if // supported by Windows, so we also need to handle the exception here if // parsing the URL above doesn't throw. const handler = Services.io.getProtocolHandler(uri.scheme); if ( handler instanceof Ci.nsIExternalProtocolHandler && !handler.externalAppExistsForScheme(uri.scheme) ) { uri = Services.io.newURI("file://" + url); return newChannelForURL( "file://" + url, { policy, window, principal }, /* recursing */ true ); } return NetUtil.newChannel(channelOptions); } // Fetch is defined differently depending on whether we are on the main thread Loading uriloader/exthandler/nsExternalProtocolHandler.cpp +33 −10 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/BasePrincipal.h" #include "mozilla/ScopeExit.h" #include "nsIURI.h" #include "nsExternalProtocolHandler.h" #include "nsString.h" Loading Loading @@ -149,25 +148,22 @@ 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); if (!haveHandler) { return NS_ERROR_UNKNOWN_PROTOCOL; } NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support " "the protocol?"); #endif RefPtr<mozilla::dom::BrowsingContext> ctx; rv = mLoadInfo->GetTargetBrowsingContext(getter_AddRefs(ctx)); if (NS_FAILED(rv)) { return rv; goto finish; } RefPtr<nsIPrincipal> triggeringPrincipal = mLoadInfo->TriggeringPrincipal(); Loading @@ -193,6 +189,9 @@ nsresult nsExtProtocolChannel::OpenURL() { } } finish: mCallbacks = nullptr; mListener = nullptr; return rv; } Loading Loading @@ -498,6 +497,22 @@ 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, Loading @@ -505,6 +520,14 @@ 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; Loading uriloader/exthandler/nsExternalProtocolHandler.h +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ class nsExternalProtocolHandler final : public nsIExternalProtocolHandler, ~nsExternalProtocolHandler(); // helper function bool HaveExternalProtocolHandler(nsIURI* aURI); nsCString m_schemeName; }; Loading uriloader/exthandler/win/nsOSHelperAppService.h +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class nsOSHelperAppService : public nsExternalHelperAppService { // override nsIExternalProtocolService methods NS_IMETHOD OSProtocolHandlerExists(const char* aProtocolScheme, bool* aHandlerExists) override; nsresult LoadUriInternal(nsIURI* aURL); NS_IMETHOD GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) override; Loading Loading
devtools/shared/DevToolsUtils.js +22 −13 Original line number Diff line number Diff line Loading @@ -730,7 +730,11 @@ function mainThreadFetch( * @param {Object} options - The options object passed to @method fetch. * @return {nsIChannel} - The newly created channel. Throws on failure. */ function newChannelForURL(url, { policy, window, principal }) { function newChannelForURL( url, { policy, window, principal }, recursing = false ) { const securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL; Loading Loading @@ -774,19 +778,24 @@ function newChannelForURL(url, { policy, window, principal }) { channelOptions.loadingPrincipal = prin; } // In xpcshell tests on Windows, opening the channel try { return NetUtil.newChannel(channelOptions); } catch (e) { // Don't infinitely recurse if newChannel keeps throwing. if (recursing) { throw e; } // In xpcshell tests on Windows, nsExternalProtocolHandler::NewChannel() // can throw NS_ERROR_UNKNOWN_PROTOCOL if the external protocol isn't // supported by Windows, so we also need to handle that case here if // supported by Windows, so we also need to handle the exception here if // parsing the URL above doesn't throw. const handler = Services.io.getProtocolHandler(uri.scheme); if ( handler instanceof Ci.nsIExternalProtocolHandler && !handler.externalAppExistsForScheme(uri.scheme) ) { uri = Services.io.newURI("file://" + url); return newChannelForURL( "file://" + url, { policy, window, principal }, /* recursing */ true ); } return NetUtil.newChannel(channelOptions); } // Fetch is defined differently depending on whether we are on the main thread Loading
uriloader/exthandler/nsExternalProtocolHandler.cpp +33 −10 Original line number Diff line number Diff line Loading @@ -7,7 +7,6 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/BasePrincipal.h" #include "mozilla/ScopeExit.h" #include "nsIURI.h" #include "nsExternalProtocolHandler.h" #include "nsString.h" Loading Loading @@ -149,25 +148,22 @@ 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); if (!haveHandler) { return NS_ERROR_UNKNOWN_PROTOCOL; } NS_ASSERTION(haveHandler, "Why do we have a channel for this url if we don't support " "the protocol?"); #endif RefPtr<mozilla::dom::BrowsingContext> ctx; rv = mLoadInfo->GetTargetBrowsingContext(getter_AddRefs(ctx)); if (NS_FAILED(rv)) { return rv; goto finish; } RefPtr<nsIPrincipal> triggeringPrincipal = mLoadInfo->TriggeringPrincipal(); Loading @@ -193,6 +189,9 @@ nsresult nsExtProtocolChannel::OpenURL() { } } finish: mCallbacks = nullptr; mListener = nullptr; return rv; } Loading Loading @@ -498,6 +497,22 @@ 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, Loading @@ -505,6 +520,14 @@ 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; Loading
uriloader/exthandler/nsExternalProtocolHandler.h +1 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ class nsExternalProtocolHandler final : public nsIExternalProtocolHandler, ~nsExternalProtocolHandler(); // helper function bool HaveExternalProtocolHandler(nsIURI* aURI); nsCString m_schemeName; }; Loading
uriloader/exthandler/win/nsOSHelperAppService.h +1 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class nsOSHelperAppService : public nsExternalHelperAppService { // override nsIExternalProtocolService methods NS_IMETHOD OSProtocolHandlerExists(const char* aProtocolScheme, bool* aHandlerExists) override; nsresult LoadUriInternal(nsIURI* aURL); NS_IMETHOD GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) override; Loading