OLD | NEW |
| (Empty) |
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. | |
4 | |
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. | |
12 | |
13 #ifndef CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
14 #define CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
15 | |
16 #include <string> | |
17 | |
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/Platform/chromium/public/WebData.h" | |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebTransformationMa
trix.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | |
25 #include "webkit/blob/blob_data.h" | |
26 #include "webkit/glue/npruntime_util.h" | |
27 #include "webkit/glue/resource_type.h" | |
28 #include "webkit/glue/webcursor.h" | |
29 #include "webkit/glue/window_open_disposition.h" | |
30 #include "webkit/plugins/webplugininfo.h" | |
31 | |
32 namespace webkit { | |
33 namespace forms { | |
34 struct PasswordForm; | |
35 } | |
36 } | |
37 | |
38 namespace webkit_glue { | |
39 struct ResourceDevToolsInfo; | |
40 struct ResourceLoadTimingInfo; | |
41 } | |
42 | |
43 // Define the NPVariant_Param struct and its enum here since it needs manual | |
44 // serialization code. | |
45 enum NPVariant_ParamEnum { | |
46 NPVARIANT_PARAM_VOID, | |
47 NPVARIANT_PARAM_NULL, | |
48 NPVARIANT_PARAM_BOOL, | |
49 NPVARIANT_PARAM_INT, | |
50 NPVARIANT_PARAM_DOUBLE, | |
51 NPVARIANT_PARAM_STRING, | |
52 // Used when when the NPObject is running in the caller's process, so we | |
53 // create an NPObjectProxy in the other process. | |
54 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, | |
55 // Used when the NPObject we're sending is running in the callee's process | |
56 // (i.e. we have an NPObjectProxy for it). In that case we want the callee | |
57 // to just use the raw pointer. | |
58 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, | |
59 }; | |
60 | |
61 struct NPVariant_Param { | |
62 NPVariant_Param(); | |
63 ~NPVariant_Param(); | |
64 | |
65 NPVariant_ParamEnum type; | |
66 bool bool_value; | |
67 int int_value; | |
68 double double_value; | |
69 std::string string_value; | |
70 int npobject_routing_id; | |
71 }; | |
72 | |
73 struct NPIdentifier_Param { | |
74 NPIdentifier_Param(); | |
75 ~NPIdentifier_Param(); | |
76 | |
77 NPIdentifier identifier; | |
78 }; | |
79 | |
80 namespace IPC { | |
81 | |
82 template <> | |
83 struct ParamTraits<WebKit::WebData> { | |
84 typedef WebKit::WebData param_type; | |
85 static void Write(Message* m, const param_type& p); | |
86 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
87 static void Log(const param_type& p, std::string* l); | |
88 }; | |
89 | |
90 template <> | |
91 struct ParamTraits<WebKit::WebTransformationMatrix> { | |
92 typedef WebKit::WebTransformationMatrix param_type; | |
93 static void Write(Message* m, const param_type& p); | |
94 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
95 static void Log(const param_type& p, std::string* l); | |
96 }; | |
97 | |
98 template <> | |
99 struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> { | |
100 typedef webkit_glue::ResourceLoadTimingInfo param_type; | |
101 static void Write(Message* m, const param_type& p); | |
102 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
103 static void Log(const param_type& p, std::string* l); | |
104 }; | |
105 | |
106 template <> | |
107 struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > { | |
108 typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type; | |
109 static void Write(Message* m, const param_type& p); | |
110 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
111 static void Log(const param_type& p, std::string* l); | |
112 }; | |
113 | |
114 template <> | |
115 struct ParamTraits<NPVariant_Param> { | |
116 typedef NPVariant_Param param_type; | |
117 static void Write(Message* m, const param_type& p); | |
118 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
119 static void Log(const param_type& p, std::string* l); | |
120 }; | |
121 | |
122 template <> | |
123 struct ParamTraits<NPIdentifier_Param> { | |
124 typedef NPIdentifier_Param param_type; | |
125 static void Write(Message* m, const param_type& p); | |
126 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
127 static void Log(const param_type& p, std::string* l); | |
128 }; | |
129 | |
130 template <> | |
131 struct ParamTraits<webkit::WebPluginMimeType> { | |
132 typedef webkit::WebPluginMimeType param_type; | |
133 static void Write(Message* m, const param_type& p); | |
134 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
135 static void Log(const param_type& p, std::string* l); | |
136 }; | |
137 | |
138 template <> | |
139 struct CONTENT_EXPORT ParamTraits<webkit::WebPluginInfo> { | |
140 typedef webkit::WebPluginInfo param_type; | |
141 static void Write(Message* m, const param_type& p); | |
142 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
143 static void Log(const param_type& p, std::string* l); | |
144 }; | |
145 | |
146 template <> | |
147 struct ParamTraits<WebCursor> { | |
148 typedef WebCursor param_type; | |
149 static void Write(Message* m, const param_type& p) { | |
150 p.Serialize(m); | |
151 } | |
152 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
153 return r->Deserialize(iter); | |
154 } | |
155 static void Log(const param_type& p, std::string* l) { | |
156 l->append("<WebCursor>"); | |
157 } | |
158 }; | |
159 | |
160 template <> | |
161 struct ParamTraits<WebKit::WebInputEvent::Type> { | |
162 typedef WebKit::WebInputEvent::Type param_type; | |
163 static void Write(Message* m, const param_type& p) { | |
164 m->WriteInt(p); | |
165 } | |
166 static bool Read(const Message* m, PickleIterator* iter, param_type* p) { | |
167 int type; | |
168 if (!m->ReadInt(iter, &type)) | |
169 return false; | |
170 *p = static_cast<WebKit::WebInputEvent::Type>(type); | |
171 return true; | |
172 } | |
173 static void Log(const param_type& p, std::string* l) { | |
174 const char* type; | |
175 switch (p) { | |
176 case WebKit::WebInputEvent::MouseDown: | |
177 type = "MouseDown"; | |
178 break; | |
179 case WebKit::WebInputEvent::MouseUp: | |
180 type = "MouseUp"; | |
181 break; | |
182 case WebKit::WebInputEvent::MouseMove: | |
183 type = "MouseMove"; | |
184 break; | |
185 case WebKit::WebInputEvent::MouseLeave: | |
186 type = "MouseLeave"; | |
187 break; | |
188 case WebKit::WebInputEvent::MouseEnter: | |
189 type = "MouseEnter"; | |
190 break; | |
191 case WebKit::WebInputEvent::MouseWheel: | |
192 type = "MouseWheel"; | |
193 break; | |
194 case WebKit::WebInputEvent::RawKeyDown: | |
195 type = "RawKeyDown"; | |
196 break; | |
197 case WebKit::WebInputEvent::KeyDown: | |
198 type = "KeyDown"; | |
199 break; | |
200 case WebKit::WebInputEvent::KeyUp: | |
201 type = "KeyUp"; | |
202 break; | |
203 default: | |
204 type = "None"; | |
205 break; | |
206 } | |
207 LogParam(std::string(type), l); | |
208 } | |
209 }; | |
210 | |
211 typedef const WebKit::WebInputEvent* WebInputEventPointer; | |
212 template <> | |
213 struct ParamTraits<WebInputEventPointer> { | |
214 typedef WebInputEventPointer param_type; | |
215 static void Write(Message* m, const param_type& p) { | |
216 m->WriteData(reinterpret_cast<const char*>(p), p->size); | |
217 } | |
218 // Note: upon read, the event has the lifetime of the message. | |
219 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
220 const char* data; | |
221 int data_length; | |
222 if (!m->ReadData(iter, &data, &data_length)) { | |
223 NOTREACHED(); | |
224 return false; | |
225 } | |
226 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) { | |
227 NOTREACHED(); | |
228 return false; | |
229 } | |
230 param_type event = reinterpret_cast<param_type>(data); | |
231 // Check that the data size matches that of the event (we check the latter | |
232 // in the delegate). | |
233 if (data_length != static_cast<int>(event->size)) { | |
234 NOTREACHED(); | |
235 return false; | |
236 } | |
237 *r = event; | |
238 return true; | |
239 } | |
240 static void Log(const param_type& p, std::string* l) { | |
241 l->append("("); | |
242 LogParam(p->size, l); | |
243 l->append(", "); | |
244 LogParam(p->type, l); | |
245 l->append(", "); | |
246 LogParam(p->timeStampSeconds, l); | |
247 l->append(")"); | |
248 } | |
249 }; | |
250 | |
251 template <> | |
252 struct SimilarTypeTraits<WebKit::WebTextDirection> { | |
253 typedef int Type; | |
254 }; | |
255 | |
256 template <> | |
257 struct SimilarTypeTraits<WindowOpenDisposition> { | |
258 typedef int Type; | |
259 }; | |
260 | |
261 template <> | |
262 struct CONTENT_EXPORT ParamTraits<webkit::forms::PasswordForm> { | |
263 typedef webkit::forms::PasswordForm param_type; | |
264 static void Write(Message* m, const param_type& p); | |
265 static bool Read(const Message* m, PickleIterator* iter, param_type* p); | |
266 static void Log(const param_type& p, std::string* l); | |
267 }; | |
268 | |
269 } // namespace IPC | |
270 | |
271 #endif // CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_ | |
OLD | NEW |