linux_aura: Disable the plugin install infobar.
[chromium-blink-merge.git] / content / public / common / common_param_traits.h
blobf527f1628008cb96cd598d2ed1e1664c294f7353
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 <string>
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"
25 #include "url/gurl.h"
26 #include "url/origin.h"
28 class SkBitmap;
30 namespace content {
31 class PageState;
34 namespace gfx {
35 class Point;
36 class Rect;
37 class RectF;
38 class Size;
39 class Vector2d;
40 } // namespace gfx
42 namespace net {
43 class HostPortPair;
44 class IPEndPoint;
47 namespace IPC {
49 template <>
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);
57 template <>
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);
65 template<>
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);
73 template <>
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);
81 template <>
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);
89 template <>
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);
97 template <>
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);
105 template <>
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);
113 template <>
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);
121 template <>
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);
129 template <>
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);
137 template <>
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);
145 template <>
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);
153 template <>
154 struct ParamTraits<gfx::NativeWindow> {
155 typedef gfx::NativeWindow param_type;
156 static void Write(Message* m, const param_type& p) {
157 #if defined(OS_WIN)
158 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
159 m->WriteUInt32(reinterpret_cast<uint32>(p));
160 #else
161 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
162 #endif
164 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
165 #if defined(OS_WIN)
166 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
167 #else
168 const char *data;
169 int data_size = 0;
170 bool result = m->ReadData(iter, &data, &data_size);
171 if (result && data_size == sizeof(gfx::NativeWindow)) {
172 memcpy(r, data, sizeof(gfx::NativeWindow));
173 } else {
174 result = false;
175 NOTREACHED();
177 return result;
178 #endif
180 static void Log(const param_type& p, std::string* l) {
181 l->append("<gfx::NativeWindow>");
185 #if defined(OS_WIN)
186 template<>
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);
200 l->append(", ");
201 LogParam(p.sequence_num, l);
202 l->append(")");
205 #endif
207 template <>
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);
219 } // namespace IPC
221 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_