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 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | |
211 ScriptPromise promise = resolver->Promise(); | |
212 if (!CheckBoilerplate(resolver)) | |
213 return promise; | |
214 | |
215 // TODO(http://crbug.com/715077): Generalize this check when 'publicKey' | |
216 // becomes a supported option. | |
217 if (!(options.hasPassword() ^ options.hasFederated())) { | |
218 resolver->Reject(DOMException::Create(kNotSupportedError, | |
219 "Only 'password' and 'federated' " | |
220 "credential types are currently " | |
221 "supported.")); | |
222 return promise; | |
223 } | |
224 | |
225 ExceptionState exception_state(script_state->GetIsolate(), | |
226 ExceptionState::kExecutionContext, | |
227 "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
| |
228 if (options.hasPassword()) { | |
229 if (options.password().isPasswordCredentialData()) { | |
230 resolver->Resolve(PasswordCredential::Create( | |
231 options.password().getAsPasswordCredentialData(), exception_state)); | |
232 } else { | |
233 resolver->Resolve(PasswordCredential::Create( | |
234 options.password().getAsHTMLFormElement(), exception_state)); | |
235 } | |
236 } else { | |
237 resolver->Resolve( | |
238 FederatedCredential::Create(options.federated(), exception_state)); | |
239 } | |
240 | |
241 return promise; | |
242 } | |
243 | |
205 ScriptPromise CredentialsContainer::requireUserMediation( | 244 ScriptPromise CredentialsContainer::requireUserMediation( |
206 ScriptState* script_state) { | 245 ScriptState* script_state) { |
207 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 246 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
208 ScriptPromise promise = resolver->Promise(); | 247 ScriptPromise promise = resolver->Promise(); |
209 if (!CheckBoilerplate(resolver)) | 248 if (!CheckBoilerplate(resolver)) |
210 return promise; | 249 return promise; |
211 | 250 |
212 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 251 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); | 252 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); |
214 return promise; | 253 return promise; |
215 } | 254 } |
216 | 255 |
217 } // namespace blink | 256 } // namespace blink |
OLD | NEW |