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" |
11 #include "bindings/core/v8/ScriptPromiseResolver.h" | 11 #include "bindings/core/v8/ScriptPromiseResolver.h" |
12 #include "core/dom/DOMException.h" | 12 #include "core/dom/DOMException.h" |
13 #include "core/dom/Document.h" | 13 #include "core/dom/Document.h" |
14 #include "core/dom/ExceptionCode.h" | 14 #include "core/dom/ExceptionCode.h" |
15 #include "core/dom/ExecutionContext.h" | 15 #include "core/dom/ExecutionContext.h" |
16 #include "core/frame/Frame.h" | 16 #include "core/frame/Frame.h" |
17 #include "core/frame/UseCounter.h" | 17 #include "core/frame/UseCounter.h" |
18 #include "core/inspector/ConsoleMessage.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" |
20 #include "modules/credentialmanager/CredentialManagerClient.h" | 21 #include "modules/credentialmanager/CredentialManagerClient.h" |
21 #include "modules/credentialmanager/CredentialRequestOptions.h" | 22 #include "modules/credentialmanager/CredentialRequestOptions.h" |
22 #include "modules/credentialmanager/FederatedCredential.h" | 23 #include "modules/credentialmanager/FederatedCredential.h" |
23 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" | 24 #include "modules/credentialmanager/FederatedCredentialRequestOptions.h" |
24 #include "modules/credentialmanager/PasswordCredential.h" | 25 #include "modules/credentialmanager/PasswordCredential.h" |
25 #include "platform/weborigin/SecurityOrigin.h" | 26 #include "platform/weborigin/SecurityOrigin.h" |
26 #include "platform/wtf/PtrUtil.h" | 27 #include "platform/wtf/PtrUtil.h" |
27 #include "public/platform/Platform.h" | 28 #include "public/platform/Platform.h" |
28 #include "public/platform/WebCredential.h" | 29 #include "public/platform/WebCredential.h" |
29 #include "public/platform/WebCredentialManagerClient.h" | 30 #include "public/platform/WebCredentialManagerClient.h" |
30 #include "public/platform/WebCredentialManagerError.h" | 31 #include "public/platform/WebCredentialManagerError.h" |
32 #include "public/platform/WebCredentialMediationRequirement.h" | |
31 #include "public/platform/WebFederatedCredential.h" | 33 #include "public/platform/WebFederatedCredential.h" |
32 #include "public/platform/WebPasswordCredential.h" | 34 #include "public/platform/WebPasswordCredential.h" |
33 | 35 |
34 namespace blink { | 36 namespace blink { |
35 | 37 |
36 static void RejectDueToCredentialManagerError( | 38 static void RejectDueToCredentialManagerError( |
37 ScriptPromiseResolver* resolver, | 39 ScriptPromiseResolver* resolver, |
38 WebCredentialManagerError reason) { | 40 WebCredentialManagerError reason) { |
39 switch (reason) { | 41 switch (reason) { |
40 case kWebCredentialManagerDisabledError: | 42 case kWebCredentialManagerDisabledError: |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 } | 163 } |
162 | 164 |
163 ScriptPromise CredentialsContainer::get( | 165 ScriptPromise CredentialsContainer::get( |
164 ScriptState* script_state, | 166 ScriptState* script_state, |
165 const CredentialRequestOptions& options) { | 167 const CredentialRequestOptions& options) { |
166 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 168 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
167 ScriptPromise promise = resolver->Promise(); | 169 ScriptPromise promise = resolver->Promise(); |
168 if (!CheckBoilerplate(resolver)) | 170 if (!CheckBoilerplate(resolver)) |
169 return promise; | 171 return promise; |
170 | 172 |
173 ExecutionContext* context = ExecutionContext::From(script_state); | |
174 // Set the default mediation option if none is provided. | |
175 // If both 'unmediated' and 'mediation' are set log a warning if they are | |
176 // contradicting. | |
177 // Also sets 'mediation' appropriately when only 'unmediated' is set. | |
178 // TODO(http://crbug.com/715077): Remove this when 'unmediated' is removed. | |
179 String mediation = "optional"; | |
180 if (options.hasUnmediated() && !options.hasMediation()) { | |
181 mediation = options.unmediated() ? "silent" : "optional"; | |
182 } else if (options.hasMediation()) { | |
183 mediation = options.mediation(); | |
Mike West
2017/05/19 15:29:56
Please add a test for invalid values.
jdoerrie
2017/05/19 16:22:37
That already exists in credentialscontainer-get-er
| |
184 if (options.hasUnmediated() && | |
185 ((options.unmediated() && options.mediation() != "silent") || | |
186 (!options.unmediated() && options.mediation() != "optional"))) { | |
187 context->AddConsoleMessage(ConsoleMessage::Create( | |
188 kJSMessageSource, kWarningMessageLevel, | |
189 "mediation: '" + options.mediation() + "' overrides unmediated: " + | |
190 (options.unmediated() ? "true" : "false") + ".")); | |
Mike West
2017/05/19 15:29:57
Please add a test for this behavior.
jdoerrie
2017/05/19 16:22:37
Done, please see
credentialscontainer-get-warning
| |
191 } | |
192 } | |
193 | |
171 Vector<KURL> providers; | 194 Vector<KURL> providers; |
172 if (options.hasFederated() && options.federated().hasProviders()) { | 195 if (options.hasFederated() && options.federated().hasProviders()) { |
173 for (const auto& string : options.federated().providers()) { | 196 for (const auto& string : options.federated().providers()) { |
174 KURL url = KURL(KURL(), string); | 197 KURL url = KURL(KURL(), string); |
175 if (url.IsValid()) | 198 if (url.IsValid()) |
176 providers.push_back(std::move(url)); | 199 providers.push_back(std::move(url)); |
177 } | 200 } |
178 } | 201 } |
179 | 202 |
180 UseCounter::Count(ExecutionContext::From(script_state), | 203 UseCounter::Feature feature; |
181 options.unmediated() | 204 WebCredentialMediationRequirement requirement; |
182 ? UseCounter::kCredentialManagerGetWithoutUI | |
183 : UseCounter::kCredentialManagerGetWithUI); | |
184 | 205 |
185 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 206 if (mediation == "silent") { |
186 ->DispatchGet(options.unmediated(), options.password(), providers, | 207 feature = UseCounter::kCredentialManagerGetMediationSilent; |
187 new RequestCallbacks(resolver)); | 208 requirement = WebCredentialMediationRequirement::kSilent; |
209 } else if (mediation == "optional") { | |
210 feature = UseCounter::kCredentialManagerGetMediationOptional; | |
211 requirement = WebCredentialMediationRequirement::kOptional; | |
212 } else { | |
213 DCHECK_EQ("required", mediation); | |
214 feature = UseCounter::kCredentialManagerGetMediationRequired; | |
215 requirement = WebCredentialMediationRequirement::kRequired; | |
216 } | |
217 | |
218 UseCounter::Count(context, feature); | |
Mike West
2017/05/19 15:29:57
Optional nit: I think it's simpler to just call `C
jdoerrie
2017/05/19 16:22:37
Done.
| |
219 | |
220 CredentialManagerClient::From(context)->DispatchGet( | |
221 requirement, options.password(), providers, | |
222 new RequestCallbacks(resolver)); | |
188 return promise; | 223 return promise; |
189 } | 224 } |
190 | 225 |
191 ScriptPromise CredentialsContainer::store(ScriptState* script_state, | 226 ScriptPromise CredentialsContainer::store(ScriptState* script_state, |
192 Credential* credential) { | 227 Credential* credential) { |
193 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 228 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
194 ScriptPromise promise = resolver->Promise(); | 229 ScriptPromise promise = resolver->Promise(); |
195 if (!CheckBoilerplate(resolver)) | 230 if (!CheckBoilerplate(resolver)) |
196 return promise; | 231 return promise; |
197 | 232 |
(...skipping 10 matching lines...) Expand all Loading... | |
208 ScriptPromise promise = resolver->Promise(); | 243 ScriptPromise promise = resolver->Promise(); |
209 if (!CheckBoilerplate(resolver)) | 244 if (!CheckBoilerplate(resolver)) |
210 return promise; | 245 return promise; |
211 | 246 |
212 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 247 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); | 248 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); |
214 return promise; | 249 return promise; |
215 } | 250 } |
216 | 251 |
217 } // namespace blink | 252 } // namespace blink |
OLD | NEW |