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

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

Issue 1671753004: [Autofill] Fill fields that have an autocomplete attributes even if not in a form. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added IPC Trait for new attribute Created 4 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/pickle.h" 12 #include "base/pickle.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/autofill/core/common/form_field_data.h" 15 #include "components/autofill/core/common/form_field_data.h"
16 16
17 namespace autofill { 17 namespace autofill {
18 18
19 namespace { 19 namespace {
20 20
21 const int kPickleVersion = 4; 21 const int kPickleVersion = 5;
22 22
23 bool ReadGURL(base::PickleIterator* iter, GURL* url) { 23 bool ReadGURL(base::PickleIterator* iter, GURL* url) {
24 std::string spec; 24 std::string spec;
25 if (!iter->ReadString(&spec)) 25 if (!iter->ReadString(&spec))
26 return false; 26 return false;
27 27
28 *url = GURL(spec); 28 *url = GURL(spec);
29 return true; 29 return true;
30 } 30 }
31 31
(...skipping 21 matching lines...) Expand all
53 return true; 53 return true;
54 } 54 }
55 55
56 void LogDeserializationError(int version) { 56 void LogDeserializationError(int version) {
57 DVLOG(1) << "Could not deserialize version " << version 57 DVLOG(1) << "Could not deserialize version " << version
58 << " FormData from pickle."; 58 << " FormData from pickle.";
59 } 59 }
60 60
61 } // namespace 61 } // namespace
62 62
63 FormData::FormData() 63 FormData::FormData() : is_form_tag(true), is_formless_checkout(false) {}
64 : is_form_tag(true) {
65 }
66 64
67 FormData::FormData(const FormData& data) 65 FormData::FormData(const FormData& data)
68 : name(data.name), 66 : name(data.name),
69 origin(data.origin), 67 origin(data.origin),
70 action(data.action), 68 action(data.action),
71 is_form_tag(data.is_form_tag), 69 is_form_tag(data.is_form_tag),
72 fields(data.fields) { 70 is_formless_checkout(data.is_formless_checkout),
73 } 71 fields(data.fields) {}
74 72
75 FormData::~FormData() { 73 FormData::~FormData() {
76 } 74 }
77 75
78 bool FormData::SameFormAs(const FormData& form) const { 76 bool FormData::SameFormAs(const FormData& form) const {
79 if (name != form.name || 77 if (name != form.name || origin != form.origin || action != form.action ||
80 origin != form.origin ||
81 action != form.action ||
82 is_form_tag != form.is_form_tag || 78 is_form_tag != form.is_form_tag ||
79 is_formless_checkout != form.is_formless_checkout ||
83 fields.size() != form.fields.size()) 80 fields.size() != form.fields.size())
84 return false; 81 return false;
85 for (size_t i = 0; i < fields.size(); ++i) { 82 for (size_t i = 0; i < fields.size(); ++i) {
86 if (!fields[i].SameFieldAs(form.fields[i])) 83 if (!fields[i].SameFieldAs(form.fields[i]))
87 return false; 84 return false;
88 } 85 }
89 return true; 86 return true;
90 } 87 }
91 88
92 bool FormData::operator<(const FormData& form) const { 89 bool FormData::operator<(const FormData& form) const {
93 return std::tie(name, origin, action, is_form_tag, fields) < 90 return std::tie(name, origin, action, is_form_tag, is_formless_checkout,
94 std::tie(form.name, form.origin, form.action, form.is_form_tag, 91 fields) < std::tie(form.name, form.origin, form.action,
95 form.fields); 92 form.is_form_tag,
93 form.is_formless_checkout, form.fields);
96 } 94 }
97 95
98 std::ostream& operator<<(std::ostream& os, const FormData& form) { 96 std::ostream& operator<<(std::ostream& os, const FormData& form) {
99 os << base::UTF16ToUTF8(form.name) << " " 97 os << base::UTF16ToUTF8(form.name) << " " << form.origin << " " << form.action
100 << form.origin << " " 98 << " " << form.is_form_tag << " " << form.is_formless_checkout << " "
101 << form.action << " "
102 << form.is_form_tag << " "
103 << "Fields:"; 99 << "Fields:";
104 for (size_t i = 0; i < form.fields.size(); ++i) { 100 for (size_t i = 0; i < form.fields.size(); ++i) {
105 os << form.fields[i] << ","; 101 os << form.fields[i] << ",";
106 } 102 }
107 return os; 103 return os;
108 } 104 }
109 105
110 void SerializeFormData(const FormData& form_data, base::Pickle* pickle) { 106 void SerializeFormData(const FormData& form_data, base::Pickle* pickle) {
111 pickle->WriteInt(kPickleVersion); 107 pickle->WriteInt(kPickleVersion);
112 pickle->WriteString16(form_data.name); 108 pickle->WriteString16(form_data.name);
113 pickle->WriteString(form_data.origin.spec()); 109 pickle->WriteString(form_data.origin.spec());
114 pickle->WriteString(form_data.action.spec()); 110 pickle->WriteString(form_data.action.spec());
115 SerializeFormFieldDataVector(form_data.fields, pickle); 111 SerializeFormFieldDataVector(form_data.fields, pickle);
116 pickle->WriteBool(form_data.is_form_tag); 112 pickle->WriteBool(form_data.is_form_tag);
113 pickle->WriteBool(form_data.is_formless_checkout);
117 } 114 }
118 115
119 void SerializeFormDataToBase64String(const FormData& form_data, 116 void SerializeFormDataToBase64String(const FormData& form_data,
120 std::string* output) { 117 std::string* output) {
121 base::Pickle pickle; 118 base::Pickle pickle;
122 SerializeFormData(form_data, &pickle); 119 SerializeFormData(form_data, &pickle);
123 Base64Encode( 120 Base64Encode(
124 base::StringPiece(static_cast<const char*>(pickle.data()), pickle.size()), 121 base::StringPiece(static_cast<const char*>(pickle.data()), pickle.size()),
125 output); 122 output);
126 } 123 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 160
164 if (version >= 3) { 161 if (version >= 3) {
165 if (!iter->ReadBool(&temp_form_data.is_form_tag)) { 162 if (!iter->ReadBool(&temp_form_data.is_form_tag)) {
166 LogDeserializationError(version); 163 LogDeserializationError(version);
167 return false; 164 return false;
168 } 165 }
169 } else { 166 } else {
170 form_data->is_form_tag = true; 167 form_data->is_form_tag = true;
171 } 168 }
172 169
170 if (version >= 5) {
171 if (!iter->ReadBool(&temp_form_data.is_formless_checkout)) {
172 LogDeserializationError(version);
173 return false;
174 }
175 }
176
173 *form_data = temp_form_data; 177 *form_data = temp_form_data;
174 return true; 178 return true;
175 } 179 }
176 180
177 bool DeserializeFormDataFromBase64String(const base::StringPiece& input, 181 bool DeserializeFormDataFromBase64String(const base::StringPiece& input,
178 FormData* form_data) { 182 FormData* form_data) {
179 if (input.empty()) 183 if (input.empty())
180 return false; 184 return false;
181 std::string pickle_data; 185 std::string pickle_data;
182 Base64Decode(input, &pickle_data); 186 Base64Decode(input, &pickle_data);
183 base::Pickle pickle(pickle_data.data(), static_cast<int>(pickle_data.size())); 187 base::Pickle pickle(pickle_data.data(), static_cast<int>(pickle_data.size()));
184 base::PickleIterator iter(pickle); 188 base::PickleIterator iter(pickle);
185 return DeserializeFormData(&iter, form_data); 189 return DeserializeFormData(&iter, form_data);
186 } 190 }
187 191
188 } // namespace autofill 192 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/form_data.h ('k') | components/autofill/core/common/form_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698