| Index: components/autofill/core/common/form_field_data.cc
|
| diff --git a/components/autofill/core/common/form_field_data.cc b/components/autofill/core/common/form_field_data.cc
|
| index 6e26b7f6ccbc3d1a867cbe1bf16370c24a384bad..992dd7abbd32da52bc83861f6e8dc424edc461b2 100644
|
| --- a/components/autofill/core/common/form_field_data.cc
|
| +++ b/components/autofill/core/common/form_field_data.cc
|
| @@ -14,7 +14,7 @@ namespace {
|
|
|
| // Increment this anytime pickle format is modified as well as provide
|
| // deserialization routine from previous kPickleVersion format.
|
| -const int kPickleVersion = 3;
|
| +const int kPickleVersion = 4;
|
|
|
| void AddVectorToPickle(std::vector<base::string16> strings,
|
| base::Pickle* pickle) {
|
| @@ -58,10 +58,31 @@ bool DeserializeSection1(base::PickleIterator* iter,
|
| iter->ReadString(&field_data->form_control_type) &&
|
| iter->ReadString(&field_data->autocomplete_attribute) &&
|
| iter->ReadUInt64(&field_data->max_length) &&
|
| - iter->ReadBool(&field_data->is_autofilled) &&
|
| - iter->ReadBool(&field_data->is_checked) &&
|
| - iter->ReadBool(&field_data->is_checkable) &&
|
| - iter->ReadBool(&field_data->is_focusable) &&
|
| + iter->ReadBool(&field_data->is_autofilled);
|
| +}
|
| +
|
| +bool DeserializeSection5(base::PickleIterator* iter,
|
| + FormFieldData* field_data) {
|
| + bool is_checked = false;
|
| + bool is_checkable = false;
|
| + const bool success =
|
| + iter->ReadBool(&is_checked) && iter->ReadBool(&is_checkable);
|
| +
|
| + if (success)
|
| + SetCheckStatus(field_data, is_checkable, is_checked);
|
| +
|
| + return success;
|
| +}
|
| +
|
| +bool DeserializeSection6(base::PickleIterator* iter,
|
| + FormFieldData* field_data) {
|
| + return ReadAsInt(iter, &field_data->check_status);
|
| + ;
|
| +}
|
| +
|
| +bool DeserializeSection7(base::PickleIterator* iter,
|
| + FormFieldData* field_data) {
|
| + return iter->ReadBool(&field_data->is_focusable) &&
|
| iter->ReadBool(&field_data->should_autocomplete);
|
| }
|
|
|
| @@ -87,13 +108,11 @@ bool DeserializeSection4(base::PickleIterator* iter,
|
| FormFieldData::FormFieldData()
|
| : max_length(0),
|
| is_autofilled(false),
|
| - is_checked(false),
|
| - is_checkable(false),
|
| + check_status(NOT_CHECKABLE),
|
| is_focusable(false),
|
| should_autocomplete(true),
|
| role(ROLE_ATTRIBUTE_OTHER),
|
| - text_direction(base::i18n::UNKNOWN_DIRECTION) {
|
| -}
|
| + text_direction(base::i18n::UNKNOWN_DIRECTION) {}
|
|
|
| FormFieldData::FormFieldData(const FormFieldData& other) = default;
|
|
|
| @@ -109,7 +128,7 @@ bool FormFieldData::SameFieldAs(const FormFieldData& field) const {
|
| placeholder == field.placeholder && max_length == field.max_length &&
|
| // is_checked and is_autofilled counts as "value" since these change
|
| // when we fill things in.
|
| - is_checkable == field.is_checkable &&
|
| + IsCheckable(check_status) == IsCheckable(field.check_status) &&
|
| is_focusable == field.is_focusable &&
|
| should_autocomplete == field.should_autocomplete &&
|
| role == field.role && text_direction == field.text_direction;
|
| @@ -142,8 +161,8 @@ bool FormFieldData::operator<(const FormFieldData& field) const {
|
| if (max_length < field.max_length) return true;
|
| if (max_length > field.max_length) return false;
|
| // Skip |is_checked| and |is_autofilled| as in SameFieldAs.
|
| - if (is_checkable < field.is_checkable) return true;
|
| - if (is_checkable > field.is_checkable) return false;
|
| + if (IsCheckable(check_status) < IsCheckable(field.check_status)) return true;
|
| + if (IsCheckable(check_status) > IsCheckable(field.check_status)) return false;
|
| if (is_focusable < field.is_focusable) return true;
|
| if (is_focusable > field.is_focusable) return false;
|
| if (should_autocomplete < field.should_autocomplete) return true;
|
| @@ -166,8 +185,7 @@ void SerializeFormFieldData(const FormFieldData& field_data,
|
| pickle->WriteString(field_data.autocomplete_attribute);
|
| pickle->WriteUInt64(field_data.max_length);
|
| pickle->WriteBool(field_data.is_autofilled);
|
| - pickle->WriteBool(field_data.is_checked);
|
| - pickle->WriteBool(field_data.is_checkable);
|
| + pickle->WriteInt(field_data.check_status);
|
| pickle->WriteBool(field_data.is_focusable);
|
| pickle->WriteBool(field_data.should_autocomplete);
|
| pickle->WriteInt(field_data.role);
|
| @@ -189,6 +207,8 @@ bool DeserializeFormFieldData(base::PickleIterator* iter,
|
| switch (version) {
|
| case 1: {
|
| if (!DeserializeSection1(iter, &temp_form_field_data) ||
|
| + !DeserializeSection5(iter, &temp_form_field_data) ||
|
| + !DeserializeSection7(iter, &temp_form_field_data) ||
|
| !DeserializeSection3(iter, &temp_form_field_data)) {
|
| LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
|
| return false;
|
| @@ -197,6 +217,8 @@ bool DeserializeFormFieldData(base::PickleIterator* iter,
|
| }
|
| case 2: {
|
| if (!DeserializeSection1(iter, &temp_form_field_data) ||
|
| + !DeserializeSection5(iter, &temp_form_field_data) ||
|
| + !DeserializeSection7(iter, &temp_form_field_data) ||
|
| !DeserializeSection2(iter, &temp_form_field_data) ||
|
| !DeserializeSection3(iter, &temp_form_field_data)) {
|
| LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
|
| @@ -206,6 +228,20 @@ bool DeserializeFormFieldData(base::PickleIterator* iter,
|
| }
|
| case 3: {
|
| if (!DeserializeSection1(iter, &temp_form_field_data) ||
|
| + !DeserializeSection5(iter, &temp_form_field_data) ||
|
| + !DeserializeSection7(iter, &temp_form_field_data) ||
|
| + !DeserializeSection2(iter, &temp_form_field_data) ||
|
| + !DeserializeSection3(iter, &temp_form_field_data) ||
|
| + !DeserializeSection4(iter, &temp_form_field_data)) {
|
| + LOG(ERROR) << "Could not deserialize FormFieldData from pickle";
|
| + return false;
|
| + }
|
| + break;
|
| + }
|
| + case 4: {
|
| + if (!DeserializeSection1(iter, &temp_form_field_data) ||
|
| + !DeserializeSection6(iter, &temp_form_field_data) ||
|
| + !DeserializeSection7(iter, &temp_form_field_data) ||
|
| !DeserializeSection2(iter, &temp_form_field_data) ||
|
| !DeserializeSection3(iter, &temp_form_field_data) ||
|
| !DeserializeSection4(iter, &temp_form_field_data)) {
|
| @@ -224,17 +260,61 @@ bool DeserializeFormFieldData(base::PickleIterator* iter,
|
| }
|
|
|
| std::ostream& operator<<(std::ostream& os, const FormFieldData& field) {
|
| + std::string check_status_str;
|
| + switch (field.check_status) {
|
| + case FormFieldData::CheckStatus::NOT_CHECKABLE:
|
| + check_status_str = "NOT_CHECKABLE";
|
| + break;
|
| + case FormFieldData::CheckStatus::CHECKABLE_BUT_UNCHECKED:
|
| + check_status_str = "CHECKABLE_BUT_UNCHECKED";
|
| + break;
|
| + case FormFieldData::CheckStatus::CHECKED:
|
| + check_status_str = "CHECKED";
|
| + break;
|
| + }
|
| +
|
| + std::string role_str;
|
| + switch (field.role) {
|
| + case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_PRESENTATION:
|
| + role_str = "ROLE_ATTRIBUTE_PRESENTATION";
|
| + break;
|
| + case FormFieldData::RoleAttribute::ROLE_ATTRIBUTE_OTHER:
|
| + role_str = "ROLE_ATTRIBUTE_OTHER";
|
| + break;
|
| + }
|
| +
|
| return os << base::UTF16ToUTF8(field.label) << " "
|
| << base::UTF16ToUTF8(field.name) << " "
|
| << base::UTF16ToUTF8(field.value) << " " << field.form_control_type
|
| << " " << field.autocomplete_attribute << " " << field.placeholder
|
| << " " << field.max_length << " "
|
| << (field.is_autofilled ? "true" : "false") << " "
|
| - << (field.is_checked ? "true" : "false") << " "
|
| - << (field.is_checkable ? "true" : "false") << " "
|
| - << (field.is_focusable ? "true" : "false") << " "
|
| - << (field.should_autocomplete ? "true" : "false") << " "
|
| - << field.role << " " << field.text_direction;
|
| + << check_status_str << (field.is_focusable ? "true" : "false")
|
| + << " " << (field.should_autocomplete ? "true" : "false") << " "
|
| + << role_str << " " << field.text_direction;
|
| +}
|
| +
|
| +bool IsCheckable(const FormFieldData::CheckStatus& check_status) {
|
| + return check_status != FormFieldData::CheckStatus::NOT_CHECKABLE;
|
| +}
|
| +
|
| +bool IsChecked(const FormFieldData::CheckStatus& check_status) {
|
| + return check_status == FormFieldData::CheckStatus::CHECKED;
|
| +}
|
| +
|
| +void SetCheckStatus(FormFieldData* form_field_data,
|
| + bool isCheckable,
|
| + bool isChecked) {
|
| + if (isChecked) {
|
| + form_field_data->check_status = FormFieldData::CheckStatus::CHECKED;
|
| + } else {
|
| + if (isCheckable) {
|
| + form_field_data->check_status =
|
| + FormFieldData::CheckStatus::CHECKABLE_BUT_UNCHECKED;
|
| + } else {
|
| + form_field_data->check_status = FormFieldData::CheckStatus::NOT_CHECKABLE;
|
| + }
|
| + }
|
| }
|
|
|
| } // namespace autofill
|
|
|