OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file is used to define IPC::ParamTraits<> specializations for a number | 5 // This file is used to define IPC::ParamTraits<> specializations for a number |
6 // of types so that they can be serialized over IPC. IPC::ParamTraits<> | 6 // of 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 | 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 | 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 | 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 | 10 // manual serialization code. This is usually because they're not structs with |
11 // public members.. | 11 // public members.. |
12 | 12 |
13 #ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ | 13 #ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ |
14 #define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ | 14 #define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ |
15 #pragma once | 15 #pragma once |
16 | 16 |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/platform_file.h" | 18 #include "base/platform_file.h" |
19 #include "base/string_number_conversions.h" | |
20 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
21 #include "ipc/ipc_message_utils.h" | 20 #include "ipc/ipc_message_utils.h" |
22 #include "net/base/ip_endpoint.h" | 21 #include "net/base/ip_endpoint.h" |
23 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebTextDirection.h" | |
26 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
27 #include "ui/gfx/surface/transport_dib.h" | 24 #include "ui/gfx/surface/transport_dib.h" |
28 #include "webkit/blob/blob_data.h" | |
29 #include "webkit/glue/npruntime_util.h" | |
30 #include "webkit/glue/resource_type.h" | 25 #include "webkit/glue/resource_type.h" |
31 #include "webkit/glue/webcursor.h" | |
32 #include "webkit/glue/window_open_disposition.h" | |
33 | 26 |
34 class SkBitmap; | 27 class SkBitmap; |
35 | 28 |
36 namespace gfx { | 29 namespace gfx { |
37 class Point; | 30 class Point; |
38 class Rect; | 31 class Rect; |
39 class Size; | 32 class Size; |
40 } // namespace gfx | 33 } // namespace gfx |
41 | 34 |
42 namespace net { | 35 namespace net { |
43 class HttpResponseHeaders; | 36 class HttpResponseHeaders; |
44 class HostPortPair; | 37 class HostPortPair; |
45 class UploadData; | 38 class UploadData; |
46 } | 39 } |
47 | 40 |
48 namespace webkit_glue { | |
49 struct PasswordForm; | |
50 struct ResourceDevToolsInfo; | |
51 struct ResourceLoadTimingInfo; | |
52 } | |
53 | |
54 // Define the NPVariant_Param struct and its enum here since it needs manual | |
55 // serialization code. | |
56 enum NPVariant_ParamEnum { | |
57 NPVARIANT_PARAM_VOID, | |
58 NPVARIANT_PARAM_NULL, | |
59 NPVARIANT_PARAM_BOOL, | |
60 NPVARIANT_PARAM_INT, | |
61 NPVARIANT_PARAM_DOUBLE, | |
62 NPVARIANT_PARAM_STRING, | |
63 // Used when when the NPObject is running in the caller's process, so we | |
64 // create an NPObjectProxy in the other process. | |
65 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, | |
66 // Used when the NPObject we're sending is running in the callee's process | |
67 // (i.e. we have an NPObjectProxy for it). In that case we want the callee | |
68 // to just use the raw pointer. | |
69 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, | |
70 }; | |
71 | |
72 struct NPVariant_Param { | |
73 NPVariant_Param(); | |
74 ~NPVariant_Param(); | |
75 | |
76 NPVariant_ParamEnum type; | |
77 bool bool_value; | |
78 int int_value; | |
79 double double_value; | |
80 std::string string_value; | |
81 int npobject_routing_id; | |
82 }; | |
83 | |
84 struct NPIdentifier_Param { | |
85 NPIdentifier_Param(); | |
86 ~NPIdentifier_Param(); | |
87 | |
88 NPIdentifier identifier; | |
89 }; | |
90 | |
91 namespace IPC { | 41 namespace IPC { |
92 | 42 |
93 template <> | 43 template <> |
94 struct ParamTraits<GURL> { | 44 struct ParamTraits<GURL> { |
95 typedef GURL param_type; | 45 typedef GURL param_type; |
96 static void Write(Message* m, const param_type& p); | 46 static void Write(Message* m, const param_type& p); |
97 static bool Read(const Message* m, void** iter, param_type* p); | 47 static bool Read(const Message* m, void** iter, param_type* p); |
98 static void Log(const param_type& p, std::string* l); | 48 static void Log(const param_type& p, std::string* l); |
99 }; | 49 }; |
100 | 50 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 90 |
141 template <> | 91 template <> |
142 struct ParamTraits<net::IPEndPoint> { | 92 struct ParamTraits<net::IPEndPoint> { |
143 typedef net::IPEndPoint param_type; | 93 typedef net::IPEndPoint param_type; |
144 static void Write(Message* m, const param_type& p); | 94 static void Write(Message* m, const param_type& p); |
145 static bool Read(const Message* m, void** iter, param_type* p); | 95 static bool Read(const Message* m, void** iter, param_type* p); |
146 static void Log(const param_type& p, std::string* l); | 96 static void Log(const param_type& p, std::string* l); |
147 }; | 97 }; |
148 | 98 |
149 template <> | 99 template <> |
150 struct ParamTraits<webkit_glue::ResourceLoadTimingInfo> { | |
151 typedef webkit_glue::ResourceLoadTimingInfo param_type; | |
152 static void Write(Message* m, const param_type& p); | |
153 static bool Read(const Message* m, void** iter, param_type* r); | |
154 static void Log(const param_type& p, std::string* l); | |
155 }; | |
156 | |
157 template <> | |
158 struct ParamTraits<scoped_refptr<webkit_glue::ResourceDevToolsInfo> > { | |
159 typedef scoped_refptr<webkit_glue::ResourceDevToolsInfo> param_type; | |
160 static void Write(Message* m, const param_type& p); | |
161 static bool Read(const Message* m, void** iter, param_type* r); | |
162 static void Log(const param_type& p, std::string* l); | |
163 }; | |
164 | |
165 template <> | |
166 struct ParamTraits<base::PlatformFileInfo> { | 100 struct ParamTraits<base::PlatformFileInfo> { |
167 typedef base::PlatformFileInfo param_type; | 101 typedef base::PlatformFileInfo param_type; |
168 static void Write(Message* m, const param_type& p); | 102 static void Write(Message* m, const param_type& p); |
169 static bool Read(const Message* m, void** iter, param_type* r); | 103 static bool Read(const Message* m, void** iter, param_type* r); |
170 static void Log(const param_type& p, std::string* l); | 104 static void Log(const param_type& p, std::string* l); |
171 }; | 105 }; |
172 | 106 |
173 template <> | 107 template <> |
174 struct SimilarTypeTraits<base::PlatformFileError> { | 108 struct SimilarTypeTraits<base::PlatformFileError> { |
175 typedef int Type; | 109 typedef int Type; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 NOTREACHED(); | 158 NOTREACHED(); |
225 } | 159 } |
226 return result; | 160 return result; |
227 #endif | 161 #endif |
228 } | 162 } |
229 static void Log(const param_type& p, std::string* l) { | 163 static void Log(const param_type& p, std::string* l) { |
230 l->append("<gfx::NativeWindow>"); | 164 l->append("<gfx::NativeWindow>"); |
231 } | 165 } |
232 }; | 166 }; |
233 | 167 |
234 template <> | |
235 struct ParamTraits<scoped_refptr<webkit_blob::BlobData > > { | |
236 typedef scoped_refptr<webkit_blob::BlobData> param_type; | |
237 static void Write(Message* m, const param_type& p); | |
238 static bool Read(const Message* m, void** iter, param_type* r); | |
239 static void Log(const param_type& p, std::string* l); | |
240 }; | |
241 | |
242 template <> | |
243 struct ParamTraits<NPVariant_Param> { | |
244 typedef NPVariant_Param param_type; | |
245 static void Write(Message* m, const param_type& p); | |
246 static bool Read(const Message* m, void** iter, param_type* r); | |
247 static void Log(const param_type& p, std::string* l); | |
248 }; | |
249 | |
250 template <> | |
251 struct ParamTraits<NPIdentifier_Param> { | |
252 typedef NPIdentifier_Param param_type; | |
253 static void Write(Message* m, const param_type& p); | |
254 static bool Read(const Message* m, void** iter, param_type* r); | |
255 static void Log(const param_type& p, std::string* l); | |
256 }; | |
257 | |
258 template <> | |
259 struct ParamTraits<WebCursor> { | |
260 typedef WebCursor param_type; | |
261 static void Write(Message* m, const param_type& p) { | |
262 p.Serialize(m); | |
263 } | |
264 static bool Read(const Message* m, void** iter, param_type* r) { | |
265 return r->Deserialize(m, iter); | |
266 } | |
267 static void Log(const param_type& p, std::string* l) { | |
268 l->append("<WebCursor>"); | |
269 } | |
270 }; | |
271 | |
272 | |
273 template <> | |
274 struct ParamTraits<WebKit::WebInputEvent::Type> { | |
275 typedef WebKit::WebInputEvent::Type param_type; | |
276 static void Write(Message* m, const param_type& p) { | |
277 m->WriteInt(p); | |
278 } | |
279 static bool Read(const Message* m, void** iter, param_type* p) { | |
280 int type; | |
281 if (!m->ReadInt(iter, &type)) | |
282 return false; | |
283 *p = static_cast<WebKit::WebInputEvent::Type>(type); | |
284 return true; | |
285 } | |
286 static void Log(const param_type& p, std::string* l) { | |
287 const char* type; | |
288 switch (p) { | |
289 case WebKit::WebInputEvent::MouseDown: | |
290 type = "MouseDown"; | |
291 break; | |
292 case WebKit::WebInputEvent::MouseUp: | |
293 type = "MouseUp"; | |
294 break; | |
295 case WebKit::WebInputEvent::MouseMove: | |
296 type = "MouseMove"; | |
297 break; | |
298 case WebKit::WebInputEvent::MouseLeave: | |
299 type = "MouseLeave"; | |
300 break; | |
301 case WebKit::WebInputEvent::MouseEnter: | |
302 type = "MouseEnter"; | |
303 break; | |
304 case WebKit::WebInputEvent::MouseWheel: | |
305 type = "MouseWheel"; | |
306 break; | |
307 case WebKit::WebInputEvent::RawKeyDown: | |
308 type = "RawKeyDown"; | |
309 break; | |
310 case WebKit::WebInputEvent::KeyDown: | |
311 type = "KeyDown"; | |
312 break; | |
313 case WebKit::WebInputEvent::KeyUp: | |
314 type = "KeyUp"; | |
315 break; | |
316 default: | |
317 type = "None"; | |
318 break; | |
319 } | |
320 LogParam(std::string(type), l); | |
321 } | |
322 }; | |
323 | |
324 typedef const WebKit::WebInputEvent* WebInputEventPointer; | |
325 template <> | |
326 struct ParamTraits<WebInputEventPointer> { | |
327 typedef WebInputEventPointer param_type; | |
328 static void Write(Message* m, const param_type& p) { | |
329 m->WriteData(reinterpret_cast<const char*>(p), p->size); | |
330 } | |
331 // Note: upon read, the event has the lifetime of the message. | |
332 static bool Read(const Message* m, void** iter, param_type* r) { | |
333 const char* data; | |
334 int data_length; | |
335 if (!m->ReadData(iter, &data, &data_length)) { | |
336 NOTREACHED(); | |
337 return false; | |
338 } | |
339 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) { | |
340 NOTREACHED(); | |
341 return false; | |
342 } | |
343 param_type event = reinterpret_cast<param_type>(data); | |
344 // Check that the data size matches that of the event (we check the latter | |
345 // in the delegate). | |
346 if (data_length != static_cast<int>(event->size)) { | |
347 NOTREACHED(); | |
348 return false; | |
349 } | |
350 *r = event; | |
351 return true; | |
352 } | |
353 static void Log(const param_type& p, std::string* l) { | |
354 l->append("("); | |
355 LogParam(p->size, l); | |
356 l->append(", "); | |
357 LogParam(p->type, l); | |
358 l->append(", "); | |
359 LogParam(p->timeStampSeconds, l); | |
360 l->append(")"); | |
361 } | |
362 }; | |
363 | |
364 #if defined(OS_WIN) | 168 #if defined(OS_WIN) |
365 template<> | 169 template<> |
366 struct ParamTraits<TransportDIB::Id> { | 170 struct ParamTraits<TransportDIB::Id> { |
367 typedef TransportDIB::Id param_type; | 171 typedef TransportDIB::Id param_type; |
368 static void Write(Message* m, const param_type& p) { | 172 static void Write(Message* m, const param_type& p) { |
369 WriteParam(m, p.handle); | 173 WriteParam(m, p.handle); |
370 WriteParam(m, p.sequence_num); | 174 WriteParam(m, p.sequence_num); |
371 } | 175 } |
372 static bool Read(const Message* m, void** iter, param_type* r) { | 176 static bool Read(const Message* m, void** iter, param_type* r) { |
373 return (ReadParam(m, iter, &r->handle) && | 177 return (ReadParam(m, iter, &r->handle) && |
(...skipping 21 matching lines...) Expand all Loading... |
395 } | 199 } |
396 static void Log(const param_type& p, std::string* l) { | 200 static void Log(const param_type& p, std::string* l) { |
397 l->append("TransportDIB("); | 201 l->append("TransportDIB("); |
398 LogParam(p.shmkey, l); | 202 LogParam(p.shmkey, l); |
399 l->append(")"); | 203 l->append(")"); |
400 } | 204 } |
401 }; | 205 }; |
402 #endif | 206 #endif |
403 | 207 |
404 template <> | 208 template <> |
405 struct SimilarTypeTraits<WebKit::WebTextDirection> { | |
406 typedef int Type; | |
407 }; | |
408 | |
409 template <> | |
410 struct ParamTraits<SkBitmap> { | 209 struct ParamTraits<SkBitmap> { |
411 typedef SkBitmap param_type; | 210 typedef SkBitmap param_type; |
412 static void Write(Message* m, const param_type& p); | 211 static void Write(Message* m, const param_type& p); |
413 | 212 |
414 // Note: This function expects parameter |r| to be of type &SkBitmap since | 213 // Note: This function expects parameter |r| to be of type &SkBitmap since |
415 // r->SetConfig() and r->SetPixels() are called. | 214 // r->SetConfig() and r->SetPixels() are called. |
416 static bool Read(const Message* m, void** iter, param_type* r); | 215 static bool Read(const Message* m, void** iter, param_type* r); |
417 | 216 |
418 static void Log(const param_type& p, std::string* l); | 217 static void Log(const param_type& p, std::string* l); |
419 }; | 218 }; |
420 | 219 |
421 template <> | |
422 struct SimilarTypeTraits<WindowOpenDisposition> { | |
423 typedef int Type; | |
424 }; | |
425 | |
426 template <> | |
427 struct ParamTraits<webkit_glue::PasswordForm> { | |
428 typedef webkit_glue::PasswordForm param_type; | |
429 static void Write(Message* m, const param_type& p); | |
430 static bool Read(const Message* m, void** iter, param_type* p); | |
431 static void Log(const param_type& p, std::string* l); | |
432 }; | |
433 | |
434 } // namespace IPC | 220 } // namespace IPC |
435 | 221 |
436 #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ | 222 #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ |
OLD | NEW |