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 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); | 75 static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); |
76 static void Log(const param_type& p, std::string* l); | 76 static void Log(const param_type& p, std::string* l); |
77 }; | 77 }; |
78 | 78 |
79 template <> | 79 template <> |
80 struct ParamTraits<gfx::NativeWindow> { | 80 struct ParamTraits<gfx::NativeWindow> { |
81 typedef gfx::NativeWindow param_type; | 81 typedef gfx::NativeWindow param_type; |
82 static void Write(Message* m, const param_type& p) { | 82 static void Write(Message* m, const param_type& p) { |
83 #if defined(OS_WIN) | 83 #if defined(OS_WIN) |
84 // HWNDs are always 32 bits on Windows, even on 64 bit systems. | 84 // HWNDs are always 32 bits on Windows, even on 64 bit systems. |
85 m->WriteUInt32(reinterpret_cast<uint32>(p)); | 85 // Cast through uintptr_t and then uint32 to make the truncation explicit. |
| 86 m->WriteUInt32(static_cast<uint32>(reinterpret_cast<uintptr_t>(p))); |
86 #else | 87 #else |
87 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); | 88 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); |
88 #endif | 89 #endif |
89 } | 90 } |
90 static bool Read(const Message* m, base::PickleIterator* iter, | 91 static bool Read(const Message* m, base::PickleIterator* iter, |
91 param_type* r) { | 92 param_type* r) { |
92 #if defined(OS_WIN) | 93 #if defined(OS_WIN) |
93 return iter->ReadUInt32(reinterpret_cast<uint32*>(r)); | 94 return iter->ReadUInt32(reinterpret_cast<uint32*>(r)); |
94 #else | 95 #else |
95 const char *data; | 96 const char *data; |
96 int data_size = 0; | 97 int data_size = 0; |
97 bool result = iter->ReadData(&data, &data_size); | 98 bool result = iter->ReadData(&data, &data_size); |
98 if (result && data_size == sizeof(gfx::NativeWindow)) { | 99 if (result && data_size == sizeof(gfx::NativeWindow)) { |
99 memcpy(r, data, sizeof(gfx::NativeWindow)); | 100 memcpy(r, data, sizeof(gfx::NativeWindow)); |
100 } else { | 101 } else { |
101 result = false; | 102 result = false; |
102 NOTREACHED(); | 103 NOTREACHED(); |
103 } | 104 } |
104 return result; | 105 return result; |
105 #endif | 106 #endif |
106 } | 107 } |
107 static void Log(const param_type& p, std::string* l) { | 108 static void Log(const param_type& p, std::string* l) { |
108 l->append("<gfx::NativeWindow>"); | 109 l->append("<gfx::NativeWindow>"); |
109 } | 110 } |
110 }; | 111 }; |
111 | 112 |
112 } // namespace IPC | 113 } // namespace IPC |
113 | 114 |
114 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ | 115 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ |
OLD | NEW |