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

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 695233002: Revert of Do not haul suggestions back to browser in AutofillHostMsg_ShowPasswordSuggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 const blink::WebFormElement& form) { 233 const blink::WebFormElement& form) {
234 logger->LogHTMLForm(message_id, 234 logger->LogHTMLForm(message_id,
235 form.name().utf8(), 235 form.name().utf8(),
236 GURL(form.action().utf8())); 236 GURL(form.action().utf8()));
237 } 237 }
238 238
239 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) { 239 bool FillDataContainsUsername(const PasswordFormFillData& fill_data) {
240 return !fill_data.basic_data.fields[0].name.empty(); 240 return !fill_data.basic_data.fields[0].name.empty();
241 } 241 }
242 242
243 // Sets |suggestions_present| to true if there are any suggestions to be derived 243 // This function attempts to fill |suggestions| and |realms| form |fill_data|
244 // from |fill_data|. Unless |show_all| is true, only considers suggestions with 244 // based on |current_username|. Returns true when |suggestions| gets filled
245 // usernames having |current_username| as a prefix. Returns true if a username 245 // from |fill_data.other_possible_usernames|, else returns false.
246 // from the |fill_data.other_possible_usernames| would be included in the 246 bool GetSuggestions(const PasswordFormFillData& fill_data,
247 // suggestions. 247 const base::string16& current_username,
248 bool GetSuggestionsStats(const PasswordFormFillData& fill_data, 248 std::vector<base::string16>* suggestions,
249 const base::string16& current_username, 249 std::vector<base::string16>* realms,
250 bool show_all, 250 bool show_all) {
251 bool* suggestions_present) { 251 bool other_possible_username_shown = false;
252 *suggestions_present = false; 252 if (show_all ||
253 StartsWith(
254 fill_data.basic_data.fields[0].value, current_username, false)) {
255 suggestions->push_back(fill_data.basic_data.fields[0].value);
256 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm));
257 }
253 258
254 for (const auto& usernames : fill_data.other_possible_usernames) { 259 for (PasswordFormFillData::LoginCollection::const_iterator iter =
255 for (size_t i = 0; i < usernames.second.size(); ++i) { 260 fill_data.additional_logins.begin();
256 if (show_all || 261 iter != fill_data.additional_logins.end();
257 StartsWith(usernames.second[i], current_username, false)) { 262 ++iter) {
258 *suggestions_present = true; 263 if (show_all || StartsWith(iter->first, current_username, false)) {
259 return true; 264 suggestions->push_back(iter->first);
265 realms->push_back(base::UTF8ToUTF16(iter->second.realm));
266 }
267 }
268
269 for (PasswordFormFillData::UsernamesCollection::const_iterator iter =
270 fill_data.other_possible_usernames.begin();
271 iter != fill_data.other_possible_usernames.end();
272 ++iter) {
273 for (size_t i = 0; i < iter->second.size(); ++i) {
274 if (show_all || StartsWith(iter->second[i], current_username, false)) {
275 other_possible_username_shown = true;
276 suggestions->push_back(iter->second[i]);
277 realms->push_back(base::UTF8ToUTF16(iter->first.realm));
260 } 278 }
261 } 279 }
262 } 280 }
263 281 return other_possible_username_shown;
264 if (show_all || StartsWith(fill_data.basic_data.fields[0].value,
265 current_username, false)) {
266 *suggestions_present = true;
267 return false;
268 }
269
270 for (const auto& login : fill_data.additional_logins) {
271 if (show_all || StartsWith(login.first, current_username, false)) {
272 *suggestions_present = true;
273 return false;
274 }
275 }
276
277 return false;
278 } 282 }
279 283
280 // This function attempts to fill |username_element| and |password_element| 284 // This function attempts to fill |username_element| and |password_element|
281 // with values from |fill_data|. The |password_element| will only have the 285 // with values from |fill_data|. The |password_element| will only have the
282 // |suggestedValue| set, and will be registered for copying that to the real 286 // |suggestedValue| set, and will be registered for copying that to the real
283 // value through |registration_callback|. The function returns true when 287 // value through |registration_callback|. The function returns true when
284 // selected username comes from |fill_data.other_possible_usernames|. 288 // selected username comes from |fill_data.other_possible_usernames|.
285 bool FillUserNameAndPassword( 289 bool FillUserNameAndPassword(
286 blink::WebInputElement* username_element, 290 blink::WebInputElement* username_element,
287 blink::WebInputElement* password_element, 291 blink::WebInputElement* password_element,
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 const blink::WebInputElement& user_input, 1101 const blink::WebInputElement& user_input,
1098 bool show_all) { 1102 bool show_all) {
1099 blink::WebFrame* frame = user_input.document().frame(); 1103 blink::WebFrame* frame = user_input.document().frame();
1100 if (!frame) 1104 if (!frame)
1101 return false; 1105 return false;
1102 1106
1103 blink::WebView* webview = frame->view(); 1107 blink::WebView* webview = frame->view();
1104 if (!webview) 1108 if (!webview)
1105 return false; 1109 return false;
1106 1110
1111 std::vector<base::string16> suggestions;
1112 std::vector<base::string16> realms;
1113 if (GetSuggestions(
1114 fill_data, user_input.value(), &suggestions, &realms, show_all)) {
1115 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
1116 }
1117
1118 DCHECK_EQ(suggestions.size(), realms.size());
1119
1107 FormData form; 1120 FormData form;
1108 FormFieldData field; 1121 FormFieldData field;
1109 FindFormAndFieldForFormControlElement( 1122 FindFormAndFieldForFormControlElement(
1110 user_input, &form, &field, REQUIRE_NONE); 1123 user_input, &form, &field, REQUIRE_NONE);
1111 1124
1112 blink::WebInputElement selected_element = user_input; 1125 blink::WebInputElement selected_element = user_input;
1113 gfx::Rect bounding_box(selected_element.boundsInViewportSpace()); 1126 gfx::Rect bounding_box(selected_element.boundsInViewportSpace());
1114 1127
1115 float scale = web_view_->pageScaleFactor(); 1128 float scale = web_view_->pageScaleFactor();
1116 gfx::RectF bounding_box_scaled(bounding_box.x() * scale, 1129 gfx::RectF bounding_box_scaled(bounding_box.x() * scale,
1117 bounding_box.y() * scale, 1130 bounding_box.y() * scale,
1118 bounding_box.width() * scale, 1131 bounding_box.width() * scale,
1119 bounding_box.height() * scale); 1132 bounding_box.height() * scale);
1120 Send(new AutofillHostMsg_ShowPasswordSuggestions( 1133 Send(new AutofillHostMsg_ShowPasswordSuggestions(
1121 routing_id(), field, user_input.value(), show_all, bounding_box_scaled)); 1134 routing_id(), field, bounding_box_scaled, suggestions, realms));
1122 1135 return !suggestions.empty();
1123 bool suggestions_present = false;
1124 if (GetSuggestionsStats(fill_data, user_input.value(), show_all,
1125 &suggestions_present)) {
1126 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
1127 }
1128 return suggestions_present;
1129 } 1136 }
1130 1137
1131 void PasswordAutofillAgent::PerformInlineAutocomplete( 1138 void PasswordAutofillAgent::PerformInlineAutocomplete(
1132 const blink::WebInputElement& username_input, 1139 const blink::WebInputElement& username_input,
1133 const blink::WebInputElement& password_input, 1140 const blink::WebInputElement& password_input,
1134 const PasswordFormFillData& fill_data) { 1141 const PasswordFormFillData& fill_data) {
1135 DCHECK(!fill_data.wait_for_username); 1142 DCHECK(!fill_data.wait_for_username);
1136 1143
1137 // We need non-const versions of the username and password inputs. 1144 // We need non-const versions of the username and password inputs.
1138 blink::WebInputElement username = username_input; 1145 blink::WebInputElement username = username_input;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form)); 1243 scoped_ptr<PasswordForm> password_form(CreatePasswordForm(form));
1237 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD && 1244 if (!password_form || (restriction == RESTRICTION_NON_EMPTY_PASSWORD &&
1238 password_form->password_value.empty() && 1245 password_form->password_value.empty() &&
1239 password_form->new_password_value.empty())) { 1246 password_form->new_password_value.empty())) {
1240 return; 1247 return;
1241 } 1248 }
1242 provisionally_saved_forms_[frame].reset(password_form.release()); 1249 provisionally_saved_forms_[frame].reset(password_form.release());
1243 } 1250 }
1244 1251
1245 } // namespace autofill 1252 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698