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

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

Issue 1447283006: [Autofill] Clicking datalist chooser arrow now shows Autofill/Autocomplete (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Initial Created 5 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
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if ((*strings)[i].length() > kMaxDataLength) 123 if ((*strings)[i].length() > kMaxDataLength)
124 (*strings)[i].resize(kMaxDataLength); 124 (*strings)[i].resize(kMaxDataLength);
125 } 125 }
126 } 126 }
127 127
128 } // namespace 128 } // namespace
129 129
130 AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions() 130 AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions()
131 : autofill_on_empty_values(false), 131 : autofill_on_empty_values(false),
132 requires_caret_at_end(false), 132 requires_caret_at_end(false),
133 datalist_only(false),
134 show_full_suggestion_list(false), 133 show_full_suggestion_list(false),
135 show_password_suggestions_only(false) { 134 show_password_suggestions_only(false) {
136 } 135 }
137 136
138 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame, 137 AutofillAgent::AutofillAgent(content::RenderFrame* render_frame,
139 PasswordAutofillAgent* password_autofill_agent, 138 PasswordAutofillAgent* password_autofill_agent,
140 PasswordGenerationAgent* password_generation_agent) 139 PasswordGenerationAgent* password_generation_agent)
141 : content::RenderFrameObserver(render_frame), 140 : content::RenderFrameObserver(render_frame),
142 form_cache_(*render_frame->GetWebFrame()), 141 form_cache_(*render_frame->GetWebFrame()),
143 password_autofill_agent_(password_autofill_agent), 142 password_autofill_agent_(password_autofill_agent),
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 ShowSuggestionsOptions options; 457 ShowSuggestionsOptions options;
459 options.autofill_on_empty_values = true; 458 options.autofill_on_empty_values = true;
460 options.requires_caret_at_end = true; 459 options.requires_caret_at_end = true;
461 ShowSuggestions(element, options); 460 ShowSuggestions(element, options);
462 } 461 }
463 } 462 }
464 463
465 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) { 464 void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
466 ShowSuggestionsOptions options; 465 ShowSuggestionsOptions options;
467 options.autofill_on_empty_values = true; 466 options.autofill_on_empty_values = true;
468 options.datalist_only = true;
469 ShowSuggestions(element, options); 467 ShowSuggestions(element, options);
470 } 468 }
471 469
472 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) { 470 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) {
473 if (!is_popup_possibly_visible_ || !element.focused()) 471 if (!is_popup_possibly_visible_ || !element.focused())
474 return; 472 return;
475 473
476 TextFieldDidChangeImpl(element); 474 TextFieldDidChangeImpl(element);
477 } 475 }
478 476
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 console_message); 643 console_message);
646 } 644 }
647 645
648 in_flight_request_form_.reset(); 646 in_flight_request_form_.reset();
649 } 647 }
650 648
651 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, 649 void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
652 const ShowSuggestionsOptions& options) { 650 const ShowSuggestionsOptions& options) {
653 if (!element.isEnabled() || element.isReadOnly()) 651 if (!element.isEnabled() || element.isReadOnly())
654 return; 652 return;
655 if (!options.datalist_only && !element.suggestedValue().isEmpty()) 653 if (!element.suggestedValue().isEmpty())
656 return; 654 return;
657 655
658 const WebInputElement* input_element = toWebInputElement(&element); 656 const WebInputElement* input_element = toWebInputElement(&element);
659 if (input_element) { 657 if (input_element) {
660 if (!input_element->isTextField()) 658 if (!input_element->isTextField())
661 return; 659 return;
662 if (!options.datalist_only && !input_element->suggestedValue().isEmpty()) 660 if (!input_element->suggestedValue().isEmpty())
663 return; 661 return;
664 } else { 662 } else {
665 DCHECK(form_util::IsTextAreaElement(element)); 663 DCHECK(form_util::IsTextAreaElement(element));
666 if (!element.toConst<WebFormControlElement>().suggestedValue().isEmpty()) 664 if (!element.toConst<WebFormControlElement>().suggestedValue().isEmpty())
667 return; 665 return;
668 } 666 }
669 667
670 // Don't attempt to autofill with values that are too large or if filling 668 // Don't attempt to autofill with values that are too large or if filling
671 // criteria are not met. 669 // criteria are not met.
672 WebString value = element.editingValue(); 670 WebString value = element.editingValue();
673 if (!options.datalist_only && 671 if (value.length() > kMaxDataLength ||
674 (value.length() > kMaxDataLength || 672 (!options.autofill_on_empty_values && value.isEmpty()) ||
675 (!options.autofill_on_empty_values && value.isEmpty()) || 673 (options.requires_caret_at_end &&
676 (options.requires_caret_at_end && 674 (element.selectionStart() != element.selectionEnd() ||
677 (element.selectionStart() != element.selectionEnd() || 675 element.selectionEnd() != static_cast<int>(value.length())))) {
678 element.selectionEnd() != static_cast<int>(value.length()))))) {
679 // Any popup currently showing is obsolete. 676 // Any popup currently showing is obsolete.
680 HidePopup(); 677 HidePopup();
681 return; 678 return;
682 } 679 }
683 680
684 element_ = element; 681 element_ = element;
685 if (form_util::IsAutofillableInputElement(input_element) && 682 if (form_util::IsAutofillableInputElement(input_element) &&
686 password_autofill_agent_->ShowSuggestions( 683 password_autofill_agent_->ShowSuggestions(
687 *input_element, options.show_full_suggestion_list, 684 *input_element, options.show_full_suggestion_list,
688 is_generation_popup_possibly_visible_)) { 685 is_generation_popup_possibly_visible_)) {
689 is_popup_possibly_visible_ = true; 686 is_popup_possibly_visible_ = true;
690 return; 687 return;
691 } 688 }
692 689
693 if (is_generation_popup_possibly_visible_) 690 if (is_generation_popup_possibly_visible_)
694 return; 691 return;
695 692
696 if (options.show_password_suggestions_only) 693 if (options.show_password_suggestions_only)
697 return; 694 return;
698 695
699 // Password field elements should only have suggestions shown by the password 696 // Password field elements should only have suggestions shown by the password
700 // autofill agent. 697 // autofill agent.
701 if (input_element && input_element->isPasswordField()) 698 if (input_element && input_element->isPasswordField())
702 return; 699 return;
703 700
704 QueryAutofillSuggestions(element, options.datalist_only); 701 QueryAutofillSuggestions(element);
705 } 702 }
706 703
707 void AutofillAgent::QueryAutofillSuggestions( 704 void AutofillAgent::QueryAutofillSuggestions(
708 const WebFormControlElement& element, 705 const WebFormControlElement& element) {
709 bool datalist_only) {
710 if (!element.document().frame()) 706 if (!element.document().frame())
711 return; 707 return;
712 708
713 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element)); 709 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element));
714 710
715 static int query_counter = 0; 711 static int query_counter = 0;
716 autofill_query_id_ = query_counter++; 712 autofill_query_id_ = query_counter++;
717 713
718 FormData form; 714 FormData form;
719 FormFieldData field; 715 FormFieldData field;
720 if (!form_util::FindFormAndFieldForFormControlElement(element, &form, 716 if (!form_util::FindFormAndFieldForFormControlElement(element, &form,
721 &field)) { 717 &field)) {
722 // If we didn't find the cached form, at least let autocomplete have a shot 718 // If we didn't find the cached form, at least let autocomplete have a shot
723 // at providing suggestions. 719 // at providing suggestions.
724 WebFormControlElementToFormField(element, form_util::EXTRACT_VALUE, &field); 720 WebFormControlElementToFormField(element, form_util::EXTRACT_VALUE, &field);
725 } 721 }
726 if (datalist_only)
727 field.should_autocomplete = false;
728 722
729 gfx::RectF bounding_box_scaled = form_util::GetScaledBoundingBox( 723 gfx::RectF bounding_box_scaled = form_util::GetScaledBoundingBox(
730 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), 724 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(),
731 &element_); 725 &element_);
732 726
733 std::vector<base::string16> data_list_values; 727 std::vector<base::string16> data_list_values;
734 std::vector<base::string16> data_list_labels; 728 std::vector<base::string16> data_list_labels;
735 const WebInputElement* input_element = toWebInputElement(&element); 729 const WebInputElement* input_element = toWebInputElement(&element);
736 if (input_element) { 730 if (input_element) {
737 // Find the datalist values and send them to the browser process. 731 // Find the datalist values and send them to the browser process.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 821
828 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 822 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
829 // No-op. Don't delete |this|. 823 // No-op. Don't delete |this|.
830 } 824 }
831 825
832 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 826 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
833 agent_->FocusChangeComplete(); 827 agent_->FocusChangeComplete();
834 } 828 }
835 829
836 } // namespace autofill 830 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698