| 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/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 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 FormFieldData::~FormFieldData() { | 63 FormFieldData::~FormFieldData() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { | 66 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { |
| 67 // A FormFieldData stores a value, but the value is not part of the identity | 67 // A FormFieldData stores a value, but the value is not part of the identity |
| 68 // of the field, so we don't want to compare the values. | 68 // of the field, so we don't want to compare the values. |
| 69 return (label == field.label && | 69 return (label == field.label && |
| 70 name == field.name && | 70 name == field.name && |
| 71 form_control_type == field.form_control_type && | 71 form_control_type == field.form_control_type && |
| 72 autocomplete_attribute == field.autocomplete_attribute && | 72 autocomplete_attribute == field.autocomplete_attribute && |
| 73 role == field.role && |
| 73 max_length == field.max_length && | 74 max_length == field.max_length && |
| 74 // is_checked and is_autofilled counts as "value" since these change | 75 // is_checked and is_autofilled counts as "value" since these change |
| 75 // when we fill things in. | 76 // when we fill things in. |
| 76 is_checkable == field.is_checkable && | 77 is_checkable == field.is_checkable && |
| 77 is_focusable == field.is_focusable && | 78 is_focusable == field.is_focusable && |
| 78 should_autocomplete == field.should_autocomplete && | 79 should_autocomplete == field.should_autocomplete && |
| 79 text_direction == field.text_direction); | 80 text_direction == field.text_direction); |
| 80 // The option values/contents whith are the list of items in the list | 81 // The option values/contents whith are the list of items in the list |
| 81 // of a drop-down are currently not considered part of the identity of | 82 // of a drop-down are currently not considered part of the identity of |
| 82 // a form element. This is debatable, since one might base heuristics | 83 // a form element. This is debatable, since one might base heuristics |
| 83 // on the types of elements that are available. Alternatively, one | 84 // on the types of elements that are available. Alternatively, one |
| 84 // could imagine some forms that dynamically change the element | 85 // could imagine some forms that dynamically change the element |
| 85 // contents (say, insert years starting from the current year) that | 86 // contents (say, insert years starting from the current year) that |
| 86 // should not be considered changes in the structure of the form. | 87 // should not be considered changes in the structure of the form. |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool FormFieldData::operator<(const FormFieldData& field) const { | 90 bool FormFieldData::operator<(const FormFieldData& field) const { |
| 90 // Like operator==, this ignores the value. | 91 // Like operator==, this ignores the value. |
| 91 if (label < field.label) return true; | 92 if (label < field.label) return true; |
| 92 if (label > field.label) return false; | 93 if (label > field.label) return false; |
| 93 if (name < field.name) return true; | 94 if (name < field.name) return true; |
| 94 if (name > field.name) return false; | 95 if (name > field.name) return false; |
| 95 if (form_control_type < field.form_control_type) return true; | 96 if (form_control_type < field.form_control_type) return true; |
| 96 if (form_control_type > field.form_control_type) return false; | 97 if (form_control_type > field.form_control_type) return false; |
| 97 if (autocomplete_attribute < field.autocomplete_attribute) return true; | 98 if (autocomplete_attribute < field.autocomplete_attribute) return true; |
| 98 if (autocomplete_attribute > field.autocomplete_attribute) return false; | 99 if (autocomplete_attribute > field.autocomplete_attribute) return false; |
| 100 if (role < field.role) return true; |
| 101 if (role > field.role) return false; |
| 99 if (max_length < field.max_length) return true; | 102 if (max_length < field.max_length) return true; |
| 100 if (max_length > field.max_length) return false; | 103 if (max_length > field.max_length) return false; |
| 101 // Skip is_checked and is_autofilled as in SameFieldAs. | 104 // Skip is_checked and is_autofilled as in SameFieldAs. |
| 102 if (is_checkable < field.is_checkable) return true; | 105 if (is_checkable < field.is_checkable) return true; |
| 103 if (is_checkable > field.is_checkable) return false; | 106 if (is_checkable > field.is_checkable) return false; |
| 104 if (is_focusable < field.is_focusable) return true; | 107 if (is_focusable < field.is_focusable) return true; |
| 105 if (is_focusable > field.is_focusable) return false; | 108 if (is_focusable > field.is_focusable) return false; |
| 106 if (should_autocomplete < field.should_autocomplete) return true; | 109 if (should_autocomplete < field.should_autocomplete) return true; |
| 107 if (should_autocomplete > field.should_autocomplete) return false; | 110 if (should_autocomplete > field.should_autocomplete) return false; |
| 108 if (text_direction < field.text_direction) return true; | 111 if (text_direction < field.text_direction) return true; |
| 109 if (text_direction > field.text_direction) return false; | 112 if (text_direction > field.text_direction) return false; |
| 110 // See operator== above for why we don't check option_values/contents. | 113 // See operator== above for why we don't check option_values/contents. |
| 111 return false; | 114 return false; |
| 112 } | 115 } |
| 113 | 116 |
| 114 void SerializeFormFieldData(const FormFieldData& field_data, | 117 void SerializeFormFieldData(const FormFieldData& field_data, |
| 115 Pickle* pickle) { | 118 Pickle* pickle) { |
| 116 pickle->WriteInt(kPickleVersion); | 119 pickle->WriteInt(kPickleVersion); |
| 117 pickle->WriteString16(field_data.label); | 120 pickle->WriteString16(field_data.label); |
| 118 pickle->WriteString16(field_data.name); | 121 pickle->WriteString16(field_data.name); |
| 119 pickle->WriteString16(field_data.value); | 122 pickle->WriteString16(field_data.value); |
| 120 pickle->WriteString(field_data.form_control_type); | 123 pickle->WriteString(field_data.form_control_type); |
| 121 pickle->WriteString(field_data.autocomplete_attribute); | 124 pickle->WriteString(field_data.autocomplete_attribute); |
| 125 pickle->WriteString(field_data.role); |
| 122 pickle->WriteSizeT(field_data.max_length); | 126 pickle->WriteSizeT(field_data.max_length); |
| 123 pickle->WriteBool(field_data.is_autofilled); | 127 pickle->WriteBool(field_data.is_autofilled); |
| 124 pickle->WriteBool(field_data.is_checked); | 128 pickle->WriteBool(field_data.is_checked); |
| 125 pickle->WriteBool(field_data.is_checkable); | 129 pickle->WriteBool(field_data.is_checkable); |
| 126 pickle->WriteBool(field_data.is_focusable); | 130 pickle->WriteBool(field_data.is_focusable); |
| 127 pickle->WriteBool(field_data.should_autocomplete); | 131 pickle->WriteBool(field_data.should_autocomplete); |
| 128 pickle->WriteInt(field_data.text_direction); | 132 pickle->WriteInt(field_data.text_direction); |
| 129 AddVectorToPickle(field_data.option_values, pickle); | 133 AddVectorToPickle(field_data.option_values, pickle); |
| 130 AddVectorToPickle(field_data.option_contents, pickle); | 134 AddVectorToPickle(field_data.option_contents, pickle); |
| 131 } | 135 } |
| 132 | 136 |
| 133 bool DeserializeFormFieldData(PickleIterator* iter, | 137 bool DeserializeFormFieldData(PickleIterator* iter, |
| 134 FormFieldData* field_data) { | 138 FormFieldData* field_data) { |
| 135 int version; | 139 int version; |
| 136 if (!iter->ReadInt(&version)) { | 140 if (!iter->ReadInt(&version)) { |
| 137 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; | 141 LOG(ERROR) << "Bad pickle of FormFieldData, no version present"; |
| 138 return false; | 142 return false; |
| 139 } | 143 } |
| 140 | 144 |
| 141 switch (version) { | 145 switch (version) { |
| 142 case 1: { | 146 case 1: { |
| 143 if (!iter->ReadString16(&field_data->label) || | 147 if (!iter->ReadString16(&field_data->label) || |
| 144 !iter->ReadString16(&field_data->name) || | 148 !iter->ReadString16(&field_data->name) || |
| 145 !iter->ReadString16(&field_data->value) || | 149 !iter->ReadString16(&field_data->value) || |
| 146 !iter->ReadString(&field_data->form_control_type) || | 150 !iter->ReadString(&field_data->form_control_type) || |
| 147 !iter->ReadString(&field_data->autocomplete_attribute) || | 151 !iter->ReadString(&field_data->autocomplete_attribute) || |
| 152 !iter->ReadString(&field_data->role) || |
| 148 !iter->ReadSizeT(&field_data->max_length) || | 153 !iter->ReadSizeT(&field_data->max_length) || |
| 149 !iter->ReadBool(&field_data->is_autofilled) || | 154 !iter->ReadBool(&field_data->is_autofilled) || |
| 150 !iter->ReadBool(&field_data->is_checked) || | 155 !iter->ReadBool(&field_data->is_checked) || |
| 151 !iter->ReadBool(&field_data->is_checkable) || | 156 !iter->ReadBool(&field_data->is_checkable) || |
| 152 !iter->ReadBool(&field_data->is_focusable) || | 157 !iter->ReadBool(&field_data->is_focusable) || |
| 153 !iter->ReadBool(&field_data->should_autocomplete) || | 158 !iter->ReadBool(&field_data->should_autocomplete) || |
| 154 !ReadTextDirection(iter, &field_data->text_direction) || | 159 !ReadTextDirection(iter, &field_data->text_direction) || |
| 155 !ReadStringVector(iter, &field_data->option_values) || | 160 !ReadStringVector(iter, &field_data->option_values) || |
| 156 !ReadStringVector(iter, &field_data->option_contents)) { | 161 !ReadStringVector(iter, &field_data->option_contents)) { |
| 157 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; | 162 LOG(ERROR) << "Could not deserialize FormFieldData from pickle"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 172 << base::UTF16ToUTF8(field.label) | 177 << base::UTF16ToUTF8(field.label) |
| 173 << " " | 178 << " " |
| 174 << base::UTF16ToUTF8(field.name) | 179 << base::UTF16ToUTF8(field.name) |
| 175 << " " | 180 << " " |
| 176 << base::UTF16ToUTF8(field.value) | 181 << base::UTF16ToUTF8(field.value) |
| 177 << " " | 182 << " " |
| 178 << field.form_control_type | 183 << field.form_control_type |
| 179 << " " | 184 << " " |
| 180 << field.autocomplete_attribute | 185 << field.autocomplete_attribute |
| 181 << " " | 186 << " " |
| 187 << field.role |
| 188 << " " |
| 182 << field.max_length | 189 << field.max_length |
| 183 << " " | 190 << " " |
| 184 << (field.is_autofilled ? "true" : "false") | 191 << (field.is_autofilled ? "true" : "false") |
| 185 << " " | 192 << " " |
| 186 << (field.is_checked ? "true" : "false") | 193 << (field.is_checked ? "true" : "false") |
| 187 << " " | 194 << " " |
| 188 << (field.is_checkable ? "true" : "false") | 195 << (field.is_checkable ? "true" : "false") |
| 189 << " " | 196 << " " |
| 190 << (field.is_focusable ? "true" : "false") | 197 << (field.is_focusable ? "true" : "false") |
| 191 << " " | 198 << " " |
| 192 << (field.should_autocomplete ? "true" : "false") | 199 << (field.should_autocomplete ? "true" : "false") |
| 193 << " " | 200 << " " |
| 194 << field.text_direction; | 201 << field.text_direction; |
| 195 } | 202 } |
| 196 | 203 |
| 197 } // namespace autofill | 204 } // namespace autofill |
| OLD | NEW |