diff --git a/devtools/shared/DevToolsUtils.js b/devtools/shared/DevToolsUtils.js index d44184fd6b..b9fc3660aa 100644 --- a/devtools/shared/DevToolsUtils.js +++ b/devtools/shared/DevToolsUtils.js @@ -537,6 +537,7 @@ function newChannelForURL(url, { policy, window, principal }) { // scheme to see if it helps. uri = Services.io.newURI("file://" + url, null, null); } + let channelOptions = { contentPolicyType: policy, securityFlags: securityFlags, @@ -557,15 +558,7 @@ function newChannelForURL(url, { policy, window, principal }) { } channelOptions.loadingPrincipal = prin; - try { - return NetUtil.newChannel(channelOptions); - } catch (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 the exception here if - // parsing the URL above doesn't throw. - return newChannelForURL("file://" + url, { policy, window, principal }); - } + return NetUtil.newChannel(channelOptions); } // Fetch is defined differently depending on whether we are on the main thread diff --git a/uriloader/exthandler/nsExternalProtocolHandler.cpp b/uriloader/exthandler/nsExternalProtocolHandler.cpp index 968e109d5f..e21083357f 100644 --- a/uriloader/exthandler/nsExternalProtocolHandler.cpp +++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "mozilla/ScopeExit.h" #include "nsIURI.h" #include "nsIURL.h" #include "nsExternalProtocolHandler.h" @@ -155,21 +156,25 @@ nsresult nsExtProtocolChannel::OpenURL() nsresult rv = NS_ERROR_FAILURE; nsCOMPtr extProtService (do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); + auto cleanup = mozilla::MakeScopeExit([&] { + mCallbacks = 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; + } nsCOMPtr aggCallbacks; rv = NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup, getter_AddRefs(aggCallbacks)); if (NS_FAILED(rv)) { - goto finish; + return rv; } rv = extProtService->LoadURI(mUrl, aggCallbacks); @@ -181,8 +186,6 @@ nsresult nsExtProtocolChannel::OpenURL() } } -finish: - mCallbacks = nullptr; return rv; } @@ -476,22 +479,6 @@ nsExternalProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_re *_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 extProtSvc(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID)); - if (!extProtSvc) { - return false; - } - - bool haveHandler = false; - extProtSvc->ExternalProtocolHandlerExists(scheme.get(), &haveHandler); - return haveHandler; -} NS_IMETHODIMP nsExternalProtocolHandler::GetProtocolFlags(uint32_t *aUritype) { @@ -525,14 +512,6 @@ nsExternalProtocolHandler::NewChannel2(nsIURI* aURI, 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 channel = new nsExtProtocolChannel(aURI, aLoadInfo); channel.forget(aRetval); return NS_OK; diff --git a/uriloader/exthandler/nsExternalProtocolHandler.h b/uriloader/exthandler/nsExternalProtocolHandler.h index 426c98da18..7c0e41ad1b 100644 --- a/uriloader/exthandler/nsExternalProtocolHandler.h +++ b/uriloader/exthandler/nsExternalProtocolHandler.h @@ -30,8 +30,7 @@ protected: ~nsExternalProtocolHandler(); // helper function - bool HaveExternalProtocolHandler(nsIURI * aURI); - nsCString m_schemeName; + nsCString m_schemeName; }; #endif // nsExternalProtocolHandler_h___ diff --git a/uriloader/exthandler/win/nsOSHelperAppService.h b/uriloader/exthandler/win/nsOSHelperAppService.h index b00529433c..b38cdfdfcd 100644 --- a/uriloader/exthandler/win/nsOSHelperAppService.h +++ b/uriloader/exthandler/win/nsOSHelperAppService.h @@ -19,7 +19,7 @@ #ifdef _WIN32_WINNT #undef _WIN32_WINNT #endif -#define _WIN32_WINNT 0x0600 +#define _WIN32_WINNT 0x0601 #include class nsMIMEInfoWin; @@ -32,7 +32,6 @@ public: // override nsIExternalProtocolService methods nsresult OSProtocolHandlerExists(const char * aProtocolScheme, bool * aHandlerExists); - nsresult LoadUriInternal(nsIURI * aURL); NS_IMETHOD GetApplicationDescription(const nsACString& aScheme, nsAString& _retval); // method overrides for windows registry look up steps....