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

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

Issue 166043006: Add password manager autocomplete suggestion when a username element in clicked. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed a comment and cleaned up a browser test Created 6 years, 9 months 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/autofill/content/renderer/autofill_agent.h" 5 #include "components/autofill/content/renderer/autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url)); 285 Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data, url));
286 } 286 }
287 287
288 void AutofillAgent::setIgnoreTextChanges(bool ignore) { 288 void AutofillAgent::setIgnoreTextChanges(bool ignore) {
289 ignore_text_changes_ = ignore; 289 ignore_text_changes_ = ignore;
290 } 290 }
291 291
292 void AutofillAgent::InputElementClicked(const WebInputElement& element, 292 void AutofillAgent::InputElementClicked(const WebInputElement& element,
293 bool was_focused, 293 bool was_focused,
294 bool is_focused) { 294 bool is_focused) {
295 if (was_focused) 295 bool show_full_suggestion_list = element.isAutofilled() || was_focused;
Garrett Casto 2014/03/06 01:23:46 I think that this was fine before hand with just e
jww 2014/03/07 02:06:06 I changed this because the experience, I felt, was
296 ShowSuggestions(element, true, false, true, false); 296 bool show_password_suggestions_only = !was_focused;
297 ShowSuggestions(element,
298 true,
299 false,
300 true,
301 false,
302 show_full_suggestion_list,
303 show_password_suggestions_only);
297 } 304 }
298 305
299 void AutofillAgent::InputElementLostFocus() { 306 void AutofillAgent::InputElementLostFocus() {
300 HidePopup(); 307 HidePopup();
301 } 308 }
302 309
303 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 310 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
304 password_autofill_agent_->TextFieldDidEndEditing(element); 311 password_autofill_agent_->TextFieldDidEndEditing(element);
305 has_shown_autofill_popup_for_current_edit_ = false; 312 has_shown_autofill_popup_for_current_edit_ = false;
306 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 313 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id()));
(...skipping 28 matching lines...) Expand all
335 if (password_generation_agent_ && 342 if (password_generation_agent_ &&
336 password_generation_agent_->TextDidChangeInTextField(element)) { 343 password_generation_agent_->TextDidChangeInTextField(element)) {
337 return; 344 return;
338 } 345 }
339 346
340 if (password_autofill_agent_->TextDidChangeInTextField(element)) { 347 if (password_autofill_agent_->TextDidChangeInTextField(element)) {
341 element_ = element; 348 element_ = element;
342 return; 349 return;
343 } 350 }
344 351
345 ShowSuggestions(element, false, true, false, false); 352 ShowSuggestions(element, false, true, false, false, false, false);
346 353
347 FormData form; 354 FormData form;
348 FormFieldData field; 355 FormFieldData field;
349 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) { 356 if (FindFormAndFieldForInputElement(element, &form, &field, REQUIRE_NONE)) {
350 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 357 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field,
351 base::TimeTicks::Now())); 358 base::TimeTicks::Now()));
352 } 359 }
353 } 360 }
354 361
355 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 362 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
356 const WebKeyboardEvent& event) { 363 const WebKeyboardEvent& event) {
357 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) { 364 if (password_autofill_agent_->TextFieldHandlingKeyDown(element, event)) {
358 element_ = element; 365 element_ = element;
359 return; 366 return;
360 } 367 }
361 368
362 if (event.windowsKeyCode == ui::VKEY_DOWN || 369 if (event.windowsKeyCode == ui::VKEY_DOWN ||
363 event.windowsKeyCode == ui::VKEY_UP) 370 event.windowsKeyCode == ui::VKEY_UP)
364 ShowSuggestions(element, true, true, true, false); 371 ShowSuggestions(element, true, true, true, false, false, false);
365 } 372 }
366 373
367 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { 374 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
368 ShowSuggestions(element, true, false, false, true); 375 ShowSuggestions(element, true, false, false, true, false, false);
369 } 376 }
370 377
371 void AutofillAgent::AcceptDataListSuggestion( 378 void AutofillAgent::AcceptDataListSuggestion(
372 const base::string16& suggested_value) { 379 const base::string16& suggested_value) {
373 base::string16 new_value = suggested_value; 380 base::string16 new_value = suggested_value;
374 // If this element takes multiple values then replace the last part with 381 // If this element takes multiple values then replace the last part with
375 // the suggestion. 382 // the suggestion.
376 if (element_.isMultiple() && 383 if (element_.isMultiple() &&
377 element_.formControlType() == WebString::fromUTF8("email")) { 384 element_.formControlType() == WebString::fromUTF8("email")) {
378 std::vector<base::string16> parts; 385 std::vector<base::string16> parts;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 in_flight_request_form_.reset(); 496 in_flight_request_form_.reset();
490 } 497 }
491 498
492 void AutofillAgent::OnPageShown() { 499 void AutofillAgent::OnPageShown() {
493 } 500 }
494 501
495 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 502 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
496 bool autofill_on_empty_values, 503 bool autofill_on_empty_values,
497 bool requires_caret_at_end, 504 bool requires_caret_at_end,
498 bool display_warning_if_disabled, 505 bool display_warning_if_disabled,
499 bool datalist_only) { 506 bool datalist_only,
507 bool show_full_suggestion_list,
508 bool show_password_suggestions_only) {
500 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() || 509 if (!element.isEnabled() || element.isReadOnly() || !element.isTextField() ||
501 element.isPasswordField()) 510 element.isPasswordField())
502 return; 511 return;
503 if (!datalist_only && !element.suggestedValue().isEmpty()) 512 if (!datalist_only && !element.suggestedValue().isEmpty())
504 return; 513 return;
505 514
506 // Don't attempt to autofill with values that are too large or if filling 515 // Don't attempt to autofill with values that are too large or if filling
507 // criteria are not met. 516 // criteria are not met.
508 WebString value = element.editingValue(); 517 WebString value = element.editingValue();
509 if (!datalist_only && 518 if (!datalist_only &&
510 (value.length() > kMaxDataLength || 519 (value.length() > kMaxDataLength ||
511 (!autofill_on_empty_values && value.isEmpty()) || 520 (!autofill_on_empty_values && value.isEmpty()) ||
512 (requires_caret_at_end && 521 (requires_caret_at_end &&
513 (element.selectionStart() != element.selectionEnd() || 522 (element.selectionStart() != element.selectionEnd() ||
514 element.selectionEnd() != static_cast<int>(value.length()))))) { 523 element.selectionEnd() != static_cast<int>(value.length()))))) {
515 // Any popup currently showing is obsolete. 524 // Any popup currently showing is obsolete.
516 HidePopup(); 525 HidePopup();
517 return; 526 return;
518 } 527 }
519 528
520 element_ = element; 529 element_ = element;
521 if (password_autofill_agent_->ShowSuggestions(element)) { 530 if (password_autofill_agent_->ShowSuggestions(element,
531 show_full_suggestion_list) ||
532 show_password_suggestions_only) {
522 is_popup_possibly_visible_ = true; 533 is_popup_possibly_visible_ = true;
523 return; 534 return;
524 } 535 }
525 536
526 // If autocomplete is disabled at the field level, ensure that the native 537 // If autocomplete is disabled at the field level, ensure that the native
527 // UI won't try to show a warning, since that may conflict with a custom 538 // UI won't try to show a warning, since that may conflict with a custom
528 // popup. Note that we cannot use the WebKit method element.autoComplete() 539 // popup. Note that we cannot use the WebKit method element.autoComplete()
529 // as it does not allow us to distinguish the case where autocomplete is 540 // as it does not allow us to distinguish the case where autocomplete is
530 // disabled for *both* the element and for the form. 541 // disabled for *both* the element and for the form.
531 const base::string16 autocomplete_attribute = 542 const base::string16 autocomplete_attribute =
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 // Only monitors dynamic forms created in the top frame. Dynamic forms 648 // Only monitors dynamic forms created in the top frame. Dynamic forms
638 // inserted in iframes are not captured yet. 649 // inserted in iframes are not captured yet.
639 if (!frame->parent()) { 650 if (!frame->parent()) {
640 password_autofill_agent_->OnDynamicFormsSeen(frame); 651 password_autofill_agent_->OnDynamicFormsSeen(frame);
641 return; 652 return;
642 } 653 }
643 } 654 }
644 } 655 }
645 656
646 } // namespace autofill 657 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698