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

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

Issue 853523004: Autofill: Set requirements for number of recognized fields in an autofillable form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, change variable name Created 5 years, 10 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_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"
11 11
12 namespace autofill { 12 namespace autofill {
13 13
14 namespace { 14 namespace {
15 15
16 const int kPickleVersion = 2; 16 const int kPickleVersion = 3;
17 17
18 bool ReadGURL(PickleIterator* iter, GURL* url) { 18 bool ReadGURL(PickleIterator* iter, GURL* url) {
19 std::string spec; 19 std::string spec;
20 if (!iter->ReadString(&spec)) 20 if (!iter->ReadString(&spec))
21 return false; 21 return false;
22 22
23 *url = GURL(spec); 23 *url = GURL(spec);
24 return true; 24 return true;
25 } 25 }
26 26
(...skipping 22 matching lines...) Expand all
49 } 49 }
50 50
51 void LogDeserializationError(int version) { 51 void LogDeserializationError(int version) {
52 DVLOG(1) << "Could not deserialize version " << version 52 DVLOG(1) << "Could not deserialize version " << version
53 << " FormData from pickle."; 53 << " FormData from pickle.";
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 FormData::FormData() 58 FormData::FormData()
59 : user_submitted(false) { 59 : user_submitted(false),
60 is_form_tag(true) {
60 } 61 }
61 62
62 FormData::FormData(const FormData& data) 63 FormData::FormData(const FormData& data)
63 : name(data.name), 64 : name(data.name),
64 origin(data.origin), 65 origin(data.origin),
65 action(data.action), 66 action(data.action),
66 user_submitted(data.user_submitted), 67 user_submitted(data.user_submitted),
68 is_form_tag(data.is_form_tag),
67 fields(data.fields) { 69 fields(data.fields) {
68 } 70 }
69 71
70 FormData::~FormData() { 72 FormData::~FormData() {
71 } 73 }
72 74
73 bool FormData::SameFormAs(const FormData& form) const { 75 bool FormData::SameFormAs(const FormData& form) const {
74 if (name != form.name || 76 if (name != form.name ||
75 origin != form.origin || 77 origin != form.origin ||
76 action != form.action || 78 action != form.action ||
77 user_submitted != form.user_submitted || 79 user_submitted != form.user_submitted ||
80 is_form_tag != form.is_form_tag ||
78 fields.size() != form.fields.size()) 81 fields.size() != form.fields.size())
79 return false; 82 return false;
80 for (size_t i = 0; i < fields.size(); ++i) { 83 for (size_t i = 0; i < fields.size(); ++i) {
81 if (!fields[i].SameFieldAs(form.fields[i])) 84 if (!fields[i].SameFieldAs(form.fields[i]))
82 return false; 85 return false;
83 } 86 }
84 return true; 87 return true;
85 } 88 }
86 89
87 bool FormData::operator<(const FormData& form) const { 90 bool FormData::operator<(const FormData& form) const {
88 if (name != form.name) 91 if (name != form.name)
89 return name < form.name; 92 return name < form.name;
90 if (origin != form.origin) 93 if (origin != form.origin)
91 return origin < form.origin; 94 return origin < form.origin;
92 if (action != form.action) 95 if (action != form.action)
93 return action < form.action; 96 return action < form.action;
94 if (user_submitted != form.user_submitted) 97 if (user_submitted != form.user_submitted)
95 return user_submitted < form.user_submitted; 98 return user_submitted < form.user_submitted;
99 if (is_form_tag != form.is_form_tag)
100 return is_form_tag < form.is_form_tag;
96 return fields < form.fields; 101 return fields < form.fields;
97 } 102 }
98 103
99 std::ostream& operator<<(std::ostream& os, const FormData& form) { 104 std::ostream& operator<<(std::ostream& os, const FormData& form) {
100 os << base::UTF16ToUTF8(form.name) << " " 105 os << base::UTF16ToUTF8(form.name) << " "
101 << form.origin << " " 106 << form.origin << " "
102 << form.action << " " 107 << form.action << " "
103 << form.user_submitted << " " 108 << form.user_submitted << " "
109 << form.is_form_tag << " "
104 << "Fields:"; 110 << "Fields:";
105 for (size_t i = 0; i < form.fields.size(); ++i) { 111 for (size_t i = 0; i < form.fields.size(); ++i) {
106 os << form.fields[i] << ","; 112 os << form.fields[i] << ",";
107 } 113 }
108 return os; 114 return os;
109 } 115 }
110 116
111 void SerializeFormData(const FormData& form_data, Pickle* pickle) { 117 void SerializeFormData(const FormData& form_data, Pickle* pickle) {
112 pickle->WriteInt(kPickleVersion); 118 pickle->WriteInt(kPickleVersion);
113 pickle->WriteString16(form_data.name); 119 pickle->WriteString16(form_data.name);
114 pickle->WriteString(form_data.origin.spec()); 120 pickle->WriteString(form_data.origin.spec());
115 pickle->WriteString(form_data.action.spec()); 121 pickle->WriteString(form_data.action.spec());
116 pickle->WriteBool(form_data.user_submitted); 122 pickle->WriteBool(form_data.user_submitted);
117 SerializeFormFieldDataVector(form_data.fields, pickle); 123 SerializeFormFieldDataVector(form_data.fields, pickle);
124 pickle->WriteBool(form_data.is_form_tag);
118 } 125 }
119 126
120 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) { 127 bool DeserializeFormData(PickleIterator* iter, FormData* form_data) {
121 int version; 128 int version;
122 if (!iter->ReadInt(&version)) { 129 if (!iter->ReadInt(&version)) {
123 DVLOG(1) << "Bad pickle of FormData, no version present"; 130 DVLOG(1) << "Bad pickle of FormData, no version present";
124 return false; 131 return false;
125 } 132 }
126 133
127 switch (version) { 134 if (version < 1 || version > kPickleVersion) {
128 case 1: { 135 DVLOG(1) << "Unknown FormData pickle version " << version;
129 base::string16 method; 136 return false;
130 if (!iter->ReadString16(&form_data->name) || 137 }
131 !iter->ReadString16(&method) || 138
132 !ReadGURL(iter, &form_data->origin) || 139 if (!iter->ReadString16(&form_data->name)) {
133 !ReadGURL(iter, &form_data->action) || 140 LogDeserializationError(version);
134 !iter->ReadBool(&form_data->user_submitted) || 141 return false;
135 !DeserializeFormFieldDataVector(iter, &form_data->fields)) { 142 }
136 LogDeserializationError(version); 143
137 return false; 144 if (version == 1) {
138 } 145 base::string16 method;
139 break; 146 if (!iter->ReadString16(&method)) {
140 } 147 LogDeserializationError(version);
141 case 2:
142 if (!iter->ReadString16(&form_data->name) ||
143 !ReadGURL(iter, &form_data->origin) ||
144 !ReadGURL(iter, &form_data->action) ||
145 !iter->ReadBool(&form_data->user_submitted) ||
146 !DeserializeFormFieldDataVector(iter, &form_data->fields)) {
147 LogDeserializationError(version);
148 return false;
149 }
150 break;
151 default: {
152 DVLOG(1) << "Unknown FormData pickle version " << version;
153 return false; 148 return false;
154 } 149 }
155 } 150 }
151
152 if (!ReadGURL(iter, &form_data->origin) ||
153 !ReadGURL(iter, &form_data->action) ||
154 !iter->ReadBool(&form_data->user_submitted) ||
155 !DeserializeFormFieldDataVector(iter, &form_data->fields)) {
156 LogDeserializationError(version);
157 return false;
158 }
159
160 if (version == 3) {
161 if (!iter->ReadBool(&form_data->is_form_tag)) {
162 LogDeserializationError(version);
163 return false;
164 }
165 } else {
166 form_data->is_form_tag = true;
167 }
168
156 return true; 169 return true;
157 } 170 }
158 171
159 } // namespace autofill 172 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698