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