AuthenticatorManager.h [plain text]
#pragma once
#if ENABLE(WEB_AUTHN)
#include "Authenticator.h"
#include "AuthenticatorTransportService.h"
#include "WebAuthenticationRequestData.h"
#include <WebCore/ExceptionData.h>
#include <WebCore/PublicKeyCredentialData.h>
#include <wtf/CompletionHandler.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/RunLoop.h>
#include <wtf/Vector.h>
namespace WebKit {
class AuthenticatorManager : public AuthenticatorTransportService::Observer, public Authenticator::Observer {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(AuthenticatorManager);
public:
using Respond = Variant<WebCore::PublicKeyCredentialData, WebCore::ExceptionData>;
using Callback = CompletionHandler<void(Respond&&)>;
using TransportSet = HashSet<WebCore::AuthenticatorTransport, WTF::IntHash<WebCore::AuthenticatorTransport>, WTF::StrongEnumHashTraits<WebCore::AuthenticatorTransport>>;
using AuthenticatorTransportService::Observer::weakPtrFactory;
AuthenticatorManager();
virtual ~AuthenticatorManager() = default;
void makeCredential(const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialCreationOptions&, Callback&&);
void getAssertion(const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialRequestOptions&, Callback&&);
virtual bool isMock() const { return false; }
protected:
Callback& pendingCompletionHandler() { return m_pendingCompletionHandler; }
RunLoop::Timer<AuthenticatorManager>& requestTimeOutTimer() { return m_requestTimeOutTimer; }
void clearStateAsync();
private:
void authenticatorAdded(Ref<Authenticator>&&) final;
void respondReceived(Respond&&) final;
virtual UniqueRef<AuthenticatorTransportService> createService(WebCore::AuthenticatorTransport, AuthenticatorTransportService::Observer&) const;
virtual void respondReceivedInternal(Respond&&);
void startDiscovery(const TransportSet&);
void initTimeOutTimer(const Optional<unsigned>& timeOutInMs);
void timeOutTimerFired();
WebAuthenticationRequestData m_pendingRequestData;
Callback m_pendingCompletionHandler;
RunLoop::Timer<AuthenticatorManager> m_requestTimeOutTimer;
Vector<UniqueRef<AuthenticatorTransportService>> m_services;
HashSet<Ref<Authenticator>> m_authenticators;
};
}
#endif // ENABLE(WEB_AUTHN)