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

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

Issue 767353002: Support for password manager suggestions on password fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Rebase on ToT Created 6 years 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 "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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 if (!autofill::IsValidPasswordFormFillData(fill_data)) 103 if (!autofill::IsValidPasswordFormFillData(fill_data))
102 return; 104 return;
103 105
104 login_to_password_info_[key] = fill_data; 106 login_to_password_info_[key] = fill_data;
105 } 107 }
106 108
107 void PasswordAutofillManager::OnShowPasswordSuggestions( 109 void PasswordAutofillManager::OnShowPasswordSuggestions(
108 int key, 110 int key,
109 base::i18n::TextDirection text_direction, 111 base::i18n::TextDirection text_direction,
110 const base::string16& typed_username, 112 const base::string16& typed_username,
111 bool show_all, 113 int options,
112 const gfx::RectF& bounds) { 114 const gfx::RectF& bounds) {
113 std::vector<base::string16> suggestions; 115 std::vector<base::string16> suggestions;
114 std::vector<base::string16> realms; 116 std::vector<base::string16> realms;
115 LoginToPasswordInfoMap::const_iterator fill_data_it = 117 LoginToPasswordInfoMap::const_iterator fill_data_it =
116 login_to_password_info_.find(key); 118 login_to_password_info_.find(key);
117 if (fill_data_it == login_to_password_info_.end()) { 119 if (fill_data_it == login_to_password_info_.end()) {
118 // Probably a compromised renderer. 120 // Probably a compromised renderer.
119 NOTREACHED(); 121 NOTREACHED();
120 return; 122 return;
121 } 123 }
122 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms, 124 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms,
123 show_all); 125 options & autofill::ShowPasswordSuggestionsOptions::SHOW_ALL);
124 DCHECK_EQ(suggestions.size(), realms.size()); 126 DCHECK_EQ(suggestions.size(), realms.size());
125 127
126 form_data_key_ = key; 128 form_data_key_ = key;
127 129
128 if (suggestions.empty()) { 130 if (suggestions.empty()) {
129 autofill_client_->HideAutofillPopup(); 131 autofill_client_->HideAutofillPopup();
130 return; 132 return;
131 } 133 }
132 134
135 base::string16 password_field_suggestions_title;
136 if (options & autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD) {
Garrett Casto 2014/12/05 19:30:54 You should merge these two new if statements.
jww 2014/12/05 20:23:10 Done.
137 password_field_suggestions_title = l10n_util::GetStringUTF16(
138 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
139 }
133 std::vector<base::string16> empty(suggestions.size()); 140 std::vector<base::string16> empty(suggestions.size());
134 std::vector<int> password_ids(suggestions.size(), 141 std::vector<int> password_ids(suggestions.size(),
135 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); 142 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY);
143 if (!password_field_suggestions_title.empty()) {
144 suggestions.insert(suggestions.begin(), password_field_suggestions_title);
145 realms.insert(realms.begin(), base::string16());
146 empty.insert(empty.begin(), base::string16());
147 password_ids.insert(password_ids.begin(), autofill::POPUP_ITEM_ID_TITLE);
148 }
136 autofill_client_->ShowAutofillPopup(bounds, 149 autofill_client_->ShowAutofillPopup(bounds,
137 text_direction, 150 text_direction,
138 suggestions, 151 suggestions,
139 realms, 152 realms,
140 empty, 153 empty,
141 password_ids, 154 password_ids,
142 weak_ptr_factory_.GetWeakPtr()); 155 weak_ptr_factory_.GetWeakPtr());
143 } 156 }
144 157
145 void PasswordAutofillManager::Reset() { 158 void PasswordAutofillManager::Reset() {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 autofill::PasswordFormFillData* found_password) { 248 autofill::PasswordFormFillData* found_password) {
236 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); 249 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key);
237 if (iter == login_to_password_info_.end()) 250 if (iter == login_to_password_info_.end())
238 return false; 251 return false;
239 252
240 *found_password = iter->second; 253 *found_password = iter->second;
241 return true; 254 return true;
242 } 255 }
243 256
244 } // namespace password_manager 257 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698