OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/autofill/autofill_agent.h" | 5 #include "chrome/renderer/autofill/autofill_agent.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 (requires_caret_at_end && | 624 (requires_caret_at_end && |
625 (element.selectionStart() != element.selectionEnd() || | 625 (element.selectionStart() != element.selectionEnd() || |
626 element.selectionEnd() != static_cast<int>(value.length())))) { | 626 element.selectionEnd() != static_cast<int>(value.length())))) { |
627 // Any popup currently showing is obsolete. | 627 // Any popup currently showing is obsolete. |
628 HidePopups(); | 628 HidePopups(); |
629 return; | 629 return; |
630 } | 630 } |
631 | 631 |
632 element_ = element; | 632 element_ = element; |
633 | 633 |
634 // If autocomplete is disabled at the form level, then we might want to show | 634 // If autocomplete is disabled at the form level, then we might want to show a |
635 // a warning in place of suggestions. However, if autocomplete is disabled | 635 // warning in place of suggestions. However, if autocomplete is disabled |
636 // specifically for this field, we never want to show a warning. Otherwise, | 636 // specifically for this field, we never want to show a warning. Otherwise, |
637 // we might interfere with custom popups (e.g. search suggestions) used by | 637 // we might interfere with custom popups (e.g. search suggestions) used by the |
638 // the website. Also, if the field has no name, then we won't have values. | 638 // website. Note that we cannot use the WebKit method element.autoComplete() |
639 const WebFormElement form = element.form(); | 639 // as it does not allow us to distinguish the case where autocomplete is |
640 if ((!element.autoComplete() && (form.isNull() || form.autoComplete())) || | 640 // disabled for *both* the element and for the form. |
| 641 // Also, if the field has no name, then we won't have values. |
| 642 const string16 autocomplete_attribute = element.getAttribute("autocomplete"); |
| 643 if (LowerCaseEqualsASCII(autocomplete_attribute, "off") || |
641 element.nameForAutofill().isEmpty()) { | 644 element.nameForAutofill().isEmpty()) { |
642 CombineDataListEntriesAndShow(element, std::vector<string16>(), | 645 CombineDataListEntriesAndShow(element, std::vector<string16>(), |
643 std::vector<string16>(), | 646 std::vector<string16>(), |
644 std::vector<string16>(), | 647 std::vector<string16>(), |
645 std::vector<int>(), false); | 648 std::vector<int>(), false); |
646 return; | 649 return; |
647 } | 650 } |
648 | 651 |
649 QueryAutofillSuggestions(element, display_warning_if_disabled); | 652 QueryAutofillSuggestions(element, display_warning_if_disabled); |
650 } | 653 } |
651 | 654 |
652 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, | 655 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, |
653 bool display_warning_if_disabled) { | 656 bool display_warning_if_disabled) { |
654 static int query_counter = 0; | 657 static int query_counter = 0; |
655 autofill_query_id_ = query_counter++; | 658 autofill_query_id_ = query_counter++; |
656 display_warning_if_disabled_ = display_warning_if_disabled; | 659 display_warning_if_disabled_ = display_warning_if_disabled; |
657 | 660 |
| 661 // If autocomplete is disabled at the form level, we want to see if there |
| 662 // would have been any suggestions were it enabled, so that we can show a |
| 663 // warning. Otherwise, we want to ignore fields that disable autocomplete, so |
| 664 // that the suggestions list does not include suggestions for these form |
| 665 // fields -- see comment 1 on http://crbug.com/69914 |
| 666 // Rather than testing the form's autocomplete enabled state, we test the |
| 667 // element's state. The DCHECK below ensures that this is equivalent. |
| 668 DCHECK(element.autoComplete() || !element.form().autoComplete()); |
| 669 const RequirementsMask requirements = |
| 670 element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; |
| 671 |
658 FormData form; | 672 FormData form; |
659 FormFieldData field; | 673 FormFieldData field; |
660 if (!FindFormAndFieldForInputElement(element, &form, &field, | 674 if (!FindFormAndFieldForInputElement(element, &form, &field, requirements)) { |
661 REQUIRE_AUTOCOMPLETE)) { | |
662 // If we didn't find the cached form, at least let autocomplete have a shot | 675 // If we didn't find the cached form, at least let autocomplete have a shot |
663 // at providing suggestions. | 676 // at providing suggestions. |
664 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 677 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
665 } | 678 } |
666 | 679 |
667 gfx::Rect bounding_box(element_.boundsInViewportSpace()); | 680 gfx::Rect bounding_box(element_.boundsInViewportSpace()); |
668 | 681 |
669 // Find the datalist values and send them to the browser process. | 682 // Find the datalist values and send them to the browser process. |
670 std::vector<string16> data_list_values; | 683 std::vector<string16> data_list_values; |
671 std::vector<string16> data_list_labels; | 684 std::vector<string16> data_list_labels; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 node->setEditingValue(substring); | 738 node->setEditingValue(substring); |
726 } | 739 } |
727 | 740 |
728 void AutofillAgent::HidePopups() { | 741 void AutofillAgent::HidePopups() { |
729 WebKit::WebView* web_view = render_view()->GetWebView(); | 742 WebKit::WebView* web_view = render_view()->GetWebView(); |
730 if (web_view) | 743 if (web_view) |
731 web_view->hidePopups(); | 744 web_view->hidePopups(); |
732 } | 745 } |
733 | 746 |
734 } // namespace autofill | 747 } // namespace autofill |
OLD | NEW |