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

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

Issue 2174303002: Move filtering logic in GetDataListSuggestions() to Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move implementation to HTMLInputElement Created 4 years, 4 months 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 return false; 103 return false;
104 104
105 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); 105 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE);
106 } 106 }
107 107
108 // Gets all the data list values (with corresponding label) for the given 108 // Gets all the data list values (with corresponding label) for the given
109 // element. 109 // element.
110 void GetDataListSuggestions(const WebInputElement& element, 110 void GetDataListSuggestions(const WebInputElement& element,
111 std::vector<base::string16>* values, 111 std::vector<base::string16>* values,
112 std::vector<base::string16>* labels) { 112 std::vector<base::string16>* labels) {
113 WebElementCollection options = element.dataListOptions(); 113 for (const auto& option : element.filteredDataListOptions()) {
114 if (options.isNull())
115 return;
116
117 // If the field accepts multiple email addresses, filter only on the last one.
118 base::string16 prefix = element.editingValue();
119 if (element.isMultiple() && element.isEmailField()) {
120 std::vector<base::string16> parts = base::SplitString(
121 prefix, base::ASCIIToUTF16(","), base::TRIM_WHITESPACE,
122 base::SPLIT_WANT_ALL);
123 if (!parts.empty())
124 base::TrimWhitespace(parts.back(), base::TRIM_LEADING, &prefix);
125 }
126
127 // Prefix filtering.
128 prefix = base::i18n::ToLower(prefix);
129 for (WebOptionElement option = options.firstItem().to<WebOptionElement>();
130 !option.isNull(); option = options.nextItem().to<WebOptionElement>()) {
131 if (!base::StartsWith(base::i18n::ToLower(base::string16(option.value())),
132 prefix, base::CompareCase::SENSITIVE) ||
133 !element.isValidValue(option.value()))
134 continue;
135
136 values->push_back(option.value()); 114 values->push_back(option.value());
137 if (option.value() != option.label()) 115 if (option.value() != option.label())
138 labels->push_back(option.label()); 116 labels->push_back(option.label());
139 else 117 else
140 labels->push_back(base::string16()); 118 labels->push_back(base::string16());
141 } 119 }
142 } 120 }
143 121
144 // Trim the vector before sending it to the browser process to ensure we 122 // Trim the vector before sending it to the browser process to ensure we
145 // don't send too much data through the IPC. 123 // don't send too much data through the IPC.
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 841 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
864 // No-op. Don't delete |this|. 842 // No-op. Don't delete |this|.
865 } 843 }
866 844
867 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 845 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
868 if (agent_) 846 if (agent_)
869 agent_->FocusChangeComplete(); 847 agent_->FocusChangeComplete();
870 } 848 }
871 849
872 } // namespace autofill 850 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698