| 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/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 using blink::WebUserGestureIndicator; | 71 using blink::WebUserGestureIndicator; |
| 72 using blink::WebVector; | 72 using blink::WebVector; |
| 73 | 73 |
| 74 namespace autofill { | 74 namespace autofill { |
| 75 | 75 |
| 76 namespace { | 76 namespace { |
| 77 | 77 |
| 78 // Gets all the data list values (with corresponding label) for the given | 78 // Gets all the data list values (with corresponding label) for the given |
| 79 // element. | 79 // element. |
| 80 void GetDataListSuggestions(const WebInputElement& element, | 80 void GetDataListSuggestions(const WebInputElement& element, |
| 81 bool ignore_current_value, | |
| 82 std::vector<base::string16>* values, | 81 std::vector<base::string16>* values, |
| 83 std::vector<base::string16>* labels) { | 82 std::vector<base::string16>* labels) { |
| 84 WebElementCollection options = element.dataListOptions(); | 83 WebElementCollection options = element.dataListOptions(); |
| 85 if (options.isNull()) | 84 if (options.isNull()) |
| 86 return; | 85 return; |
| 87 | 86 |
| 88 base::string16 prefix; | 87 // If the field accepts multiple email addresses, filter only on the last one. |
| 89 if (!ignore_current_value) { | 88 base::string16 prefix = element.editingValue(); |
| 90 prefix = element.editingValue(); | 89 if (element.isMultiple() && element.isEmailField()) { |
| 91 if (element.isMultiple() && element.isEmailField()) { | 90 std::vector<base::string16> parts = base::SplitString( |
| 92 const base::char16 comma[2] = { ',', 0 }; | 91 prefix, base::ASCIIToUTF16(","), base::TRIM_WHITESPACE, |
| 93 std::vector<base::string16> parts = base::SplitString( | 92 base::SPLIT_WANT_ALL); |
| 94 prefix, comma, base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 93 if (!parts.empty()) { |
| 95 if (parts.size() > 0) { | 94 base::TrimWhitespace(parts[parts.size() - 1], base::TRIM_LEADING, |
| 96 base::TrimWhitespace(parts[parts.size() - 1], base::TRIM_LEADING, | 95 &prefix); |
| 97 &prefix); | |
| 98 } | |
| 99 } | 96 } |
| 100 } | 97 } |
| 98 |
| 99 // Prefix filtering. |
| 101 prefix = base::i18n::ToLower(prefix); | 100 prefix = base::i18n::ToLower(prefix); |
| 102 for (WebOptionElement option = options.firstItem().to<WebOptionElement>(); | 101 for (WebOptionElement option = options.firstItem().to<WebOptionElement>(); |
| 103 !option.isNull(); option = options.nextItem().to<WebOptionElement>()) { | 102 !option.isNull(); option = options.nextItem().to<WebOptionElement>()) { |
| 104 if (!base::StartsWith(base::i18n::ToLower(base::string16(option.value())), | 103 if (!base::StartsWith(base::i18n::ToLower(base::string16(option.value())), |
| 105 prefix, base::CompareCase::SENSITIVE) || | 104 prefix, base::CompareCase::SENSITIVE) || |
| 106 !element.isValidValue(option.value())) | 105 !element.isValidValue(option.value())) |
| 107 continue; | 106 continue; |
| 108 | 107 |
| 109 values->push_back(option.value()); | 108 values->push_back(option.value()); |
| 110 if (option.value() != option.label()) | 109 if (option.value() != option.label()) |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 gfx::RectF bounding_box_scaled = form_util::GetScaledBoundingBox( | 731 gfx::RectF bounding_box_scaled = form_util::GetScaledBoundingBox( |
| 733 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), | 732 render_frame()->GetRenderView()->GetWebView()->pageScaleFactor(), |
| 734 &element_); | 733 &element_); |
| 735 | 734 |
| 736 std::vector<base::string16> data_list_values; | 735 std::vector<base::string16> data_list_values; |
| 737 std::vector<base::string16> data_list_labels; | 736 std::vector<base::string16> data_list_labels; |
| 738 const WebInputElement* input_element = toWebInputElement(&element); | 737 const WebInputElement* input_element = toWebInputElement(&element); |
| 739 if (input_element) { | 738 if (input_element) { |
| 740 // Find the datalist values and send them to the browser process. | 739 // Find the datalist values and send them to the browser process. |
| 741 GetDataListSuggestions(*input_element, | 740 GetDataListSuggestions(*input_element, |
| 742 datalist_only, | |
| 743 &data_list_values, | 741 &data_list_values, |
| 744 &data_list_labels); | 742 &data_list_labels); |
| 745 TrimStringVectorForIPC(&data_list_values); | 743 TrimStringVectorForIPC(&data_list_values); |
| 746 TrimStringVectorForIPC(&data_list_labels); | 744 TrimStringVectorForIPC(&data_list_labels); |
| 747 } | 745 } |
| 748 | 746 |
| 749 is_popup_possibly_visible_ = true; | 747 is_popup_possibly_visible_ = true; |
| 750 Send(new AutofillHostMsg_SetDataList(routing_id(), | 748 Send(new AutofillHostMsg_SetDataList(routing_id(), |
| 751 data_list_values, | 749 data_list_values, |
| 752 data_list_labels)); | 750 data_list_labels)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 829 |
| 832 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 830 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 833 // No-op. Don't delete |this|. | 831 // No-op. Don't delete |this|. |
| 834 } | 832 } |
| 835 | 833 |
| 836 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | 834 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 837 agent_->FocusChangeComplete(); | 835 agent_->FocusChangeComplete(); |
| 838 } | 836 } |
| 839 | 837 |
| 840 } // namespace autofill | 838 } // namespace autofill |
| OLD | NEW |