Loosen up heuristics for detecting account creation forms.
[chromium-blink-merge.git] / content / public / common / common_param_traits.h
blob1d2531f6a44e7b5998cdb081f384b9a07b57470a
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"
28 class SkBitmap;
30 namespace content {
31 struct Referrer;
34 namespace gfx {
35 class Point;
36 class Rect;
37 class RectF;
38 class Size;
39 } // namespace gfx
41 namespace net {
42 class HttpResponseHeaders;
43 class HostPortPair;
44 class UploadData;
47 namespace ui {
48 class Range;
51 namespace webkit_glue {
52 class ResourceRequestBody;
55 namespace IPC {
57 template <>
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);
65 template <>
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);
73 template <>
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);
81 template <>
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);
90 template <>
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);
98 template<>
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);
106 template <>
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);
114 template <>
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);
122 template <>
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);
130 template <>
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);
138 template <>
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);
146 template <>
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);
154 template <>
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);
162 template <>
163 struct ParamTraits<gfx::NativeWindow> {
164 typedef gfx::NativeWindow param_type;
165 static void Write(Message* m, const param_type& p) {
166 #if defined(OS_WIN)
167 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
168 m->WriteUInt32(reinterpret_cast<uint32>(p));
169 #else
170 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
171 #endif
173 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
174 #if defined(OS_WIN)
175 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
176 #else
177 const char *data;
178 int data_size = 0;
179 bool result = m->ReadData(iter, &data, &data_size);
180 if (result && data_size == sizeof(gfx::NativeWindow)) {
181 memcpy(r, data, sizeof(gfx::NativeWindow));
182 } else {
183 result = false;
184 NOTREACHED();
186 return result;
187 #endif
189 static void Log(const param_type& p, std::string* l) {
190 l->append("<gfx::NativeWindow>");
194 template <>
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);
202 #if defined(OS_WIN)
203 template<>
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);
217 l->append(", ");
218 LogParam(p.sequence_num, l);
219 l->append(")");
222 #endif
224 #if defined(USE_X11)
225 template<>
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);
237 l->append(")");
240 #endif
242 template <>
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);
254 } // namespace IPC
256 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_