Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: components/autofill/core/browser/password_autofill_manager.cc

Issue 184103016: Autofill: Refactoring to support fetching password after a username is selected (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor PasswordAutofillManager in password_manager component. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/password_manager/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 {
11
12 //////////////////////////////////////////////////////////////////////////////// 10 ////////////////////////////////////////////////////////////////////////////////
13 // PasswordAutofillManager, public: 11 // PasswordAutofillManager, public:
14 12
15 PasswordAutofillManager::PasswordAutofillManager( 13 PasswordAutofillManager::PasswordAutofillManager(
16 AutofillDriver* autofill_driver) : autofill_driver_(autofill_driver) { 14 PasswordManagerClient* password_manager_client,
15 AutofillDriver* autofill_driver)
16 : password_manager_client_(password_manager_client),
17 autofill_driver_(autofill_driver) {
18 DCHECK(password_manager_client);
17 DCHECK(autofill_driver); 19 DCHECK(autofill_driver);
18 } 20 }
19 21
20 PasswordAutofillManager::~PasswordAutofillManager() { 22 PasswordAutofillManager::~PasswordAutofillManager() {
21 } 23 }
22 24
23 bool PasswordAutofillManager::DidAcceptAutofillSuggestion( 25 void PasswordAutofillManager::DidAcceptAutofillSuggestion(
24 const FormFieldData& field, 26 const FormFieldData& field,
25 const base::string16& username) { 27 const base::string16& username) {
26 PasswordFormFillData password; 28 PasswordFormFillData fill_data;
27 if (!FindLoginInfo(field, &password)) 29 base::string16 password;
28 return false; 30 if (FindLoginInfo(field, &fill_data) &&
29 31 GetPasswordForUsername(username, fill_data, &password)) {
30 if (WillFillUserNameAndPassword(username, password)) { 32 autofill_driver_->RendererShouldAcceptPasswordAutofillSuggestion(
31 autofill_driver_->RendererShouldAcceptPasswordAutofillSuggestion(username); 33 username, password);
32 return true; 34 return;
33 } 35 }
34 36 NOTREACHED();
35 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) {
56 // TODO(dubroy): When password access requires some kind of authentication
57 // (e.g. Keychain access on Mac OS), use |password_manager_client_| here to
58 // fetch the actual password. See crbug.com/178358 for more context.
59
54 // Look for any suitable matches to current field text. 60 // Look for any suitable matches to current field text.
55 if (fill_data.basic_data.fields[0].value == current_username) 61 if (fill_data.basic_data.fields[0].value == current_username) {
62 *password = fill_data.basic_data.fields[1].value;
56 return true; 63 return true;
64 }
57 65
58 // Scan additional logins for a match. 66 // Scan additional logins for a match.
59 for (PasswordFormFillData::LoginCollection::const_iterator iter = 67 for (PasswordFormFillData::LoginCollection::const_iterator iter =
60 fill_data.additional_logins.begin(); 68 fill_data.additional_logins.begin();
61 iter != fill_data.additional_logins.end(); ++iter) { 69 iter != fill_data.additional_logins.end(); ++iter) {
62 if (iter->first == current_username) 70 if (iter->first == current_username) {
63 return true; 71 *password = iter->second.password;
72 return true;
73 }
64 } 74 }
65 75
66 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter 76 for (PasswordFormFillData::UsernamesCollection::const_iterator usernames_iter
67 = fill_data.other_possible_usernames.begin(); 77 = fill_data.other_possible_usernames.begin();
68 usernames_iter != fill_data.other_possible_usernames.end(); 78 usernames_iter != fill_data.other_possible_usernames.end();
69 ++usernames_iter) { 79 ++usernames_iter) {
70 for (size_t i = 0; i < usernames_iter->second.size(); ++i) { 80 for (size_t i = 0; i < usernames_iter->second.size(); ++i) {
71 if (usernames_iter->second[i] == current_username) 81 if (usernames_iter->second[i] == current_username) {
82 *password = usernames_iter->first.password;
72 return true; 83 return true;
84 }
73 } 85 }
74 } 86 }
75 87
76 return false; 88 return false;
77 } 89 }
78 90
79 bool PasswordAutofillManager::FindLoginInfo( 91 bool PasswordAutofillManager::FindLoginInfo(
80 const FormFieldData& field, 92 const FormFieldData& field,
81 PasswordFormFillData* found_password) { 93 PasswordFormFillData* found_password) {
82 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); 94 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
83 if (iter == login_to_password_info_.end()) 95 if (iter == login_to_password_info_.end())
84 return false; 96 return false;
85 97
86 *found_password = iter->second; 98 *found_password = iter->second;
87 return true; 99 return true;
88 } 100 }
89
90 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698