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_
17 #include "base/memory/ref_counted.h"
18 #include "content/common/content_export.h"
19 #include "content/public/common/common_param_traits_macros.h"
20 #include "googleurl/src/gurl.h"
21 #include "ipc/ipc_message_utils.h"
22 #include "ui/gfx/native_widget_types.h"
23 #include "ui/surface/transport_dib.h"
46 struct CONTENT_EXPORT ParamTraits
<GURL
> {
47 typedef GURL param_type
;
48 static void Write(Message
* m
, const param_type
& p
);
49 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
50 static void Log(const param_type
& p
, std::string
* l
);
54 struct CONTENT_EXPORT ParamTraits
<net::HostPortPair
> {
55 typedef net::HostPortPair param_type
;
56 static void Write(Message
* m
, const param_type
& p
);
57 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
58 static void Log(const param_type
& p
, std::string
* l
);
62 struct CONTENT_EXPORT ParamTraits
<content::Referrer
> {
63 typedef content::Referrer param_type
;
64 static void Write(Message
* m
, const param_type
& p
);
65 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
66 static void Log(const param_type
& p
, std::string
* l
);
70 struct CONTENT_EXPORT ParamTraits
<gfx::Point
> {
71 typedef gfx::Point param_type
;
72 static void Write(Message
* m
, const param_type
& p
);
73 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
74 static void Log(const param_type
& p
, std::string
* l
);
78 struct CONTENT_EXPORT ParamTraits
<gfx::PointF
> {
79 typedef gfx::PointF param_type
;
80 static void Write(Message
* m
, const param_type
& p
);
81 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
82 static void Log(const param_type
& p
, std::string
* l
);
86 struct CONTENT_EXPORT ParamTraits
<gfx::Size
> {
87 typedef gfx::Size param_type
;
88 static void Write(Message
* m
, const param_type
& p
);
89 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
90 static void Log(const param_type
& p
, std::string
* l
);
94 struct CONTENT_EXPORT ParamTraits
<gfx::SizeF
> {
95 typedef gfx::SizeF param_type
;
96 static void Write(Message
* m
, const param_type
& p
);
97 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
98 static void Log(const param_type
& p
, std::string
* l
);
102 struct CONTENT_EXPORT ParamTraits
<gfx::Vector2d
> {
103 typedef gfx::Vector2d param_type
;
104 static void Write(Message
* m
, const param_type
& p
);
105 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
106 static void Log(const param_type
& p
, std::string
* l
);
110 struct CONTENT_EXPORT ParamTraits
<gfx::Vector2dF
> {
111 typedef gfx::Vector2dF param_type
;
112 static void Write(Message
* m
, const param_type
& p
);
113 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
114 static void Log(const param_type
& p
, std::string
* l
);
118 struct CONTENT_EXPORT ParamTraits
<gfx::Rect
> {
119 typedef gfx::Rect param_type
;
120 static void Write(Message
* m
, const param_type
& p
);
121 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
122 static void Log(const param_type
& p
, std::string
* l
);
126 struct CONTENT_EXPORT ParamTraits
<gfx::RectF
> {
127 typedef gfx::RectF param_type
;
128 static void Write(Message
* m
, const param_type
& p
);
129 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
130 static void Log(const param_type
& p
, std::string
* l
);
134 struct ParamTraits
<gfx::NativeWindow
> {
135 typedef gfx::NativeWindow param_type
;
136 static void Write(Message
* m
, const param_type
& p
) {
138 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
139 m
->WriteUInt32(reinterpret_cast<uint32
>(p
));
141 m
->WriteData(reinterpret_cast<const char*>(&p
), sizeof(p
));
144 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
146 return m
->ReadUInt32(iter
, reinterpret_cast<uint32
*>(r
));
150 bool result
= m
->ReadData(iter
, &data
, &data_size
);
151 if (result
&& data_size
== sizeof(gfx::NativeWindow
)) {
152 memcpy(r
, data
, sizeof(gfx::NativeWindow
));
160 static void Log(const param_type
& p
, std::string
* l
) {
161 l
->append("<gfx::NativeWindow>");
167 struct ParamTraits
<TransportDIB::Id
> {
168 typedef TransportDIB::Id param_type
;
169 static void Write(Message
* m
, const param_type
& p
) {
170 WriteParam(m
, p
.handle
);
171 WriteParam(m
, p
.sequence_num
);
173 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
174 return (ReadParam(m
, iter
, &r
->handle
) &&
175 ReadParam(m
, iter
, &r
->sequence_num
));
177 static void Log(const param_type
& p
, std::string
* l
) {
178 l
->append("TransportDIB(");
179 LogParam(p
.handle
, l
);
181 LogParam(p
.sequence_num
, l
);
186 #if defined(USE_AURA)
188 struct ParamTraits
<HWND
> {
189 typedef HWND param_type
;
190 static void Write(Message
* m
, const param_type
& p
) {
191 m
->WriteUInt32(reinterpret_cast<uint32
>(p
));
193 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
194 DCHECK_EQ(sizeof(param_type
), sizeof(uint32
));
195 return m
->ReadUInt32(iter
, reinterpret_cast<uint32
*>(r
));
197 static void Log(const param_type
& p
, std::string
* l
) {
201 #endif // defined(USE_AURA)
202 #endif // defined(OS_WIN)
206 struct ParamTraits
<TransportDIB::Id
> {
207 typedef TransportDIB::Id param_type
;
208 static void Write(Message
* m
, const param_type
& p
) {
209 WriteParam(m
, p
.shmkey
);
211 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
212 return ReadParam(m
, iter
, &r
->shmkey
);
214 static void Log(const param_type
& p
, std::string
* l
) {
215 l
->append("TransportDIB(");
216 LogParam(p
.shmkey
, l
);
223 struct CONTENT_EXPORT ParamTraits
<SkBitmap
> {
224 typedef SkBitmap param_type
;
225 static void Write(Message
* m
, const param_type
& p
);
227 // Note: This function expects parameter |r| to be of type &SkBitmap since
228 // r->SetConfig() and r->SetPixels() are called.
229 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
231 static void Log(const param_type
& p
, std::string
* l
);
236 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_