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 "ipc/ipc_message_utils.h"
21 #include "ui/gfx/native_widget_types.h"
22 #include "ui/surface/transport_dib.h"
47 struct CONTENT_EXPORT ParamTraits<GURL> {
48 typedef GURL param_type;
49 static void Write(Message* m, const param_type& p);
50 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
51 static void Log(const param_type& p, std::string* l);
55 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> {
56 typedef net::HostPortPair param_type;
57 static void Write(Message* m, const param_type& p);
58 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
59 static void Log(const param_type& p, std::string* l);
63 struct CONTENT_EXPORT ParamTraits<content::PageState> {
64 typedef content::PageState param_type;
65 static void Write(Message* m, const param_type& p);
66 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
67 static void Log(const param_type& p, std::string* l);
71 struct CONTENT_EXPORT ParamTraits<content::Referrer> {
72 typedef content::Referrer param_type;
73 static void Write(Message* m, const param_type& p);
74 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
75 static void Log(const param_type& p, std::string* l);
79 struct CONTENT_EXPORT ParamTraits<gfx::Point> {
80 typedef gfx::Point param_type;
81 static void Write(Message* m, const param_type& p);
82 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
83 static void Log(const param_type& p, std::string* l);
87 struct CONTENT_EXPORT ParamTraits<gfx::PointF> {
88 typedef gfx::PointF param_type;
89 static void Write(Message* m, const param_type& p);
90 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
91 static void Log(const param_type& p, std::string* l);
95 struct CONTENT_EXPORT ParamTraits<gfx::Size> {
96 typedef gfx::Size param_type;
97 static void Write(Message* m, const param_type& p);
98 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
99 static void Log(const param_type& p, std::string* l);
103 struct CONTENT_EXPORT ParamTraits<gfx::SizeF> {
104 typedef gfx::SizeF param_type;
105 static void Write(Message* m, const param_type& p);
106 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
107 static void Log(const param_type& p, std::string* l);
111 struct CONTENT_EXPORT ParamTraits<gfx::Vector2d> {
112 typedef gfx::Vector2d param_type;
113 static void Write(Message* m, const param_type& p);
114 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
115 static void Log(const param_type& p, std::string* l);
119 struct CONTENT_EXPORT ParamTraits<gfx::Vector2dF> {
120 typedef gfx::Vector2dF param_type;
121 static void Write(Message* m, const param_type& p);
122 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
123 static void Log(const param_type& p, std::string* l);
127 struct CONTENT_EXPORT ParamTraits<gfx::Rect> {
128 typedef gfx::Rect param_type;
129 static void Write(Message* m, const param_type& p);
130 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
131 static void Log(const param_type& p, std::string* l);
135 struct CONTENT_EXPORT ParamTraits<gfx::RectF> {
136 typedef gfx::RectF param_type;
137 static void Write(Message* m, const param_type& p);
138 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
139 static void Log(const param_type& p, std::string* l);
143 struct ParamTraits<gfx::NativeWindow> {
144 typedef gfx::NativeWindow param_type;
145 static void Write(Message* m, const param_type& p) {
147 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
148 m->WriteUInt32(reinterpret_cast<uint32>(p));
150 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
153 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
155 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
159 bool result = m->ReadData(iter, &data, &data_size);
160 if (result && data_size == sizeof(gfx::NativeWindow)) {
161 memcpy(r, data, sizeof(gfx::NativeWindow));
169 static void Log(const param_type& p, std::string* l) {
170 l->append("<gfx::NativeWindow>");
176 struct ParamTraits<TransportDIB::Id> {
177 typedef TransportDIB::Id param_type;
178 static void Write(Message* m, const param_type& p) {
179 WriteParam(m, p.handle);
180 WriteParam(m, p.sequence_num);
182 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
183 return (ReadParam(m, iter, &r->handle) &&
184 ReadParam(m, iter, &r->sequence_num));
186 static void Log(const param_type& p, std::string* l) {
187 l->append("TransportDIB(");
188 LogParam(p.handle, l);
190 LogParam(p.sequence_num, l);
196 #if defined(TOOLKIT_GTK)
198 struct ParamTraits<TransportDIB::Id> {
199 typedef TransportDIB::Id param_type;
200 static void Write(Message* m, const param_type& p) {
201 WriteParam(m, p.shmkey);
203 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
204 return ReadParam(m, iter, &r->shmkey);
206 static void Log(const param_type& p, std::string* l) {
207 l->append("TransportDIB(");
208 LogParam(p.shmkey, l);
215 struct CONTENT_EXPORT ParamTraits<SkBitmap> {
216 typedef SkBitmap param_type;
217 static void Write(Message* m, const param_type& p);
219 // Note: This function expects parameter |r| to be of type &SkBitmap since
220 // r->SetConfig() and r->SetPixels() are called.
221 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
223 static void Log(const param_type& p, std::string* l);
228 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_