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/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "modules/credentialmanager/CredentialRequestOptions.h" | 21 #include "modules/credentialmanager/CredentialRequestOptions.h" |
22 #include "modules/credentialmanager/FederatedCredential.h" | 22 #include "modules/credentialmanager/FederatedCredential.h" |
23 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" | 23 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" |
24 #include "modules/credentialmanager/PasswordCredential.h" | 24 #include "modules/credentialmanager/PasswordCredential.h" |
25 #include "platform/weborigin/SecurityOrigin.h" | 25 #include "platform/weborigin/SecurityOrigin.h" |
26 #include "platform/wtf/PtrUtil.h" | 26 #include "platform/wtf/PtrUtil.h" |
27 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
28 #include "public/platform/WebCredential.h" | 28 #include "public/platform/WebCredential.h" |
29 #include "public/platform/WebCredentialManagerClient.h" | 29 #include "public/platform/WebCredentialManagerClient.h" |
30 #include "public/platform/WebCredentialManagerError.h" | 30 #include "public/platform/WebCredentialManagerError.h" |
31 #include "public/platform/WebCredentialMediationRequirement.h" | |
31 #include "public/platform/WebFederatedCredential.h" | 32 #include "public/platform/WebFederatedCredential.h" |
32 #include "public/platform/WebPasswordCredential.h" | 33 #include "public/platform/WebPasswordCredential.h" |
33 | 34 |
34 namespace blink { | 35 namespace blink { |
35 | 36 |
36 static void RejectDueToCredentialManagerError( | 37 static void RejectDueToCredentialManagerError( |
37 ScriptPromiseResolver* resolver, | 38 ScriptPromiseResolver* resolver, |
38 WebCredentialManagerError reason) { | 39 WebCredentialManagerError reason) { |
39 switch (reason) { | 40 switch (reason) { |
40 case kWebCredentialManagerDisabledError: | 41 case kWebCredentialManagerDisabledError: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 162 } |
162 | 163 |
163 ScriptPromise CredentialsContainer::get( | 164 ScriptPromise CredentialsContainer::get( |
164 ScriptState* script_state, | 165 ScriptState* script_state, |
165 const CredentialRequestOptions& options) { | 166 const CredentialRequestOptions& options) { |
166 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 167 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
167 ScriptPromise promise = resolver->Promise(); | 168 ScriptPromise promise = resolver->Promise(); |
168 if (!CheckBoilerplate(resolver)) | 169 if (!CheckBoilerplate(resolver)) |
169 return promise; | 170 return promise; |
170 | 171 |
172 // Set the default mediation option if none is provided. | |
vasilii
2017/05/18 16:16:12
I think it does more. Copying one to another.
jdoerrie
2017/05/19 09:03:18
Done.
| |
173 if (!options.hasUnmediated() && !options.hasMediation()) { | |
174 options.mediation() = "optional"; | |
175 } else if (options.hasUnmediated() && !options.hasMediation()) { | |
176 options.mediation() = options.unmediated() ? "silent" : "optional"; | |
177 } else if (options.hasUnmediated() && options.hasMediation()) { | |
178 resolver->Reject(DOMException::Create( | |
179 kNotSupportedError, | |
180 "At most one of 'unmediated' and 'mediation' can be specified.")); | |
181 return promise; | |
182 } | |
183 | |
171 Vector<KURL> providers; | 184 Vector<KURL> providers; |
172 if (options.hasFederated() && options.federated().hasProviders()) { | 185 if (options.hasFederated() && options.federated().hasProviders()) { |
173 for (const auto& string : options.federated().providers()) { | 186 for (const auto& string : options.federated().providers()) { |
174 KURL url = KURL(KURL(), string); | 187 KURL url = KURL(KURL(), string); |
175 if (url.IsValid()) | 188 if (url.IsValid()) |
176 providers.push_back(std::move(url)); | 189 providers.push_back(std::move(url)); |
177 } | 190 } |
178 } | 191 } |
179 | 192 |
180 UseCounter::Count(ExecutionContext::From(script_state), | 193 UseCounter::Feature feature; |
181 options.unmediated() | 194 WebCredentialMediationRequirement mediation; |
182 ? UseCounter::kCredentialManagerGetWithoutUI | 195 |
183 : UseCounter::kCredentialManagerGetWithUI); | 196 if (options.mediation() == "silent") { |
197 feature = UseCounter::kCredentialManagerGetMediationSilent; | |
198 mediation = WebCredentialMediationRequirement::kSilent; | |
199 } else if (options.mediation() == "optional") { | |
200 feature = UseCounter::kCredentialManagerGetMediationOptional; | |
201 mediation = WebCredentialMediationRequirement::kOptional; | |
202 } else { | |
203 DCHECK_EQ("required", options.mediation()); | |
204 feature = UseCounter::kCredentialManagerGetMediationRequired; | |
205 mediation = WebCredentialMediationRequirement::kRequired; | |
206 } | |
207 | |
208 UseCounter::Count(ExecutionContext::From(script_state), feature); | |
184 | 209 |
185 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 210 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
186 ->DispatchGet(options.unmediated(), options.password(), providers, | 211 ->DispatchGet(mediation, options.password(), providers, |
187 new RequestCallbacks(resolver)); | 212 new RequestCallbacks(resolver)); |
188 return promise; | 213 return promise; |
189 } | 214 } |
190 | 215 |
191 ScriptPromise CredentialsContainer::store(ScriptState* script_state, | 216 ScriptPromise CredentialsContainer::store(ScriptState* script_state, |
192 Credential* credential) { | 217 Credential* credential) { |
193 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 218 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
194 ScriptPromise promise = resolver->Promise(); | 219 ScriptPromise promise = resolver->Promise(); |
195 if (!CheckBoilerplate(resolver)) | 220 if (!CheckBoilerplate(resolver)) |
196 return promise; | 221 return promise; |
(...skipping 11 matching lines...) Expand all Loading... | |
208 ScriptPromise promise = resolver->Promise(); | 233 ScriptPromise promise = resolver->Promise(); |
209 if (!CheckBoilerplate(resolver)) | 234 if (!CheckBoilerplate(resolver)) |
210 return promise; | 235 return promise; |
211 | 236 |
212 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 237 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); | 238 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); |
214 return promise; | 239 return promise; |
215 } | 240 } |
216 | 241 |
217 } // namespace blink | 242 } // namespace blink |
OLD | NEW |