Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / content / public / common / webkit_param_traits.cc
blob5d586d8f4f32f3c350777bc7097c91880d25aef5
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // NOTE: New trait definitions that will be used by Chrome Frame must be placed
6 // in common_param_traits2.cc.
8 #include "content/public/common/webkit_param_traits.h"
10 #include "base/string_number_conversions.h"
11 #include "content/public/common/common_param_traits.h"
12 #include "content/public/common/content_constants.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
14 #include "webkit/forms/password_form.h"
15 #include "webkit/glue/resource_loader_bridge.h"
16 #include "webkit/plugins/npapi/plugin_host.h"
18 NPIdentifier_Param::NPIdentifier_Param()
19 : identifier() {
22 NPIdentifier_Param::~NPIdentifier_Param() {
25 NPVariant_Param::NPVariant_Param()
26 : type(NPVARIANT_PARAM_VOID),
27 bool_value(false),
28 int_value(0),
29 double_value(0),
30 npobject_routing_id(-1) {
33 NPVariant_Param::~NPVariant_Param() {
36 namespace IPC {
38 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Write(
39 Message* m, const param_type& p) {
40 WriteParam(m, p.base_time.is_null());
41 if (p.base_time.is_null())
42 return;
43 WriteParam(m, p.base_ticks);
44 WriteParam(m, p.base_time);
45 WriteParam(m, p.proxy_start);
46 WriteParam(m, p.proxy_end);
47 WriteParam(m, p.dns_start);
48 WriteParam(m, p.dns_end);
49 WriteParam(m, p.connect_start);
50 WriteParam(m, p.connect_end);
51 WriteParam(m, p.ssl_start);
52 WriteParam(m, p.ssl_end);
53 WriteParam(m, p.send_start);
54 WriteParam(m, p.send_end);
55 WriteParam(m, p.receive_headers_start);
56 WriteParam(m, p.receive_headers_end);
59 bool ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Read(
60 const Message* m, PickleIterator* iter, param_type* r) {
61 bool is_null;
62 if (!ReadParam(m, iter, &is_null))
63 return false;
64 if (is_null)
65 return true;
67 return
68 ReadParam(m, iter, &r->base_ticks) &&
69 ReadParam(m, iter, &r->base_time) &&
70 ReadParam(m, iter, &r->proxy_start) &&
71 ReadParam(m, iter, &r->proxy_end) &&
72 ReadParam(m, iter, &r->dns_start) &&
73 ReadParam(m, iter, &r->dns_end) &&
74 ReadParam(m, iter, &r->connect_start) &&
75 ReadParam(m, iter, &r->connect_end) &&
76 ReadParam(m, iter, &r->ssl_start) &&
77 ReadParam(m, iter, &r->ssl_end) &&
78 ReadParam(m, iter, &r->send_start) &&
79 ReadParam(m, iter, &r->send_end) &&
80 ReadParam(m, iter, &r->receive_headers_start) &&
81 ReadParam(m, iter, &r->receive_headers_end);
84 void ParamTraits<webkit_glue::ResourceLoadTimingInfo>::Log(const param_type& p,
85 std::string* l) {
86 l->append("(");
87 LogParam(p.base_ticks, l);
88 l->append(", ");
89 LogParam(p.base_time, l);
90 l->append(", ");
91 LogParam(p.proxy_start, l);
92 l->append(", ");
93 LogParam(p.proxy_end, l);
94 l->append(", ");
95 LogParam(p.dns_start, l);
96 l->append(", ");
97 LogParam(p.dns_end, l);
98 l->append(", ");
99 LogParam(p.connect_start, l);
100 l->append(", ");
101 LogParam(p.connect_end, l);
102 l->append(", ");
103 LogParam(p.ssl_start, l);
104 l->append(", ");
105 LogParam(p.ssl_end, l);
106 l->append(", ");
107 LogParam(p.send_start, l);
108 l->append(", ");
109 LogParam(p.send_end, l);
110 l->append(", ");
111 LogParam(p.receive_headers_start, l);
112 l->append(", ");
113 LogParam(p.receive_headers_end, l);
114 l->append(")");
117 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Write(
118 Message* m, const param_type& p) {
119 WriteParam(m, p.get() != NULL);
120 if (p.get()) {
121 WriteParam(m, p->http_status_code);
122 WriteParam(m, p->http_status_text);
123 WriteParam(m, p->request_headers);
124 WriteParam(m, p->response_headers);
125 WriteParam(m, p->request_headers_text);
126 WriteParam(m, p->response_headers_text);
130 bool ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Read(
131 const Message* m, PickleIterator* iter, param_type* r) {
132 bool has_object;
133 if (!ReadParam(m, iter, &has_object))
134 return false;
135 if (!has_object)
136 return true;
137 *r = new webkit_glue::ResourceDevToolsInfo();
138 return
139 ReadParam(m, iter, &(*r)->http_status_code) &&
140 ReadParam(m, iter, &(*r)->http_status_text) &&
141 ReadParam(m, iter, &(*r)->request_headers) &&
142 ReadParam(m, iter, &(*r)->response_headers) &&
143 ReadParam(m, iter, &(*r)->request_headers_text) &&
144 ReadParam(m, iter, &(*r)->response_headers_text);
147 void ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> >::Log(
148 const param_type& p, std::string* l) {
149 l->append("(");
150 if (p) {
151 LogParam(p->request_headers, l);
152 l->append(", ");
153 LogParam(p->response_headers, l);
155 l->append(")");
158 void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) {
159 WriteParam(m, static_cast<int>(p.type));
160 if (p.type == NPVARIANT_PARAM_BOOL) {
161 WriteParam(m, p.bool_value);
162 } else if (p.type == NPVARIANT_PARAM_INT) {
163 WriteParam(m, p.int_value);
164 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
165 WriteParam(m, p.double_value);
166 } else if (p.type == NPVARIANT_PARAM_STRING) {
167 WriteParam(m, p.string_value);
168 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
169 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
170 // This is the routing id used to connect NPObjectProxy in the other
171 // process with NPObjectStub in this process or to identify the raw
172 // npobject pointer to be used in the callee process.
173 WriteParam(m, p.npobject_routing_id);
174 } else {
175 DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL);
179 bool ParamTraits<NPVariant_Param>::Read(const Message* m,
180 PickleIterator* iter,
181 param_type* r) {
182 int type;
183 if (!ReadParam(m, iter, &type))
184 return false;
186 bool result = false;
187 r->type = static_cast<NPVariant_ParamEnum>(type);
188 if (r->type == NPVARIANT_PARAM_BOOL) {
189 result = ReadParam(m, iter, &r->bool_value);
190 } else if (r->type == NPVARIANT_PARAM_INT) {
191 result = ReadParam(m, iter, &r->int_value);
192 } else if (r->type == NPVARIANT_PARAM_DOUBLE) {
193 result = ReadParam(m, iter, &r->double_value);
194 } else if (r->type == NPVARIANT_PARAM_STRING) {
195 result = ReadParam(m, iter, &r->string_value);
196 } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
197 r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
198 result = ReadParam(m, iter, &r->npobject_routing_id);
199 } else if ((r->type == NPVARIANT_PARAM_VOID) ||
200 (r->type == NPVARIANT_PARAM_NULL)) {
201 result = true;
202 } else {
203 NOTREACHED();
206 return result;
209 void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) {
210 l->append(StringPrintf("NPVariant_Param(%d, ", static_cast<int>(p.type)));
211 if (p.type == NPVARIANT_PARAM_BOOL) {
212 LogParam(p.bool_value, l);
213 } else if (p.type == NPVARIANT_PARAM_INT) {
214 LogParam(p.int_value, l);
215 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
216 LogParam(p.double_value, l);
217 } else if (p.type == NPVARIANT_PARAM_STRING) {
218 LogParam(p.string_value, l);
219 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
220 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
221 LogParam(p.npobject_routing_id, l);
222 } else {
223 l->append("<none>");
225 l->append(")");
228 void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) {
229 webkit_glue::SerializeNPIdentifier(p.identifier, m);
232 bool ParamTraits<NPIdentifier_Param>::Read(const Message* m,
233 PickleIterator* iter,
234 param_type* r) {
235 return webkit_glue::DeserializeNPIdentifier(iter, &r->identifier);
238 void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) {
239 if (WebKit::WebBindings::identifierIsString(p.identifier)) {
240 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier);
241 l->append(str);
242 webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(str);
243 } else {
244 l->append(base::IntToString(
245 WebKit::WebBindings::intFromIdentifier(p.identifier)));
249 void ParamTraits<webkit::WebPluginMimeType>::Write(Message* m,
250 const param_type& p) {
251 WriteParam(m, p.mime_type);
252 WriteParam(m, p.file_extensions);
253 WriteParam(m, p.description);
254 WriteParam(m, p.additional_param_names);
255 WriteParam(m, p.additional_param_values);
258 bool ParamTraits<webkit::WebPluginMimeType>::Read(const Message* m,
259 PickleIterator* iter,
260 param_type* p) {
261 return
262 ReadParam(m, iter, &p->mime_type) &&
263 ReadParam(m, iter, &p->file_extensions) &&
264 ReadParam(m, iter, &p->description) &&
265 ReadParam(m, iter, &p->additional_param_names) &&
266 ReadParam(m, iter, &p->additional_param_values);
269 void ParamTraits<webkit::WebPluginMimeType>::Log(
270 const param_type& p, std::string* l) {
271 l->append("(");
272 LogParam(p.mime_type, l); l->append(", ");
273 LogParam(p.file_extensions, l); l->append(", ");
274 LogParam(p.description, l); l->append(", ");
275 LogParam(p.additional_param_names, l); l->append(", ");
276 LogParam(p.additional_param_values, l);
277 l->append(")");
280 void ParamTraits<webkit::WebPluginInfo>::Write(Message* m,
281 const param_type& p) {
282 WriteParam(m, p.name);
283 WriteParam(m, p.path);
284 WriteParam(m, p.version);
285 WriteParam(m, p.desc);
286 WriteParam(m, p.mime_types);
287 WriteParam(m, p.type);
290 bool ParamTraits<webkit::WebPluginInfo>::Read(const Message* m,
291 PickleIterator* iter,
292 param_type* p) {
293 return
294 ReadParam(m, iter, &p->name) &&
295 ReadParam(m, iter, &p->path) &&
296 ReadParam(m, iter, &p->version) &&
297 ReadParam(m, iter, &p->desc) &&
298 ReadParam(m, iter, &p->mime_types) &&
299 ReadParam(m, iter, &p->type);
301 void ParamTraits<webkit::WebPluginInfo>::Log(const param_type& p,
302 std::string* l) {
303 l->append("(");
304 LogParam(p.name, l); l->append(", ");
305 LogParam(p.path, l); l->append(", ");
306 LogParam(p.version, l); l->append(", ");
307 LogParam(p.desc, l); l->append(", ");
308 LogParam(p.mime_types, l); l->append(", ");
309 LogParam(p.type, l);
310 l->append(")");
313 void ParamTraits<webkit::forms::PasswordForm>::Write(Message* m,
314 const param_type& p) {
315 WriteParam(m, p.signon_realm);
316 WriteParam(m, p.origin);
317 WriteParam(m, p.action);
318 WriteParam(m, p.submit_element);
319 WriteParam(m, p.username_element);
320 WriteParam(m, p.username_value);
321 WriteParam(m, p.password_element);
322 WriteParam(m, p.password_value);
323 WriteParam(m, p.old_password_element);
324 WriteParam(m, p.old_password_value);
325 WriteParam(m, p.ssl_valid);
326 WriteParam(m, p.preferred);
327 WriteParam(m, p.blacklisted_by_user);
330 bool ParamTraits<webkit::forms::PasswordForm>::Read(const Message* m,
331 PickleIterator* iter,
332 param_type* p) {
333 return
334 ReadParam(m, iter, &p->signon_realm) &&
335 ReadParam(m, iter, &p->origin) &&
336 ReadParam(m, iter, &p->action) &&
337 ReadParam(m, iter, &p->submit_element) &&
338 ReadParam(m, iter, &p->username_element) &&
339 ReadParam(m, iter, &p->username_value) &&
340 ReadParam(m, iter, &p->password_element) &&
341 ReadParam(m, iter, &p->password_value) &&
342 ReadParam(m, iter, &p->old_password_element) &&
343 ReadParam(m, iter, &p->old_password_value) &&
344 ReadParam(m, iter, &p->ssl_valid) &&
345 ReadParam(m, iter, &p->preferred) &&
346 ReadParam(m, iter, &p->blacklisted_by_user);
348 void ParamTraits<webkit::forms::PasswordForm>::Log(const param_type& p,
349 std::string* l) {
350 l->append("<PasswordForm>");
353 } // namespace IPC