Bug 1945969 - part 4: simplify android implementation of RecvIsUVPAA. r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D236884
This commit is contained in:
John Schanck
2025-02-12 02:12:58 +00:00
parent fb5fb15d92
commit a4916409c2

View File

@@ -42,6 +42,8 @@ void WebAuthnTransactionParent::DisconnectTransaction() {
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister( mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister(
const WebAuthnMakeCredentialInfo& aTransactionInfo, const WebAuthnMakeCredentialInfo& aTransactionInfo,
RequestRegisterResolver&& aResolver) { RequestRegisterResolver&& aResolver) {
MOZ_ASSERT(NS_IsMainThread());
if (!mWebAuthnService) { if (!mWebAuthnService) {
mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1"); mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1");
if (!mWebAuthnService) { if (!mWebAuthnService) {
@@ -202,6 +204,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister(
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign( mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign(
const WebAuthnGetAssertionInfo& aTransactionInfo, const WebAuthnGetAssertionInfo& aTransactionInfo,
RequestSignResolver&& aResolver) { RequestSignResolver&& aResolver) {
MOZ_ASSERT(NS_IsMainThread());
if (!mWebAuthnService) { if (!mWebAuthnService) {
mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1"); mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1");
if (!mWebAuthnService) { if (!mWebAuthnService) {
@@ -344,6 +348,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign(
} }
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel() { mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel() {
MOZ_ASSERT(NS_IsMainThread());
if (mTransactionId.isNothing()) { if (mTransactionId.isNothing()) {
return IPC_OK(); return IPC_OK();
} }
@@ -354,6 +360,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel() {
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA( mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA(
RequestIsUVPAAResolver&& aResolver) { RequestIsUVPAAResolver&& aResolver) {
MOZ_ASSERT(NS_IsMainThread());
#ifdef MOZ_WIDGET_ANDROID #ifdef MOZ_WIDGET_ANDROID
// Try the nsIWebAuthnService. If we're configured for tests we // Try the nsIWebAuthnService. If we're configured for tests we
// will get a result. Otherwise we expect NS_ERROR_NOT_IMPLEMENTED. // will get a result. Otherwise we expect NS_ERROR_NOT_IMPLEMENTED.
@@ -374,33 +382,24 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA(
} }
// The GeckoView implementation of // The GeckoView implementation of
// isUserVerifiyingPlatformAuthenticatorAvailable does not block, but we must // isUserVerifiyingPlatformAuthenticatorAvailable dispatches the work to a
// call it on the main thread. It returns a MozPromise which we can ->Then to // background thread and returns a MozPromise which we can ->Then to call
// call aResolver on the IPDL background thread. // aResolver on the current thread.
//
// Bug 1550788: there is an unnecessary layer of dispatching here: ipdl ->
// main -> a background thread. Other platforms just do ipdl -> a background
// thread.
nsCOMPtr<nsISerialEventTarget> target = GetCurrentSerialEventTarget(); nsCOMPtr<nsISerialEventTarget> target = GetCurrentSerialEventTarget();
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction( auto result = java::WebAuthnTokenManager::
__func__, [target, resolver = std::move(aResolver)]() { WebAuthnIsUserVerifyingPlatformAuthenticatorAvailable();
auto result = java::WebAuthnTokenManager:: auto geckoResult = java::GeckoResult::LocalRef(std::move(result));
WebAuthnIsUserVerifyingPlatformAuthenticatorAvailable(); MozPromise<bool, bool, false>::FromGeckoResult(geckoResult)
auto geckoResult = java::GeckoResult::LocalRef(std::move(result)); ->Then(target, __func__,
MozPromise<bool, bool, false>::FromGeckoResult(geckoResult) [resolver = std::move(aResolver)](
->Then( const MozPromise<bool, bool, false>::ResolveOrRejectValue&
target, __func__, aValue) {
[resolver]( if (aValue.IsResolve()) {
const MozPromise<bool, bool, false>::ResolveOrRejectValue& resolver(aValue.ResolveValue());
aValue) { } else {
if (aValue.IsResolve()) { resolver(false);
resolver(aValue.ResolveValue()); }
} else { });
resolver(false);
}
});
}));
NS_DispatchToMainThread(runnable.forget());
return IPC_OK(); return IPC_OK();
#else #else
@@ -433,6 +432,7 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA(
void WebAuthnTransactionParent::ActorDestroy(ActorDestroyReason aWhy) { void WebAuthnTransactionParent::ActorDestroy(ActorDestroyReason aWhy) {
// Called either by Send__delete__() in RecvDestroyMe() above, or when // Called either by Send__delete__() in RecvDestroyMe() above, or when
// the channel disconnects. Ensure the token manager forgets about us. // the channel disconnects. Ensure the token manager forgets about us.
MOZ_ASSERT(NS_IsMainThread());
if (mTransactionId.isSome()) { if (mTransactionId.isSome()) {
DisconnectTransaction(); DisconnectTransaction();