Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 |
| 53 bool DeserializeCommonSection1(base::PickleIterator* iter, | 53 bool DeserializeCommonSection1(base::PickleIterator* iter, |
| 54 FormFieldData* field_data) { | 54 FormFieldData* field_data) { |
| 55 return iter->ReadString16(&field_data->label) && | 55 return iter->ReadString16(&field_data->label) && |
| 56 iter->ReadString16(&field_data->name) && | 56 iter->ReadString16(&field_data->name) && |
| 57 iter->ReadString16(&field_data->value) && | 57 iter->ReadString16(&field_data->value) && |
| 58 iter->ReadString(&field_data->form_control_type) && | 58 iter->ReadString(&field_data->form_control_type) && |
| 59 iter->ReadString(&field_data->autocomplete_attribute) && | 59 iter->ReadString(&field_data->autocomplete_attribute) && |
| 60 iter->ReadUInt64(&field_data->max_length) && | 60 iter->ReadUInt64(&field_data->max_length) && |
| 61 iter->ReadBool(&field_data->is_autofilled) && | 61 iter->ReadBool(&field_data->is_autofilled) && |
| 62 iter->ReadBool(&field_data->is_checked) && | 62 iter->Readint(&field_data->check_status) && |
|
vabr (Chromium)
2016/05/31 15:48:25
No, this would break reading old serializations of
| |
| 63 iter->ReadBool(&field_data->is_checkable) && | |
| 64 iter->ReadBool(&field_data->is_focusable) && | 63 iter->ReadBool(&field_data->is_focusable) && |
| 65 iter->ReadBool(&field_data->should_autocomplete); | 64 iter->ReadBool(&field_data->should_autocomplete); |
| 66 } | 65 } |
| 67 | 66 |
| 68 bool DeserializeCommonSection2(base::PickleIterator* iter, | 67 bool DeserializeCommonSection2(base::PickleIterator* iter, |
| 69 FormFieldData* field_data) { | 68 FormFieldData* field_data) { |
| 70 return ReadAsInt(iter, &field_data->text_direction) && | 69 return ReadAsInt(iter, &field_data->text_direction) && |
| 71 ReadStringVector(iter, &field_data->option_values) && | 70 ReadStringVector(iter, &field_data->option_values) && |
| 72 ReadStringVector(iter, &field_data->option_contents); | 71 ReadStringVector(iter, &field_data->option_contents); |
| 73 } | 72 } |
| 74 | 73 |
| 75 bool DeserializeVersion2Specific(base::PickleIterator* iter, | 74 bool DeserializeVersion2Specific(base::PickleIterator* iter, |
| 76 FormFieldData* field_data) { | 75 FormFieldData* field_data) { |
| 77 return ReadAsInt(iter, &field_data->role); | 76 return ReadAsInt(iter, &field_data->role); |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool DeserializeVersion3Specific(base::PickleIterator* iter, | 79 bool DeserializeVersion3Specific(base::PickleIterator* iter, |
| 81 FormFieldData* field_data) { | 80 FormFieldData* field_data) { |
| 82 return iter->ReadString16(&field_data->placeholder); | 81 return iter->ReadString16(&field_data->placeholder); |
| 83 } | 82 } |
| 84 | 83 |
| 85 } // namespace | 84 } // namespace |
| 86 | 85 |
| 87 FormFieldData::FormFieldData() | 86 FormFieldData::FormFieldData() |
| 88 : max_length(0), | 87 : max_length(0), |
| 89 is_autofilled(false), | 88 is_autofilled(false), |
| 90 is_checked(false), | 89 check_status(CHECK_STATUS_NOT_CHECKABLE); |
| 91 is_checkable(false), | |
| 92 is_focusable(false), | 90 is_focusable(false), |
| 93 should_autocomplete(true), | 91 should_autocomplete(true), |
| 94 role(ROLE_ATTRIBUTE_OTHER), | 92 role(ROLE_ATTRIBUTE_OTHER), |
| 95 text_direction(base::i18n::UNKNOWN_DIRECTION) { | 93 text_direction(base::i18n::UNKNOWN_DIRECTION) { |
| 96 } | 94 } |
| 97 | 95 |
| 98 FormFieldData::FormFieldData(const FormFieldData& other) = default; | 96 FormFieldData::FormFieldData(const FormFieldData& other) = default; |
| 99 | 97 |
| 100 FormFieldData::~FormFieldData() { | 98 FormFieldData::~FormFieldData() { |
| 101 } | 99 } |
| 102 | 100 |
| 103 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { | 101 bool FormFieldData::SameFieldAs(const FormFieldData& field) const { |
| 104 // A FormFieldData stores a value, but the value is not part of the identity | 102 // A FormFieldData stores a value, but the value is not part of the identity |
| 105 // of the field, so we don't want to compare the values. | 103 // of the field, so we don't want to compare the values. |
| 104 bool is_checkable = | |
|
vabr (Chromium)
2016/05/31 15:48:25
Why don't you just compare check_status with field
Hwanseung Lee(hs1217.lee)
2016/06/09 15:41:59
i saw this annotation
113 // is_checked a
| |
| 105 (check_status == CHECK_STATUS_NOT_CHECKABLE) ? false : true; | |
| 106 bool field_is_checkable = | |
| 107 (field.check_status == CHECK_STATUS_NOT_CHECKABLE) ? false : true; | |
| 108 | |
| 106 return label == field.label && name == field.name && | 109 return label == field.label && name == field.name && |
| 107 form_control_type == field.form_control_type && | 110 form_control_type == field.form_control_type && |
| 108 autocomplete_attribute == field.autocomplete_attribute && | 111 autocomplete_attribute == field.autocomplete_attribute && |
| 109 placeholder == field.placeholder && max_length == field.max_length && | 112 placeholder == field.placeholder && max_length == field.max_length && |
| 110 // is_checked and is_autofilled counts as "value" since these change | 113 // is_checked and is_autofilled counts as "value" since these change |
| 111 // when we fill things in. | 114 // when we fill things in. |
| 112 is_checkable == field.is_checkable && | 115 is_checkable == field_is_checkable && |
| 113 is_focusable == field.is_focusable && | 116 is_focusable == field.is_focusable && |
| 114 should_autocomplete == field.should_autocomplete && | 117 should_autocomplete == field.should_autocomplete && |
| 115 role == field.role && text_direction == field.text_direction; | 118 role == field.role && text_direction == field.text_direction; |
| 116 // The option values/contents which are the list of items in the list | 119 // The option values/contents which are the list of items in the list |
| 117 // of a drop-down are currently not considered part of the identity of | 120 // of a drop-down are currently not considered part of the identity of |
| 118 // a form element. This is debatable, since one might base heuristics | 121 // a form element. This is debatable, since one might base heuristics |
| 119 // on the types of elements that are available. Alternatively, one | 122 // on the types of elements that are available. Alternatively, one |
| 120 // could imagine some forms that dynamically change the element | 123 // could imagine some forms that dynamically change the element |
| 121 // contents (say, insert years starting from the current year) that | 124 // contents (say, insert years starting from the current year) that |
| 122 // should not be considered changes in the structure of the form. | 125 // should not be considered changes in the structure of the form. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 135 if (name > field.name) return false; | 138 if (name > field.name) return false; |
| 136 if (form_control_type < field.form_control_type) return true; | 139 if (form_control_type < field.form_control_type) return true; |
| 137 if (form_control_type > field.form_control_type) return false; | 140 if (form_control_type > field.form_control_type) return false; |
| 138 if (autocomplete_attribute < field.autocomplete_attribute) return true; | 141 if (autocomplete_attribute < field.autocomplete_attribute) return true; |
| 139 if (autocomplete_attribute > field.autocomplete_attribute) return false; | 142 if (autocomplete_attribute > field.autocomplete_attribute) return false; |
| 140 if (placeholder < field.placeholder) return true; | 143 if (placeholder < field.placeholder) return true; |
| 141 if (placeholder > field.placeholder) return false; | 144 if (placeholder > field.placeholder) return false; |
| 142 if (max_length < field.max_length) return true; | 145 if (max_length < field.max_length) return true; |
| 143 if (max_length > field.max_length) return false; | 146 if (max_length > field.max_length) return false; |
| 144 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. | 147 // Skip |is_checked| and |is_autofilled| as in SameFieldAs. |
| 145 if (is_checkable < field.is_checkable) return true; | 148 bool is_checkable = |
|
vabr (Chromium)
2016/05/31 15:48:25
Again, just use check_status directly. But you wil
Hwanseung Lee(hs1217.lee)
2016/06/09 15:41:59
i saw this annotation
113 // is_checked a
| |
| 146 if (is_checkable > field.is_checkable) return false; | 149 (check_status == CHECK_STATUS_NOT_CHECKABLE) ? false : true; |
| 150 bool field_is_checkable = | |
| 151 (field.check_status == CHECK_STATUS_NOT_CHECKABLE) ? false : true; | |
| 152 if (is_checkable < field_is_checkable) return true; | |
| 153 if (is_checkable > field_is_checkable) return false; | |
| 147 if (is_focusable < field.is_focusable) return true; | 154 if (is_focusable < field.is_focusable) return true; |
| 148 if (is_focusable > field.is_focusable) return false; | 155 if (is_focusable > field.is_focusable) return false; |
| 149 if (should_autocomplete < field.should_autocomplete) return true; | 156 if (should_autocomplete < field.should_autocomplete) return true; |
| 150 if (should_autocomplete > field.should_autocomplete) return false; | 157 if (should_autocomplete > field.should_autocomplete) return false; |
| 151 if (role < field.role) return true; | 158 if (role < field.role) return true; |
| 152 if (role > field.role) return false; | 159 if (role > field.role) return false; |
| 153 if (text_direction < field.text_direction) return true; | 160 if (text_direction < field.text_direction) return true; |
| 154 if (text_direction > field.text_direction) return false; | 161 if (text_direction > field.text_direction) return false; |
| 155 // See operator== above for why we don't check option_values/contents. | 162 // See operator== above for why we don't check option_values/contents. |
| 156 return false; | 163 return false; |
| 157 } | 164 } |
| 158 | 165 |
| 159 void SerializeFormFieldData(const FormFieldData& field_data, | 166 void SerializeFormFieldData(const FormFieldData& field_data, |
| 160 base::Pickle* pickle) { | 167 base::Pickle* pickle) { |
| 161 pickle->WriteInt(kPickleVersion); | 168 pickle->WriteInt(kPickleVersion); |
| 162 pickle->WriteString16(field_data.label); | 169 pickle->WriteString16(field_data.label); |
| 163 pickle->WriteString16(field_data.name); | 170 pickle->WriteString16(field_data.name); |
| 164 pickle->WriteString16(field_data.value); | 171 pickle->WriteString16(field_data.value); |
| 165 pickle->WriteString(field_data.form_control_type); | 172 pickle->WriteString(field_data.form_control_type); |
| 166 pickle->WriteString(field_data.autocomplete_attribute); | 173 pickle->WriteString(field_data.autocomplete_attribute); |
| 167 pickle->WriteUInt64(field_data.max_length); | 174 pickle->WriteUInt64(field_data.max_length); |
| 168 pickle->WriteBool(field_data.is_autofilled); | 175 pickle->WriteBool(field_data.is_autofilled); |
| 169 pickle->WriteBool(field_data.is_checked); | 176 pickle->WriteInt(field_data.check_status); |
| 170 pickle->WriteBool(field_data.is_checkable); | |
| 171 pickle->WriteBool(field_data.is_focusable); | 177 pickle->WriteBool(field_data.is_focusable); |
| 172 pickle->WriteBool(field_data.should_autocomplete); | 178 pickle->WriteBool(field_data.should_autocomplete); |
| 173 pickle->WriteInt(field_data.role); | 179 pickle->WriteInt(field_data.role); |
| 174 pickle->WriteInt(field_data.text_direction); | 180 pickle->WriteInt(field_data.text_direction); |
| 175 AddVectorToPickle(field_data.option_values, pickle); | 181 AddVectorToPickle(field_data.option_values, pickle); |
| 176 AddVectorToPickle(field_data.option_contents, pickle); | 182 AddVectorToPickle(field_data.option_contents, pickle); |
| 177 pickle->WriteString16(field_data.placeholder); | 183 pickle->WriteString16(field_data.placeholder); |
| 178 } | 184 } |
| 179 | 185 |
| 180 bool DeserializeFormFieldData(base::PickleIterator* iter, | 186 bool DeserializeFormFieldData(base::PickleIterator* iter, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 return true; | 229 return true; |
| 224 } | 230 } |
| 225 | 231 |
| 226 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) { | 232 std::ostream& operator<<(std::ostream& os, const FormFieldData& field) { |
| 227 return os << base::UTF16ToUTF8(field.label) << " " | 233 return os << base::UTF16ToUTF8(field.label) << " " |
| 228 << base::UTF16ToUTF8(field.name) << " " | 234 << base::UTF16ToUTF8(field.name) << " " |
| 229 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type | 235 << base::UTF16ToUTF8(field.value) << " " << field.form_control_type |
| 230 << " " << field.autocomplete_attribute << " " << field.placeholder | 236 << " " << field.autocomplete_attribute << " " << field.placeholder |
| 231 << " " << field.max_length << " " | 237 << " " << field.max_length << " " |
| 232 << (field.is_autofilled ? "true" : "false") << " " | 238 << (field.is_autofilled ? "true" : "false") << " " |
| 233 << (field.is_checked ? "true" : "false") << " " | 239 << field.check_status |
|
vabr (Chromium)
2016/05/31 15:48:25
Once you change the type to enum class, this will
| |
| 234 << (field.is_checkable ? "true" : "false") << " " | |
| 235 << (field.is_focusable ? "true" : "false") << " " | 240 << (field.is_focusable ? "true" : "false") << " " |
| 236 << (field.should_autocomplete ? "true" : "false") << " " | 241 << (field.should_autocomplete ? "true" : "false") << " " |
| 237 << field.role << " " << field.text_direction; | 242 << field.role << " " << field.text_direction; |
| 238 } | 243 } |
| 239 | 244 |
| 240 } // namespace autofill | 245 } // namespace autofill |
| OLD | NEW |