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

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

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

Powered by Google App Engine
This is Rietveld 408576698