Bug 1945969 - part 5: rename WebAuthnManager to WebAuthnHandler. r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D237257
This commit is contained in:
John Schanck
2025-02-12 02:12:58 +00:00
parent a4916409c2
commit 9d5bf243c0
10 changed files with 76 additions and 82 deletions

View File

@@ -14,7 +14,7 @@
#include "mozilla/dom/Promise-inl.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_security.h"
#include "mozilla/dom/WebAuthnManager.h"
#include "mozilla/dom/WebAuthnHandler.h"
#include "mozilla/dom/WindowGlobalChild.h"
#include "mozilla/dom/WindowContext.h"
#include "nsContentUtils.h"
@@ -24,7 +24,8 @@
namespace mozilla::dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent, mManager)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent,
mWebAuthnHandler)
NS_IMPL_CYCLE_COLLECTING_ADDREF(CredentialsContainer)
NS_IMPL_CYCLE_COLLECTING_RELEASE(CredentialsContainer)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CredentialsContainer)
@@ -133,19 +134,19 @@ CredentialsContainer::CredentialsContainer(nsPIDOMWindowInner* aParent)
CredentialsContainer::~CredentialsContainer() = default;
void CredentialsContainer::EnsureWebAuthnManager() {
void CredentialsContainer::EnsureWebAuthnHandler() {
MOZ_ASSERT(NS_IsMainThread());
if (!mManager) {
mManager = new WebAuthnManager(mParent);
if (!mWebAuthnHandler) {
mWebAuthnHandler = new WebAuthnHandler(mParent);
}
}
already_AddRefed<WebAuthnManager> CredentialsContainer::GetWebAuthnManager() {
already_AddRefed<WebAuthnHandler> CredentialsContainer::GetWebAuthnHandler() {
MOZ_ASSERT(NS_IsMainThread());
EnsureWebAuthnManager();
RefPtr<WebAuthnManager> ref = mManager;
EnsureWebAuthnHandler();
RefPtr<WebAuthnHandler> ref = mWebAuthnHandler;
return ref.forget();
}
@@ -191,9 +192,10 @@ already_AddRefed<Promise> CredentialsContainer::Get(
return promise.forget();
}
EnsureWebAuthnManager();
return mManager->GetAssertion(aOptions.mPublicKey.Value(),
conditionallyMediated, aOptions.mSignal, aRv);
EnsureWebAuthnHandler();
return mWebAuthnHandler->GetAssertion(aOptions.mPublicKey.Value(),
conditionallyMediated,
aOptions.mSignal, aRv);
}
if (aOptions.mIdentity.WasPassed() &&
@@ -265,9 +267,9 @@ already_AddRefed<Promise> CredentialsContainer::Create(
return CreateAndRejectWithNotAllowed(mParent, aRv);
}
EnsureWebAuthnManager();
return mManager->MakeCredential(aOptions.mPublicKey.Value(),
aOptions.mSignal, aRv);
EnsureWebAuthnHandler();
return mWebAuthnHandler->MakeCredential(aOptions.mPublicKey.Value(),
aOptions.mSignal, aRv);
}
if (aOptions.mIdentity.WasPassed() &&
@@ -304,8 +306,8 @@ already_AddRefed<Promise> CredentialsContainer::Store(
return CreateAndRejectWithNotAllowed(mParent, aRv);
}
EnsureWebAuthnManager();
return mManager->Store(aCredential, aRv);
EnsureWebAuthnHandler();
return mWebAuthnHandler->Store(aCredential, aRv);
}
if (type.EqualsLiteral("identity") &&

View File

@@ -11,7 +11,7 @@
namespace mozilla::dom {
class WebAuthnManager;
class WebAuthnHandler;
class CredentialsContainer final : public nsISupports, public nsWrapperCache {
public:
@@ -22,7 +22,7 @@ class CredentialsContainer final : public nsISupports, public nsWrapperCache {
nsPIDOMWindowInner* GetParentObject() const { return mParent; }
already_AddRefed<WebAuthnManager> GetWebAuthnManager();
already_AddRefed<WebAuthnHandler> GetWebAuthnHandler();
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
@@ -41,10 +41,10 @@ class CredentialsContainer final : public nsISupports, public nsWrapperCache {
private:
~CredentialsContainer();
void EnsureWebAuthnManager();
void EnsureWebAuthnHandler();
nsCOMPtr<nsPIDOMWindowInner> mParent;
RefPtr<WebAuthnManager> mManager;
RefPtr<WebAuthnHandler> mWebAuthnHandler;
bool mActiveIdentityRequest;
};

View File

@@ -15,7 +15,7 @@
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PublicKeyCredential.h"
#include "mozilla/dom/WebAuthenticationBinding.h"
#include "mozilla/dom/WebAuthnManager.h"
#include "mozilla/dom/WebAuthnHandler.h"
#include "nsCycleCollectionParticipant.h"
#ifdef MOZ_WIDGET_ANDROID
@@ -121,9 +121,9 @@ PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(
return nullptr;
}
RefPtr<WebAuthnManager> manager =
window->Navigator()->Credentials()->GetWebAuthnManager();
return manager->IsUVPAA(aGlobal, aError);
RefPtr<WebAuthnHandler> handler =
window->Navigator()->Credentials()->GetWebAuthnHandler();
return handler->IsUVPAA(aGlobal, aError);
}
/* static */

View File

@@ -19,7 +19,7 @@
#include "mozilla/dom/AuthenticatorAttestationResponse.h"
#include "mozilla/dom/PublicKeyCredential.h"
#include "mozilla/dom/PWebAuthnTransaction.h"
#include "mozilla/dom/WebAuthnManager.h"
#include "mozilla/dom/WebAuthnHandler.h"
#include "mozilla/dom/WebAuthnTransactionChild.h"
#include "mozilla/dom/WebAuthnUtil.h"
#include "mozilla/dom/WindowGlobalChild.h"
@@ -39,17 +39,17 @@ namespace mozilla::dom {
**********************************************************************/
namespace {
static mozilla::LazyLogModule gWebAuthnManagerLog("webauthnmanager");
static mozilla::LazyLogModule gWebAuthnHandlerLog("webauthnhandler");
}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebAuthnManager)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebAuthnHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(WebAuthnManager, mWindow, mTransaction)
NS_IMPL_CYCLE_COLLECTION(WebAuthnHandler, mWindow, mTransaction)
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebAuthnManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebAuthnManager)
NS_IMPL_CYCLE_COLLECTING_ADDREF(WebAuthnHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(WebAuthnHandler)
/***********************************************************************
* Utility Functions
@@ -135,7 +135,7 @@ nsresult GetOrigin(nsPIDOMWindowInner* aParent,
// 4.1.1.3 If callerOrigin is an opaque origin, reject promise with a
// DOMException whose name is "NotAllowedError", and terminate this
// algorithm
MOZ_LOG(gWebAuthnManagerLog, LogLevel::Debug,
MOZ_LOG(gWebAuthnHandlerLog, LogLevel::Debug,
("Rejecting due to opaque origin"));
return NS_ERROR_DOM_NOT_ALLOWED_ERR;
}
@@ -200,10 +200,10 @@ nsresult RelaxSameOrigin(nsPIDOMWindowInner* aParent,
}
/***********************************************************************
* WebAuthnManager Implementation
* WebAuthnHandler Implementation
**********************************************************************/
WebAuthnManager::~WebAuthnManager() {
WebAuthnHandler::~WebAuthnHandler() {
MOZ_ASSERT(NS_IsMainThread());
if (mActor) {
if (mTransaction.isSome()) {
@@ -213,7 +213,7 @@ WebAuthnManager::~WebAuthnManager() {
}
}
bool WebAuthnManager::MaybeCreateActor() {
bool WebAuthnHandler::MaybeCreateActor() {
MOZ_ASSERT(NS_IsMainThread());
if (mActor) {
@@ -229,17 +229,17 @@ bool WebAuthnManager::MaybeCreateActor() {
}
mActor = actor;
mActor->SetManager(this);
mActor->SetHandler(this);
return true;
}
void WebAuthnManager::ActorDestroyed() {
void WebAuthnHandler::ActorDestroyed() {
MOZ_ASSERT(NS_IsMainThread());
mActor = nullptr;
}
already_AddRefed<Promise> WebAuthnManager::MakeCredential(
already_AddRefed<Promise> WebAuthnHandler::MakeCredential(
const PublicKeyCredentialCreationOptions& aOptions,
const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError) {
MOZ_ASSERT(NS_IsMainThread());
@@ -545,7 +545,7 @@ already_AddRefed<Promise> WebAuthnManager::MakeCredential(
const size_t MAX_ALLOWED_CREDENTIALS = 20;
already_AddRefed<Promise> WebAuthnManager::GetAssertion(
already_AddRefed<Promise> WebAuthnHandler::GetAssertion(
const PublicKeyCredentialRequestOptions& aOptions,
const bool aConditionallyMediated,
const Optional<OwningNonNull<AbortSignal>>& aSignal, ErrorResult& aError) {
@@ -803,7 +803,7 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
return promise.forget();
}
already_AddRefed<Promise> WebAuthnManager::Store(const Credential& aCredential,
already_AddRefed<Promise> WebAuthnHandler::Store(const Credential& aCredential,
ErrorResult& aError) {
MOZ_ASSERT(NS_IsMainThread());
@@ -823,7 +823,7 @@ already_AddRefed<Promise> WebAuthnManager::Store(const Credential& aCredential,
return promise.forget();
}
already_AddRefed<Promise> WebAuthnManager::IsUVPAA(GlobalObject& aGlobal,
already_AddRefed<Promise> WebAuthnHandler::IsUVPAA(GlobalObject& aGlobal,
ErrorResult& aError) {
RefPtr<Promise> promise =
Promise::Create(xpc::CurrentNativeGlobal(aGlobal.Context()), aError);
@@ -849,7 +849,7 @@ already_AddRefed<Promise> WebAuthnManager::IsUVPAA(GlobalObject& aGlobal,
return promise.forget();
}
void WebAuthnManager::FinishMakeCredential(
void WebAuthnHandler::FinishMakeCredential(
const WebAuthnMakeCredentialResult& aResult) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mTransaction.isSome());
@@ -928,7 +928,7 @@ void WebAuthnManager::FinishMakeCredential(
ResolveTransaction(credential);
}
void WebAuthnManager::FinishGetAssertion(
void WebAuthnHandler::FinishGetAssertion(
const WebAuthnGetAssertionResult& aResult) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mTransaction.isSome());
@@ -1003,7 +1003,7 @@ void WebAuthnManager::FinishGetAssertion(
ResolveTransaction(credential);
}
void WebAuthnManager::RunAbortAlgorithm() {
void WebAuthnHandler::RunAbortAlgorithm() {
if (NS_WARN_IF(mTransaction.isNothing())) {
return;
}
@@ -1021,7 +1021,7 @@ void WebAuthnManager::RunAbortAlgorithm() {
CancelTransaction(reason);
}
void WebAuthnManager::ResolveTransaction(
void WebAuthnHandler::ResolveTransaction(
const RefPtr<PublicKeyCredential>& aCredential) {
MOZ_ASSERT(mTransaction.isSome());
@@ -1040,7 +1040,7 @@ void WebAuthnManager::ResolveTransaction(
}
template <typename T>
void WebAuthnManager::RejectTransaction(const T& aReason) {
void WebAuthnHandler::RejectTransaction(const T& aReason) {
MOZ_ASSERT(mTransaction.isSome());
switch (mTransaction.ref().mType) {

View File

@@ -4,8 +4,8 @@
* 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/. */
#ifndef mozilla_dom_WebAuthnManager_h
#define mozilla_dom_WebAuthnManager_h
#ifndef mozilla_dom_WebAuthnHandler_h
#define mozilla_dom_WebAuthnHandler_h
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h"
@@ -17,15 +17,15 @@
#include "mozilla/dom/WebAuthnTransactionChild.h"
/*
* Content process manager for the WebAuthn protocol. Created on calls to the
* WebAuthentication DOM object, this manager handles establishing IPC channels
* for WebAuthn transactions, as well as keeping track of JS Promise objects
* representing transactions in flight.
* Content process handler for the WebAuthn protocol. Created on calls to the
* WebAuthentication DOM object, this is responsible for establishing IPC
* channels for WebAuthn transactions as well as keeping track of JS Promise
* objects representing transactions in flight.
*
* The WebAuthn spec (https://www.w3.org/TR/webauthn/) allows for two different
* types of transactions: registration and signing. When either of these is
* requested via the DOM API, the following steps are executed in the
* WebAuthnManager:
* WebAuthnHandler:
*
* - Validation of the request. Return a failed promise to js if request does
* not have correct parameters.
@@ -34,15 +34,12 @@
* another transaction is already running in this content process, cancel it.
* Return a pending promise to js.
*
* - Send transaction information to parent process (by running the Start*
* functions of WebAuthnManager). Assuming another transaction is currently in
* flight in another content process, parent will handle canceling it.
* - Send transaction information to parent process.
*
* - On return of successful transaction information from parent process, turn
* information into DOM object format required by spec, and resolve promise
* (by running the Finish* functions of WebAuthnManager). On cancellation
* request from parent, reject promise with corresponding error code. Either
* outcome will also close the IPC channel.
* (by running the Finish* functions of WebAuthnHandler). On cancellation
* request from parent, reject promise with corresponding error code.
*
*/
@@ -68,7 +65,7 @@ class WebAuthnTransaction {
// These holders are used to track the transaction once it has been dispatched
// to the parent process. Once ->Track()'d, they must either be disconnected
// (through a call to WebAuthnManager::CancelTransaction) or completed
// (through a call to WebAuthnHandler::CancelTransaction) or completed
// (through a response on the IPC channel) before this WebAuthnTransaction is
// destroyed.
MozPromiseRequestHolder<PWebAuthnTransactionChild::RequestRegisterPromise>
@@ -77,12 +74,12 @@ class WebAuthnTransaction {
mSignHolder;
};
class WebAuthnManager final : public AbortFollower {
class WebAuthnHandler final : public AbortFollower {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(WebAuthnManager)
NS_DECL_CYCLE_COLLECTION_CLASS(WebAuthnHandler)
explicit WebAuthnManager(nsPIDOMWindowInner* aWindow) : mWindow(aWindow) {
explicit WebAuthnHandler(nsPIDOMWindowInner* aWindow) : mWindow(aWindow) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aWindow);
}
@@ -107,7 +104,7 @@ class WebAuthnManager final : public AbortFollower {
void RunAbortAlgorithm() override;
private:
virtual ~WebAuthnManager();
virtual ~WebAuthnHandler();
bool MaybeCreateActor();
@@ -159,4 +156,4 @@ inline void ImplCycleCollectionUnlink(WebAuthnTransaction& aTransaction) {
} // namespace mozilla::dom
#endif // mozilla_dom_WebAuthnManager_h
#endif // mozilla_dom_WebAuthnHandler_h

View File

@@ -4,21 +4,21 @@
* 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/dom/WebAuthnManager.h"
#include "mozilla/dom/WebAuthnHandler.h"
#include "mozilla/dom/WebAuthnTransactionChild.h"
namespace mozilla::dom {
void WebAuthnTransactionChild::SetManager(WebAuthnManager* aManager) {
mManager = aManager;
void WebAuthnTransactionChild::SetHandler(WebAuthnHandler* aHandler) {
mHandler = aHandler;
}
void WebAuthnTransactionChild::ActorDestroy(ActorDestroyReason why) {
// Called by either a __delete__ message from the parent, or when the
// channel disconnects. Clear out the child actor reference to be sure.
if (mManager) {
mManager->ActorDestroyed();
mManager = nullptr;
if (mHandler) {
mHandler->ActorDestroyed();
mHandler = nullptr;
}
}

View File

@@ -12,13 +12,13 @@
/*
* Child process IPC implementation for WebAuthn API. Receives results of
* WebAuthn transactions from the parent process, and sends them to the
* WebAuthnManager either cancel the transaction, or be formatted and relayed to
* WebAuthnHandler either cancel the transaction, or be formatted and relayed to
* content.
*/
namespace mozilla::dom {
class WebAuthnManager;
class WebAuthnHandler;
class WebAuthnTransactionChild final : public PWebAuthnTransactionChild {
public:
@@ -28,13 +28,12 @@ class WebAuthnTransactionChild final : public PWebAuthnTransactionChild {
void ActorDestroy(ActorDestroyReason why) override;
void SetManager(WebAuthnManager* aMananger);
void SetHandler(WebAuthnHandler* aMananger);
private:
~WebAuthnTransactionChild() = default;
// Nulled by ~WebAuthnManager() when disconnecting.
WebAuthnManager* mManager;
WebAuthnHandler* mHandler;
};
} // namespace mozilla::dom

View File

@@ -7,10 +7,6 @@
#ifndef mozilla_dom_WebAuthnUtil_h
#define mozilla_dom_WebAuthnUtil_h
/*
* Utility functions used by both WebAuthnManager and U2FTokenManager.
*/
#include "mozilla/dom/WebAuthenticationBinding.h"
#include "ipc/IPCMessageUtils.h"

View File

@@ -406,7 +406,7 @@ WinWebAuthnService::MakeCredential(uint64_t aTransactionId,
winRequireResidentKey = FALSE;
winPreferResidentKey = FALSE;
} else {
// WebAuthnManager::MakeCredential is supposed to assign one of the
// WebAuthnHandler::MakeCredential is supposed to assign one of the
// above values, so this shouldn't happen.
MOZ_ASSERT_UNREACHABLE();
aPromise->Reject(NS_ERROR_DOM_UNKNOWN_ERR);

View File

@@ -28,7 +28,7 @@ EXPORTS.mozilla.dom += [
"AuthenticatorAttestationResponse.h",
"AuthenticatorResponse.h",
"PublicKeyCredential.h",
"WebAuthnManager.h",
"WebAuthnHandler.h",
"WebAuthnPromiseHolder.h",
"WebAuthnTransactionChild.h",
"WebAuthnTransactionParent.h",
@@ -43,7 +43,7 @@ UNIFIED_SOURCES += [
"PublicKeyCredential.cpp",
"WebAuthnArgs.cpp",
"WebAuthnAutoFillEntry.cpp",
"WebAuthnManager.cpp",
"WebAuthnHandler.cpp",
"WebAuthnPromiseHolder.cpp",
"WebAuthnResult.cpp",
"WebAuthnService.cpp",