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 "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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
| 15 #include "components/password_manager/content/browser/content_password_manager_d river.h" | 15 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
| 16 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" | 16 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" |
| 17 #include "components/password_manager/core/browser/affiliated_match_helper.h" | 17 #include "components/password_manager/core/browser/affiliated_match_helper.h" |
| 18 #include "components/password_manager/core/browser/credential_manager_logger.h" | 18 #include "components/password_manager/core/browser/credential_manager_logger.h" |
| 19 #include "components/password_manager/core/browser/form_fetcher_impl.h" | 19 #include "components/password_manager/core/browser/form_fetcher_impl.h" |
| 20 #include "components/password_manager/core/browser/form_saver.h" | 20 #include "components/password_manager/core/browser/form_saver.h" |
| 21 #include "components/password_manager/core/browser/password_manager_client.h" | 21 #include "components/password_manager/core/browser/password_manager_client.h" |
| 22 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 22 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
| 23 #include "components/password_manager/core/browser/password_manager_util.h" | 23 #include "components/password_manager/core/browser/password_manager_util.h" |
| 24 #include "components/password_manager/core/browser/password_store.h" | 24 #include "components/password_manager/core/browser/password_store.h" |
| 25 #include "components/password_manager/core/common/credential_manager_types.h" | |
| 26 #include "components/password_manager/core/common/password_manager_pref_names.h" | 25 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 28 | 27 |
| 29 namespace password_manager { | 28 namespace password_manager { |
| 30 | 29 |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 void RunMojoGetCallback(mojom::CredentialManager::GetCallback callback, | 32 void RunMojoGetCallback(mojom::CredentialManager::GetCallback callback, |
| 34 const CredentialInfo& info) { | 33 const CredentialInfo& info) { |
| 35 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); | 34 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, info); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 !client_->OnCredentialManagerUsed()) | 138 !client_->OnCredentialManagerUsed()) |
| 140 return; | 139 return; |
| 141 | 140 |
| 142 if (!pending_require_user_mediation_) { | 141 if (!pending_require_user_mediation_) { |
| 143 pending_require_user_mediation_.reset( | 142 pending_require_user_mediation_.reset( |
| 144 new CredentialManagerPendingRequireUserMediationTask(this)); | 143 new CredentialManagerPendingRequireUserMediationTask(this)); |
| 145 } | 144 } |
| 146 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin()); | 145 pending_require_user_mediation_->AddOrigin(GetSynthesizedFormForOrigin()); |
| 147 } | 146 } |
| 148 | 147 |
| 149 void CredentialManagerImpl::Get(bool zero_click_only, | 148 void CredentialManagerImpl::Get(mojom::CredentialMediationRequirement mediation, |
| 150 bool include_passwords, | 149 bool include_passwords, |
| 151 const std::vector<GURL>& federations, | 150 const std::vector<GURL>& federations, |
| 152 GetCallback callback) { | 151 GetCallback callback) { |
| 153 using metrics_util::LogCredentialManagerGetResult; | 152 using metrics_util::LogCredentialManagerGetResult; |
| 154 metrics_util::CredentialManagerGetMediation mediation_status = | 153 |
| 155 zero_click_only ? metrics_util::CREDENTIAL_MANAGER_GET_UNMEDIATED | 154 mediation_ = [mediation]() { |
| 156 : metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED; | 155 switch (mediation) { |
| 156 case mojom::CredentialMediationRequirement::SILENT: | |
| 157 return CredentialMediationRequirement::SILENT; | |
| 158 case mojom::CredentialMediationRequirement::OPTIONAL: | |
| 159 return CredentialMediationRequirement::OPTIONAL; | |
| 160 case mojom::CredentialMediationRequirement::REQUIRED: | |
| 161 return CredentialMediationRequirement::REQUIRED; | |
| 162 } | |
| 163 NOTREACHED(); | |
| 164 return CredentialMediationRequirement::OPTIONAL; | |
| 165 }(); | |
|
vasilii
2017/05/18 12:34:03
Ideally it should go away.
jdoerrie
2017/05/18 14:57:24
Done.
| |
| 166 | |
| 157 PasswordStore* store = GetPasswordStore(); | 167 PasswordStore* store = GetPasswordStore(); |
| 158 if (password_manager_util::IsLoggingActive(client_)) { | 168 if (password_manager_util::IsLoggingActive(client_)) { |
| 159 CredentialManagerLogger(client_->GetLogManager()) | 169 CredentialManagerLogger(client_->GetLogManager()) |
| 160 .LogRequestCredential(web_contents()->GetLastCommittedURL(), | 170 .LogRequestCredential(web_contents()->GetLastCommittedURL(), mediation_, |
| 161 zero_click_only, federations); | 171 federations); |
| 162 } | 172 } |
| 163 if (pending_request_ || !store) { | 173 if (pending_request_ || !store) { |
| 164 // Callback error. | 174 // Callback error. |
| 165 std::move(callback).Run( | 175 std::move(callback).Run( |
| 166 pending_request_ | 176 pending_request_ |
| 167 ? mojom::CredentialManagerError::PENDINGREQUEST | 177 ? mojom::CredentialManagerError::PENDINGREQUEST |
| 168 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, | 178 : mojom::CredentialManagerError::PASSWORDSTOREUNAVAILABLE, |
| 169 base::nullopt); | 179 base::nullopt); |
| 170 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED, | 180 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_REJECTED, |
| 171 mediation_status); | 181 mediation_); |
| 172 return; | 182 return; |
| 173 } | 183 } |
| 174 | 184 |
| 175 // Return an empty credential if the current page has TLS errors, or if the | 185 // Return an empty credential if the current page has TLS errors, or if the |
| 176 // page is being prerendered. | 186 // page is being prerendered. |
| 177 if (!client_->IsFillingEnabledForCurrentPage() || | 187 if (!client_->IsFillingEnabledForCurrentPage() || |
| 178 !client_->OnCredentialManagerUsed()) { | 188 !client_->OnCredentialManagerUsed()) { |
| 179 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, | 189 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, |
| 180 CredentialInfo()); | 190 CredentialInfo()); |
| 181 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 191 LogCredentialManagerGetResult(metrics_util::CREDENTIAL_MANAGER_GET_NONE, |
| 182 mediation_status); | 192 mediation_); |
| 183 return; | 193 return; |
| 184 } | 194 } |
| 185 // Return an empty credential if zero-click is required but disabled. | 195 // Return an empty credential if zero-click is required but disabled. |
| 186 if (zero_click_only && !IsZeroClickAllowed()) { | 196 if (mediation_ == CredentialMediationRequirement::SILENT && |
| 197 !IsZeroClickAllowed()) { | |
| 187 // Callback with empty credential info. | 198 // Callback with empty credential info. |
| 188 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, | 199 std::move(callback).Run(mojom::CredentialManagerError::SUCCESS, |
| 189 CredentialInfo()); | 200 CredentialInfo()); |
| 190 LogCredentialManagerGetResult( | 201 LogCredentialManagerGetResult( |
| 191 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, | 202 metrics_util::CREDENTIAL_MANAGER_GET_NONE_ZERO_CLICK_OFF, mediation_); |
| 192 mediation_status); | |
| 193 return; | 203 return; |
| 194 } | 204 } |
| 195 | 205 |
| 196 pending_request_.reset(new CredentialManagerPendingRequestTask( | 206 pending_request_.reset(new CredentialManagerPendingRequestTask( |
| 197 this, base::Bind(&RunMojoGetCallback, base::Passed(&callback)), | 207 this, base::Bind(&RunMojoGetCallback, base::Passed(&callback)), |
| 198 zero_click_only, include_passwords, federations)); | 208 mediation_, include_passwords, federations)); |
| 199 // This will result in a callback to | 209 // This will result in a callback to |
| 200 // PendingRequestTask::OnGetPasswordStoreResults(). | 210 // PendingRequestTask::OnGetPasswordStoreResults(). |
| 201 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), | 211 GetPasswordStore()->GetLogins(GetSynthesizedFormForOrigin(), |
| 202 pending_request_.get()); | 212 pending_request_.get()); |
| 203 } | 213 } |
| 204 | 214 |
| 205 bool CredentialManagerImpl::IsZeroClickAllowed() const { | 215 bool CredentialManagerImpl::IsZeroClickAllowed() const { |
| 206 return *auto_signin_enabled_ && !client_->IsIncognito(); | 216 return *auto_signin_enabled_ && !client_->IsIncognito(); |
| 207 } | 217 } |
| 208 | 218 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 227 | 237 |
| 228 if (password_manager_util::IsLoggingActive(client_)) { | 238 if (password_manager_util::IsLoggingActive(client_)) { |
| 229 CredentialManagerLogger(client_->GetLogManager()) | 239 CredentialManagerLogger(client_->GetLogManager()) |
| 230 .LogSendCredential(web_contents()->GetLastCommittedURL(), info.type); | 240 .LogSendCredential(web_contents()->GetLastCommittedURL(), info.type); |
| 231 } | 241 } |
| 232 send_callback.Run(info); | 242 send_callback.Run(info); |
| 233 pending_request_.reset(); | 243 pending_request_.reset(); |
| 234 } | 244 } |
| 235 | 245 |
| 236 void CredentialManagerImpl::SendPasswordForm( | 246 void CredentialManagerImpl::SendPasswordForm( |
| 237 const SendCredentialCallback& send_callback, | 247 const SendCredentialCallback& send_callback, |
|
vasilii
2017/05/18 12:34:03
It should get |mediation| as a parameter. |mediati
jdoerrie
2017/05/18 14:57:24
Done.
| |
| 238 const autofill::PasswordForm* form) { | 248 const autofill::PasswordForm* form) { |
| 239 CredentialInfo info; | 249 CredentialInfo info; |
| 240 if (form) { | 250 if (form) { |
| 241 password_manager::CredentialType type_to_return = | 251 password_manager::CredentialType type_to_return = |
| 242 form->federation_origin.unique() | 252 form->federation_origin.unique() |
| 243 ? CredentialType::CREDENTIAL_TYPE_PASSWORD | 253 ? CredentialType::CREDENTIAL_TYPE_PASSWORD |
| 244 : CredentialType::CREDENTIAL_TYPE_FEDERATED; | 254 : CredentialType::CREDENTIAL_TYPE_FEDERATED; |
| 245 info = CredentialInfo(*form, type_to_return); | 255 info = CredentialInfo(*form, type_to_return); |
| 246 if (PasswordStore* store = GetPasswordStore()) { | 256 if (PasswordStore* store = GetPasswordStore()) { |
| 247 if (form->skip_zero_click && IsZeroClickAllowed()) { | 257 if (form->skip_zero_click && IsZeroClickAllowed()) { |
| 248 autofill::PasswordForm update_form = *form; | 258 autofill::PasswordForm update_form = *form; |
| 249 update_form.skip_zero_click = false; | 259 update_form.skip_zero_click = false; |
| 250 store->UpdateLogin(update_form); | 260 store->UpdateLogin(update_form); |
| 251 } | 261 } |
| 252 } | 262 } |
| 253 base::RecordAction( | 263 base::RecordAction( |
| 254 base::UserMetricsAction("CredentialManager_AccountChooser_Accepted")); | 264 base::UserMetricsAction("CredentialManager_AccountChooser_Accepted")); |
| 255 metrics_util::LogCredentialManagerGetResult( | 265 metrics_util::LogCredentialManagerGetResult( |
| 256 metrics_util::CREDENTIAL_MANAGER_GET_ACCOUNT_CHOOSER, | 266 metrics_util::CREDENTIAL_MANAGER_GET_ACCOUNT_CHOOSER, mediation_); |
| 257 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED); | |
| 258 } else { | 267 } else { |
| 259 base::RecordAction( | 268 base::RecordAction( |
| 260 base::UserMetricsAction("CredentialManager_AccountChooser_Dismissed")); | 269 base::UserMetricsAction("CredentialManager_AccountChooser_Dismissed")); |
| 261 metrics_util::LogCredentialManagerGetResult( | 270 metrics_util::LogCredentialManagerGetResult( |
| 262 metrics_util::CREDENTIAL_MANAGER_GET_NONE, | 271 metrics_util::CREDENTIAL_MANAGER_GET_NONE, mediation_); |
| 263 metrics_util::CREDENTIAL_MANAGER_GET_MEDIATED); | |
| 264 } | 272 } |
| 265 SendCredential(send_callback, info); | 273 SendCredential(send_callback, info); |
| 266 } | 274 } |
| 267 | 275 |
| 268 PasswordManagerClient* CredentialManagerImpl::client() const { | 276 PasswordManagerClient* CredentialManagerImpl::client() const { |
| 269 return client_; | 277 return client_; |
| 270 } | 278 } |
| 271 | 279 |
| 272 PasswordStore* CredentialManagerImpl::GetPasswordStore() { | 280 PasswordStore* CredentialManagerImpl::GetPasswordStore() { |
| 273 return client_ ? client_->GetPasswordStore() : nullptr; | 281 return client_ ? client_->GetPasswordStore() : nullptr; |
| 274 } | 282 } |
| 275 | 283 |
| 276 void CredentialManagerImpl::DoneRequiringUserMediation() { | 284 void CredentialManagerImpl::DoneRequiringUserMediation() { |
| 277 DCHECK(pending_require_user_mediation_); | 285 DCHECK(pending_require_user_mediation_); |
| 278 pending_require_user_mediation_.reset(); | 286 pending_require_user_mediation_.reset(); |
| 279 } | 287 } |
| 280 | 288 |
| 281 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() | 289 PasswordStore::FormDigest CredentialManagerImpl::GetSynthesizedFormForOrigin() |
| 282 const { | 290 const { |
| 283 PasswordStore::FormDigest digest = { | 291 PasswordStore::FormDigest digest = { |
| 284 autofill::PasswordForm::SCHEME_HTML, std::string(), | 292 autofill::PasswordForm::SCHEME_HTML, std::string(), |
| 285 web_contents()->GetLastCommittedURL().GetOrigin()}; | 293 web_contents()->GetLastCommittedURL().GetOrigin()}; |
| 286 digest.signon_realm = digest.origin.spec(); | 294 digest.signon_realm = digest.origin.spec(); |
| 287 return digest; | 295 return digest; |
| 288 } | 296 } |
| 289 | 297 |
| 290 } // namespace password_manager | 298 } // namespace password_manager |
| OLD | NEW |