OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/credentialmanager/CredentialsContainer.h" | 5 #include "modules/credentialmanager/CredentialsContainer.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include "bindings/core/v8/Dictionary.h" | 9 #include "bindings/core/v8/Dictionary.h" |
| 10 #include "bindings/core/v8/ExceptionState.h" |
10 #include "bindings/core/v8/ScriptPromise.h" | 11 #include "bindings/core/v8/ScriptPromise.h" |
11 #include "bindings/core/v8/ScriptPromiseResolver.h" | 12 #include "bindings/core/v8/ScriptPromiseResolver.h" |
12 #include "core/dom/DOMException.h" | 13 #include "core/dom/DOMException.h" |
13 #include "core/dom/Document.h" | 14 #include "core/dom/Document.h" |
14 #include "core/dom/ExceptionCode.h" | 15 #include "core/dom/ExceptionCode.h" |
15 #include "core/dom/ExecutionContext.h" | 16 #include "core/dom/ExecutionContext.h" |
16 #include "core/frame/Frame.h" | 17 #include "core/frame/Frame.h" |
17 #include "core/frame/UseCounter.h" | 18 #include "core/frame/UseCounter.h" |
18 #include "core/page/FrameTree.h" | 19 #include "core/page/FrameTree.h" |
19 #include "modules/credentialmanager/Credential.h" | 20 #include "modules/credentialmanager/Credential.h" |
| 21 #include "modules/credentialmanager/CredentialCreationOptions.h" |
20 #include "modules/credentialmanager/CredentialManagerClient.h" | 22 #include "modules/credentialmanager/CredentialManagerClient.h" |
21 #include "modules/credentialmanager/CredentialRequestOptions.h" | 23 #include "modules/credentialmanager/CredentialRequestOptions.h" |
22 #include "modules/credentialmanager/FederatedCredential.h" | 24 #include "modules/credentialmanager/FederatedCredential.h" |
23 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" | 25 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" |
24 #include "modules/credentialmanager/PasswordCredential.h" | 26 #include "modules/credentialmanager/PasswordCredential.h" |
25 #include "platform/weborigin/SecurityOrigin.h" | 27 #include "platform/weborigin/SecurityOrigin.h" |
26 #include "platform/wtf/PtrUtil.h" | 28 #include "platform/wtf/PtrUtil.h" |
27 #include "public/platform/Platform.h" | 29 #include "public/platform/Platform.h" |
28 #include "public/platform/WebCredential.h" | 30 #include "public/platform/WebCredential.h" |
29 #include "public/platform/WebCredentialManagerClient.h" | 31 #include "public/platform/WebCredentialManagerClient.h" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (!CheckBoilerplate(resolver)) | 197 if (!CheckBoilerplate(resolver)) |
196 return promise; | 198 return promise; |
197 | 199 |
198 auto web_credential = | 200 auto web_credential = |
199 WebCredential::Create(credential->GetPlatformCredential()); | 201 WebCredential::Create(credential->GetPlatformCredential()); |
200 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 202 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
201 ->DispatchStore(*web_credential, new NotificationCallbacks(resolver)); | 203 ->DispatchStore(*web_credential, new NotificationCallbacks(resolver)); |
202 return promise; | 204 return promise; |
203 } | 205 } |
204 | 206 |
| 207 ScriptPromise CredentialsContainer::create( |
| 208 ScriptState* script_state, |
| 209 const CredentialCreationOptions& options, |
| 210 ExceptionState& exception_state) { |
| 211 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 212 ScriptPromise promise = resolver->Promise(); |
| 213 if (!CheckBoilerplate(resolver)) |
| 214 return promise; |
| 215 |
| 216 // TODO(http://crbug.com/715077): Generalize this check when 'publicKey' |
| 217 // becomes a supported option. |
| 218 if (!(options.hasPassword() ^ options.hasFederated())) { |
| 219 resolver->Reject(DOMException::Create(kNotSupportedError, |
| 220 "Only 'password' and 'federated' " |
| 221 "credential types are currently " |
| 222 "supported.")); |
| 223 return promise; |
| 224 } |
| 225 |
| 226 if (options.hasPassword()) { |
| 227 if (options.password().isPasswordCredentialData()) { |
| 228 resolver->Resolve(PasswordCredential::Create( |
| 229 options.password().getAsPasswordCredentialData(), exception_state)); |
| 230 } else { |
| 231 resolver->Resolve(PasswordCredential::Create( |
| 232 options.password().getAsHTMLFormElement(), exception_state)); |
| 233 } |
| 234 } else { |
| 235 resolver->Resolve( |
| 236 FederatedCredential::Create(options.federated(), exception_state)); |
| 237 } |
| 238 |
| 239 return promise; |
| 240 } |
| 241 |
205 ScriptPromise CredentialsContainer::requireUserMediation( | 242 ScriptPromise CredentialsContainer::requireUserMediation( |
206 ScriptState* script_state) { | 243 ScriptState* script_state) { |
207 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 244 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
208 ScriptPromise promise = resolver->Promise(); | 245 ScriptPromise promise = resolver->Promise(); |
209 if (!CheckBoilerplate(resolver)) | 246 if (!CheckBoilerplate(resolver)) |
210 return promise; | 247 return promise; |
211 | 248 |
212 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 249 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); | 250 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); |
214 return promise; | 251 return promise; |
215 } | 252 } |
216 | 253 |
217 } // namespace blink | 254 } // namespace blink |
OLD | NEW |