Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: content/common/common_param_traits.h

Issue 8368004: Move common_param_traits and webkit_param_traits to content/public/common. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/clipboard_messages.h ('k') | content/common/common_param_traits.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
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..
12
13 #ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
14 #define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
15 #pragma once
16
17 #include "base/memory/ref_counted.h"
18 #include "base/platform_file.h"
19 #include "content/common/content_export.h"
20 #include "content/common/dom_storage_common.h"
21 #include "content/public/common/page_transition_types.h"
22 #include "googleurl/src/gurl.h"
23 #include "ipc/ipc_message_utils.h"
24 #include "net/base/ip_endpoint.h"
25 #include "net/url_request/url_request_status.h"
26 #include "ui/gfx/native_widget_types.h"
27 #include "ui/gfx/surface/transport_dib.h"
28 #include "webkit/glue/resource_type.h"
29
30 class SkBitmap;
31
32 namespace gfx {
33 class Point;
34 class Rect;
35 class Size;
36 } // namespace gfx
37
38 namespace net {
39 class HttpResponseHeaders;
40 class HostPortPair;
41 class UploadData;
42 }
43
44 namespace ui {
45 class Range;
46 }
47
48 namespace IPC {
49
50 template <>
51 struct CONTENT_EXPORT ParamTraits<GURL> {
52 typedef GURL param_type;
53 static void Write(Message* m, const param_type& p);
54 static bool Read(const Message* m, void** iter, param_type* p);
55 static void Log(const param_type& p, std::string* l);
56 };
57
58 template <>
59 struct ParamTraits<ResourceType::Type> {
60 typedef ResourceType::Type param_type;
61 static void Write(Message* m, const param_type& p);
62 static bool Read(const Message* m, void** iter, param_type* p);
63 static void Log(const param_type& p, std::string* l);
64 };
65
66 template <>
67 struct CONTENT_EXPORT ParamTraits<net::URLRequestStatus> {
68 typedef net::URLRequestStatus param_type;
69 static void Write(Message* m, const param_type& p);
70 static bool Read(const Message* m, void** iter, param_type* r);
71 static void Log(const param_type& p, std::string* l);
72 };
73
74 template <>
75 struct CONTENT_EXPORT ParamTraits<scoped_refptr<net::UploadData> > {
76 typedef scoped_refptr<net::UploadData> param_type;
77 static void Write(Message* m, const param_type& p);
78 static bool Read(const Message* m, void** iter, param_type* r);
79 static void Log(const param_type& p, std::string* l);
80 };
81
82 template<>
83 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> {
84 typedef net::HostPortPair param_type;
85 static void Write(Message* m, const param_type& p);
86 static bool Read(const Message* m, void** iter, param_type* r);
87 static void Log(const param_type& p, std::string* l);
88 };
89
90 template <>
91 struct ParamTraits<scoped_refptr<net::HttpResponseHeaders> > {
92 typedef scoped_refptr<net::HttpResponseHeaders> param_type;
93 static void Write(Message* m, const param_type& p);
94 static bool Read(const Message* m, void** iter, param_type* r);
95 static void Log(const param_type& p, std::string* l);
96 };
97
98 template <>
99 struct ParamTraits<net::IPEndPoint> {
100 typedef net::IPEndPoint param_type;
101 static void Write(Message* m, const param_type& p);
102 static bool Read(const Message* m, void** iter, param_type* p);
103 static void Log(const param_type& p, std::string* l);
104 };
105
106 template <>
107 struct ParamTraits<base::PlatformFileInfo> {
108 typedef base::PlatformFileInfo param_type;
109 static void Write(Message* m, const param_type& p);
110 static bool Read(const Message* m, void** iter, param_type* r);
111 static void Log(const param_type& p, std::string* l);
112 };
113
114 template <>
115 struct CONTENT_EXPORT ParamTraits<gfx::Point> {
116 typedef gfx::Point param_type;
117 static void Write(Message* m, const param_type& p);
118 static bool Read(const Message* m, void** iter, param_type* r);
119 static void Log(const param_type& p, std::string* l);
120 };
121
122 template <>
123 struct CONTENT_EXPORT ParamTraits<gfx::Size> {
124 typedef gfx::Size param_type;
125 static void Write(Message* m, const param_type& p);
126 static bool Read(const Message* m, void** iter, param_type* r);
127 static void Log(const param_type& p, std::string* l);
128 };
129
130 template <>
131 struct CONTENT_EXPORT ParamTraits<gfx::Rect> {
132 typedef gfx::Rect param_type;
133 static void Write(Message* m, const param_type& p);
134 static bool Read(const Message* m, void** iter, param_type* r);
135 static void Log(const param_type& p, std::string* l);
136 };
137
138 template <>
139 struct ParamTraits<gfx::NativeWindow> {
140 typedef gfx::NativeWindow param_type;
141 static void Write(Message* m, const param_type& p) {
142 #if defined(OS_WIN)
143 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
144 m->WriteUInt32(reinterpret_cast<uint32>(p));
145 #else
146 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
147 #endif
148 }
149 static bool Read(const Message* m, void** iter, param_type* r) {
150 #if defined(OS_WIN)
151 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
152 #else
153 const char *data;
154 int data_size = 0;
155 bool result = m->ReadData(iter, &data, &data_size);
156 if (result && data_size == sizeof(gfx::NativeWindow)) {
157 memcpy(r, data, sizeof(gfx::NativeWindow));
158 } else {
159 result = false;
160 NOTREACHED();
161 }
162 return result;
163 #endif
164 }
165 static void Log(const param_type& p, std::string* l) {
166 l->append("<gfx::NativeWindow>");
167 }
168 };
169
170 template <>
171 struct CONTENT_EXPORT ParamTraits<ui::Range> {
172 typedef ui::Range param_type;
173 static void Write(Message* m, const param_type& p);
174 static bool Read(const Message* m, void** iter, param_type* r);
175 static void Log(const param_type& p, std::string* l);
176 };
177
178 #if defined(OS_WIN)
179 template<>
180 struct ParamTraits<TransportDIB::Id> {
181 typedef TransportDIB::Id param_type;
182 static void Write(Message* m, const param_type& p) {
183 WriteParam(m, p.handle);
184 WriteParam(m, p.sequence_num);
185 }
186 static bool Read(const Message* m, void** iter, param_type* r) {
187 return (ReadParam(m, iter, &r->handle) &&
188 ReadParam(m, iter, &r->sequence_num));
189 }
190 static void Log(const param_type& p, std::string* l) {
191 l->append("TransportDIB(");
192 LogParam(p.handle, l);
193 l->append(", ");
194 LogParam(p.sequence_num, l);
195 l->append(")");
196 }
197 };
198 #endif
199
200 #if defined(USE_X11)
201 template<>
202 struct ParamTraits<TransportDIB::Id> {
203 typedef TransportDIB::Id param_type;
204 static void Write(Message* m, const param_type& p) {
205 WriteParam(m, p.shmkey);
206 }
207 static bool Read(const Message* m, void** iter, param_type* r) {
208 return ReadParam(m, iter, &r->shmkey);
209 }
210 static void Log(const param_type& p, std::string* l) {
211 l->append("TransportDIB(");
212 LogParam(p.shmkey, l);
213 l->append(")");
214 }
215 };
216 #endif
217
218 template <>
219 struct CONTENT_EXPORT ParamTraits<SkBitmap> {
220 typedef SkBitmap param_type;
221 static void Write(Message* m, const param_type& p);
222
223 // Note: This function expects parameter |r| to be of type &SkBitmap since
224 // r->SetConfig() and r->SetPixels() are called.
225 static bool Read(const Message* m, void** iter, param_type* r);
226
227 static void Log(const param_type& p, std::string* l);
228 };
229
230 template <>
231 struct SimilarTypeTraits<base::PlatformFileError> {
232 typedef int Type;
233 };
234
235 template <>
236 struct SimilarTypeTraits<DOMStorageType> {
237 typedef int Type;
238 };
239
240 template <>
241 struct SimilarTypeTraits<content::PageTransition> {
242 typedef int Type;
243 };
244
245 } // namespace IPC
246
247 #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
OLDNEW
« no previous file with comments | « content/common/clipboard_messages.h ('k') | content/common/common_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698