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

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

Issue 492043003: Fill on account select in the password manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Re-added check that form contains a username field. Created 6 years, 1 month 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 "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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_driver.h" 13 #include "components/autofill/core/browser/autofill_driver.h"
14 #include "components/autofill/core/browser/popup_item_ids.h" 14 #include "components/autofill/core/browser/popup_item_ids.h"
15 #include "components/autofill/core/common/autofill_data_validation.h" 15 #include "components/autofill/core/common/autofill_data_validation.h"
16 #include "components/password_manager/core/browser/password_manager_client.h" 16 #include "components/password_manager/core/browser/password_manager_client.h"
17 #include "components/password_manager/core/browser/password_manager_driver.h" 17 #include "components/password_manager/core/browser/password_manager_driver.h"
18 #include "components/strings/grit/components_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
18 20
19 namespace password_manager { 21 namespace password_manager {
20 22
21 namespace { 23 namespace {
22 24
23 // This function attempts to fill |suggestions| and |realms| form |fill_data| 25 // This function attempts to fill |suggestions| and |realms| form |fill_data|
24 // based on |current_username|. Unless |show_all| is true, it only picks 26 // based on |current_username|. Unless |show_all| is true, it only picks
25 // suggestions where the username has |current_username| as a prefix. 27 // suggestions where the username has |current_username| as a prefix.
26 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, 28 void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
27 const base::string16& current_username, 29 const base::string16& current_username,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 100
99 void PasswordAutofillManager::OnAddPasswordFormMapping( 101 void PasswordAutofillManager::OnAddPasswordFormMapping(
100 int key, 102 int key,
101 const autofill::PasswordFormFillData& fill_data) { 103 const autofill::PasswordFormFillData& fill_data) {
102 if (!autofill::IsValidPasswordFormFillData(fill_data)) 104 if (!autofill::IsValidPasswordFormFillData(fill_data))
103 return; 105 return;
104 106
105 login_to_password_info_[key] = fill_data; 107 login_to_password_info_[key] = fill_data;
106 } 108 }
107 109
108 void PasswordAutofillManager::OnShowPasswordSuggestions( 110 void PasswordAutofillManager::ShowPasswordSuggestions(
Garrett Casto 2014/11/23 07:49:48 Nit: I would just keep this as one function for no
jww 2014/11/25 02:46:26 Done.
109 int key, 111 int key,
110 base::i18n::TextDirection text_direction, 112 base::i18n::TextDirection text_direction,
111 const base::string16& typed_username, 113 const base::string16& typed_username,
114 const base::string16& title,
112 bool show_all, 115 bool show_all,
113 const gfx::RectF& bounds) { 116 const gfx::RectF& bounds) {
114 std::vector<base::string16> suggestions; 117 std::vector<base::string16> suggestions;
115 std::vector<base::string16> realms; 118 std::vector<base::string16> realms;
116 LoginToPasswordInfoMap::const_iterator fill_data_it = 119 LoginToPasswordInfoMap::const_iterator fill_data_it =
117 login_to_password_info_.find(key); 120 login_to_password_info_.find(key);
118 if (fill_data_it == login_to_password_info_.end()) { 121 if (fill_data_it == login_to_password_info_.end()) {
119 // Probably a compromised renderer. 122 // Probably a compromised renderer.
120 NOTREACHED(); 123 NOTREACHED();
121 return; 124 return;
122 } 125 }
123 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms, 126 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms,
124 show_all); 127 show_all);
125 DCHECK_EQ(suggestions.size(), realms.size()); 128 DCHECK_EQ(suggestions.size(), realms.size());
126 129
127 form_data_key_ = key; 130 form_data_key_ = key;
128 131
129 if (suggestions.empty()) { 132 if (suggestions.empty()) {
130 autofill_client_->HideAutofillPopup(); 133 autofill_client_->HideAutofillPopup();
131 return; 134 return;
132 } 135 }
133 136
134 std::vector<base::string16> empty(suggestions.size()); 137 std::vector<base::string16> empty(suggestions.size());
135 std::vector<int> password_ids(suggestions.size(), 138 std::vector<int> password_ids(suggestions.size(),
136 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); 139 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY);
140 if (!title.empty()) {
141 suggestions.insert(suggestions.begin(), title);
142 realms.insert(realms.begin(), base::string16());
143 empty.insert(empty.begin(), base::string16());
144 password_ids.insert(password_ids.begin(), autofill::POPUP_ITEM_ID_TITLE);
145 }
137 autofill_client_->ShowAutofillPopup(bounds, 146 autofill_client_->ShowAutofillPopup(bounds,
138 text_direction, 147 text_direction,
139 suggestions, 148 suggestions,
140 realms, 149 realms,
141 empty, 150 empty,
142 password_ids, 151 password_ids,
143 weak_ptr_factory_.GetWeakPtr()); 152 weak_ptr_factory_.GetWeakPtr());
144 } 153 }
145 154
155 void PasswordAutofillManager::OnShowPasswordSuggestions(
156 int key,
157 base::i18n::TextDirection text_direction,
158 const base::string16& typed_username,
159 int options,
160 const gfx::RectF& bounds) {
161 bool show_all =
162 (options & autofill::ShowPasswordSuggestionsOptions::SHOW_ALL);
163 bool is_password_field =
164 (options & autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD);
165 base::string16 title;
166 if (is_password_field) {
167 title = l10n_util::GetStringUTF16(
168 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
169 }
170 ShowPasswordSuggestions(key, text_direction, typed_username, title, show_all,
171 bounds);
172 }
173
146 void PasswordAutofillManager::Reset() { 174 void PasswordAutofillManager::Reset() {
147 login_to_password_info_.clear(); 175 login_to_password_info_.clear();
148 } 176 }
149 177
150 bool PasswordAutofillManager::FillSuggestionForTest( 178 bool PasswordAutofillManager::FillSuggestionForTest(
151 int key, 179 int key,
152 const base::string16& username) { 180 const base::string16& username) {
153 return FillSuggestion(key, username); 181 return FillSuggestion(key, username);
154 } 182 }
155 183
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 autofill::PasswordFormFillData* found_password) { 265 autofill::PasswordFormFillData* found_password) {
238 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); 266 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key);
239 if (iter == login_to_password_info_.end()) 267 if (iter == login_to_password_info_.end())
240 return false; 268 return false;
241 269
242 *found_password = iter->second; 270 *found_password = iter->second;
243 return true; 271 return true;
244 } 272 }
245 273
246 } // namespace password_manager 274 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698