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 "net/base/ip_endpoint.h"
23 #include "net/url_request/url_request_status.h"
24 #include "ui/gfx/native_widget_types.h"
25 #include "ui/surface/transport_dib.h"
26 #include "webkit/base/data_element.h"
42 class HttpResponseHeaders
;
51 namespace webkit_glue
{
52 class ResourceRequestBody
;
58 struct CONTENT_EXPORT ParamTraits
<GURL
> {
59 typedef GURL 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::URLRequestStatus
> {
67 typedef net::URLRequestStatus 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
<scoped_refptr
<net::UploadData
> > {
75 typedef scoped_refptr
<net::UploadData
> param_type
;
76 static void Write(Message
* m
, const param_type
& p
);
77 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
78 static void Log(const param_type
& p
, std::string
* l
);
82 struct CONTENT_EXPORT ParamTraits
<scoped_refptr
<
83 webkit_glue::ResourceRequestBody
> > {
84 typedef scoped_refptr
<webkit_glue::ResourceRequestBody
> 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
);
91 struct CONTENT_EXPORT ParamTraits
<webkit_base::DataElement
> {
92 typedef webkit_base::DataElement 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
);
99 struct CONTENT_EXPORT ParamTraits
<net::HostPortPair
> {
100 typedef net::HostPortPair 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
);
107 struct ParamTraits
<scoped_refptr
<net::HttpResponseHeaders
> > {
108 typedef scoped_refptr
<net::HttpResponseHeaders
> 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
);
115 struct ParamTraits
<net::IPEndPoint
> {
116 typedef net::IPEndPoint param_type
;
117 static void Write(Message
* m
, const param_type
& p
);
118 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
119 static void Log(const param_type
& p
, std::string
* l
);
123 struct CONTENT_EXPORT ParamTraits
<content::Referrer
> {
124 typedef content::Referrer param_type
;
125 static void Write(Message
* m
, const param_type
& p
);
126 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* p
);
127 static void Log(const param_type
& p
, std::string
* l
);
131 struct CONTENT_EXPORT ParamTraits
<gfx::Point
> {
132 typedef gfx::Point 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
);
139 struct CONTENT_EXPORT ParamTraits
<gfx::Size
> {
140 typedef gfx::Size 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
);
147 struct CONTENT_EXPORT ParamTraits
<gfx::Rect
> {
148 typedef gfx::Rect param_type
;
149 static void Write(Message
* m
, const param_type
& p
);
150 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
151 static void Log(const param_type
& p
, std::string
* l
);
155 struct CONTENT_EXPORT ParamTraits
<gfx::RectF
> {
156 typedef gfx::RectF param_type
;
157 static void Write(Message
* m
, const param_type
& p
);
158 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
159 static void Log(const param_type
& p
, std::string
* l
);
163 struct ParamTraits
<gfx::NativeWindow
> {
164 typedef gfx::NativeWindow param_type
;
165 static void Write(Message
* m
, const param_type
& p
) {
167 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
168 m
->WriteUInt32(reinterpret_cast<uint32
>(p
));
170 m
->WriteData(reinterpret_cast<const char*>(&p
), sizeof(p
));
173 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
175 return m
->ReadUInt32(iter
, reinterpret_cast<uint32
*>(r
));
179 bool result
= m
->ReadData(iter
, &data
, &data_size
);
180 if (result
&& data_size
== sizeof(gfx::NativeWindow
)) {
181 memcpy(r
, data
, sizeof(gfx::NativeWindow
));
189 static void Log(const param_type
& p
, std::string
* l
) {
190 l
->append("<gfx::NativeWindow>");
195 struct CONTENT_EXPORT ParamTraits
<ui::Range
> {
196 typedef ui::Range param_type
;
197 static void Write(Message
* m
, const param_type
& p
);
198 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
199 static void Log(const param_type
& p
, std::string
* l
);
204 struct ParamTraits
<TransportDIB::Id
> {
205 typedef TransportDIB::Id param_type
;
206 static void Write(Message
* m
, const param_type
& p
) {
207 WriteParam(m
, p
.handle
);
208 WriteParam(m
, p
.sequence_num
);
210 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
211 return (ReadParam(m
, iter
, &r
->handle
) &&
212 ReadParam(m
, iter
, &r
->sequence_num
));
214 static void Log(const param_type
& p
, std::string
* l
) {
215 l
->append("TransportDIB(");
216 LogParam(p
.handle
, l
);
218 LogParam(p
.sequence_num
, l
);
226 struct ParamTraits
<TransportDIB::Id
> {
227 typedef TransportDIB::Id param_type
;
228 static void Write(Message
* m
, const param_type
& p
) {
229 WriteParam(m
, p
.shmkey
);
231 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
) {
232 return ReadParam(m
, iter
, &r
->shmkey
);
234 static void Log(const param_type
& p
, std::string
* l
) {
235 l
->append("TransportDIB(");
236 LogParam(p
.shmkey
, l
);
243 struct CONTENT_EXPORT ParamTraits
<SkBitmap
> {
244 typedef SkBitmap param_type
;
245 static void Write(Message
* m
, const param_type
& p
);
247 // Note: This function expects parameter |r| to be of type &SkBitmap since
248 // r->SetConfig() and r->SetPixels() are called.
249 static bool Read(const Message
* m
, PickleIterator
* iter
, param_type
* r
);
251 static void Log(const param_type
& p
, std::string
* l
);
256 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_