| 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 "components/password_manager/content/browser/credential_manager_impl.h" | 5 #include "components/password_manager/content/browser/credential_manager_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // Return an empty credential if zero-click is required but disabled. | 170 // Return an empty credential if zero-click is required but disabled. |
| 171 if (zero_click_only && !IsZeroClickAllowed()) { | 171 if (zero_click_only && !IsZeroClickAllowed()) { |
| 172 // Callback with empty credential info. | 172 // Callback with empty credential info. |
| 173 callback.Run(mojom::CredentialManagerError::SUCCESS, CredentialInfo()); | 173 callback.Run(mojom::CredentialManagerError::SUCCESS, CredentialInfo()); |
| 174 LogCredentialManagerGetResult( | 174 LogCredentialManagerGetResult( |
| 175 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, | 175 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, |
| 176 mediation_status); | 176 mediation_status); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (store->affiliated_match_helper()) { | |
| 181 store->affiliated_match_helper()->GetAffiliatedAndroidRealms( | |
| 182 GetSynthesizedFormForOrigin(), | |
| 183 base::Bind(&CredentialManagerImpl::ScheduleRequestTask, | |
| 184 weak_factory_.GetWeakPtr(), callback, zero_click_only, | |
| 185 include_passwords, federations)); | |
| 186 } else { | |
| 187 std::vector<std::string> no_affiliated_realms; | |
| 188 ScheduleRequestTask(callback, zero_click_only, include_passwords, | |
| 189 federations, no_affiliated_realms); | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 void CredentialManagerImpl::ScheduleRequestTask( | |
| 194 const GetCallback& callback, | |
| 195 bool zero_click_only, | |
| 196 bool include_passwords, | |
| 197 const std::vector<GURL>& federations, | |
| 198 const std::vector<std::string>& android_realms) { | |
| 199 DCHECK(GetPasswordStore()); | |
| 200 pending_request_.reset(new CredentialManagerPendingRequestTask( | 180 pending_request_.reset(new CredentialManagerPendingRequestTask( |
| 201 this, base::Bind(&RunMojoGetCallback, callback), zero_click_only, | 181 this, base::Bind(&RunMojoGetCallback, callback), zero_click_only, |
| 202 web_contents()->GetLastCommittedURL().GetOrigin(), include_passwords, | 182 include_passwords, federations)); |
| 203 federations, android_realms)); | |
| 204 | |
| 205 // This will result in a callback to | 183 // This will result in a callback to |
| 206 // PendingRequestTask::OnGetPasswordStoreResults(). | 184 // PendingRequestTask::OnGetPasswordStoreResults(). |
| 207 GetPasswordStore()->GetAutofillableLogins(pending_request_.get()); | 185 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), |
| 208 } | 186 pending_request_.get()); |
| 209 | |
| 210 PasswordStore* CredentialManagerImpl::GetPasswordStore() { | |
| 211 return client_ ? client_->GetPasswordStore() : nullptr; | |
| 212 } | 187 } |
| 213 | 188 |
| 214 bool CredentialManagerImpl::IsZeroClickAllowed() const { | 189 bool CredentialManagerImpl::IsZeroClickAllowed() const { |
| 215 return *auto_signin_enabled_ && !client_->IsOffTheRecord(); | 190 return *auto_signin_enabled_ && !client_->IsOffTheRecord(); |
| 216 } | 191 } |
| 217 | 192 |
| 218 GURL CredentialManagerImpl::GetOrigin() const { | 193 GURL CredentialManagerImpl::GetOrigin() const { |
| 219 return web_contents()->GetLastCommittedURL().GetOrigin(); | 194 return web_contents()->GetLastCommittedURL().GetOrigin(); |
| 220 } | 195 } |
| 221 | 196 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 246 metrics_util::CREDENTIAL_MANAGER_GET_NONE, |
| 272 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED); | 247 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED); |
| 273 } | 248 } |
| 274 SendCredential(send_callback, info); | 249 SendCredential(send_callback, info); |
| 275 } | 250 } |
| 276 | 251 |
| 277 PasswordManagerClient* CredentialManagerImpl::client() const { | 252 PasswordManagerClient* CredentialManagerImpl::client() const { |
| 278 return client_; | 253 return client_; |
| 279 } | 254 } |
| 280 | 255 |
| 256 PasswordStore* CredentialManagerImpl::GetPasswordStore() { |
| 257 return client_ ? client_->GetPasswordStore() : nullptr; |
| 258 } |
| 259 |
| 260 void CredentialManagerImpl::DoneRequiringUserMediation() { |
| 261 DCHECK(pending_require_user_mediation_); |
| 262 pending_require_user_mediation_.reset(); |
| 263 } |
| 264 |
| 281 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() | 265 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() |
| 282 const { | 266 const { |
| 283 PasswordStore::FormDigest digest = { | 267 PasswordStore::FormDigest digest = { |
| 284 autofill::PasswordForm::SCHEME_HTML, std::string(), | 268 autofill::PasswordForm::SCHEME_HTML, std::string(), |
| 285 web_contents()->GetLastCommittedURL().GetOrigin()}; | 269 web_contents()->GetLastCommittedURL().GetOrigin()}; |
| 286 digest.signon_realm = digest.origin.spec(); | 270 digest.signon_realm = digest.origin.spec(); |
| 287 return digest; | 271 return digest; |
| 288 } | 272 } |
| 289 | 273 |
| 290 void CredentialManagerImpl::DoneRequiringUserMediation() { | |
| 291 DCHECK(pending_require_user_mediation_); | |
| 292 pending_require_user_mediation_.reset(); | |
| 293 } | |
| 294 | |
| 295 } // namespace password_manager | 274 } // namespace password_manager |
| OLD | NEW |