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 "components/password_manager/core/browser/password_autofill_manager.h" | 5 #include "components/password_manager/core/browser/password_autofill_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 23 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
24 // based on |current_username|. Unless |show_all| is true, it only picks | 24 // based on |current_username|. Unless |show_all| is true, it only picks |
25 // suggestions where the username has |current_username| as a prefix. | 25 // suggestions where the username has |current_username| as a prefix. |
26 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 26 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
27 const base::string16& current_username, | 27 const base::string16& current_username, |
28 std::vector<base::string16>* suggestions, | 28 std::vector<base::string16>* suggestions, |
29 std::vector<base::string16>* realms, | 29 std::vector<base::string16>* realms, |
30 bool show_all) { | 30 bool show_all) { |
31 if (show_all || | 31 if (show_all || |
32 StartsWith( | 32 StartsWith(fill_data.username_field.value, current_username, false)) { |
33 fill_data.basic_data.fields[0].value, current_username, false)) { | 33 suggestions->push_back(fill_data.username_field.value); |
34 suggestions->push_back(fill_data.basic_data.fields[0].value); | |
35 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); | 34 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); |
36 } | 35 } |
37 | 36 |
38 for (const auto& login : fill_data.additional_logins) { | 37 for (const auto& login : fill_data.additional_logins) { |
39 if (show_all || StartsWith(login.first, current_username, false)) { | 38 if (show_all || StartsWith(login.first, current_username, false)) { |
40 suggestions->push_back(login.first); | 39 suggestions->push_back(login.first); |
41 realms->push_back(base::UTF8ToUTF16(login.second.realm)); | 40 realms->push_back(base::UTF8ToUTF16(login.second.realm)); |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 193 |
195 bool PasswordAutofillManager::GetPasswordForUsername( | 194 bool PasswordAutofillManager::GetPasswordForUsername( |
196 const base::string16& current_username, | 195 const base::string16& current_username, |
197 const autofill::PasswordFormFillData& fill_data, | 196 const autofill::PasswordFormFillData& fill_data, |
198 base::string16* password) { | 197 base::string16* password) { |
199 // TODO(dubroy): When password access requires some kind of authentication | 198 // TODO(dubroy): When password access requires some kind of authentication |
200 // (e.g. Keychain access on Mac OS), use |password_manager_client_| here to | 199 // (e.g. Keychain access on Mac OS), use |password_manager_client_| here to |
201 // fetch the actual password. See crbug.com/178358 for more context. | 200 // fetch the actual password. See crbug.com/178358 for more context. |
202 | 201 |
203 // Look for any suitable matches to current field text. | 202 // Look for any suitable matches to current field text. |
204 if (fill_data.basic_data.fields[0].value == current_username) { | 203 if (fill_data.username_field.value == current_username) { |
205 *password = fill_data.basic_data.fields[1].value; | 204 *password = fill_data.password_field.value; |
206 return true; | 205 return true; |
207 } | 206 } |
208 | 207 |
209 // Scan additional logins for a match. | 208 // Scan additional logins for a match. |
210 for (autofill::PasswordFormFillData::LoginCollection::const_iterator iter = | 209 for (autofill::PasswordFormFillData::LoginCollection::const_iterator iter = |
211 fill_data.additional_logins.begin(); | 210 fill_data.additional_logins.begin(); |
212 iter != fill_data.additional_logins.end(); | 211 iter != fill_data.additional_logins.end(); |
213 ++iter) { | 212 ++iter) { |
214 if (iter->first == current_username) { | 213 if (iter->first == current_username) { |
215 *password = iter->second.password; | 214 *password = iter->second.password; |
(...skipping 21 matching lines...) Expand all Loading... |
237 autofill::PasswordFormFillData* found_password) { | 236 autofill::PasswordFormFillData* found_password) { |
238 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 237 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
239 if (iter == login_to_password_info_.end()) | 238 if (iter == login_to_password_info_.end()) |
240 return false; | 239 return false; |
241 | 240 |
242 *found_password = iter->second; | 241 *found_password = iter->second; |
243 return true; | 242 return true; |
244 } | 243 } |
245 | 244 |
246 } // namespace password_manager | 245 } // namespace password_manager |
OLD | NEW |