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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 // Any popup currently showing is obsolete. | 593 // Any popup currently showing is obsolete. |
594 WebKit::WebView* web_view = render_view()->GetWebView(); | 594 WebKit::WebView* web_view = render_view()->GetWebView(); |
595 if (web_view) | 595 if (web_view) |
596 web_view->hidePopups(); | 596 web_view->hidePopups(); |
597 | 597 |
598 return; | 598 return; |
599 } | 599 } |
600 | 600 |
601 element_ = element; | 601 element_ = element; |
602 | 602 |
603 // If autocomplete is disabled at the form level, then we might want to show | 603 // If autocomplete is disabled at the form level, then we might want to show a |
604 // a warning in place of suggestions. However, if autocomplete is disabled | 604 // warning in place of suggestions. However, if autocomplete is disabled |
605 // specifically for this field, we never want to show a warning. Otherwise, | 605 // specifically for this field, we never want to show a warning. Otherwise, |
606 // we might interfere with custom popups (e.g. search suggestions) used by | 606 // we might interfere with custom popups (e.g. search suggestions) used by the |
607 // the website. Also, if the field has no name, then we won't have values. | 607 // website. Note that we cannot use the WebKit method element.autoComplete() |
608 const WebFormElement form = element.form(); | 608 // as it does not allow us to distinguish the case where autocomplete is |
609 if ((!element.autoComplete() && (form.isNull() || form.autoComplete())) || | 609 // disabled for *both* the element and for the form. |
610 // Also, if the field has no name, then we won't have values. | |
611 const string16 autocomplete_attribute = | |
612 StringToLowerASCII(string16(element.getAttribute("autocomplete"))); | |
Dan Beam
2012/11/06 02:22:17
I'm confused by these conversions - are you doing
Ilya Sherman
2012/11/06 03:45:08
The WebKit data is utf-16 encoded, but uses a WebK
Evan Stade
2012/11/06 04:16:27
LowerCaseEqualsASCII?
Ilya Sherman
2012/11/06 04:28:42
Ah, good call. Done.
| |
613 if (autocomplete_attribute == ASCIIToUTF16("off") || | |
610 element.nameForAutofill().isEmpty()) { | 614 element.nameForAutofill().isEmpty()) { |
611 CombineDataListEntriesAndShow(element, std::vector<string16>(), | 615 CombineDataListEntriesAndShow(element, std::vector<string16>(), |
612 std::vector<string16>(), | 616 std::vector<string16>(), |
613 std::vector<string16>(), | 617 std::vector<string16>(), |
614 std::vector<int>(), false); | 618 std::vector<int>(), false); |
615 return; | 619 return; |
616 } | 620 } |
617 | 621 |
618 QueryAutofillSuggestions(element, display_warning_if_disabled); | 622 QueryAutofillSuggestions(element, display_warning_if_disabled); |
619 } | 623 } |
620 | 624 |
621 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, | 625 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element, |
622 bool display_warning_if_disabled) { | 626 bool display_warning_if_disabled) { |
623 static int query_counter = 0; | 627 static int query_counter = 0; |
624 autofill_query_id_ = query_counter++; | 628 autofill_query_id_ = query_counter++; |
625 display_warning_if_disabled_ = display_warning_if_disabled; | 629 display_warning_if_disabled_ = display_warning_if_disabled; |
626 | 630 |
631 // If autocomplete is disabled at the form level, we want to see if there | |
632 // would have been any suggestions were it enabled, so that we can show a | |
633 // warning. Otherwise, we want to ignore fields that disable autocomplete, so | |
634 // that the suggestions list does not include suggestions for these form | |
635 // fields -- see comment 1 on http://crbug.com/69914 | |
636 // Rather than testing the form's autocomplete enabled state, we test the | |
637 // element's state. The DCHECK below ensures that this is equivalent. | |
638 DCHECK(element.autoComplete() || !element.form().autoComplete()); | |
639 const RequirementsMask requirements = | |
640 element.autoComplete() ? REQUIRE_AUTOCOMPLETE : REQUIRE_NONE; | |
641 | |
627 FormData form; | 642 FormData form; |
628 FormFieldData field; | 643 FormFieldData field; |
629 if (!FindFormAndFieldForInputElement(element, &form, &field, | 644 if (!FindFormAndFieldForInputElement(element, &form, &field, requirements)) { |
630 REQUIRE_AUTOCOMPLETE)) { | |
631 // If we didn't find the cached form, at least let autocomplete have a shot | 645 // If we didn't find the cached form, at least let autocomplete have a shot |
632 // at providing suggestions. | 646 // at providing suggestions. |
633 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); | 647 WebFormControlElementToFormField(element, EXTRACT_VALUE, &field); |
634 } | 648 } |
635 | 649 |
636 gfx::Rect bounding_box(element_.boundsInViewportSpace()); | 650 gfx::Rect bounding_box(element_.boundsInViewportSpace()); |
637 | 651 |
638 // Find the datalist values and send them to the browser process. | 652 // Find the datalist values and send them to the browser process. |
639 std::vector<string16> data_list_values; | 653 std::vector<string16> data_list_values; |
640 std::vector<string16> data_list_labels; | 654 std::vector<string16> data_list_labels; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 void AutofillAgent::SetNodeText(const string16& value, | 702 void AutofillAgent::SetNodeText(const string16& value, |
689 WebKit::WebInputElement* node) { | 703 WebKit::WebInputElement* node) { |
690 did_set_node_text_ = true; | 704 did_set_node_text_ = true; |
691 string16 substring = value; | 705 string16 substring = value; |
692 substring = substring.substr(0, node->maxLength()); | 706 substring = substring.substr(0, node->maxLength()); |
693 | 707 |
694 node->setEditingValue(substring); | 708 node->setEditingValue(substring); |
695 } | 709 } |
696 | 710 |
697 } // namespace autofill | 711 } // namespace autofill |
OLD | NEW |