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

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

Issue 2073093002: [Password Generation] Sends CSS classes inside autofill proto (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed useless FormStructure recreation in FormStructureTest.EncodeUploadRequest_WithCssClasses Created 4 years, 6 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 = 4; 17 const int kPickleVersion = 5;
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bool DeserializeSection2(base::PickleIterator* iter, 96 bool DeserializeSection2(base::PickleIterator* iter,
97 FormFieldData* field_data) { 97 FormFieldData* field_data) {
98 return ReadAsInt(iter, &field_data->role); 98 return ReadAsInt(iter, &field_data->role);
99 } 99 }
100 100
101 bool DeserializeSection4(base::PickleIterator* iter, 101 bool DeserializeSection4(base::PickleIterator* iter,
102 FormFieldData* field_data) { 102 FormFieldData* field_data) {
103 return iter->ReadString16(&field_data->placeholder); 103 return iter->ReadString16(&field_data->placeholder);
104 } 104 }
105 105
106 bool DeserializeSection8(base::PickleIterator* iter,
107 FormFieldData* field_data) {
108 return iter->ReadString16(&field_data->css_classes);
109 }
110
106 } // namespace 111 } // namespace
107 112
108 FormFieldData::FormFieldData() 113 FormFieldData::FormFieldData()
109 : max_length(0), 114 : max_length(0),
110 is_autofilled(false), 115 is_autofilled(false),
111 check_status(NOT_CHECKABLE), 116 check_status(NOT_CHECKABLE),
112 is_focusable(false), 117 is_focusable(false),
113 should_autocomplete(true), 118 should_autocomplete(true),
114 role(ROLE_ATTRIBUTE_OTHER), 119 role(ROLE_ATTRIBUTE_OTHER),
115 text_direction(base::i18n::UNKNOWN_DIRECTION) {} 120 text_direction(base::i18n::UNKNOWN_DIRECTION) {}
116 121
117 FormFieldData::FormFieldData(const FormFieldData& other) = default; 122 FormFieldData::FormFieldData(const FormFieldData& other) = default;
118 123
119 FormFieldData::~FormFieldData() { 124 FormFieldData::~FormFieldData() {
120 } 125 }
121 126
122 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { 127 bool FormFieldData::SameFieldAs(const FormFieldData& field) const {
123 // A FormFieldData stores a value, but the value is not part of the identity 128 // A FormFieldData stores a value, but the value is not part of the identity
124 // of the field, so we don't want to compare the values. 129 // of the field, so we don't want to compare the values.
125 return label == field.label && name == field.name && 130 return label == field.label && name == field.name &&
126 form_control_type == field.form_control_type && 131 form_control_type == field.form_control_type &&
127 autocomplete_attribute == field.autocomplete_attribute && 132 autocomplete_attribute == field.autocomplete_attribute &&
128 placeholder == field.placeholder && max_length == field.max_length && 133 placeholder == field.placeholder && max_length == field.max_length &&
134 css_classes == field.css_classes &&
129 // is_checked and is_autofilled counts as "value" since these change 135 // is_checked and is_autofilled counts as "value" since these change
130 // when we fill things in. 136 // when we fill things in.
131 IsCheckable(check_status) == IsCheckable(field.check_status) && 137 IsCheckable(check_status) == IsCheckable(field.check_status) &&
132 is_focusable == field.is_focusable && 138 is_focusable == field.is_focusable &&
133 should_autocomplete == field.should_autocomplete && 139 should_autocomplete == field.should_autocomplete &&
134 role == field.role && text_direction == field.text_direction; 140 role == field.role && text_direction == field.text_direction;
135 // The option values/contents which are the list of items in the list 141 // The option values/contents which are the list of items in the list
136 // of a drop-down are currently not considered part of the identity of 142 // of a drop-down are currently not considered part of the identity of
137 // a form element. This is debatable, since one might base heuristics 143 // a form element. This is debatable, since one might base heuristics
138 // on the types of elements that are available. Alternatively, one 144 // on the types of elements that are available. Alternatively, one
(...skipping 14 matching lines...) Expand all
153 if (name < field.name) return true; 159 if (name < field.name) return true;
154 if (name > field.name) return false; 160 if (name > field.name) return false;
155 if (form_control_type < field.form_control_type) return true; 161 if (form_control_type < field.form_control_type) return true;
156 if (form_control_type > field.form_control_type) return false; 162 if (form_control_type > field.form_control_type) return false;
157 if (autocomplete_attribute < field.autocomplete_attribute) return true; 163 if (autocomplete_attribute < field.autocomplete_attribute) return true;
158 if (autocomplete_attribute > field.autocomplete_attribute) return false; 164 if (autocomplete_attribute > field.autocomplete_attribute) return false;
159 if (placeholder < field.placeholder) return true; 165 if (placeholder < field.placeholder) return true;
160 if (placeholder > field.placeholder) return false; 166 if (placeholder > field.placeholder) return false;
161 if (max_length < field.max_length) return true; 167 if (max_length < field.max_length) return true;
162 if (max_length > field.max_length) return false; 168 if (max_length > field.max_length) return false;
169 if (css_classes < field.css_classes) return true;
170 if (css_classes > field.css_classes) return false;
163 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. 171 // Skip |is_checked| and |is_autofilled| as in SameFieldAs.
164 if (IsCheckable(check_status) < IsCheckable(field.check_status)) return true; 172 if (IsCheckable(check_status) < IsCheckable(field.check_status)) return true;
165 if (IsCheckable(check_status) > IsCheckable(field.check_status)) return false; 173 if (IsCheckable(check_status) > IsCheckable(field.check_status)) return false;
166 if (is_focusable < field.is_focusable) return true; 174 if (is_focusable < field.is_focusable) return true;
167 if (is_focusable > field.is_focusable) return false; 175 if (is_focusable > field.is_focusable) return false;
168 if (should_autocomplete < field.should_autocomplete) return true; 176 if (should_autocomplete < field.should_autocomplete) return true;
169 if (should_autocomplete > field.should_autocomplete) return false; 177 if (should_autocomplete > field.should_autocomplete) return false;
170 if (role < field.role) return true; 178 if (role < field.role) return true;
171 if (role > field.role) return false; 179 if (role > field.role) return false;
172 if (text_direction < field.text_direction) return true; 180 if (text_direction < field.text_direction) return true;
(...skipping 13 matching lines...) Expand all
186 pickle->WriteUInt64(field_data.max_length); 194 pickle->WriteUInt64(field_data.max_length);
187 pickle->WriteBool(field_data.is_autofilled); 195 pickle->WriteBool(field_data.is_autofilled);
188 pickle->WriteInt(field_data.check_status); 196 pickle->WriteInt(field_data.check_status);
189 pickle->WriteBool(field_data.is_focusable); 197 pickle->WriteBool(field_data.is_focusable);
190 pickle->WriteBool(field_data.should_autocomplete); 198 pickle->WriteBool(field_data.should_autocomplete);
191 pickle->WriteInt(field_data.role); 199 pickle->WriteInt(field_data.role);
192 pickle->WriteInt(field_data.text_direction); 200 pickle->WriteInt(field_data.text_direction);
193 AddVectorToPickle(field_data.option_values, pickle); 201 AddVectorToPickle(field_data.option_values, pickle);
194 AddVectorToPickle(field_data.option_contents, pickle); 202 AddVectorToPickle(field_data.option_contents, pickle);
195 pickle->WriteString16(field_data.placeholder); 203 pickle->WriteString16(field_data.placeholder);
204 pickle->WriteString16(field_data.css_classes);
196 } 205 }
197 206
198 bool DeserializeFormFieldData(base::PickleIterator* iter, 207 bool DeserializeFormFieldData(base::PickleIterator* iter,
199 FormFieldData* field_data) { 208 FormFieldData* field_data) {
200 int version; 209 int version;
201 FormFieldData temp_form_field_data; 210 FormFieldData temp_form_field_data;
202 if (!iter->ReadInt(&version)) { 211 if (!iter->ReadInt(&version)) {
203 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; 212 LOG(ERROR) << "Bad pickle of FormFieldData, no version present";
204 return false; 213 return false;
205 } 214 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 !DeserializeSection6(iter, &temp_form_field_data) || 252 !DeserializeSection6(iter, &temp_form_field_data) ||
244 !DeserializeSection7(iter, &temp_form_field_data) || 253 !DeserializeSection7(iter, &temp_form_field_data) ||
245 !DeserializeSection2(iter, &temp_form_field_data) || 254 !DeserializeSection2(iter, &temp_form_field_data) ||
246 !DeserializeSection3(iter, &temp_form_field_data) || 255 !DeserializeSection3(iter, &temp_form_field_data) ||
247 !DeserializeSection4(iter, &temp_form_field_data)) { 256 !DeserializeSection4(iter, &temp_form_field_data)) {
248 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 257 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
249 return false; 258 return false;
250 } 259 }
251 break; 260 break;
252 } 261 }
262 case 5: {
263 if (!DeserializeSection1(iter, &temp_form_field_data) ||
264 !DeserializeSection6(iter, &temp_form_field_data) ||
265 !DeserializeSection7(iter, &temp_form_field_data) ||
266 !DeserializeSection2(iter, &temp_form_field_data) ||
267 !DeserializeSection3(iter, &temp_form_field_data) ||
268 !DeserializeSection4(iter, &temp_form_field_data) ||
269 !DeserializeSection8(iter, &temp_form_field_data)) {
270 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
271 return false;
272 }
273 break;
274 }
253 default: { 275 default: {
254 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; 276 LOG(ERROR) << "Unknown FormFieldData pickle version " << version;
255 return false; 277 return false;
256 } 278 }
257 } 279 }
258 *field_data = temp_form_field_data; 280 *field_data = temp_form_field_data;
259 return true; 281 return true;
260 } 282 }
261 283
262 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) { 284 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) {
(...skipping 17 matching lines...) Expand all
280 break; 302 break;
281 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER: 303 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER:
282 role_str = "ROLE_ATTRIBUTE_OTHER"; 304 role_str = "ROLE_ATTRIBUTE_OTHER";
283 break; 305 break;
284 } 306 }
285 307
286 return os << base::UTF16ToUTF8(field.label) << " " 308 return os << base::UTF16ToUTF8(field.label) << " "
287 << base::UTF16ToUTF8(field.name) << " " 309 << base::UTF16ToUTF8(field.name) << " "
288 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type 310 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type
289 << " " << field.autocomplete_attribute << " " << field.placeholder 311 << " " << field.autocomplete_attribute << " " << field.placeholder
290 << " " << field.max_length << " " 312 << " " << field.max_length << " " << field.css_classes << " "
291 << (field.is_autofilled ? "true" : "false") << " " 313 << (field.is_autofilled ? "true" : "false") << " "
292 << check_status_str << (field.is_focusable ? "true" : "false") 314 << check_status_str << (field.is_focusable ? "true" : "false")
293 << " " << (field.should_autocomplete ? "true" : "false") << " " 315 << " " << (field.should_autocomplete ? "true" : "false") << " "
294 << role_str << " " << field.text_direction; 316 << role_str << " " << field.text_direction;
295 } 317 }
296 318
297 bool IsCheckable(const FormFieldData::CheckStatus& check_status) { 319 bool IsCheckable(const FormFieldData::CheckStatus& check_status) {
298 return check_status != FormFieldData::CheckStatus::NOT_CHECKABLE; 320 return check_status != FormFieldData::CheckStatus::NOT_CHECKABLE;
299 } 321 }
300 322
(...skipping 10 matching lines...) Expand all
311 if (isCheckable) { 333 if (isCheckable) {
312 form_field_data->check_status = 334 form_field_data->check_status =
313 FormFieldData::CheckStatus::CHECKABLE_BUT_UNCHECKED; 335 FormFieldData::CheckStatus::CHECKABLE_BUT_UNCHECKED;
314 } else { 336 } else {
315 form_field_data->check_status = FormFieldData::CheckStatus::NOT_CHECKABLE; 337 form_field_data->check_status = FormFieldData::CheckStatus::NOT_CHECKABLE;
316 } 338 }
317 } 339 }
318 } 340 }
319 341
320 } // namespace autofill 342 } // 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