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

Side by Side Diff: components/autofill/core/common/form_field_data.cc

Issue 1842693003: [Autofill] Fill fields where the value equals the placeholder attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 8 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/core/common/form_field_data.h" 5 #include "components/autofill/core/common/form_field_data.h"
6 6
7 #include "base/pickle.h" 7 #include "base/pickle.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 10
11 namespace autofill { 11 namespace autofill {
12 12
13 namespace { 13 namespace {
14 14
15 // Increment this anytime pickle format is modified as well as provide 15 // Increment this anytime pickle format is modified as well as provide
16 // deserialization routine from previous kPickleVersion format. 16 // deserialization routine from previous kPickleVersion format.
17 const int kPickleVersion = 2; 17 const int kPickleVersion = 3;
18 18
19 void AddVectorToPickle(std::vector<base::string16> strings, 19 void AddVectorToPickle(std::vector<base::string16> strings,
20 base::Pickle* pickle) { 20 base::Pickle* pickle) {
21 pickle->WriteInt(static_cast<int>(strings.size())); 21 pickle->WriteInt(static_cast<int>(strings.size()));
22 for (size_t i = 0; i < strings.size(); ++i) { 22 for (size_t i = 0; i < strings.size(); ++i) {
23 pickle->WriteString16(strings[i]); 23 pickle->WriteString16(strings[i]);
24 } 24 }
25 } 25 }
26 26
27 bool ReadStringVector(base::PickleIterator* iter, 27 bool ReadStringVector(base::PickleIterator* iter,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 return ReadAsInt(iter, &field_data->text_direction) && 70 return ReadAsInt(iter, &field_data->text_direction) &&
71 ReadStringVector(iter, &field_data->option_values) && 71 ReadStringVector(iter, &field_data->option_values) &&
72 ReadStringVector(iter, &field_data->option_contents); 72 ReadStringVector(iter, &field_data->option_contents);
73 } 73 }
74 74
75 bool DeserializeVersion2Specific(base::PickleIterator* iter, 75 bool DeserializeVersion2Specific(base::PickleIterator* iter,
76 FormFieldData* field_data) { 76 FormFieldData* field_data) {
77 return ReadAsInt(iter, &field_data->role); 77 return ReadAsInt(iter, &field_data->role);
78 } 78 }
79 79
80 bool DeserializeVersion3Specific(base::PickleIterator* iter,
81 FormFieldData* field_data) {
82 return iter->ReadString16(&field_data->placeholder);
83 }
84
80 } // namespace 85 } // namespace
81 86
82 FormFieldData::FormFieldData() 87 FormFieldData::FormFieldData()
83 : max_length(0), 88 : max_length(0),
84 is_autofilled(false), 89 is_autofilled(false),
85 is_checked(false), 90 is_checked(false),
86 is_checkable(false), 91 is_checkable(false),
87 is_focusable(false), 92 is_focusable(false),
88 should_autocomplete(true), 93 should_autocomplete(true),
89 role(ROLE_ATTRIBUTE_OTHER), 94 role(ROLE_ATTRIBUTE_OTHER),
90 text_direction(base::i18n::UNKNOWN_DIRECTION) { 95 text_direction(base::i18n::UNKNOWN_DIRECTION) {
91 } 96 }
92 97
93 FormFieldData::FormFieldData(const FormFieldData& other) = default; 98 FormFieldData::FormFieldData(const FormFieldData& other) = default;
94 99
95 FormFieldData::~FormFieldData() { 100 FormFieldData::~FormFieldData() {
96 } 101 }
97 102
98 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { 103 bool FormFieldData::SameFieldAs(const FormFieldData& field) const {
99 // A FormFieldData stores a value, but the value is not part of the identity 104 // A FormFieldData stores a value, but the value is not part of the identity
100 // of the field, so we don't want to compare the values. 105 // of the field, so we don't want to compare the values.
101 return label == field.label && name == field.name && 106 return label == field.label && name == field.name &&
102 form_control_type == field.form_control_type && 107 form_control_type == field.form_control_type &&
103 autocomplete_attribute == field.autocomplete_attribute && 108 autocomplete_attribute == field.autocomplete_attribute &&
104 max_length == field.max_length && 109 placeholder == field.placeholder && max_length == field.max_length &&
105 // is_checked and is_autofilled counts as "value" since these change 110 // is_checked and is_autofilled counts as "value" since these change
106 // when we fill things in. 111 // when we fill things in.
107 is_checkable == field.is_checkable && 112 is_checkable == field.is_checkable &&
108 is_focusable == field.is_focusable && 113 is_focusable == field.is_focusable &&
109 should_autocomplete == field.should_autocomplete && 114 should_autocomplete == field.should_autocomplete &&
110 role == field.role && text_direction == field.text_direction; 115 role == field.role && text_direction == field.text_direction;
111 // The option values/contents which are the list of items in the list 116 // The option values/contents which are the list of items in the list
112 // of a drop-down are currently not considered part of the identity of 117 // of a drop-down are currently not considered part of the identity of
113 // a form element. This is debatable, since one might base heuristics 118 // a form element. This is debatable, since one might base heuristics
114 // on the types of elements that are available. Alternatively, one 119 // on the types of elements that are available. Alternatively, one
115 // could imagine some forms that dynamically change the element 120 // could imagine some forms that dynamically change the element
116 // contents (say, insert years starting from the current year) that 121 // contents (say, insert years starting from the current year) that
117 // should not be considered changes in the structure of the form. 122 // should not be considered changes in the structure of the form.
118 } 123 }
119 124
120 bool FormFieldData::operator<(const FormFieldData& field) const { 125 bool FormFieldData::operator<(const FormFieldData& field) const {
121 // This does not use std::tie() as that generates more implicit variables 126 // This does not use std::tie() as that generates more implicit variables
122 // than the max-vartrack-size for var-tracking-assignments when compiling 127 // than the max-vartrack-size for var-tracking-assignments when compiling
123 // for Android, producing build warnings. (See https://crbug.com/555171 for 128 // for Android, producing build warnings. (See https://crbug.com/555171 for
124 // context.) 129 // context.)
125 130
126 // Like operator==, this ignores the value. 131 // Like operator==, this ignores the value.
127 if (label < field.label) return true; 132 if (label < field.label) return true;
128 if (label > field.label) return false; 133 if (label > field.label) return false;
129 if (name < field.name) return true; 134 if (name < field.name) return true;
130 if (name > field.name) return false; 135 if (name > field.name) return false;
131 if (form_control_type < field.form_control_type) return true; 136 if (form_control_type < field.form_control_type) return true;
132 if (form_control_type > field.form_control_type) return false; 137 if (form_control_type > field.form_control_type) return false;
133 if (autocomplete_attribute < field.autocomplete_attribute) return true; 138 if (autocomplete_attribute < field.autocomplete_attribute) return true;
134 if (autocomplete_attribute > field.autocomplete_attribute) return false; 139 if (autocomplete_attribute > field.autocomplete_attribute) return false;
140 if (placeholder < field.placeholder) return true;
141 if (placeholder > field.placeholder) return false;
135 if (max_length < field.max_length) return true; 142 if (max_length < field.max_length) return true;
136 if (max_length > field.max_length) return false; 143 if (max_length > field.max_length) return false;
137 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. 144 // Skip |is_checked| and |is_autofilled| as in SameFieldAs.
138 if (is_checkable < field.is_checkable) return true; 145 if (is_checkable < field.is_checkable) return true;
139 if (is_checkable > field.is_checkable) return false; 146 if (is_checkable > field.is_checkable) return false;
140 if (is_focusable < field.is_focusable) return true; 147 if (is_focusable < field.is_focusable) return true;
141 if (is_focusable > field.is_focusable) return false; 148 if (is_focusable > field.is_focusable) return false;
142 if (should_autocomplete < field.should_autocomplete) return true; 149 if (should_autocomplete < field.should_autocomplete) return true;
143 if (should_autocomplete > field.should_autocomplete) return false; 150 if (should_autocomplete > field.should_autocomplete) return false;
144 if (role < field.role) return true; 151 if (role < field.role) return true;
(...skipping 15 matching lines...) Expand all
160 pickle->WriteUInt64(field_data.max_length); 167 pickle->WriteUInt64(field_data.max_length);
161 pickle->WriteBool(field_data.is_autofilled); 168 pickle->WriteBool(field_data.is_autofilled);
162 pickle->WriteBool(field_data.is_checked); 169 pickle->WriteBool(field_data.is_checked);
163 pickle->WriteBool(field_data.is_checkable); 170 pickle->WriteBool(field_data.is_checkable);
164 pickle->WriteBool(field_data.is_focusable); 171 pickle->WriteBool(field_data.is_focusable);
165 pickle->WriteBool(field_data.should_autocomplete); 172 pickle->WriteBool(field_data.should_autocomplete);
166 pickle->WriteInt(field_data.role); 173 pickle->WriteInt(field_data.role);
167 pickle->WriteInt(field_data.text_direction); 174 pickle->WriteInt(field_data.text_direction);
168 AddVectorToPickle(field_data.option_values, pickle); 175 AddVectorToPickle(field_data.option_values, pickle);
169 AddVectorToPickle(field_data.option_contents, pickle); 176 AddVectorToPickle(field_data.option_contents, pickle);
177 pickle->WriteString16(field_data.placeholder);
170 } 178 }
171 179
172 bool DeserializeFormFieldData(base::PickleIterator* iter, 180 bool DeserializeFormFieldData(base::PickleIterator* iter,
173 FormFieldData* field_data) { 181 FormFieldData* field_data) {
174 int version; 182 int version;
175 FormFieldData temp_form_field_data; 183 FormFieldData temp_form_field_data;
176 if (!iter->ReadInt(&version)) { 184 if (!iter->ReadInt(&version)) {
177 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; 185 LOG(ERROR) << "Bad pickle of FormFieldData, no version present";
178 return false; 186 return false;
179 } 187 }
180 188
181 switch (version) { 189 switch (version) {
182 case 1: { 190 case 1: {
183 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 191 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
184 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 192 !DeserializeCommonSection2(iter, &temp_form_field_data)) {
185 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 193 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
186 return false; 194 return false;
187 } 195 }
188 break; 196 break;
189 } 197 }
190 case 2: { 198 case 2: {
191 if (!DeserializeCommonSection1(iter, &temp_form_field_data) || 199 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
192 !DeserializeVersion2Specific(iter, &temp_form_field_data) || 200 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
193 !DeserializeCommonSection2(iter, &temp_form_field_data)) { 201 !DeserializeCommonSection2(iter, &temp_form_field_data)) {
194 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 202 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
195 return false; 203 return false;
196 } 204 }
197 break; 205 break;
198 } 206 }
207 case 3: {
208 if (!DeserializeCommonSection1(iter, &temp_form_field_data) ||
209 !DeserializeVersion2Specific(iter, &temp_form_field_data) ||
210 !DeserializeCommonSection2(iter, &temp_form_field_data) ||
211 !DeserializeVersion3Specific(iter, &temp_form_field_data)) {
212 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
213 return false;
214 }
215 break;
216 }
199 default: { 217 default: {
200 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; 218 LOG(ERROR) << "Unknown FormFieldData pickle version " << version;
201 return false; 219 return false;
202 } 220 }
203 } 221 }
204 *field_data = temp_form_field_data; 222 *field_data = temp_form_field_data;
205 return true; 223 return true;
206 } 224 }
207 225
208 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) { 226 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) {
209 return os << base::UTF16ToUTF8(field.label) << " " 227 return os << base::UTF16ToUTF8(field.label) << " "
210 << base::UTF16ToUTF8(field.name) << " " 228 << base::UTF16ToUTF8(field.name) << " "
211 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type 229 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type
212 << " " << field.autocomplete_attribute << " " << field.max_length 230 << " " << field.autocomplete_attribute << " " << field.placeholder
213 << " " << (field.is_autofilled ? "true" : "false") << " " 231 << " " << field.max_length << " "
232 << (field.is_autofilled ? "true" : "false") << " "
214 << (field.is_checked ? "true" : "false") << " " 233 << (field.is_checked ? "true" : "false") << " "
215 << (field.is_checkable ? "true" : "false") << " " 234 << (field.is_checkable ? "true" : "false") << " "
216 << (field.is_focusable ? "true" : "false") << " " 235 << (field.is_focusable ? "true" : "false") << " "
217 << (field.should_autocomplete ? "true" : "false") << " " 236 << (field.should_autocomplete ? "true" : "false") << " "
218 << field.role << " " << field.text_direction; 237 << field.role << " " << field.text_direction;
219 } 238 }
220 239
221 } // namespace autofill 240 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/form_field_data.h ('k') | components/autofill/core/common/form_field_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698