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/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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 display_warning = false; | 656 display_warning = false; |
657 } | 657 } |
658 | 658 |
659 QueryAutofillSuggestions(element, display_warning, options.datalist_only); | 659 QueryAutofillSuggestions(element, display_warning, options.datalist_only); |
660 } | 660 } |
661 | 661 |
662 void AutofillAgent::QueryAutofillSuggestions( | 662 void AutofillAgent::QueryAutofillSuggestions( |
663 const WebFormControlElement& element, | 663 const WebFormControlElement& element, |
664 bool display_warning_if_disabled, | 664 bool display_warning_if_disabled, |
665 bool datalist_only) { | 665 bool datalist_only) { |
666 if (!element.document().frame()) | 666 blink::WebDocument document = element.document(); |
667 if (!document.frame()) | |
667 return; | 668 return; |
668 | 669 |
669 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element)); | 670 DCHECK(toWebInputElement(&element) || IsTextAreaElement(element)); |
670 | 671 |
671 static int query_counter = 0; | 672 static int query_counter = 0; |
672 autofill_query_id_ = query_counter++; | 673 autofill_query_id_ = query_counter++; |
673 display_warning_if_disabled_ = display_warning_if_disabled; | 674 display_warning_if_disabled_ = display_warning_if_disabled; |
674 | 675 |
675 // If autocomplete is disabled at the form level, we want to see if there | 676 // If autocomplete is disabled at the form level, we want to see if there |
676 // would have been any suggestions were it enabled, so that we can show a | 677 // would have been any suggestions were it enabled, so that we can show a |
677 // warning. Otherwise, we want to ignore fields that disable autocomplete, so | 678 // warning. Otherwise, we want to ignore fields that disable autocomplete, so |
678 // that the suggestions list does not include suggestions for these form | 679 // that the suggestions list does not include suggestions for these form |
679 // fields -- see comment 1 on http://crbug.com/69914 | 680 // fields -- see comment 1 on http://crbug.com/69914 |
680 RequirementsMask requirements = | 681 RequirementsMask requirements = |
681 element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; | 682 element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; |
682 | 683 |
683 // If we're ignoring autocomplete="off", always extract everything. | 684 // If we're ignoring autocomplete="off", always extract everything. |
684 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 685 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
685 switches::kRespectAutocompleteOffForAutofill)) { | 686 switches::kRespectAutocompleteOffForAutofill)) { |
686 requirements = REQUIRE_NONE; | 687 requirements = REQUIRE_NONE; |
687 } | 688 } |
688 | 689 |
689 FormData form; | 690 FormData form; |
690 FormFieldData field; | 691 FormFieldData field; |
691 if (!FindFormAndFieldForFormControlElement(element, &form, &field, | 692 if (!FindFormAndFieldForFormControlElement(element, &form, &field, |
Evan Stade
2014/12/12 19:59:35
hmmm, why doesn't the unowned form just go in the
Lei Zhang
2014/12/12 22:06:23
FindFormAndFieldForFormControlElement() works on t
| |
692 requirements)) { | 693 requirements)) { |
693 // If we didn't find the cached form, at least let autocomplete have a shot | 694 // No associated form element, try the form for unowned form elements. |
Evan Stade
2014/12/12 19:59:35
nit: s/form for/synthetic form for/
Lei Zhang
2014/12/12 22:06:23
Done.
| |
694 // at providing suggestions. | 695 FormData unowned_form; |
695 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 696 FormFieldData unowned_field; |
697 std::vector<WebElement> fieldsets; | |
698 std::vector<WebFormControlElement> control_elements = | |
699 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); | |
700 const ExtractMask extract_mask = | |
Evan Stade
2014/12/12 19:59:35
nit: dislike this variable because it makes it see
Lei Zhang
2014/12/12 22:06:23
Done.
| |
701 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | |
702 if (UnownedFormElementsAndFieldSetsToFormData(fieldsets, control_elements, | |
703 &element, document.url(), | |
704 requirements, extract_mask, | |
705 &unowned_form, | |
706 &unowned_field)) { | |
707 form = unowned_form; | |
708 field = unowned_field; | |
709 } else { | |
710 // If we didn't find the cached form, at least let autocomplete have a | |
711 // shot at providing suggestions. | |
712 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | |
713 } | |
696 } | 714 } |
697 if (datalist_only) | 715 if (datalist_only) |
698 field.should_autocomplete = false; | 716 field.should_autocomplete = false; |
699 | 717 |
700 gfx::RectF bounding_box_scaled = GetScaledBoundingBox( | 718 gfx::RectF bounding_box_scaled = GetScaledBoundingBox( |
701 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), | 719 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), |
702 &element_); | 720 &element_); |
703 | 721 |
704 std::vector<base::string16> data_list_values; | 722 std::vector<base::string16> data_list_values; |
705 std::vector<base::string16> data_list_labels; | 723 std::vector<base::string16> data_list_labels; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 void AutofillAgent::LegacyAutofillAgent::Resized() { | 845 void AutofillAgent::LegacyAutofillAgent::Resized() { |
828 agent_->Resized(); | 846 agent_->Resized(); |
829 } | 847 } |
830 | 848 |
831 void AutofillAgent::LegacyAutofillAgent::FrameWillClose( | 849 void AutofillAgent::LegacyAutofillAgent::FrameWillClose( |
832 blink::WebFrame* frame) { | 850 blink::WebFrame* frame) { |
833 agent_->LegacyFrameWillClose(frame); | 851 agent_->LegacyFrameWillClose(frame); |
834 } | 852 } |
835 | 853 |
836 } // namespace autofill | 854 } // namespace autofill |
OLD | NEW |