Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / content / public / common / webkit_param_traits.h
blobc819122702b54c27b0dbab6cc6d0f094a42f5d92
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 // This file is used to define IPC::ParamTraits<> specializations for a number
6 // of WebKit types so that they can be serialized over IPC. IPC::ParamTraits<>
7 // specializations for basic types (like int and std::string) and types in the
8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains
9 // specializations for types that are used by the content code, and which need
10 // manual serialization code. This is usually because they're not structs with
11 // public members.
13 #ifndef CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_
14 #define CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_
16 #include <string>
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "ipc/ipc_message_utils.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h"
23 #include "webkit/blob/blob_data.h"
24 #include "webkit/glue/npruntime_util.h"
25 #include "webkit/glue/resource_type.h"
26 #include "webkit/glue/webcursor.h"
27 #include "webkit/glue/window_open_disposition.h"
28 #include "webkit/plugins/webplugininfo.h"
30 namespace webkit {
31 namespace forms {
32 struct PasswordForm;
36 namespace webkit_glue {
37 struct ResourceDevToolsInfo;
38 struct ResourceLoadTimingInfo;
41 // Define the NPVariant_Param struct and its enum here since it needs manual
42 // serialization code.
43 enum NPVariant_ParamEnum {
44 NPVARIANT_PARAM_VOID,
45 NPVARIANT_PARAM_NULL,
46 NPVARIANT_PARAM_BOOL,
47 NPVARIANT_PARAM_INT,
48 NPVARIANT_PARAM_DOUBLE,
49 NPVARIANT_PARAM_STRING,
50 // Used when when the NPObject is running in the caller's process, so we
51 // create an NPObjectProxy in the other process.
52 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
53 // Used when the NPObject we're sending is running in the callee's process
54 // (i.e. we have an NPObjectProxy for it). In that case we want the callee
55 // to just use the raw pointer.
56 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
59 struct NPVariant_Param {
60 NPVariant_Param();
61 ~NPVariant_Param();
63 NPVariant_ParamEnum type;
64 bool bool_value;
65 int int_value;
66 double double_value;
67 std::string string_value;
68 int npobject_routing_id;
71 struct NPIdentifier_Param {
72 NPIdentifier_Param();
73 ~NPIdentifier_Param();
75 NPIdentifier identifier;
78 namespace IPC {
80 template <>
81 struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> {
82 typedef webkit_glue::ResourceLoadTimingInfo param_type;
83 static void Write(Message* m, const param_type& p);
84 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
85 static void Log(const param_type& p, std::string* l);
88 template <>
89 struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > {
90 typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type;
91 static void Write(Message* m, const param_type& p);
92 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
93 static void Log(const param_type& p, std::string* l);
96 template <>
97 struct ParamTraits<NPVariant_Param> {
98 typedef NPVariant_Param param_type;
99 static void Write(Message* m, const param_type& p);
100 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
101 static void Log(const param_type& p, std::string* l);
104 template <>
105 struct ParamTraits<NPIdentifier_Param> {
106 typedef NPIdentifier_Param param_type;
107 static void Write(Message* m, const param_type& p);
108 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
109 static void Log(const param_type& p, std::string* l);
112 template <>
113 struct ParamTraits<webkit::WebPluginMimeType> {
114 typedef webkit::WebPluginMimeType param_type;
115 static void Write(Message* m, const param_type& p);
116 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
117 static void Log(const param_type& p, std::string* l);
120 template <>
121 struct CONTENT_EXPORT ParamTraits<webkit::WebPluginInfo> {
122 typedef webkit::WebPluginInfo param_type;
123 static void Write(Message* m, const param_type& p);
124 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
125 static void Log(const param_type& p, std::string* l);
128 template <>
129 struct ParamTraits<WebCursor> {
130 typedef WebCursor param_type;
131 static void Write(Message* m, const param_type& p) {
132 p.Serialize(m);
134 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
135 return r->Deserialize(iter);
137 static void Log(const param_type& p, std::string* l) {
138 l->append("<WebCursor>");
142 template <>
143 struct ParamTraits<WebKit::WebInputEvent::Type> {
144 typedef WebKit::WebInputEvent::Type param_type;
145 static void Write(Message* m, const param_type& p) {
146 m->WriteInt(p);
148 static bool Read(const Message* m, PickleIterator* iter, param_type* p) {
149 int type;
150 if (!m->ReadInt(iter, &type))
151 return false;
152 *p = static_cast<WebKit::WebInputEvent::Type>(type);
153 return true;
155 static void Log(const param_type& p, std::string* l) {
156 const char* type;
157 switch (p) {
158 case WebKit::WebInputEvent::MouseDown:
159 type = "MouseDown";
160 break;
161 case WebKit::WebInputEvent::MouseUp:
162 type = "MouseUp";
163 break;
164 case WebKit::WebInputEvent::MouseMove:
165 type = "MouseMove";
166 break;
167 case WebKit::WebInputEvent::MouseLeave:
168 type = "MouseLeave";
169 break;
170 case WebKit::WebInputEvent::MouseEnter:
171 type = "MouseEnter";
172 break;
173 case WebKit::WebInputEvent::MouseWheel:
174 type = "MouseWheel";
175 break;
176 case WebKit::WebInputEvent::RawKeyDown:
177 type = "RawKeyDown";
178 break;
179 case WebKit::WebInputEvent::KeyDown:
180 type = "KeyDown";
181 break;
182 case WebKit::WebInputEvent::KeyUp:
183 type = "KeyUp";
184 break;
185 default:
186 type = "None";
187 break;
189 LogParam(std::string(type), l);
193 typedef const WebKit::WebInputEvent* WebInputEventPointer;
194 template <>
195 struct ParamTraits<WebInputEventPointer> {
196 typedef WebInputEventPointer param_type;
197 static void Write(Message* m, const param_type& p) {
198 m->WriteData(reinterpret_cast<const char*>(p), p->size);
200 // Note: upon read, the event has the lifetime of the message.
201 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
202 const char* data;
203 int data_length;
204 if (!m->ReadData(iter, &data, &data_length)) {
205 NOTREACHED();
206 return false;
208 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) {
209 NOTREACHED();
210 return false;
212 param_type event = reinterpret_cast<param_type>(data);
213 // Check that the data size matches that of the event (we check the latter
214 // in the delegate).
215 if (data_length != static_cast<int>(event->size)) {
216 NOTREACHED();
217 return false;
219 *r = event;
220 return true;
222 static void Log(const param_type& p, std::string* l) {
223 l->append("(");
224 LogParam(p->size, l);
225 l->append(", ");
226 LogParam(p->type, l);
227 l->append(", ");
228 LogParam(p->timeStampSeconds, l);
229 l->append(")");
233 template <>
234 struct SimilarTypeTraits<WebKit::WebTextDirection> {
235 typedef int Type;
238 template <>
239 struct SimilarTypeTraits<WindowOpenDisposition> {
240 typedef int Type;
243 template <>
244 struct CONTENT_EXPORT ParamTraits<webkit::forms::PasswordForm> {
245 typedef webkit::forms::PasswordForm param_type;
246 static void Write(Message* m, const param_type& p);
247 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
248 static void Log(const param_type& p, std::string* l);
251 } // namespace IPC
253 #endif // CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_