From a4916409c252cad0b310665b83040b25450f5526 Mon Sep 17 00:00:00 2001 From: John Schanck Date: Wed, 12 Feb 2025 02:12:58 +0000 Subject: [PATCH] Bug 1945969 - part 4: simplify android implementation of RecvIsUVPAA. r=keeler Differential Revision: https://phabricator.services.mozilla.com/D236884 --- dom/webauthn/WebAuthnTransactionParent.cpp | 52 +++++++++++----------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/dom/webauthn/WebAuthnTransactionParent.cpp b/dom/webauthn/WebAuthnTransactionParent.cpp index a44811c74a23..025ef2bbc9ef 100644 --- a/dom/webauthn/WebAuthnTransactionParent.cpp +++ b/dom/webauthn/WebAuthnTransactionParent.cpp @@ -42,6 +42,8 @@ void WebAuthnTransactionParent::DisconnectTransaction() { mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister( const WebAuthnMakeCredentialInfo& aTransactionInfo, RequestRegisterResolver&& aResolver) { + MOZ_ASSERT(NS_IsMainThread()); + if (!mWebAuthnService) { mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1"); if (!mWebAuthnService) { @@ -202,6 +204,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister( mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign( const WebAuthnGetAssertionInfo& aTransactionInfo, RequestSignResolver&& aResolver) { + MOZ_ASSERT(NS_IsMainThread()); + if (!mWebAuthnService) { mWebAuthnService = do_GetService("@mozilla.org/webauthn/service;1"); if (!mWebAuthnService) { @@ -344,6 +348,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign( } mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel() { + MOZ_ASSERT(NS_IsMainThread()); + if (mTransactionId.isNothing()) { return IPC_OK(); } @@ -354,6 +360,8 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel() { mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA( RequestIsUVPAAResolver&& aResolver) { + MOZ_ASSERT(NS_IsMainThread()); + #ifdef MOZ_WIDGET_ANDROID // Try the nsIWebAuthnService. If we're configured for tests we // will get a result. Otherwise we expect NS_ERROR_NOT_IMPLEMENTED. @@ -374,33 +382,24 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA( } // The GeckoView implementation of - // isUserVerifiyingPlatformAuthenticatorAvailable does not block, but we must - // call it on the main thread. It returns a MozPromise which we can ->Then to - // call aResolver on the IPDL background thread. - // - // Bug 1550788: there is an unnecessary layer of dispatching here: ipdl -> - // main -> a background thread. Other platforms just do ipdl -> a background - // thread. + // isUserVerifiyingPlatformAuthenticatorAvailable dispatches the work to a + // background thread and returns a MozPromise which we can ->Then to call + // aResolver on the current thread. nsCOMPtr target = GetCurrentSerialEventTarget(); - nsCOMPtr runnable(NS_NewRunnableFunction( - __func__, [target, resolver = std::move(aResolver)]() { - auto result = java::WebAuthnTokenManager:: - WebAuthnIsUserVerifyingPlatformAuthenticatorAvailable(); - auto geckoResult = java::GeckoResult::LocalRef(std::move(result)); - MozPromise::FromGeckoResult(geckoResult) - ->Then( - target, __func__, - [resolver]( - const MozPromise::ResolveOrRejectValue& - aValue) { - if (aValue.IsResolve()) { - resolver(aValue.ResolveValue()); - } else { - resolver(false); - } - }); - })); - NS_DispatchToMainThread(runnable.forget()); + auto result = java::WebAuthnTokenManager:: + WebAuthnIsUserVerifyingPlatformAuthenticatorAvailable(); + auto geckoResult = java::GeckoResult::LocalRef(std::move(result)); + MozPromise::FromGeckoResult(geckoResult) + ->Then(target, __func__, + [resolver = std::move(aResolver)]( + const MozPromise::ResolveOrRejectValue& + aValue) { + if (aValue.IsResolve()) { + resolver(aValue.ResolveValue()); + } else { + resolver(false); + } + }); return IPC_OK(); #else @@ -433,6 +432,7 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA( void WebAuthnTransactionParent::ActorDestroy(ActorDestroyReason aWhy) { // Called either by Send__delete__() in RecvDestroyMe() above, or when // the channel disconnects. Ensure the token manager forgets about us. + MOZ_ASSERT(NS_IsMainThread()); if (mTransactionId.isSome()) { DisconnectTransaction();