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

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

Issue 2640783002: [Password Generation] Send id attribute to server for HTML based form classifier (Closed)
Patch Set: Fixed failed test Created 3 years, 11 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 #include "components/autofill/core/common/autofill_util.h" 10 #include "components/autofill/core/common/autofill_util.h"
11 11
12 namespace autofill { 12 namespace autofill {
13 13
14 namespace { 14 namespace {
15 15
16 // Increment this anytime pickle format is modified as well as provide 16 // Increment this anytime pickle format is modified as well as provide
17 // deserialization routine from previous kPickleVersion format. 17 // deserialization routine from previous kPickleVersion format.
18 const int kPickleVersion = 6; 18 const int kPickleVersion = 7;
19 19
20 void AddVectorToPickle(std::vector<base::string16> strings, 20 void AddVectorToPickle(std::vector<base::string16> strings,
21 base::Pickle* pickle) { 21 base::Pickle* pickle) {
22 pickle->WriteInt(static_cast<int>(strings.size())); 22 pickle->WriteInt(static_cast<int>(strings.size()));
23 for (size_t i = 0; i < strings.size(); ++i) { 23 for (size_t i = 0; i < strings.size(); ++i) {
24 pickle->WriteString16(strings[i]); 24 pickle->WriteString16(strings[i]);
25 } 25 }
26 } 26 }
27 27
28 bool ReadStringVector(base::PickleIterator* iter, 28 bool ReadStringVector(base::PickleIterator* iter,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool DeserializeSection8(base::PickleIterator* iter, 107 bool DeserializeSection8(base::PickleIterator* iter,
108 FormFieldData* field_data) { 108 FormFieldData* field_data) {
109 return iter->ReadString16(&field_data->css_classes); 109 return iter->ReadString16(&field_data->css_classes);
110 } 110 }
111 111
112 bool DeserializeSection9(base::PickleIterator* iter, 112 bool DeserializeSection9(base::PickleIterator* iter,
113 FormFieldData* field_data) { 113 FormFieldData* field_data) {
114 return iter->ReadUInt32(&field_data->properties_mask); 114 return iter->ReadUInt32(&field_data->properties_mask);
115 } 115 }
116 116
117 bool DeserializeSection10(base::PickleIterator* iter,
118 FormFieldData* field_data) {
119 return iter->ReadString16(&field_data->id);
120 }
121
117 } // namespace 122 } // namespace
118 123
119 FormFieldData::FormFieldData() 124 FormFieldData::FormFieldData()
120 : max_length(0), 125 : max_length(0),
121 is_autofilled(false), 126 is_autofilled(false),
122 check_status(NOT_CHECKABLE), 127 check_status(NOT_CHECKABLE),
123 is_focusable(false), 128 is_focusable(false),
124 should_autocomplete(true), 129 should_autocomplete(true),
125 role(ROLE_ATTRIBUTE_OTHER), 130 role(ROLE_ATTRIBUTE_OTHER),
126 text_direction(base::i18n::UNKNOWN_DIRECTION), 131 text_direction(base::i18n::UNKNOWN_DIRECTION),
127 properties_mask(0) {} 132 properties_mask(0) {}
128 133
129 FormFieldData::FormFieldData(const FormFieldData& other) = default; 134 FormFieldData::FormFieldData(const FormFieldData& other) = default;
130 135
131 FormFieldData::~FormFieldData() { 136 FormFieldData::~FormFieldData() {
132 } 137 }
133 138
134 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { 139 bool FormFieldData::SameFieldAs(const FormFieldData& field) const {
135 // A FormFieldData stores a value, but the value is not part of the identity 140 // A FormFieldData stores a value, but the value is not part of the identity
136 // of the field, so we don't want to compare the values. 141 // of the field, so we don't want to compare the values.
137 return label == field.label && name == field.name && 142 return label == field.label && name == field.name && id == field.id &&
138 form_control_type == field.form_control_type && 143 form_control_type == field.form_control_type &&
139 autocomplete_attribute == field.autocomplete_attribute && 144 autocomplete_attribute == field.autocomplete_attribute &&
140 placeholder == field.placeholder && max_length == field.max_length && 145 placeholder == field.placeholder && max_length == field.max_length &&
141 css_classes == field.css_classes && 146 css_classes == field.css_classes &&
142 // is_checked and is_autofilled counts as "value" since these change 147 // is_checked and is_autofilled counts as "value" since these change
143 // when we fill things in. 148 // when we fill things in.
144 IsCheckable(check_status) == IsCheckable(field.check_status) && 149 IsCheckable(check_status) == IsCheckable(field.check_status) &&
145 is_focusable == field.is_focusable && 150 is_focusable == field.is_focusable &&
146 should_autocomplete == field.should_autocomplete && 151 should_autocomplete == field.should_autocomplete &&
147 role == field.role && text_direction == field.text_direction; 152 role == field.role && text_direction == field.text_direction;
(...skipping 22 matching lines...) Expand all
170 // This does not use std::tie() as that generates more implicit variables 175 // This does not use std::tie() as that generates more implicit variables
171 // than the max-vartrack-size for var-tracking-assignments when compiling 176 // than the max-vartrack-size for var-tracking-assignments when compiling
172 // for Android, producing build warnings. (See https://crbug.com/555171 for 177 // for Android, producing build warnings. (See https://crbug.com/555171 for
173 // context.) 178 // context.)
174 179
175 // Like SameFieldAs this ignores the value. 180 // Like SameFieldAs this ignores the value.
176 if (label < field.label) return true; 181 if (label < field.label) return true;
177 if (label > field.label) return false; 182 if (label > field.label) return false;
178 if (name < field.name) return true; 183 if (name < field.name) return true;
179 if (name > field.name) return false; 184 if (name > field.name) return false;
185 if (id < field.id) return true;
186 if (id > field.id) return false;
180 if (form_control_type < field.form_control_type) return true; 187 if (form_control_type < field.form_control_type) return true;
181 if (form_control_type > field.form_control_type) return false; 188 if (form_control_type > field.form_control_type) return false;
182 if (autocomplete_attribute < field.autocomplete_attribute) return true; 189 if (autocomplete_attribute < field.autocomplete_attribute) return true;
183 if (autocomplete_attribute > field.autocomplete_attribute) return false; 190 if (autocomplete_attribute > field.autocomplete_attribute) return false;
184 if (placeholder < field.placeholder) return true; 191 if (placeholder < field.placeholder) return true;
185 if (placeholder > field.placeholder) return false; 192 if (placeholder > field.placeholder) return false;
186 if (max_length < field.max_length) return true; 193 if (max_length < field.max_length) return true;
187 if (max_length > field.max_length) return false; 194 if (max_length > field.max_length) return false;
188 if (css_classes < field.css_classes) return true; 195 if (css_classes < field.css_classes) return true;
189 if (css_classes > field.css_classes) return false; 196 if (css_classes > field.css_classes) return false;
(...skipping 25 matching lines...) Expand all
215 pickle->WriteInt(field_data.check_status); 222 pickle->WriteInt(field_data.check_status);
216 pickle->WriteBool(field_data.is_focusable); 223 pickle->WriteBool(field_data.is_focusable);
217 pickle->WriteBool(field_data.should_autocomplete); 224 pickle->WriteBool(field_data.should_autocomplete);
218 pickle->WriteInt(field_data.role); 225 pickle->WriteInt(field_data.role);
219 pickle->WriteInt(field_data.text_direction); 226 pickle->WriteInt(field_data.text_direction);
220 AddVectorToPickle(field_data.option_values, pickle); 227 AddVectorToPickle(field_data.option_values, pickle);
221 AddVectorToPickle(field_data.option_contents, pickle); 228 AddVectorToPickle(field_data.option_contents, pickle);
222 pickle->WriteString16(field_data.placeholder); 229 pickle->WriteString16(field_data.placeholder);
223 pickle->WriteString16(field_data.css_classes); 230 pickle->WriteString16(field_data.css_classes);
224 pickle->WriteUInt32(field_data.properties_mask); 231 pickle->WriteUInt32(field_data.properties_mask);
232 pickle->WriteString16(field_data.id);
225 } 233 }
226 234
227 bool DeserializeFormFieldData(base::PickleIterator* iter, 235 bool DeserializeFormFieldData(base::PickleIterator* iter,
228 FormFieldData* field_data) { 236 FormFieldData* field_data) {
229 int version; 237 int version;
230 FormFieldData temp_form_field_data; 238 FormFieldData temp_form_field_data;
231 if (!iter->ReadInt(&version)) { 239 if (!iter->ReadInt(&version)) {
232 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; 240 LOG(ERROR) << "Bad pickle of FormFieldData, no version present";
233 return false; 241 return false;
234 } 242 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 !DeserializeSection2(iter, &temp_form_field_data) || 307 !DeserializeSection2(iter, &temp_form_field_data) ||
300 !DeserializeSection3(iter, &temp_form_field_data) || 308 !DeserializeSection3(iter, &temp_form_field_data) ||
301 !DeserializeSection4(iter, &temp_form_field_data) || 309 !DeserializeSection4(iter, &temp_form_field_data) ||
302 !DeserializeSection8(iter, &temp_form_field_data) || 310 !DeserializeSection8(iter, &temp_form_field_data) ||
303 !DeserializeSection9(iter, &temp_form_field_data)) { 311 !DeserializeSection9(iter, &temp_form_field_data)) {
304 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; 312 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
305 return false; 313 return false;
306 } 314 }
307 break; 315 break;
308 } 316 }
317 case 7: {
318 if (!DeserializeSection1(iter, &temp_form_field_data) ||
319 !DeserializeSection6(iter, &temp_form_field_data) ||
320 !DeserializeSection7(iter, &temp_form_field_data) ||
321 !DeserializeSection2(iter, &temp_form_field_data) ||
322 !DeserializeSection3(iter, &temp_form_field_data) ||
323 !DeserializeSection4(iter, &temp_form_field_data) ||
324 !DeserializeSection8(iter, &temp_form_field_data) ||
325 !DeserializeSection9(iter, &temp_form_field_data) ||
326 !DeserializeSection10(iter, &temp_form_field_data)) {
327 LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
328 return false;
329 }
330 break;
331 }
309 default: { 332 default: {
310 LOG(ERROR) << "Unknown FormFieldData pickle version " << version; 333 LOG(ERROR) << "Unknown FormFieldData pickle version " << version;
311 return false; 334 return false;
312 } 335 }
313 } 336 }
314 *field_data = temp_form_field_data; 337 *field_data = temp_form_field_data;
315 return true; 338 return true;
316 } 339 }
317 340
318 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) { 341 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) {
(...skipping 15 matching lines...) Expand all
334 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION: 357 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION:
335 role_str = "ROLE_ATTRIBUTE_PRESENTATION"; 358 role_str = "ROLE_ATTRIBUTE_PRESENTATION";
336 break; 359 break;
337 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER: 360 case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER:
338 role_str = "ROLE_ATTRIBUTE_OTHER"; 361 role_str = "ROLE_ATTRIBUTE_OTHER";
339 break; 362 break;
340 } 363 }
341 364
342 return os << base::UTF16ToUTF8(field.label) << " " 365 return os << base::UTF16ToUTF8(field.label) << " "
343 << base::UTF16ToUTF8(field.name) << " " 366 << base::UTF16ToUTF8(field.name) << " "
367 << base::UTF16ToUTF8(field.id) << " "
344 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type 368 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type
345 << " " << field.autocomplete_attribute << " " << field.placeholder 369 << " " << field.autocomplete_attribute << " " << field.placeholder
346 << " " << field.max_length << " " << field.css_classes << " " 370 << " " << field.max_length << " " << field.css_classes << " "
347 << (field.is_autofilled ? "true" : "false") << " " 371 << (field.is_autofilled ? "true" : "false") << " "
348 << check_status_str << (field.is_focusable ? "true" : "false") 372 << check_status_str << (field.is_focusable ? "true" : "false")
349 << " " << (field.should_autocomplete ? "true" : "false") << " " 373 << " " << (field.should_autocomplete ? "true" : "false") << " "
350 << role_str << " " << field.text_direction << " " 374 << role_str << " " << field.text_direction << " "
351 << field.properties_mask; 375 << field.properties_mask;
352 } 376 }
353 377
354 } // namespace autofill 378 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698