Index: third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp |
diff --git a/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp b/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp |
index ff35965185a0314d8dca14c145930f627e48eadc..764aa08f4acd0fe1269115c3aef4250305aa0943 100644 |
--- a/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp |
+++ b/third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp |
@@ -7,6 +7,7 @@ |
#include <memory> |
#include <utility> |
#include "bindings/core/v8/Dictionary.h" |
+#include "bindings/core/v8/ExceptionState.h" |
#include "bindings/core/v8/ScriptPromise.h" |
#include "bindings/core/v8/ScriptPromiseResolver.h" |
#include "core/dom/DOMException.h" |
@@ -17,6 +18,7 @@ |
#include "core/frame/UseCounter.h" |
#include "core/page/FrameTree.h" |
#include "modules/credentialmanager/Credential.h" |
+#include "modules/credentialmanager/CredentialCreationOptions.h" |
#include "modules/credentialmanager/CredentialManagerClient.h" |
#include "modules/credentialmanager/CredentialRequestOptions.h" |
#include "modules/credentialmanager/FederatedCredential.h" |
@@ -202,6 +204,41 @@ ScriptPromise CredentialsContainer::store(ScriptState* script_state, |
return promise; |
} |
+ScriptPromise CredentialsContainer::create( |
+ ScriptState* script_state, |
+ const CredentialCreationOptions& options, |
+ ExceptionState& exception_state) { |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
+ ScriptPromise promise = resolver->Promise(); |
+ if (!CheckBoilerplate(resolver)) |
+ return promise; |
+ |
+ // TODO(http://crbug.com/715077): Generalize this check when 'publicKey' |
+ // becomes a supported option. |
+ if (!(options.hasPassword() ^ options.hasFederated())) { |
+ resolver->Reject(DOMException::Create(kNotSupportedError, |
+ "Only 'password' and 'federated' " |
+ "credential types are currently " |
+ "supported.")); |
+ return promise; |
+ } |
+ |
+ if (options.hasPassword()) { |
+ if (options.password().isPasswordCredentialData()) { |
+ resolver->Resolve(PasswordCredential::Create( |
+ options.password().getAsPasswordCredentialData(), exception_state)); |
+ } else { |
+ resolver->Resolve(PasswordCredential::Create( |
+ options.password().getAsHTMLFormElement(), exception_state)); |
+ } |
+ } else { |
+ resolver->Resolve( |
+ FederatedCredential::Create(options.federated(), exception_state)); |
+ } |
+ |
+ return promise; |
+} |
+ |
ScriptPromise CredentialsContainer::requireUserMediation( |
ScriptState* script_state) { |
ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |