Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/modules/credentialmanager/CredentialsContainer.cpp

Issue 2884703002: Implement CredentialsContainer::create (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (!(options.hasPassword() ^ options.hasFederated())) {
Mike West 2017/05/16 09:21:00 XOR works today, as we only have two entities. Whe
jdoerrie 2017/05/16 13:29:56 Done.
216 resolver->Reject(DOMException::Create(
217 kNotSupportedError,
218 "Exactly one of password or federated must be provided."));
Mike West 2017/05/16 09:21:00 I'd rephrase this to something like, "Only 'passwo
jdoerrie 2017/05/16 13:29:56 Done.
219 return promise;
220 }
221
222 ExceptionState exception_state(script_state->GetIsolate(),
223 ExceptionState::kConstructionContext,
Mike West 2017/05/16 09:21:00 Nit: This isn't actually a constructor, it's just
jdoerrie 2017/05/16 13:29:56 Done.
224 "navigator.credentials", "create");
jdoerrie 2017/05/16 06:34:27 Here I was the most unsure about, I just looked fo
Mike West 2017/05/16 09:21:00 Nit: Please replace "navigator.credentials" with "
jdoerrie 2017/05/16 13:29:56 Done.
225 if (options.hasPassword()) {
226 if (options.password().isPasswordCredentialData()) {
227 resolver->Resolve(PasswordCredential::Create(
228 options.password().getAsPasswordCredentialData(), exception_state));
229 } else {
230 resolver->Resolve(PasswordCredential::Create(
Mike West 2017/05/16 09:21:00 When you write tests, can you verify that passing
jdoerrie 2017/05/16 13:29:56 Done.
231 options.password().getAsHTMLFormElement(), exception_state));
232 }
233 } else {
234 resolver->Resolve(
235 FederatedCredential::Create(options.federated(), exception_state));
Mike West 2017/05/16 09:20:59 When you write tests, can you verify that passing
jdoerrie 2017/05/16 13:29:56 Done.
236 }
237
238 return promise;
239 }
240
205 ScriptPromise CredentialsContainer::requireUserMediation( 241 ScriptPromise CredentialsContainer::requireUserMediation(
206 ScriptState* script_state) { 242 ScriptState* script_state) {
207 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 243 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
208 ScriptPromise promise = resolver->Promise(); 244 ScriptPromise promise = resolver->Promise();
209 if (!CheckBoilerplate(resolver)) 245 if (!CheckBoilerplate(resolver))
210 return promise; 246 return promise;
211 247
212 CredentialManagerClient::From(ExecutionContext::From(script_state)) 248 CredentialManagerClient::From(ExecutionContext::From(script_state))
213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); 249 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver));
214 return promise; 250 return promise;
215 } 251 }
216 252
217 } // namespace blink 253 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698