Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "components/autofill/core/browser/autofill_driver.h" | 6 #include "components/autofill/core/browser/autofill_driver.h" |
| 7 #include "components/autofill/core/browser/password_autofill_manager.h" | 7 #include "components/autofill/core/browser/password_autofill_manager.h" |
| 8 #include "ui/events/keycodes/keyboard_codes.h" | 8 #include "ui/events/keycodes/keyboard_codes.h" |
| 9 | 9 |
| 10 namespace autofill { | 10 namespace autofill { |
| 11 | 11 |
| 12 //////////////////////////////////////////////////////////////////////////////// | 12 //////////////////////////////////////////////////////////////////////////////// |
| 13 // PasswordAutofillManager, public: | 13 // PasswordAutofillManager, public: |
| 14 | 14 |
| 15 PasswordAutofillManager::PasswordAutofillManager( | 15 PasswordAutofillManager::PasswordAutofillManager( |
| 16 AutofillDriver* autofill_driver) : autofill_driver_(autofill_driver) { | 16 PasswordManagerClient* password_manager_client, |
| 17 AutofillDriver* autofill_driver) | |
| 18 : password_manager_client_(password_manager_client), | |
| 19 autofill_driver_(autofill_driver) { | |
| 20 DCHECK(password_manager_client); | |
| 17 DCHECK(autofill_driver); | 21 DCHECK(autofill_driver); |
| 18 } | 22 } |
| 19 | 23 |
| 20 PasswordAutofillManager::~PasswordAutofillManager() { | 24 PasswordAutofillManager::~PasswordAutofillManager() { |
| 21 } | 25 } |
| 22 | 26 |
| 23 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | 27 void PasswordAutofillManager::DidAcceptAutofillSuggestion( |
|
Garrett Casto
2014/03/06 00:42:05
You should change the function name if this is mea
| |
| 24 const FormFieldData& field, | 28 const FormFieldData& field, |
| 25 const base::string16& username) { | 29 const base::string16& username) { |
| 26 PasswordFormFillData password; | 30 PasswordFormFillData fill_data; |
| 27 if (!FindLoginInfo(field, &password)) | 31 base::string16 password; |
| 28 return false; | 32 if (FindLoginInfo(field, &fill_data) && |
| 29 | 33 GetPasswordForUsername(username, fill_data, &password)) { |
| 30 if (WillFillUserNameAndPassword(username, password)) { | 34 autofill_driver_->RendererShouldAcceptPasswordAutofillSuggestion( |
| 31 autofill_driver_->RendererShouldAcceptPasswordAutofillSuggestion(username); | 35 username, password); |
| 32 return true; | 36 return; |
| 33 } | 37 } |
| 34 | 38 NOTREACHED(); |
| 35 return false; | |
| 36 } | 39 } |
| 37 | 40 |
| 38 void PasswordAutofillManager::AddPasswordFormMapping( | 41 void PasswordAutofillManager::AddPasswordFormMapping( |
| 39 const FormFieldData& username_element, | 42 const FormFieldData& username_element, |
| 40 const PasswordFormFillData& password) { | 43 const PasswordFormFillData& password) { |
| 41 login_to_password_info_[username_element] = password; | 44 login_to_password_info_[username_element] = password; |
| 42 } | 45 } |
| 43 | 46 |
| 44 void PasswordAutofillManager::Reset() { | 47 void PasswordAutofillManager::Reset() { |
| 45 login_to_password_info_.clear(); | 48 login_to_password_info_.clear(); |
| 46 } | 49 } |
| 47 | 50 |
| 48 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
| 49 // PasswordAutofillManager, private: | 52 // PasswordAutofillManager, private: |
| 50 | 53 |
| 51 bool PasswordAutofillManager::WillFillUserNameAndPassword( | 54 bool PasswordAutofillManager::GetPasswordForUsername( |
| 52 const base::string16& current_username, | 55 const base::string16& current_username, |
| 53 const PasswordFormFillData& fill_data) { | 56 const PasswordFormFillData& fill_data, |
| 57 base::string16* password) { | |
| 58 // TODO(dubroy): When password access requires some kind of authentication | |
|
Garrett Casto
2014/03/06 00:42:05
This still has the same dependence problems that I
Patrick Dubroy
2014/03/10 14:29:57
Yeah, that might be slightly better, though it sti
Ilya Sherman
2014/03/10 21:44:07
Yes, if we can do that, definitely let's! :)
| |
| 59 // (e.g. Keychain access on Mac OS), use |password_manager_client_| here to | |
| 60 // fetch the actual password. See crbug.com/178358 for more context. | |
| 61 | |
| 54 // Look for any suitable matches to current field text. | 62 // Look for any suitable matches to current field text. |
| 55 if (fill_data.basic_data.fields[0].value == current_username) | 63 if (fill_data.basic_data.fields[0].value == current_username) { |
| 64 *password = fill_data.basic_data.fields[1].value; | |
| 56 return true; | 65 return true; |
| 66 } | |
| 57 | 67 |
| 58 // Scan additional logins for a match. | 68 // Scan additional logins for a match. |
| 59 for (PasswordFormFillData::LoginCollection::const_iterator iter = | 69 for (PasswordFormFillData::LoginCollection::const_iterator iter = |
| 60 fill_data.additional_logins.begin(); | 70 fill_data.additional_logins.begin(); |
| 61 iter != fill_data.additional_logins.end(); ++iter) { | 71 iter != fill_data.additional_logins.end(); ++iter) { |
| 62 if (iter->first == current_username) | 72 if (iter->first == current_username) { |
| 63 return true; | 73 *password = iter->second.password; |
| 74 return true; | |
| 75 } | |
| 64 } | 76 } |
| 65 | 77 |
| 66 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter | 78 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter |
| 67 = fill_data.other_possible_usernames.begin(); | 79 = fill_data.other_possible_usernames.begin(); |
| 68 usernames_iter != fill_data.other_possible_usernames.end(); | 80 usernames_iter != fill_data.other_possible_usernames.end(); |
| 69 ++usernames_iter) { | 81 ++usernames_iter) { |
| 70 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { | 82 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { |
| 71 if (usernames_iter->second[i] == current_username) | 83 if (usernames_iter->second[i] == current_username) { |
| 84 *password = usernames_iter->first.password; | |
| 72 return true; | 85 return true; |
| 86 } | |
| 73 } | 87 } |
| 74 } | 88 } |
| 75 | 89 |
| 76 return false; | 90 return false; |
| 77 } | 91 } |
| 78 | 92 |
| 79 bool PasswordAutofillManager::FindLoginInfo( | 93 bool PasswordAutofillManager::FindLoginInfo( |
| 80 const FormFieldData& field, | 94 const FormFieldData& field, |
| 81 PasswordFormFillData* found_password) { | 95 PasswordFormFillData* found_password) { |
| 82 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | 96 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); |
| 83 if (iter == login_to_password_info_.end()) | 97 if (iter == login_to_password_info_.end()) |
| 84 return false; | 98 return false; |
| 85 | 99 |
| 86 *found_password = iter->second; | 100 *found_password = iter->second; |
| 87 return true; | 101 return true; |
| 88 } | 102 } |
| 89 | 103 |
| 90 } // namespace autofill | 104 } // namespace autofill |
| OLD | NEW |