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 "base/strings/utf_string_conversions.h" | |
Garrett Casto
2014/03/05 07:36:09
Unused?
Patrick Dubroy
2014/03/05 16:31:50
Done.
| |
6 #include "components/autofill/core/browser/autofill_driver.h" | 7 #include "components/autofill/core/browser/autofill_driver.h" |
7 #include "components/autofill/core/browser/password_autofill_manager.h" | 8 #include "components/autofill/core/browser/password_autofill_manager.h" |
8 #include "ui/events/keycodes/keyboard_codes.h" | 9 #include "ui/events/keycodes/keyboard_codes.h" |
9 | 10 |
10 namespace autofill { | 11 namespace autofill { |
11 | 12 |
12 //////////////////////////////////////////////////////////////////////////////// | 13 //////////////////////////////////////////////////////////////////////////////// |
13 // PasswordAutofillManager, public: | 14 // PasswordAutofillManager, public: |
14 | 15 |
15 PasswordAutofillManager::PasswordAutofillManager( | 16 PasswordAutofillManager::PasswordAutofillManager(PasswordManagerDriver* driver) |
16 AutofillDriver* autofill_driver) : autofill_driver_(autofill_driver) { | 17 : driver_(driver) { |
17 DCHECK(autofill_driver); | 18 DCHECK(driver); |
18 } | 19 } |
19 | 20 |
20 PasswordAutofillManager::~PasswordAutofillManager() { | 21 PasswordAutofillManager::~PasswordAutofillManager() { |
21 } | 22 } |
22 | 23 |
23 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( | 24 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( |
24 const FormFieldData& field, | 25 const FormFieldData& field, |
25 const base::string16& username) { | 26 const base::string16& username) { |
26 PasswordFormFillData password; | 27 PasswordFormFillData fill_data; |
27 if (!FindLoginInfo(field, &password)) | 28 if (!FindLoginInfo(field, &fill_data)) |
28 return false; | 29 return false; |
29 | 30 |
30 if (WillFillUserNameAndPassword(username, password)) { | 31 base::string16 password; |
31 autofill_driver_->RendererShouldAcceptPasswordAutofillSuggestion(username); | 32 if (GetPasswordForUsername(username, fill_data, &password)) { |
33 driver_->RendererShouldAcceptPasswordAutofillSuggestion(username, password); | |
32 return true; | 34 return true; |
33 } | 35 } |
34 | |
35 return false; | 36 return false; |
36 } | 37 } |
37 | 38 |
38 void PasswordAutofillManager::AddPasswordFormMapping( | 39 void PasswordAutofillManager::AddPasswordFormMapping( |
39 const FormFieldData& username_element, | 40 const FormFieldData& username_element, |
40 const PasswordFormFillData& password) { | 41 const PasswordFormFillData& password) { |
41 login_to_password_info_[username_element] = password; | 42 login_to_password_info_[username_element] = password; |
42 } | 43 } |
43 | 44 |
44 void PasswordAutofillManager::Reset() { | 45 void PasswordAutofillManager::Reset() { |
45 login_to_password_info_.clear(); | 46 login_to_password_info_.clear(); |
46 } | 47 } |
47 | 48 |
48 //////////////////////////////////////////////////////////////////////////////// | 49 //////////////////////////////////////////////////////////////////////////////// |
49 // PasswordAutofillManager, private: | 50 // PasswordAutofillManager, private: |
50 | 51 |
51 bool PasswordAutofillManager::WillFillUserNameAndPassword( | 52 bool PasswordAutofillManager::GetPasswordForUsername( |
52 const base::string16& current_username, | 53 const base::string16& current_username, |
53 const PasswordFormFillData& fill_data) { | 54 const PasswordFormFillData& fill_data, |
55 base::string16 *password) { | |
Garrett Casto
2014/03/05 07:36:09
"base::string16* password"
Patrick Dubroy
2014/03/05 16:31:50
Done.
| |
54 // Look for any suitable matches to current field text. | 56 // Look for any suitable matches to current field text. |
55 if (fill_data.basic_data.fields[0].value == current_username) | 57 if (fill_data.basic_data.fields[0].value == current_username) { |
58 *password = fill_data.basic_data.fields[1].value; | |
56 return true; | 59 return true; |
60 } | |
57 | 61 |
58 // Scan additional logins for a match. | 62 // Scan additional logins for a match. |
59 for (PasswordFormFillData::LoginCollection::const_iterator iter = | 63 for (PasswordFormFillData::LoginCollection::const_iterator iter = |
60 fill_data.additional_logins.begin(); | 64 fill_data.additional_logins.begin(); |
61 iter != fill_data.additional_logins.end(); ++iter) { | 65 iter != fill_data.additional_logins.end(); ++iter) { |
62 if (iter->first == current_username) | 66 if (iter->first == current_username) { |
63 return true; | 67 *password = iter->second.password; |
68 return true; | |
69 } | |
64 } | 70 } |
65 | 71 |
66 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter | 72 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter |
67 = fill_data.other_possible_usernames.begin(); | 73 = fill_data.other_possible_usernames.begin(); |
68 usernames_iter != fill_data.other_possible_usernames.end(); | 74 usernames_iter != fill_data.other_possible_usernames.end(); |
69 ++usernames_iter) { | 75 ++usernames_iter) { |
70 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { | 76 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { |
71 if (usernames_iter->second[i] == current_username) | 77 if (usernames_iter->second[i] == current_username) { |
78 *password = usernames_iter->first.password; | |
72 return true; | 79 return true; |
80 } | |
73 } | 81 } |
74 } | 82 } |
75 | 83 |
76 return false; | 84 return false; |
77 } | 85 } |
78 | 86 |
79 bool PasswordAutofillManager::FindLoginInfo( | 87 bool PasswordAutofillManager::FindLoginInfo( |
80 const FormFieldData& field, | 88 const FormFieldData& field, |
81 PasswordFormFillData* found_password) { | 89 PasswordFormFillData* found_password) { |
82 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); | 90 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); |
83 if (iter == login_to_password_info_.end()) | 91 if (iter == login_to_password_info_.end()) |
84 return false; | 92 return false; |
85 | 93 |
86 *found_password = iter->second; | 94 *found_password = iter->second; |
87 return true; | 95 return true; |
88 } | 96 } |
89 | 97 |
90 } // namespace autofill | 98 } // namespace autofill |
OLD | NEW |