1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

[uri] Fix issues with external protocol handlers.

Remove early return in nsExternalProtocolHandler::NewChannel when handler doesn't exist.
Fix devtools expectation that newChannel throws for unsupported external handlers
This commit is contained in:
Moonchild
2024-06-11 19:19:55 +02:00
committed by roytam1
parent bcdf7dc845
commit a09accc204
4 changed files with 13 additions and 43 deletions
+2 -9
View File
@@ -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
@@ -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<nsIExternalProtocolService> 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<nsIInterfaceRequestor> 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<nsIExternalProtocolService> 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<nsIChannel> channel = new nsExtProtocolChannel(aURI, aLoadInfo);
channel.forget(aRetval);
return NS_OK;
@@ -30,8 +30,7 @@ protected:
~nsExternalProtocolHandler();
// helper function
bool HaveExternalProtocolHandler(nsIURI * aURI);
nsCString m_schemeName;
nsCString m_schemeName;
};
#endif // nsExternalProtocolHandler_h___
@@ -19,7 +19,7 @@
#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0600
#define _WIN32_WINNT 0x0601
#include <shlobj.h>
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....