| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 13 |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "app/gfx/native_widget_types.h" | 16 #include "app/gfx/native_widget_types.h" |
| 17 #include "chrome/common/page_zoom.h" |
| 17 #include "chrome/common/thumbnail_score.h" | 18 #include "chrome/common/thumbnail_score.h" |
| 18 #include "chrome/common/transport_dib.h" | 19 #include "chrome/common/transport_dib.h" |
| 19 #include "ipc/ipc_message_utils.h" | 20 #include "ipc/ipc_message_utils.h" |
| 20 #include "net/base/upload_data.h" | 21 #include "net/base/upload_data.h" |
| 21 #include "net/url_request/url_request_status.h" | 22 #include "net/url_request/url_request_status.h" |
| 22 #include "webkit/glue/webcursor.h" | 23 #include "webkit/glue/webcursor.h" |
| 23 #include "webkit/glue/window_open_disposition.h" | 24 #include "webkit/glue/window_open_disposition.h" |
| 24 | 25 |
| 25 // Forward declarations. | 26 // Forward declarations. |
| 26 class GURL; | 27 class GURL; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 typedef gfx::Size param_type; | 84 typedef gfx::Size param_type; |
| 84 static void Write(Message* m, const param_type& p); | 85 static void Write(Message* m, const param_type& p); |
| 85 static bool Read(const Message* m, void** iter, param_type* r); | 86 static bool Read(const Message* m, void** iter, param_type* r); |
| 86 static void Log(const param_type& p, std::wstring* l); | 87 static void Log(const param_type& p, std::wstring* l); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 template <> | 90 template <> |
| 90 struct ParamTraits<gfx::NativeWindow> { | 91 struct ParamTraits<gfx::NativeWindow> { |
| 91 typedef gfx::NativeWindow param_type; | 92 typedef gfx::NativeWindow param_type; |
| 92 static void Write(Message* m, const param_type& p) { | 93 static void Write(Message* m, const param_type& p) { |
| 93 m->WriteIntPtr(reinterpret_cast<intptr_t>(p)); | 94 WriteParam(m, reinterpret_cast<intptr_t>(p)); |
| 94 } | 95 } |
| 95 static bool Read(const Message* m, void** iter, param_type* r) { | 96 static bool Read(const Message* m, void** iter, param_type* r) { |
| 96 DCHECK_EQ(sizeof(param_type), sizeof(intptr_t)); | 97 intptr_t value; |
| 97 return m->ReadIntPtr(iter, reinterpret_cast<intptr_t*>(r)); | 98 if (!ReadParam(m, iter, &value)) |
| 99 return false; |
| 100 *r = reinterpret_cast<param_type>(value); |
| 101 return true; |
| 98 } | 102 } |
| 99 static void Log(const param_type& p, std::wstring* l) { | 103 static void Log(const param_type& p, std::wstring* l) { |
| 100 l->append(StringPrintf(L"0x%X", p)); | 104 LogParam(reinterpret_cast<intptr_t>(p), l); |
| 105 } |
| 106 }; |
| 107 |
| 108 |
| 109 template <> |
| 110 struct ParamTraits<PageZoom::Function> { |
| 111 typedef PageZoom::Function param_type; |
| 112 static void Write(Message* m, const param_type& p) { |
| 113 WriteParam(m, static_cast<int>(p)); |
| 114 } |
| 115 static bool Read(const Message* m, void** iter, param_type* r) { |
| 116 int value; |
| 117 if (!ReadParam(m, iter, &value)) |
| 118 return false; |
| 119 *r = static_cast<param_type>(value); |
| 120 return true; |
| 121 } |
| 122 static void Log(const param_type& p, std::wstring* l) { |
| 123 LogParam(static_cast<int>(p), l); |
| 101 } | 124 } |
| 102 }; | 125 }; |
| 103 | 126 |
| 104 | 127 |
| 105 template <> | 128 template <> |
| 106 struct ParamTraits<WindowOpenDisposition> { | 129 struct ParamTraits<WindowOpenDisposition> { |
| 107 typedef WindowOpenDisposition param_type; | 130 typedef WindowOpenDisposition param_type; |
| 108 static void Write(Message* m, const param_type& p) { | 131 static void Write(Message* m, const param_type& p) { |
| 109 m->WriteInt(p); | 132 WriteParam(m, static_cast<int>(p)); |
| 110 } | 133 } |
| 111 static bool Read(const Message* m, void** iter, param_type* r) { | 134 static bool Read(const Message* m, void** iter, param_type* r) { |
| 112 int temp; | 135 int value; |
| 113 bool res = m->ReadInt(iter, &temp); | 136 if (!ReadParam(m, iter, &value)) |
| 114 *r = static_cast<WindowOpenDisposition>(temp); | 137 return false; |
| 115 return res; | 138 *r = static_cast<param_type>(value); |
| 139 return true; |
| 116 } | 140 } |
| 117 static void Log(const param_type& p, std::wstring* l) { | 141 static void Log(const param_type& p, std::wstring* l) { |
| 118 l->append(StringPrintf(L"%d", p)); | 142 LogParam(static_cast<int>(p), l); |
| 119 } | 143 } |
| 120 }; | 144 }; |
| 121 | 145 |
| 122 | 146 |
| 123 template <> | 147 template <> |
| 124 struct ParamTraits<WebCursor> { | 148 struct ParamTraits<WebCursor> { |
| 125 typedef WebCursor param_type; | 149 typedef WebCursor param_type; |
| 126 static void Write(Message* m, const param_type& p) { | 150 static void Write(Message* m, const param_type& p) { |
| 127 p.Serialize(m); | 151 p.Serialize(m); |
| 128 } | 152 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 346 } |
| 323 static void Log(const param_type& p, std::wstring* l) { | 347 static void Log(const param_type& p, std::wstring* l) { |
| 324 l->append(StringPrintf(L"(%f, %d, %d)", | 348 l->append(StringPrintf(L"(%f, %d, %d)", |
| 325 p.boring_score, p.good_clipping, p.at_top)); | 349 p.boring_score, p.good_clipping, p.at_top)); |
| 326 } | 350 } |
| 327 }; | 351 }; |
| 328 | 352 |
| 329 } // namespace IPC | 353 } // namespace IPC |
| 330 | 354 |
| 331 #endif // CHROME_COMMON_COMMON_PARAM_TRAITS_H_ | 355 #endif // CHROME_COMMON_COMMON_PARAM_TRAITS_H_ |
| OLD | NEW |