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_data.h" | 5 #include "components/autofill/core/common/form_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/form_field_data.h" | 10 #include "components/autofill/core/common/form_field_data.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 origin(data.origin), | 64 origin(data.origin), |
65 action(data.action), | 65 action(data.action), |
66 user_submitted(data.user_submitted), | 66 user_submitted(data.user_submitted), |
67 fields(data.fields) { | 67 fields(data.fields) { |
68 } | 68 } |
69 | 69 |
70 FormData::~FormData() { | 70 FormData::~FormData() { |
71 } | 71 } |
72 | 72 |
73 bool FormData::operator==(const FormData& form) const { | 73 bool FormData::operator==(const FormData& form) const { |
74 return name == form.name && | 74 return name == form.name && origin == form.origin && action == form.action && |
75 origin == form.origin && | 75 user_submitted == form.user_submitted && username == form.username && |
76 action == form.action && | 76 password == form.password && fields == form.fields; |
77 user_submitted == form.user_submitted && | |
78 fields == form.fields; | |
79 } | 77 } |
80 | 78 |
81 bool FormData::operator!=(const FormData& form) const { | 79 bool FormData::operator!=(const FormData& form) const { |
82 return !operator==(form); | 80 return !operator==(form); |
83 } | 81 } |
84 | 82 |
85 bool FormData::operator<(const FormData& form) const { | 83 bool FormData::operator<(const FormData& form) const { |
86 if (name != form.name) | 84 if (name != form.name) |
87 return name < form.name; | 85 return name < form.name; |
88 if (origin != form.origin) | 86 if (origin != form.origin) |
89 return origin < form.origin; | 87 return origin < form.origin; |
90 if (action != form.action) | 88 if (action != form.action) |
91 return action < form.action; | 89 return action < form.action; |
92 if (user_submitted != form.user_submitted) | 90 if (user_submitted != form.user_submitted) |
93 return user_submitted < form.user_submitted; | 91 return user_submitted < form.user_submitted; |
94 return fields < form.fields; | 92 return fields < form.fields; |
95 } | 93 } |
96 | 94 |
97 std::ostream& operator<<(std::ostream& os, const FormData& form) { | 95 std::ostream& operator<<(std::ostream& os, const FormData& form) { |
98 os << base::UTF16ToUTF8(form.name) << " " | 96 os << base::UTF16ToUTF8(form.name) << " " << form.origin << " " << form.action |
99 << form.origin << " " | 97 << " " << form.user_submitted << " " << form.username << " " |
100 << form.action << " " | 98 << form.password << " " |
101 << form.user_submitted << " " | |
102 << "Fields:"; | 99 << "Fields:"; |
103 for (size_t i = 0; i < form.fields.size(); ++i) { | 100 for (size_t i = 0; i < form.fields.size(); ++i) { |
104 os << form.fields[i] << ","; | 101 os << form.fields[i] << ","; |
105 } | 102 } |
106 return os; | 103 return os; |
107 } | 104 } |
108 | 105 |
109 void SerializeFormData(const FormData& form_data, Pickle* pickle) { | 106 void SerializeFormData(const FormData& form_data, Pickle* pickle) { |
110 pickle->WriteInt(kPickleVersion); | 107 pickle->WriteInt(kPickleVersion); |
111 pickle->WriteString16(form_data.name); | 108 pickle->WriteString16(form_data.name); |
112 pickle->WriteString(form_data.origin.spec()); | 109 pickle->WriteString(form_data.origin.spec()); |
113 pickle->WriteString(form_data.action.spec()); | 110 pickle->WriteString(form_data.action.spec()); |
114 pickle->WriteBool(form_data.user_submitted); | 111 pickle->WriteBool(form_data.user_submitted); |
| 112 SerializeFormFieldData(form_data.username, pickle); |
| 113 SerializeFormFieldData(form_data.password, pickle); |
115 SerializeFormFieldDataVector(form_data.fields, pickle); | 114 SerializeFormFieldDataVector(form_data.fields, pickle); |
116 } | 115 } |
117 | 116 |
118 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { | 117 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { |
119 int version; | 118 int version; |
120 if (!iter->ReadInt(&version)) { | 119 if (!iter->ReadInt(&version)) { |
121 DVLOG(1) << "Bad pickle of FormData, no version present"; | 120 DVLOG(1) << "Bad pickle of FormData, no version present"; |
122 return false; | 121 return false; |
123 } | 122 } |
124 | 123 |
125 switch (version) { | 124 switch (version) { |
126 case 1: { | 125 case 1: { |
127 base::string16 method; | 126 base::string16 method; |
128 if (!iter->ReadString16(&form_data->name) || | 127 if (!iter->ReadString16(&form_data->name) || |
129 !iter->ReadString16(&method) || | 128 !iter->ReadString16(&method) || !ReadGURL(iter, &form_data->origin) || |
130 !ReadGURL(iter, &form_data->origin) || | |
131 !ReadGURL(iter, &form_data->action) || | 129 !ReadGURL(iter, &form_data->action) || |
132 !iter->ReadBool(&form_data->user_submitted) || | 130 !iter->ReadBool(&form_data->user_submitted) || |
| 131 !DeserializeFormFieldData(iter, &form_data->username) || |
| 132 !DeserializeFormFieldData(iter, &form_data->password) || |
133 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { | 133 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { |
134 LogDeserializationError(version); | 134 LogDeserializationError(version); |
135 return false; | 135 return false; |
136 } | 136 } |
137 break; | 137 break; |
138 } | 138 } |
139 case 2: | 139 case 2: |
140 if (!iter->ReadString16(&form_data->name) || | 140 if (!iter->ReadString16(&form_data->name) || |
141 !ReadGURL(iter, &form_data->origin) || | 141 !ReadGURL(iter, &form_data->origin) || |
142 !ReadGURL(iter, &form_data->action) || | 142 !ReadGURL(iter, &form_data->action) || |
143 !iter->ReadBool(&form_data->user_submitted) || | 143 !iter->ReadBool(&form_data->user_submitted) || |
| 144 !DeserializeFormFieldData(iter, &form_data->username) || |
| 145 !DeserializeFormFieldData(iter, &form_data->password) || |
144 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { | 146 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { |
145 LogDeserializationError(version); | 147 LogDeserializationError(version); |
146 return false; | 148 return false; |
147 } | 149 } |
148 break; | 150 break; |
149 default: { | 151 default: { |
150 DVLOG(1) << "Unknown FormData pickle version " << version; | 152 DVLOG(1) << "Unknown FormData pickle version " << version; |
151 return false; | 153 return false; |
152 } | 154 } |
153 } | 155 } |
154 return true; | 156 return true; |
155 } | 157 } |
156 | 158 |
157 } // namespace autofill | 159 } // namespace autofill |
OLD | NEW |