Chromium Code Reviews| 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..f84e12d1d9cc5ee706f008217fa51a6842210f03 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,43 @@ ScriptPromise CredentialsContainer::store(ScriptState* script_state, |
| return promise; |
| } |
| +ScriptPromise CredentialsContainer::create( |
| + ScriptState* script_state, |
| + const CredentialCreationOptions& options) { |
| + 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; |
| + } |
| + |
| + ExceptionState exception_state(script_state->GetIsolate(), |
| + ExceptionState::kExecutionContext, |
| + "CredentialsContainer", "create"); |
|
haraken
2017/05/17 14:51:50
Can we add [RaisesException=Constructor] to the ID
jdoerrie
2017/05/19 10:04:49
Done, given that this is not really a constructor
|
| + 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); |