AuthenticatorManager.h [plain text]
#pragma once
#if ENABLE(WEB_AUTHN)
#include "Authenticator.h"
#include "AuthenticatorTransportService.h"
#include "WebAuthenticationRequestData.h"
#include <WebCore/AuthenticatorResponse.h>
#include <WebCore/ExceptionData.h>
#include <wtf/CompletionHandler.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/RunLoop.h>
#include <wtf/Vector.h>
namespace API {
class WebAuthenticationPanel;
}
namespace WebKit {
class AuthenticatorManager : public AuthenticatorTransportService::Observer, public Authenticator::Observer {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(AuthenticatorManager);
public:
using Respond = Variant<Ref<WebCore::AuthenticatorResponse>, WebCore::ExceptionData>;
using Callback = CompletionHandler<void(Respond&&)>;
using TransportSet = HashSet<WebCore::AuthenticatorTransport, WTF::IntHash<WebCore::AuthenticatorTransport>, WTF::StrongEnumHashTraits<WebCore::AuthenticatorTransport>>;
using AuthenticatorTransportService::Observer::weakPtrFactory;
using WeakValueType = AuthenticatorTransportService::Observer::WeakValueType;
const static size_t maxTransportNumber;
AuthenticatorManager();
virtual ~AuthenticatorManager() = default;
void handleRequest(WebAuthenticationRequestData&&, Callback&&);
void cancelRequest(const WebCore::PageIdentifier&, const Optional<WebCore::FrameIdentifier>&); void cancelRequest(const API::WebAuthenticationPanel&);
virtual bool isMock() const { return false; }
protected:
RunLoop::Timer<AuthenticatorManager>& requestTimeOutTimer() { return m_requestTimeOutTimer; }
void clearStateAsync(); void clearState();
void invokePendingCompletionHandler(Respond&&);
private:
void authenticatorAdded(Ref<Authenticator>&&) final;
void serviceStatusUpdated(WebAuthenticationStatus) final;
void respondReceived(Respond&&) final;
void downgrade(Authenticator* id, Ref<Authenticator>&& downgradedAuthenticator) final;
void authenticatorStatusUpdated(WebAuthenticationStatus) final;
virtual UniqueRef<AuthenticatorTransportService> createService(WebCore::AuthenticatorTransport, AuthenticatorTransportService::Observer&) const;
virtual void respondReceivedInternal(Respond&&) { }
virtual void filterTransports(TransportSet&) const;
void startDiscovery(const TransportSet&);
void initTimeOutTimer();
void timeOutTimerFired();
void runPanel();
void restartDiscovery();
TransportSet getTransports() const;
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)