Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/browser/password_manager.h" | 5 #include "components/password_manager/core/browser/password_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "components/autofill/core/common/autofill_data_validation.h" | |
| 14 #include "components/autofill/core/common/password_autofill_util.h" | 15 #include "components/autofill/core/common/password_autofill_util.h" |
| 16 #include "components/password_manager/core/browser/password_autofill_manager.h" | |
| 15 #include "components/password_manager/core/browser/password_form_manager.h" | 17 #include "components/password_manager/core/browser/password_form_manager.h" |
| 16 #include "components/password_manager/core/browser/password_manager_client.h" | 18 #include "components/password_manager/core/browser/password_manager_client.h" |
| 17 #include "components/password_manager/core/browser/password_manager_driver.h" | 19 #include "components/password_manager/core/browser/password_manager_driver.h" |
| 18 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 20 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
| 19 #include "components/password_manager/core/common/password_manager_pref_names.h" | 21 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 20 #include "components/user_prefs/pref_registry_syncable.h" | 22 #include "components/user_prefs/pref_registry_syncable.h" |
| 21 | 23 |
| 22 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
| 23 using autofill::PasswordFormMap; | 25 using autofill::PasswordFormMap; |
| 24 | 26 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 223 |
| 222 void PasswordManager::RemoveObserver(LoginModelObserver* observer) { | 224 void PasswordManager::RemoveObserver(LoginModelObserver* observer) { |
| 223 observers_.RemoveObserver(observer); | 225 observers_.RemoveObserver(observer); |
| 224 } | 226 } |
| 225 | 227 |
| 226 void PasswordManager::DidNavigateMainFrame(bool is_in_page) { | 228 void PasswordManager::DidNavigateMainFrame(bool is_in_page) { |
| 227 // Clear data after main frame navigation if the navigation was to a | 229 // Clear data after main frame navigation if the navigation was to a |
| 228 // different page. | 230 // different page. |
| 229 if (!is_in_page) | 231 if (!is_in_page) |
| 230 pending_login_managers_.clear(); | 232 pending_login_managers_.clear(); |
| 233 | |
| 234 driver_->GetPasswordAutofillManager()->Reset(); | |
|
Garrett Casto
2014/03/12 01:09:22
This should only happen if the navigation is not i
Patrick Dubroy
2014/03/12 16:47:09
Done.
| |
| 231 } | 235 } |
| 232 | 236 |
| 233 void PasswordManager::OnPasswordFormSubmitted( | 237 void PasswordManager::OnPasswordFormSubmitted( |
| 234 const PasswordForm& password_form) { | 238 const PasswordForm& password_form) { |
| 235 ProvisionallySavePassword(password_form); | 239 ProvisionallySavePassword(password_form); |
| 236 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { | 240 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { |
| 237 submission_callbacks_[i].Run(password_form); | 241 submission_callbacks_[i].Run(password_form); |
| 238 } | 242 } |
| 239 | 243 |
| 240 pending_login_managers_.clear(); | 244 pending_login_managers_.clear(); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 UMA_HISTOGRAM_COUNTS("PasswordGeneration.Submitted", 1); | 307 UMA_HISTOGRAM_COUNTS("PasswordGeneration.Submitted", 1); |
| 304 | 308 |
| 305 if (ShouldPromptUserToSavePassword()) { | 309 if (ShouldPromptUserToSavePassword()) { |
| 306 client_->PromptUserToSavePassword(provisional_save_manager_.release()); | 310 client_->PromptUserToSavePassword(provisional_save_manager_.release()); |
| 307 } else { | 311 } else { |
| 308 provisional_save_manager_->Save(); | 312 provisional_save_manager_->Save(); |
| 309 provisional_save_manager_.reset(); | 313 provisional_save_manager_.reset(); |
| 310 } | 314 } |
| 311 } | 315 } |
| 312 | 316 |
| 317 void PasswordManager::OnAddPasswordFormMapping( | |
|
Garrett Casto
2014/03/12 01:09:22
Any reason why you are doing Driver -> PasswordMan
Patrick Dubroy
2014/03/12 16:47:09
Do you mean why is this function defined in Passwo
Garrett Casto
2014/03/14 08:25:22
I guess it depends on how you think the code shoul
Patrick Dubroy
2014/03/14 12:07:19
Makes sense. Fixed to be as you described.
| |
| 318 const autofill::FormFieldData& username_field, | |
| 319 const autofill::PasswordFormFillData& fill_data) { | |
| 320 if (!autofill::IsValidFormFieldData(username_field) || | |
| 321 !autofill::IsValidPasswordFormFillData(fill_data)) | |
| 322 return; | |
| 323 | |
| 324 driver_->GetPasswordAutofillManager()->AddPasswordFormMapping( | |
| 325 username_field, fill_data); | |
| 326 } | |
| 327 | |
| 328 void PasswordManager::OnShowPasswordSuggestions( | |
| 329 const autofill::FormFieldData& field, | |
| 330 const gfx::RectF& bounds, | |
| 331 const std::vector<base::string16>& suggestions, | |
| 332 const std::vector<base::string16>& realms) { | |
| 333 if (!autofill::IsValidString16Vector(suggestions) || | |
| 334 !autofill::IsValidString16Vector(realms) || | |
| 335 suggestions.size() != realms.size()) | |
| 336 return; | |
| 337 | |
| 338 driver_->GetPasswordAutofillManager()->ShowPasswordSuggestions( | |
| 339 field, bounds, suggestions, realms); | |
| 340 } | |
| 341 | |
| 313 void PasswordManager::PossiblyInitializeUsernamesExperiment( | 342 void PasswordManager::PossiblyInitializeUsernamesExperiment( |
| 314 const PasswordFormMap& best_matches) const { | 343 const PasswordFormMap& best_matches) const { |
| 315 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) | 344 if (base::FieldTrialList::Find(kOtherPossibleUsernamesExperiment)) |
| 316 return; | 345 return; |
| 317 | 346 |
| 318 bool other_possible_usernames_exist = false; | 347 bool other_possible_usernames_exist = false; |
| 319 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); | 348 for (autofill::PasswordFormMap::const_iterator it = best_matches.begin(); |
| 320 it != best_matches.end(); ++it) { | 349 it != best_matches.end(); ++it) { |
| 321 if (!it->second->other_possible_usernames.empty()) { | 350 if (!it->second->other_possible_usernames.empty()) { |
| 322 other_possible_usernames_exist = true; | 351 other_possible_usernames_exist = true; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 FOR_EACH_OBSERVER( | 414 FOR_EACH_OBSERVER( |
| 386 LoginModelObserver, | 415 LoginModelObserver, |
| 387 observers_, | 416 observers_, |
| 388 OnAutofillDataAvailable(preferred_match.username_value, | 417 OnAutofillDataAvailable(preferred_match.username_value, |
| 389 preferred_match.password_value)); | 418 preferred_match.password_value)); |
| 390 break; | 419 break; |
| 391 } | 420 } |
| 392 | 421 |
| 393 client_->PasswordWasAutofilled(best_matches); | 422 client_->PasswordWasAutofilled(best_matches); |
| 394 } | 423 } |
| OLD | NEW |