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(
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,23 +382,16 @@ 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<nsISerialEventTarget> target = GetCurrentSerialEventTarget();
nsCOMPtr<nsIRunnable> runnable(NS_NewRunnableFunction(
__func__, [target, resolver = std::move(aResolver)]() {
auto result = java::WebAuthnTokenManager::
WebAuthnIsUserVerifyingPlatformAuthenticatorAvailable();
auto geckoResult = java::GeckoResult::LocalRef(std::move(result));
MozPromise<bool, bool, false>::FromGeckoResult(geckoResult)
->Then(
target, __func__,
[resolver](
->Then(target, __func__,
[resolver = std::move(aResolver)](
const MozPromise<bool, bool, false>::ResolveOrRejectValue&
aValue) {
if (aValue.IsResolve()) {
@@ -399,8 +400,6 @@ mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestIsUVPAA(
resolver(false);
}
});
}));
NS_DispatchToMainThread(runnable.forget());
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();