[WebAuthN] Implement authenticatorMakeCredential
[WebKit-https.git] / Source / WebKit / UIProcess / CredentialManagement / WebCredentialsMessengerProxy.cpp
index 47d5d7c..feabea8 100644 (file)
@@ -32,6 +32,8 @@
 #include "WebCredentialsMessengerProxyMessages.h"
 #include "WebPageProxy.h"
 #include "WebProcessProxy.h"
+#include <WebCore/ExceptionData.h>
+#include <WebCore/LocalAuthenticator.h>
 
 namespace WebKit {
 
@@ -39,6 +41,7 @@ WebCredentialsMessengerProxy::WebCredentialsMessengerProxy(WebPageProxy& webPage
     : m_webPageProxy(webPageProxy)
 {
     m_webPageProxy.process().addMessageReceiver(Messages::WebCredentialsMessengerProxy::messageReceiverName(), m_webPageProxy.pageID(), *this);
+    m_authenticator = std::make_unique<WebCore::LocalAuthenticator>();
 }
 
 WebCredentialsMessengerProxy::~WebCredentialsMessengerProxy()
@@ -46,17 +49,49 @@ WebCredentialsMessengerProxy::~WebCredentialsMessengerProxy()
     m_webPageProxy.process().removeMessageReceiver(Messages::WebCredentialsMessengerProxy::messageReceiverName(), m_webPageProxy.pageID());
 }
 
-void WebCredentialsMessengerProxy::makeCredential(uint64_t)
+void WebCredentialsMessengerProxy::makeCredential(uint64_t messageId, const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialCreationOptions& options)
+{
+    // FIXME(182767)
+    if (!m_authenticator) {
+        exceptionReply(messageId, { WebCore::NotAllowedError, ASCIILiteral("No avaliable authenticators.") });
+        return;
+    }
+    // FIXME(183534): Weak pointers doesn't work in another thread because of race condition.
+    auto weakThis = m_weakFactory.createWeakPtr(*this);
+    auto callback = [weakThis, messageId] (const Vector<uint8_t>& credentialId, const Vector<uint8_t>& attestationObject) {
+        if (!weakThis)
+            return;
+        weakThis->makeCredentialReply(messageId, credentialId, attestationObject);
+    };
+    auto exceptionCallback = [weakThis, messageId] (const WebCore::ExceptionData& exception) {
+        if (!weakThis)
+            return;
+        weakThis->exceptionReply(messageId, exception);
+    };
+    m_authenticator->makeCredential(hash, options, WTFMove(callback), WTFMove(exceptionCallback));
+}
+
+void WebCredentialsMessengerProxy::getAssertion(uint64_t)
 {
 }
 
 void WebCredentialsMessengerProxy::isUserVerifyingPlatformAuthenticatorAvailable(uint64_t messageId)
 {
-    platformIsUserVerifyingPlatformAuthenticatorAvailable(messageId);
+    if (!m_authenticator) {
+        isUserVerifyingPlatformAuthenticatorAvailableReply(messageId, false);
+        return;
+    }
+    isUserVerifyingPlatformAuthenticatorAvailableReply(messageId, m_authenticator->isAvailable());
 }
 
-void WebCredentialsMessengerProxy::getAssertion(uint64_t)
+void WebCredentialsMessengerProxy::exceptionReply(uint64_t messageId, const WebCore::ExceptionData& exception)
+{
+    m_webPageProxy.send(Messages::WebCredentialsMessenger::ExceptionReply(messageId, exception));
+}
+
+void WebCredentialsMessengerProxy::makeCredentialReply(uint64_t messageId, const Vector<uint8_t>& credentialId, const Vector<uint8_t>& attestationObject)
 {
+    m_webPageProxy.send(Messages::WebCredentialsMessenger::MakeCredentialReply(messageId, credentialId, attestationObject));
 }
 
 void WebCredentialsMessengerProxy::isUserVerifyingPlatformAuthenticatorAvailableReply(uint64_t messageId, bool result)