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 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, or because the same type is being used in multiple
12 // *_messages.h headers.
14 #ifndef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_
15 #define CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_
19 #include "base/memory/ref_counted.h"
20 #include "content/common/content_export.h"
21 #include "content/public/common/common_param_traits_macros.h"
22 #include "ipc/ipc_message_utils.h"
23 #include "ui/gfx/native_widget_types.h"
24 #include "ui/surface/transport_dib.h"
26 #include "url/origin.h"
50 struct CONTENT_EXPORT ParamTraits
<GURL
> {
51 typedef GURL param_type
;
52 static void Write(Message
* m
, const param_type
& p
);
53 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
54 static void Log(const param_type
& p
, std::string
* l
);
58 struct CONTENT_EXPORT ParamTraits
<url::Origin
> {
59 typedef url::Origin param_type
;
60 static void Write(Message
* m
, const param_type
& p
);
61 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
62 static void Log(const param_type
& p
, std::string
* l
);
66 struct CONTENT_EXPORT ParamTraits
<net::HostPortPair
> {
67 typedef net::HostPortPair param_type
;
68 static void Write(Message
* m
, const param_type
& p
);
69 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
70 static void Log(const param_type
& p
, std::string
* l
);
74 struct CONTENT_EXPORT ParamTraits
<net::IPEndPoint
> {
75 typedef net::IPEndPoint param_type
;
76 static void Write(Message
* m
, const param_type
& p
);
77 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
78 static void Log(const param_type
& p
, std::string
* l
);
82 struct CONTENT_EXPORT ParamTraits
<content::PageState
> {
83 typedef content::PageState param_type
;
84 static void Write(Message
* m
, const param_type
& p
);
85 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
86 static void Log(const param_type
& p
, std::string
* l
);
90 struct CONTENT_EXPORT ParamTraits
<gfx::Point
> {
91 typedef gfx::Point param_type
;
92 static void Write(Message
* m
, const param_type
& p
);
93 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
94 static void Log(const param_type
& p
, std::string
* l
);
98 struct CONTENT_EXPORT ParamTraits
<gfx::PointF
> {
99 typedef gfx::PointF param_type
;
100 static void Write(Message
* m
, const param_type
& p
);
101 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
102 static void Log(const param_type
& p
, std::string
* l
);
106 struct CONTENT_EXPORT ParamTraits
<gfx::Size
> {
107 typedef gfx::Size param_type
;
108 static void Write(Message
* m
, const param_type
& p
);
109 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
110 static void Log(const param_type
& p
, std::string
* l
);
114 struct CONTENT_EXPORT ParamTraits
<gfx::SizeF
> {
115 typedef gfx::SizeF param_type
;
116 static void Write(Message
* m
, const param_type
& p
);
117 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
118 static void Log(const param_type
& p
, std::string
* l
);
122 struct CONTENT_EXPORT ParamTraits
<gfx::Vector2d
> {
123 typedef gfx::Vector2d param_type
;
124 static void Write(Message
* m
, const param_type
& p
);
125 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
126 static void Log(const param_type
& p
, std::string
* l
);
130 struct CONTENT_EXPORT ParamTraits
<gfx::Vector2dF
> {
131 typedef gfx::Vector2dF param_type
;
132 static void Write(Message
* m
, const param_type
& p
);
133 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
134 static void Log(const param_type
& p
, std::string
* l
);
138 struct CONTENT_EXPORT ParamTraits
<gfx::Rect
> {
139 typedef gfx::Rect param_type
;
140 static void Write(Message
* m
, const param_type
& p
);
141 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
142 static void Log(const param_type
& p
, std::string
* l
);
146 struct CONTENT_EXPORT ParamTraits
<gfx::RectF
> {
147 typedef gfx::RectF param_type
;
148 static void Write(Message
* m
, const param_type
& p
);
149 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
150 static void Log(const param_type
& p
, std::string
* l
);
154 struct ParamTraits
<gfx::NativeWindow
> {
155 typedef gfx::NativeWindow param_type
;
156 static void Write(Message
* m
, const param_type
& p
) {
158 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
159 m
->WriteUInt32(reinterpret_cast<uint32
>(p
));
161 m
->WriteData(reinterpret_cast<const char*>(&p
), sizeof(p
));
164 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
166 return m
->ReadUInt32(iter
, reinterpret_cast<uint32
*>(r
));
170 bool result
= m
->ReadData(iter
, &data
, &data_size
);
171 if (result
&& data_size
== sizeof(gfx::NativeWindow
)) {
172 memcpy(r
, data
, sizeof(gfx::NativeWindow
));
180 static void Log(const param_type
& p
, std::string
* l
) {
181 l
->append("<gfx::NativeWindow>");
187 struct ParamTraits
<TransportDIB::Id
> {
188 typedef TransportDIB::Id param_type
;
189 static void Write(Message
* m
, const param_type
& p
) {
190 WriteParam(m
, p
.handle
);
191 WriteParam(m
, p
.sequence_num
);
193 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
194 return (ReadParam(m
, iter
, &r
->handle
) &&
195 ReadParam(m
, iter
, &r
->sequence_num
));
197 static void Log(const param_type
& p
, std::string
* l
) {
198 l
->append("TransportDIB(");
199 LogParam(p
.handle
, l
);
201 LogParam(p
.sequence_num
, l
);
208 struct CONTENT_EXPORT ParamTraits
<SkBitmap
> {
209 typedef SkBitmap param_type
;
210 static void Write(Message
* m
, const param_type
& p
);
212 // Note: This function expects parameter |r| to be of type &SkBitmap since
213 // r->SetConfig() and r->SetPixels() are called.
214 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
216 static void Log(const param_type
& p
, std::string
* l
);
221 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_