OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 used by the content code, and which need | 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 | 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 | 11 // public members, or because the same type is being used in multiple |
12 // *_messages.h headers. | 12 // *_messages.h headers. |
13 | 13 |
14 #ifndef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ | 14 #ifndef CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ |
15 #define CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ | 15 #define CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "content/public/common/common_param_traits_macros.h" | 21 #include "content/public/common/common_param_traits_macros.h" |
22 #include "ipc/ipc_message_utils.h" | 22 #include "ipc/ipc_message_utils.h" |
23 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
24 #include "ui/surface/transport_dib.h" | 24 #include "ui/surface/transport_dib.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 #include "url/origin.h" | 26 #include "url/origin.h" |
27 | 27 |
| 28 #if defined(OS_WIN) |
| 29 #include "base/win/win_util.h" |
| 30 #endif |
| 31 |
28 namespace content { | 32 namespace content { |
29 class PageState; | 33 class PageState; |
30 } | 34 } |
31 | 35 |
32 namespace net { | 36 namespace net { |
33 class HostPortPair; | 37 class HostPortPair; |
34 class IPEndPoint; | 38 class IPEndPoint; |
35 } | 39 } |
36 | 40 |
37 namespace IPC { | 41 namespace IPC { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 static void Write(Message* m, const param_type& p); | 78 static void Write(Message* m, const param_type& p); |
75 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 79 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); |
76 static void Log(const param_type& p, std::string* l); | 80 static void Log(const param_type& p, std::string* l); |
77 }; | 81 }; |
78 | 82 |
79 template <> | 83 template <> |
80 struct ParamTraits<gfx::NativeWindow> { | 84 struct ParamTraits<gfx::NativeWindow> { |
81 typedef gfx::NativeWindow param_type; | 85 typedef gfx::NativeWindow param_type; |
82 static void Write(Message* m, const param_type& p) { | 86 static void Write(Message* m, const param_type& p) { |
83 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
84 // HWNDs are always 32 bits on Windows, even on 64 bit systems. | 88 m->WriteUInt32(base::win::HandleToUint32(p)); |
85 m->WriteUInt32(reinterpret_cast<uint32>(p)); | |
86 #else | 89 #else |
87 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); | 90 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); |
88 #endif | 91 #endif |
89 } | 92 } |
90 static bool Read(const Message* m, base::PickleIterator* iter, | 93 static bool Read(const Message* m, base::PickleIterator* iter, |
91 param_type* r) { | 94 param_type* r) { |
92 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
93 return iter->ReadUInt32(reinterpret_cast<uint32*>(r)); | 96 return iter->ReadUInt32(reinterpret_cast<uint32*>(r)); |
94 #else | 97 #else |
95 const char *data; | 98 const char *data; |
96 int data_size = 0; | 99 int data_size = 0; |
97 bool result = iter->ReadData(&data, &data_size); | 100 bool result = iter->ReadData(&data, &data_size); |
98 if (result && data_size == sizeof(gfx::NativeWindow)) { | 101 if (result && data_size == sizeof(gfx::NativeWindow)) { |
99 memcpy(r, data, sizeof(gfx::NativeWindow)); | 102 memcpy(r, data, sizeof(gfx::NativeWindow)); |
100 } else { | 103 } else { |
101 result = false; | 104 result = false; |
102 NOTREACHED(); | 105 NOTREACHED(); |
103 } | 106 } |
104 return result; | 107 return result; |
105 #endif | 108 #endif |
106 } | 109 } |
107 static void Log(const param_type& p, std::string* l) { | 110 static void Log(const param_type& p, std::string* l) { |
108 l->append("<gfx::NativeWindow>"); | 111 l->append("<gfx::NativeWindow>"); |
109 } | 112 } |
110 }; | 113 }; |
111 | 114 |
112 } // namespace IPC | 115 } // namespace IPC |
113 | 116 |
114 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ | 117 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ |
OLD | NEW |