Chromium Code Reviews| 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. Also checks that at | |
| 173 // most one of 'unmediated' and 'mediation' is provided and sets 'mediation' | |
| 174 // appropriately when only 'unmediated' is set. | |
| 175 // TODO(http://crbug.com/715077): Remove this when 'unmediated' is removed. | |
| 176 if (!options.hasUnmediated() && !options.hasMediation()) { | |
| 177 options.mediation() = "optional"; | |
|
Mike West
2017/05/19 09:42:35
Nit: Assigning to `mediation()` doesn't seem like
jdoerrie
2017/05/19 09:59:51
Yeah, this needs to be `setMediation`. It might be
| |
| 178 } else if (options.hasUnmediated() && !options.hasMediation()) { | |
| 179 options.mediation() = options.unmediated() ? "silent" : "optional"; | |
| 180 } else if (options.hasUnmediated() && options.hasMediation()) { | |
| 181 resolver->Reject(DOMException::Create( | |
| 182 kNotSupportedError, | |
| 183 "At most one of 'unmediated' and 'mediation' can be specified.")); | |
|
Mike West
2017/05/19 09:42:35
I don't think this is what we agreed on. I thought
jdoerrie
2017/05/19 09:59:51
Agreed, fair point. Should we just silently ignore
| |
| 184 return promise; | |
| 185 } | |
| 186 | |
| 171 Vector<KURL> providers; | 187 Vector<KURL> providers; |
| 172 if (options.hasFederated() && options.federated().hasProviders()) { | 188 if (options.hasFederated() && options.federated().hasProviders()) { |
| 173 for (const auto& string : options.federated().providers()) { | 189 for (const auto& string : options.federated().providers()) { |
| 174 KURL url = KURL(KURL(), string); | 190 KURL url = KURL(KURL(), string); |
| 175 if (url.IsValid()) | 191 if (url.IsValid()) |
| 176 providers.push_back(std::move(url)); | 192 providers.push_back(std::move(url)); |
| 177 } | 193 } |
| 178 } | 194 } |
| 179 | 195 |
| 180 UseCounter::Count(ExecutionContext::From(script_state), | 196 UseCounter::Feature feature; |
| 181 options.unmediated() | 197 WebCredentialMediationRequirement mediation; |
| 182 ? UseCounter::kCredentialManagerGetWithoutUI | 198 |
| 183 : UseCounter::kCredentialManagerGetWithUI); | 199 if (options.mediation() == "silent") { |
| 200 feature = UseCounter::kCredentialManagerGetMediationSilent; | |
| 201 mediation = WebCredentialMediationRequirement::kSilent; | |
| 202 } else if (options.mediation() == "optional") { | |
| 203 feature = UseCounter::kCredentialManagerGetMediationOptional; | |
| 204 mediation = WebCredentialMediationRequirement::kOptional; | |
| 205 } else { | |
| 206 DCHECK_EQ("required", options.mediation()); | |
| 207 feature = UseCounter::kCredentialManagerGetMediationRequired; | |
| 208 mediation = WebCredentialMediationRequirement::kRequired; | |
| 209 } | |
| 210 | |
| 211 UseCounter::Count(ExecutionContext::From(script_state), feature); | |
| 184 | 212 |
| 185 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 213 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
| 186 ->DispatchGet(options.unmediated(), options.password(), providers, | 214 ->DispatchGet(mediation, options.password(), providers, |
| 187 new RequestCallbacks(resolver)); | 215 new RequestCallbacks(resolver)); |
| 188 return promise; | 216 return promise; |
| 189 } | 217 } |
| 190 | 218 |
| 191 ScriptPromise CredentialsContainer::store(ScriptState* script_state, | 219 ScriptPromise CredentialsContainer::store(ScriptState* script_state, |
| 192 Credential* credential) { | 220 Credential* credential) { |
| 193 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 221 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 194 ScriptPromise promise = resolver->Promise(); | 222 ScriptPromise promise = resolver->Promise(); |
| 195 if (!CheckBoilerplate(resolver)) | 223 if (!CheckBoilerplate(resolver)) |
| 196 return promise; | 224 return promise; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 208 ScriptPromise promise = resolver->Promise(); | 236 ScriptPromise promise = resolver->Promise(); |
| 209 if (!CheckBoilerplate(resolver)) | 237 if (!CheckBoilerplate(resolver)) |
| 210 return promise; | 238 return promise; |
| 211 | 239 |
| 212 CredentialManagerClient::From(ExecutionContext::From(script_state)) | 240 CredentialManagerClient::From(ExecutionContext::From(script_state)) |
| 213 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); | 241 ->DispatchRequireUserMediation(new NotificationCallbacks(resolver)); |
| 214 return promise; | 242 return promise; |
| 215 } | 243 } |
| 216 | 244 |
| 217 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |