APIWebAuthenticationPanel.cpp [plain text]
#include "config.h"
#include "APIWebAuthenticationPanel.h"
#if ENABLE(WEB_AUTHN)
#include "APIWebAuthenticationPanelClient.h"
#include "AuthenticatorManager.h"
#include "MockAuthenticatorManager.h"
#include <WebCore/WebAuthenticationConstants.h>
namespace API {
using namespace WebCore;
using namespace WebKit;
Ref<WebAuthenticationPanel> WebAuthenticationPanel::create(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type)
{
return adoptRef(*new WebAuthenticationPanel(manager, rpId, transports, type));
}
WebAuthenticationPanel::WebAuthenticationPanel()
: m_manager(makeUnique<AuthenticatorManager>())
, m_client(makeUniqueRef<WebAuthenticationPanelClient>())
{
m_manager->enableNativeSupport();
}
WebAuthenticationPanel::WebAuthenticationPanel(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type)
: m_client(makeUniqueRef<WebAuthenticationPanelClient>())
, m_weakManager(makeWeakPtr(manager))
, m_rpId(rpId)
, m_clientDataType(type)
{
m_transports = Vector<AuthenticatorTransport>();
m_transports.reserveInitialCapacity(AuthenticatorManager::maxTransportNumber);
if (transports.contains(AuthenticatorTransport::Usb))
m_transports.uncheckedAppend(AuthenticatorTransport::Usb);
if (transports.contains(AuthenticatorTransport::Nfc))
m_transports.uncheckedAppend(AuthenticatorTransport::Nfc);
if (transports.contains(AuthenticatorTransport::Internal))
m_transports.uncheckedAppend(AuthenticatorTransport::Internal);
}
WebAuthenticationPanel::~WebAuthenticationPanel() = default;
void WebAuthenticationPanel::handleRequest(WebAuthenticationRequestData&& request, Callback&& callback)
{
ASSERT(m_manager);
request.weakPanel = makeWeakPtr(*this);
m_manager->handleRequest(WTFMove(request), WTFMove(callback));
}
void WebAuthenticationPanel::cancel() const
{
if (m_weakManager) {
m_weakManager->cancelRequest(*this);
return;
}
m_manager->cancel();
}
void WebAuthenticationPanel::setMockConfiguration(WebCore::MockWebAuthenticationConfiguration&& configuration)
{
ASSERT(m_manager);
if (!m_manager->isMock()) {
m_manager = makeUnique<MockAuthenticatorManager>(WTFMove(configuration));
m_manager->enableNativeSupport();
return;
}
static_cast<MockAuthenticatorManager*>(m_manager.get())->setTestConfiguration(WTFMove(configuration));
}
void WebAuthenticationPanel::setClient(UniqueRef<WebAuthenticationPanelClient>&& client)
{
m_client = WTFMove(client);
}
}
#endif // ENABLE(WEB_AUTHN)