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
13 #ifndef CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_
14 #define CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_
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"
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
{
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
{
63 NPVariant_ParamEnum type
;
67 std::string string_value
;
68 int npobject_routing_id
;
71 struct NPIdentifier_Param
{
73 ~NPIdentifier_Param();
75 NPIdentifier identifier
;
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
);
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
);
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
);
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
);
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
);
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
);
129 struct ParamTraits
<WebCursor
> {
130 typedef WebCursor param_type
;
131 static void Write(Message
* m
, const param_type
& p
) {
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>");
143 struct ParamTraits
<WebKit::WebInputEvent::Type
> {
144 typedef WebKit::WebInputEvent::Type param_type
;
145 static void Write(Message
* m
, const param_type
& p
) {
148 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
) {
150 if (!m
->ReadInt(iter
, &type
))
152 *p
= static_cast<WebKit::WebInputEvent::Type
>(type
);
155 static void Log(const param_type
& p
, std::string
* l
) {
158 case WebKit::WebInputEvent::MouseDown
:
161 case WebKit::WebInputEvent::MouseUp
:
164 case WebKit::WebInputEvent::MouseMove
:
167 case WebKit::WebInputEvent::MouseLeave
:
170 case WebKit::WebInputEvent::MouseEnter
:
173 case WebKit::WebInputEvent::MouseWheel
:
176 case WebKit::WebInputEvent::RawKeyDown
:
179 case WebKit::WebInputEvent::KeyDown
:
182 case WebKit::WebInputEvent::KeyUp
:
189 LogParam(std::string(type
), l
);
193 typedef const WebKit::WebInputEvent
* WebInputEventPointer
;
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
) {
204 if (!m
->ReadData(iter
, &data
, &data_length
)) {
208 if (data_length
< static_cast<int>(sizeof(WebKit::WebInputEvent
))) {
212 param_type event
= reinterpret_cast<param_type
>(data
);
213 // Check that the data size matches that of the event (we check the latter
215 if (data_length
!= static_cast<int>(event
->size
)) {
222 static void Log(const param_type
& p
, std::string
* l
) {
224 LogParam(p
->size
, l
);
226 LogParam(p
->type
, l
);
228 LogParam(p
->timeStampSeconds
, l
);
234 struct SimilarTypeTraits
<WebKit::WebTextDirection
> {
239 struct SimilarTypeTraits
<WindowOpenDisposition
> {
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
);
253 #endif // CONTENT_PUBLIC_COMMON_WEBKIT_PARAM_TRAITS_H_