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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 65 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
66 const base::string16& current_username, | 66 const base::string16& current_username, |
67 std::vector<autofill::Suggestion>* suggestions, | 67 std::vector<autofill::Suggestion>* suggestions, |
68 bool show_all) { | 68 bool show_all) { |
69 if (show_all || base::StartsWith(fill_data.username_field.value, | 69 if (show_all || base::StartsWith(fill_data.username_field.value, |
70 current_username, false)) { | 70 current_username, false)) { |
71 autofill::Suggestion suggestion( | 71 autofill::Suggestion suggestion( |
72 ReplaceEmptyUsername(fill_data.username_field.value)); | 72 ReplaceEmptyUsername(fill_data.username_field.value)); |
73 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); | 73 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); |
74 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 74 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 75 suggestion.match_start = current_username.size(); |
75 suggestions->push_back(suggestion); | 76 suggestions->push_back(suggestion); |
76 } | 77 } |
77 | 78 |
78 for (const auto& login : fill_data.additional_logins) { | 79 for (const auto& login : fill_data.additional_logins) { |
79 if (show_all || base::StartsWith(login.first, current_username, false)) { | 80 if (show_all || base::StartsWith(login.first, current_username, false)) { |
80 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); | 81 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); |
81 suggestion.label = GetHumanReadableRealm(login.second.realm); | 82 suggestion.label = GetHumanReadableRealm(login.second.realm); |
82 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 83 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 84 suggestion.match_start = current_username.size(); |
83 suggestions->push_back(suggestion); | 85 suggestions->push_back(suggestion); |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 for (const auto& usernames : fill_data.other_possible_usernames) { | 89 for (const auto& usernames : fill_data.other_possible_usernames) { |
88 for (size_t i = 0; i < usernames.second.size(); ++i) { | 90 for (size_t i = 0; i < usernames.second.size(); ++i) { |
89 if (show_all || | 91 if (show_all || |
90 base::StartsWith(usernames.second[i], current_username, false)) { | 92 base::StartsWith(usernames.second[i], current_username, false)) { |
91 autofill::Suggestion suggestion( | 93 autofill::Suggestion suggestion( |
92 ReplaceEmptyUsername(usernames.second[i])); | 94 ReplaceEmptyUsername(usernames.second[i])); |
93 suggestion.label = GetHumanReadableRealm(usernames.first.realm); | 95 suggestion.label = GetHumanReadableRealm(usernames.first.realm); |
94 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 96 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 97 suggestion.match_start = current_username.size(); |
95 suggestions->push_back(suggestion); | 98 suggestions->push_back(suggestion); |
96 } | 99 } |
97 } | 100 } |
98 } | 101 } |
99 } | 102 } |
100 | 103 |
101 } // namespace | 104 } // namespace |
102 | 105 |
103 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
104 // PasswordAutofillManager, public: | 107 // PasswordAutofillManager, public: |
(...skipping 19 matching lines...) Expand all Loading... |
124 bool is_android_credential = FacetURI::FromPotentiallyInvalidSpec( | 127 bool is_android_credential = FacetURI::FromPotentiallyInvalidSpec( |
125 password_and_realm.realm).IsValidAndroidFacetURI(); | 128 password_and_realm.realm).IsValidAndroidFacetURI(); |
126 metrics_util::LogFilledCredentialIsFromAndroidApp(is_android_credential); | 129 metrics_util::LogFilledCredentialIsFromAndroidApp(is_android_credential); |
127 password_manager_driver_->FillSuggestion( | 130 password_manager_driver_->FillSuggestion( |
128 username, password_and_realm.password); | 131 username, password_and_realm.password); |
129 return true; | 132 return true; |
130 } | 133 } |
131 return false; | 134 return false; |
132 } | 135 } |
133 | 136 |
134 bool PasswordAutofillManager::PreviewSuggestion( | 137 bool PasswordAutofillManager::PreviewSuggestion(int key, |
135 int key, | 138 const base::string16& username, |
136 const base::string16& username) { | 139 size_t match_start) { |
137 autofill::PasswordFormFillData fill_data; | 140 autofill::PasswordFormFillData fill_data; |
138 autofill::PasswordAndRealm password_and_realm; | 141 autofill::PasswordAndRealm password_and_realm; |
139 if (FindLoginInfo(key, &fill_data) && | 142 if (FindLoginInfo(key, &fill_data) && |
140 GetPasswordAndRealmForUsername( | 143 GetPasswordAndRealmForUsername( |
141 username, fill_data, &password_and_realm)) { | 144 username, fill_data, &password_and_realm)) { |
142 password_manager_driver_->PreviewSuggestion( | 145 password_manager_driver_->PreviewSuggestion( |
143 username, password_and_realm.password); | 146 username, password_and_realm.password, match_start); |
144 return true; | 147 return true; |
145 } | 148 } |
146 return false; | 149 return false; |
147 } | 150 } |
148 | 151 |
149 void PasswordAutofillManager::OnAddPasswordFormMapping( | 152 void PasswordAutofillManager::OnAddPasswordFormMapping( |
150 int key, | 153 int key, |
151 const autofill::PasswordFormFillData& fill_data) { | 154 const autofill::PasswordFormFillData& fill_data) { |
152 if (!autofill::IsValidPasswordFormFillData(fill_data)) | 155 if (!autofill::IsValidPasswordFormFillData(fill_data)) |
153 return; | 156 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 199 } |
197 | 200 |
198 bool PasswordAutofillManager::FillSuggestionForTest( | 201 bool PasswordAutofillManager::FillSuggestionForTest( |
199 int key, | 202 int key, |
200 const base::string16& username) { | 203 const base::string16& username) { |
201 return FillSuggestion(key, username); | 204 return FillSuggestion(key, username); |
202 } | 205 } |
203 | 206 |
204 bool PasswordAutofillManager::PreviewSuggestionForTest( | 207 bool PasswordAutofillManager::PreviewSuggestionForTest( |
205 int key, | 208 int key, |
206 const base::string16& username) { | 209 const base::string16& username, |
207 return PreviewSuggestion(key, username); | 210 size_t match_start) { |
| 211 return PreviewSuggestion(key, username, match_start); |
208 } | 212 } |
209 | 213 |
210 void PasswordAutofillManager::OnPopupShown() { | 214 void PasswordAutofillManager::OnPopupShown() { |
211 } | 215 } |
212 | 216 |
213 void PasswordAutofillManager::OnPopupHidden() { | 217 void PasswordAutofillManager::OnPopupHidden() { |
214 } | 218 } |
215 | 219 |
216 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value, | 220 void PasswordAutofillManager::DidSelectSuggestion(const base::string16& value, |
217 int identifier) { | 221 int identifier, |
| 222 size_t match_start) { |
218 ClearPreviewedForm(); | 223 ClearPreviewedForm(); |
219 bool success = PreviewSuggestion(form_data_key_, value); | 224 bool success = PreviewSuggestion(form_data_key_, value, match_start); |
220 DCHECK(success); | 225 DCHECK(success); |
221 } | 226 } |
222 | 227 |
223 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, | 228 void PasswordAutofillManager::DidAcceptSuggestion(const base::string16& value, |
224 int identifier, | 229 int identifier, |
225 int position) { | 230 int position) { |
226 bool success = FillSuggestion(form_data_key_, value); | 231 bool success = FillSuggestion(form_data_key_, value); |
227 DCHECK(success); | 232 DCHECK(success); |
228 autofill_client_->HideAutofillPopup(); | 233 autofill_client_->HideAutofillPopup(); |
229 } | 234 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 autofill::PasswordFormFillData* found_password) { | 303 autofill::PasswordFormFillData* found_password) { |
299 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 304 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
300 if (iter == login_to_password_info_.end()) | 305 if (iter == login_to_password_info_.end()) |
301 return false; | 306 return false; |
302 | 307 |
303 *found_password = iter->second; | 308 *found_password = iter->second; |
304 return true; | 309 return true; |
305 } | 310 } |
306 | 311 |
307 } // namespace password_manager | 312 } // namespace password_manager |
OLD | NEW |