OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file is used to define IPC::ParamTraits<> specializations for a number | 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<> | 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 | 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 | 8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains |
9 // specializations for types that are shared by more than one child process. | 9 // specializations for types that are shared by more than one child process. |
10 | 10 |
11 #ifndef CHROME_COMMON_COMMON_PARAM_TRAITS_H_ | 11 #ifndef CHROME_COMMON_COMMON_PARAM_TRAITS_H_ |
12 #define CHROME_COMMON_COMMON_PARAM_TRAITS_H_ | 12 #define CHROME_COMMON_COMMON_PARAM_TRAITS_H_ |
13 #pragma once | 13 #pragma once |
14 | 14 |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "app/surface/transport_dib.h" | 17 #include "app/surface/transport_dib.h" |
| 18 #include "base/ref_counted.h" |
18 #include "chrome/common/content_settings.h" | 19 #include "chrome/common/content_settings.h" |
19 #include "chrome/common/geoposition.h" | |
20 #include "chrome/common/page_zoom.h" | 20 #include "chrome/common/page_zoom.h" |
21 #include "gfx/native_widget_types.h" | 21 #include "gfx/native_widget_types.h" |
22 #include "ipc/ipc_message_utils.h" | 22 #include "ipc/ipc_message_utils.h" |
23 #include "net/base/upload_data.h" | |
24 #include "net/url_request/url_request_status.h" | 23 #include "net/url_request/url_request_status.h" |
25 #include "printing/native_metafile.h" | 24 #include "printing/native_metafile.h" |
26 #include "webkit/glue/webcursor.h" | 25 #include "webkit/glue/webcursor.h" |
27 #include "webkit/glue/window_open_disposition.h" | 26 #include "webkit/glue/window_open_disposition.h" |
28 | 27 |
29 // Forward declarations. | 28 // Forward declarations. |
| 29 struct Geoposition; |
30 class GURL; | 30 class GURL; |
31 class SkBitmap; | 31 class SkBitmap; |
32 class DictionaryValue; | 32 class DictionaryValue; |
33 class ListValue; | 33 class ListValue; |
34 struct ThumbnailScore; | 34 struct ThumbnailScore; |
35 class URLRequestStatus; | 35 class URLRequestStatus; |
36 class WebCursor; | 36 class WebCursor; |
37 | 37 |
38 namespace gfx { | 38 namespace gfx { |
39 class Point; | 39 class Point; |
40 class Rect; | 40 class Rect; |
41 class Size; | 41 class Size; |
42 } // namespace gfx | 42 } // namespace gfx |
43 | 43 |
| 44 namespace net { |
| 45 class UploadData; |
| 46 } |
| 47 |
44 namespace printing { | 48 namespace printing { |
45 struct PageRange; | 49 struct PageRange; |
46 } // namespace printing | 50 } // namespace printing |
47 | 51 |
48 namespace webkit_glue { | 52 namespace webkit_glue { |
49 struct PasswordForm; | 53 struct PasswordForm; |
50 struct WebApplicationInfo; | 54 struct WebApplicationInfo; |
51 } // namespace webkit_glue | 55 } // namespace webkit_glue |
52 | 56 |
53 namespace IPC { | 57 namespace IPC { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 256 |
253 // Traits for URLRequestStatus | 257 // Traits for URLRequestStatus |
254 template <> | 258 template <> |
255 struct ParamTraits<URLRequestStatus> { | 259 struct ParamTraits<URLRequestStatus> { |
256 typedef URLRequestStatus param_type; | 260 typedef URLRequestStatus param_type; |
257 static void Write(Message* m, const param_type& p); | 261 static void Write(Message* m, const param_type& p); |
258 static bool Read(const Message* m, void** iter, param_type* r); | 262 static bool Read(const Message* m, void** iter, param_type* r); |
259 static void Log(const param_type& p, std::string* l); | 263 static void Log(const param_type& p, std::string* l); |
260 }; | 264 }; |
261 | 265 |
262 | |
263 // Traits for net::UploadData::Element. | |
264 template <> | |
265 struct ParamTraits<net::UploadData::Element> { | |
266 typedef net::UploadData::Element param_type; | |
267 static void Write(Message* m, const param_type& p) { | |
268 WriteParam(m, static_cast<int>(p.type())); | |
269 if (p.type() == net::UploadData::TYPE_BYTES) { | |
270 m->WriteData(&p.bytes()[0], static_cast<int>(p.bytes().size())); | |
271 } else { | |
272 WriteParam(m, p.file_path()); | |
273 WriteParam(m, p.file_range_offset()); | |
274 WriteParam(m, p.file_range_length()); | |
275 WriteParam(m, p.expected_file_modification_time()); | |
276 } | |
277 } | |
278 static bool Read(const Message* m, void** iter, param_type* r) { | |
279 int type; | |
280 if (!ReadParam(m, iter, &type)) | |
281 return false; | |
282 if (type == net::UploadData::TYPE_BYTES) { | |
283 const char* data; | |
284 int len; | |
285 if (!m->ReadData(iter, &data, &len)) | |
286 return false; | |
287 r->SetToBytes(data, len); | |
288 } else { | |
289 DCHECK(type == net::UploadData::TYPE_FILE); | |
290 FilePath file_path; | |
291 uint64 offset, length; | |
292 base::Time expected_modification_time; | |
293 if (!ReadParam(m, iter, &file_path)) | |
294 return false; | |
295 if (!ReadParam(m, iter, &offset)) | |
296 return false; | |
297 if (!ReadParam(m, iter, &length)) | |
298 return false; | |
299 if (!ReadParam(m, iter, &expected_modification_time)) | |
300 return false; | |
301 r->SetToFilePathRange(file_path, offset, length, | |
302 expected_modification_time); | |
303 } | |
304 return true; | |
305 } | |
306 static void Log(const param_type& p, std::string* l) { | |
307 l->append("<net::UploadData::Element>"); | |
308 } | |
309 }; | |
310 | |
311 // Traits for net::UploadData. | 266 // Traits for net::UploadData. |
312 template <> | 267 template <> |
313 struct ParamTraits<scoped_refptr<net::UploadData> > { | 268 struct ParamTraits<scoped_refptr<net::UploadData> > { |
314 typedef scoped_refptr<net::UploadData> param_type; | 269 typedef scoped_refptr<net::UploadData> param_type; |
315 static void Write(Message* m, const param_type& p) { | 270 static void Write(Message* m, const param_type& p); |
316 WriteParam(m, p.get() != NULL); | 271 static bool Read(const Message* m, void** iter, param_type* r); |
317 if (p) { | 272 static void Log(const param_type& p, std::string* l); |
318 WriteParam(m, *p->elements()); | |
319 WriteParam(m, p->identifier()); | |
320 } | |
321 } | |
322 static bool Read(const Message* m, void** iter, param_type* r) { | |
323 bool has_object; | |
324 if (!ReadParam(m, iter, &has_object)) | |
325 return false; | |
326 if (!has_object) | |
327 return true; | |
328 std::vector<net::UploadData::Element> elements; | |
329 if (!ReadParam(m, iter, &elements)) | |
330 return false; | |
331 int64 identifier; | |
332 if (!ReadParam(m, iter, &identifier)) | |
333 return false; | |
334 *r = new net::UploadData; | |
335 (*r)->swap_elements(&elements); | |
336 (*r)->set_identifier(identifier); | |
337 return true; | |
338 } | |
339 static void Log(const param_type& p, std::string* l) { | |
340 l->append("<net::UploadData>"); | |
341 } | |
342 }; | 273 }; |
343 | 274 |
344 template<> | 275 template<> |
345 struct ParamTraits<ThumbnailScore> { | 276 struct ParamTraits<ThumbnailScore> { |
346 typedef ThumbnailScore param_type; | 277 typedef ThumbnailScore param_type; |
347 static void Write(Message* m, const param_type& p); | 278 static void Write(Message* m, const param_type& p); |
348 static bool Read(const Message* m, void** iter, param_type* r); | 279 static bool Read(const Message* m, void** iter, param_type* r); |
349 static void Log(const param_type& p, std::string* l); | 280 static void Log(const param_type& p, std::string* l); |
350 }; | 281 }; |
351 | 282 |
352 template <> | 283 template <> |
353 struct ParamTraits<Geoposition> { | 284 struct ParamTraits<Geoposition> { |
354 typedef Geoposition param_type; | 285 typedef Geoposition param_type; |
355 static void Write(Message* m, const param_type& p); | 286 static void Write(Message* m, const param_type& p); |
356 static bool Read(const Message* m, void** iter, param_type* p); | 287 static bool Read(const Message* m, void** iter, param_type* p); |
357 static void Log(const param_type& p, std::string* l); | 288 static void Log(const param_type& p, std::string* l); |
358 }; | 289 }; |
359 | 290 |
360 template <> | 291 template <> |
361 struct ParamTraits<Geoposition::ErrorCode> { | |
362 typedef Geoposition::ErrorCode param_type; | |
363 static void Write(Message* m, const param_type& p); | |
364 static bool Read(const Message* m, void** iter, param_type* p); | |
365 static void Log(const param_type& p, std::string* l); | |
366 }; | |
367 | |
368 template <> | |
369 struct ParamTraits<webkit_glue::PasswordForm> { | 292 struct ParamTraits<webkit_glue::PasswordForm> { |
370 typedef webkit_glue::PasswordForm param_type; | 293 typedef webkit_glue::PasswordForm param_type; |
371 static void Write(Message* m, const param_type& p); | 294 static void Write(Message* m, const param_type& p); |
372 static bool Read(const Message* m, void** iter, param_type* p); | 295 static bool Read(const Message* m, void** iter, param_type* p); |
373 static void Log(const param_type& p, std::string* l); | 296 static void Log(const param_type& p, std::string* l); |
374 }; | 297 }; |
375 | 298 |
376 template <> | 299 template <> |
377 struct ParamTraits<printing::PageRange> { | 300 struct ParamTraits<printing::PageRange> { |
378 typedef printing::PageRange param_type; | 301 typedef printing::PageRange param_type; |
379 static void Write(Message* m, const param_type& p); | 302 static void Write(Message* m, const param_type& p); |
380 static bool Read(const Message* m, void** iter, param_type* r); | 303 static bool Read(const Message* m, void** iter, param_type* r); |
381 static void Log(const param_type& p, std::string* l); | 304 static void Log(const param_type& p, std::string* l); |
382 }; | 305 }; |
383 | 306 |
384 template <> | 307 template <> |
385 struct ParamTraits<printing::NativeMetafile> { | 308 struct ParamTraits<printing::NativeMetafile> { |
386 typedef printing::NativeMetafile param_type; | 309 typedef printing::NativeMetafile param_type; |
387 static void Write(Message* m, const param_type& p); | 310 static void Write(Message* m, const param_type& p); |
388 static bool Read(const Message* m, void** iter, param_type* r); | 311 static bool Read(const Message* m, void** iter, param_type* r); |
389 static void Log(const param_type& p, std::string* l); | 312 static void Log(const param_type& p, std::string* l); |
390 }; | 313 }; |
391 | 314 |
392 } // namespace IPC | 315 } // namespace IPC |
393 | 316 |
394 #endif // CHROME_COMMON_COMMON_PARAM_TRAITS_H_ | 317 #endif // CHROME_COMMON_COMMON_PARAM_TRAITS_H_ |
OLD | NEW |