Fix official builder compile error when building aura on windows
[chromium-blink-merge.git] / content / public / common / common_param_traits.h
blob74fab383e2b4b73cebcdc0d1e755a6ae592f4a96
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"
25 class SkBitmap;
27 namespace content {
28 struct Referrer;
31 namespace gfx {
32 class Point;
33 class Rect;
34 class RectF;
35 class Size;
36 class Vector2d;
37 } // namespace gfx
39 namespace net {
40 class HostPortPair;
43 namespace IPC {
45 template <>
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);
53 template<>
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);
61 template <>
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);
69 template <>
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);
77 template <>
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);
85 template <>
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);
93 template <>
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);
101 template <>
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);
109 template <>
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);
117 template <>
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);
125 template <>
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);
133 template <>
134 struct ParamTraits<gfx::NativeWindow> {
135 typedef gfx::NativeWindow param_type;
136 static void Write(Message* m, const param_type& p) {
137 #if defined(OS_WIN)
138 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
139 m->WriteUInt32(reinterpret_cast<uint32>(p));
140 #else
141 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
142 #endif
144 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
145 #if defined(OS_WIN)
146 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
147 #else
148 const char *data;
149 int data_size = 0;
150 bool result = m->ReadData(iter, &data, &data_size);
151 if (result && data_size == sizeof(gfx::NativeWindow)) {
152 memcpy(r, data, sizeof(gfx::NativeWindow));
153 } else {
154 result = false;
155 NOTREACHED();
157 return result;
158 #endif
160 static void Log(const param_type& p, std::string* l) {
161 l->append("<gfx::NativeWindow>");
165 #if defined(OS_WIN)
166 template<>
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);
180 l->append(", ");
181 LogParam(p.sequence_num, l);
182 l->append(")");
186 #if defined(USE_AURA)
187 template <>
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) {
198 l->append("<HWND>");
201 #endif // defined(USE_AURA)
202 #endif // defined(OS_WIN)
204 #if defined(USE_X11)
205 template<>
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);
217 l->append(")");
220 #endif
222 template <>
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);
234 } // namespace IPC
236 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_