OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 // | 4 // |
5 // This file contains ParamTraits templates to support serialization of WebKit | 5 // This file contains ParamTraits templates to support serialization of WebKit |
6 // data types over IPC. | 6 // data types over IPC. |
7 // | 7 // |
8 // NOTE: IT IS IMPORTANT THAT ONLY POD (plain old data) TYPES ARE SERIALIZED. | 8 // NOTE: IT IS IMPORTANT THAT ONLY POD (plain old data) TYPES ARE SERIALIZED. |
9 // | 9 // |
10 // There are several reasons for this restrictions: | 10 // There are several reasons for this restrictions: |
11 // | 11 // |
12 // o We don't want inclusion of this file to imply linking to WebKit code. | 12 // o We don't want inclusion of this file to imply linking to WebKit code. |
13 // | 13 // |
14 // o Many WebKit structures are not thread-safe. WebString, for example, | 14 // o Many WebKit structures are not thread-safe. WebString, for example, |
15 // contains a reference counted buffer, which does not use thread-safe | 15 // contains a reference counted buffer, which does not use thread-safe |
16 // reference counting. If we allowed serializing WebString, then we may ru
n | 16 // reference counting. If we allowed serializing WebString, then we may ru
n |
17 // the risk of introducing subtle thread-safety bugs if people passed a | 17 // the risk of introducing subtle thread-safety bugs if people passed a |
18 // WebString across threads via PostTask(NewRunnableMethod(...)). | 18 // WebString across threads via PostTask(NewRunnableMethod(...)). |
19 // | 19 // |
20 // o The WebKit API has redundant types for strings, and we should avoid usin
g | 20 // o The WebKit API has redundant types for strings, and we should avoid usin
g |
21 // those beyond code that interfaces with the WebKit API. | 21 // those beyond code that interfaces with the WebKit API. |
22 | 22 |
23 #ifndef CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 23 #ifndef CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
24 #define CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 24 #define CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
25 | 25 |
26 #include "ipc/ipc_message_utils.h" | 26 #include "ipc/ipc_message_utils.h" |
27 #include "webkit/api/public/WebCache.h" | 27 #include "webkit/api/public/WebCache.h" |
28 #include "webkit/api/public/WebCompositionCommand.h" | 28 #include "webkit/api/public/WebCompositionCommand.h" |
29 #include "webkit/api/public/WebConsoleMessage.h" | 29 #include "webkit/api/public/WebConsoleMessage.h" |
| 30 #include "webkit/api/public/WebDragOperation.h" |
30 #include "webkit/api/public/WebFindOptions.h" | 31 #include "webkit/api/public/WebFindOptions.h" |
31 #include "webkit/api/public/WebInputEvent.h" | 32 #include "webkit/api/public/WebInputEvent.h" |
32 #include "webkit/api/public/WebScreenInfo.h" | 33 #include "webkit/api/public/WebScreenInfo.h" |
33 #include "webkit/api/public/WebTextDirection.h" | 34 #include "webkit/api/public/WebTextDirection.h" |
34 | 35 |
35 namespace IPC { | 36 namespace IPC { |
36 | 37 |
37 template <> | 38 template <> |
38 struct ParamTraits<WebKit::WebRect> { | 39 struct ParamTraits<WebKit::WebRect> { |
39 typedef WebKit::WebRect param_type; | 40 typedef WebKit::WebRect param_type; |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (!ReadParam(m, iter, &value)) | 296 if (!ReadParam(m, iter, &value)) |
296 return false; | 297 return false; |
297 *r = static_cast<param_type>(value); | 298 *r = static_cast<param_type>(value); |
298 return true; | 299 return true; |
299 } | 300 } |
300 static void Log(const param_type& p, std::wstring* l) { | 301 static void Log(const param_type& p, std::wstring* l) { |
301 LogParam(static_cast<int>(p), l); | 302 LogParam(static_cast<int>(p), l); |
302 } | 303 } |
303 }; | 304 }; |
304 | 305 |
| 306 template <> |
| 307 struct ParamTraits<WebKit::WebDragOperation> { |
| 308 typedef WebKit::WebDragOperation param_type; |
| 309 static void Write(Message* m, const param_type& p) { |
| 310 m->WriteInt(p); |
| 311 } |
| 312 static bool Read(const Message* m, void** iter, param_type* r) { |
| 313 int temp; |
| 314 bool res = m->ReadInt(iter, &temp); |
| 315 *r = static_cast<param_type>(temp); |
| 316 return res; |
| 317 } |
| 318 static void Log(const param_type& p, std::wstring* l) { |
| 319 l->append(StringPrintf(L"%d", p)); |
| 320 } |
| 321 }; |
| 322 |
305 } // namespace IPC | 323 } // namespace IPC |
306 | 324 |
307 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 325 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
OLD | NEW |