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

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

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve rebased code. Created 6 years, 7 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
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/popup_item_ids.h" 7 #include "components/autofill/core/browser/popup_item_ids.h"
8 #include "components/autofill/core/common/autofill_data_validation.h" 8 #include "components/autofill/core/common/autofill_data_validation.h"
9 #include "components/password_manager/core/browser/password_autofill_manager.h" 9 #include "components/password_manager/core/browser/password_autofill_manager.h"
10 #include "components/password_manager/core/browser/password_manager_client.h" 10 #include "components/password_manager/core/browser/password_manager_client.h"
(...skipping 22 matching lines...) Expand all
33 base::string16 password; 33 base::string16 password;
34 if (FindLoginInfo(field, &fill_data) && 34 if (FindLoginInfo(field, &fill_data) &&
35 GetPasswordForUsername(username, fill_data, &password)) { 35 GetPasswordForUsername(username, fill_data, &password)) {
36 PasswordManagerDriver* driver = password_manager_client_->GetDriver(); 36 PasswordManagerDriver* driver = password_manager_client_->GetDriver();
37 driver->AcceptPasswordAutofillSuggestion(username, password); 37 driver->AcceptPasswordAutofillSuggestion(username, password);
38 return true; 38 return true;
39 } 39 }
40 return false; 40 return false;
41 } 41 }
42 42
43 bool PasswordAutofillManager::SelectSuggestion(
44 const autofill::FormFieldData& field,
45 const base::string16& username) {
46 autofill::PasswordFormFillData fill_data;
47 base::string16 password;
48 if (FindLoginInfo(field, &fill_data) &&
49 GetPasswordForUsername(username, fill_data, &password)) {
50 PasswordManagerDriver* driver = password_manager_client_->GetDriver();
51 driver->PreviewPasswordAutofillSuggestion(username, password);
52 return true;
53 }
54 return false;
55 }
56
43 void PasswordAutofillManager::OnAddPasswordFormMapping( 57 void PasswordAutofillManager::OnAddPasswordFormMapping(
44 const autofill::FormFieldData& field, 58 const autofill::FormFieldData& field,
45 const autofill::PasswordFormFillData& fill_data) { 59 const autofill::PasswordFormFillData& fill_data) {
46 if (!autofill::IsValidFormFieldData(field) || 60 if (!autofill::IsValidFormFieldData(field) ||
47 !autofill::IsValidPasswordFormFillData(fill_data)) 61 !autofill::IsValidPasswordFormFillData(fill_data))
48 return; 62 return;
49 63
50 login_to_password_info_[field] = fill_data; 64 login_to_password_info_[field] = fill_data;
51 } 65 }
52 66
(...skipping 30 matching lines...) Expand all
83 void PasswordAutofillManager::Reset() { 97 void PasswordAutofillManager::Reset() {
84 login_to_password_info_.clear(); 98 login_to_password_info_.clear();
85 } 99 }
86 100
87 bool PasswordAutofillManager::AcceptSuggestionForTest( 101 bool PasswordAutofillManager::AcceptSuggestionForTest(
88 const autofill::FormFieldData& field, 102 const autofill::FormFieldData& field,
89 const base::string16& username) { 103 const base::string16& username) {
90 return AcceptSuggestion(field, username); 104 return AcceptSuggestion(field, username);
91 } 105 }
92 106
107 bool PasswordAutofillManager::SelectSuggestionForTest(
108 const autofill::FormFieldData& field,
109 const base::string16& username) {
110 return SelectSuggestion(field, username);
111 }
112
93 void PasswordAutofillManager::OnPopupShown() { 113 void PasswordAutofillManager::OnPopupShown() {
94 } 114 }
95 115
96 void PasswordAutofillManager::OnPopupHidden() { 116 void PasswordAutofillManager::OnPopupHidden() {
97 } 117 }
98 118
99 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value, 119 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value,
100 int identifier) { 120 int identifier) {
101 // This is called to preview an autofill suggestion, but we don't currently 121 ClearPreviewedForm();
102 // do that for password forms (crbug.com/63421). If it is ever implemented, 122 if (!SelectSuggestion(form_field_, value))
103 // ClearPreviewedForm() must also be implemented(). 123 NOTREACHED();
Ilya Sherman 2014/05/13 00:44:05 nit: Please write these two lines as bool success
ziran.sun 2014/05/14 15:35:12 What about NOTREACHED() uses in other places of th
Ilya Sherman 2014/05/14 23:10:58 Yes, let's do that :)
ziran.sun 2014/05/15 12:36:37 Done.
104 } 124 }
105 125
106 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, 126 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value,
107 int identifier) { 127 int identifier) {
108 if (!AcceptSuggestion(form_field_, value)) 128 if (!AcceptSuggestion(form_field_, value))
109 NOTREACHED(); 129 NOTREACHED();
110 autofill_manager_delegate_->HideAutofillPopup(); 130 autofill_manager_delegate_->HideAutofillPopup();
111 } 131 }
112 132
113 void PasswordAutofillManager::RemoveSuggestion(const base::string16& value, 133 void PasswordAutofillManager::RemoveSuggestion(const base::string16& value,
114 int identifier) { 134 int identifier) {
115 NOTREACHED(); 135 NOTREACHED();
116 } 136 }
117 137
118 void PasswordAutofillManager::ClearPreviewedForm() { 138 void PasswordAutofillManager::ClearPreviewedForm() {
119 // There is currently no preview for password autofill (crbug.com/63421). 139 PasswordManagerDriver* driver = password_manager_client_->GetDriver();
120 // This function needs an implemention if preview is ever implemented. 140 driver->ClearPasswordPreviewedForm();
121 } 141 }
122 142
123 //////////////////////////////////////////////////////////////////////////////// 143 ////////////////////////////////////////////////////////////////////////////////
124 // PasswordAutofillManager, private: 144 // PasswordAutofillManager, private:
125 145
126 bool PasswordAutofillManager::GetPasswordForUsername( 146 bool PasswordAutofillManager::GetPasswordForUsername(
127 const base::string16& current_username, 147 const base::string16& current_username,
128 const autofill::PasswordFormFillData& fill_data, 148 const autofill::PasswordFormFillData& fill_data,
129 base::string16* password) { 149 base::string16* password) {
130 // TODO(dubroy): When password access requires some kind of authentication 150 // TODO(dubroy): When password access requires some kind of authentication
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 autofill::PasswordFormFillData* found_password) { 188 autofill::PasswordFormFillData* found_password) {
169 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field); 189 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(field);
170 if (iter == login_to_password_info_.end()) 190 if (iter == login_to_password_info_.end())
171 return false; 191 return false;
172 192
173 *found_password = iter->second; 193 *found_password = iter->second;
174 return true; 194 return true;
175 } 195 }
176 196
177 } // namespace password_manager 197 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698