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 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 | 16 // reference counting. If we allowed serializing WebString, then we may |
17 // run the risk of introducing subtle thread-safety bugs if people passed a | 17 // run 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 | 20 // o The WebKit API has redundant types for strings, and we should avoid |
21 // using those beyond code that interfaces with the WebKit API. | 21 // using 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 #pragma once | 25 #pragma once |
26 | 26 |
27 #include "ipc/ipc_message_utils.h" | 27 #include "ipc/ipc_message_utils.h" |
28 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" | 28 #include "third_party/WebKit/WebKit/chromium/public/WebCache.h" |
| 29 #include "third_party/WebKit/WebKit/chromium/public/WebCompositionUnderline.h" |
29 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" | 30 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" |
30 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 31 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
31 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" | 32 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" |
| 33 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" |
32 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 34 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
33 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" | 35 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" |
34 #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" |
| 37 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" |
35 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" | 38 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
36 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" | 39 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" |
37 | 40 |
38 namespace WebKit { | |
39 struct WebCompositionUnderline; | |
40 struct WebFindOptions; | |
41 struct WebRect; | |
42 struct WebScreenInfo; | |
43 } | |
44 | |
45 namespace IPC { | 41 namespace IPC { |
46 | 42 |
47 template <> | 43 template <> |
48 struct ParamTraits<WebKit::WebRect> { | 44 struct ParamTraits<WebKit::WebRect> { |
49 typedef WebKit::WebRect param_type; | 45 typedef WebKit::WebRect param_type; |
50 static void Write(Message* m, const param_type& p); | 46 static void Write(Message* m, const param_type& p) { |
51 static bool Read(const Message* m, void** iter, param_type* p); | 47 WriteParam(m, p.x); |
52 static void Log(const param_type& p, std::wstring* l); | 48 WriteParam(m, p.y); |
| 49 WriteParam(m, p.width); |
| 50 WriteParam(m, p.height); |
| 51 } |
| 52 static bool Read(const Message* m, void** iter, param_type* p) { |
| 53 return |
| 54 ReadParam(m, iter, &p->x) && |
| 55 ReadParam(m, iter, &p->y) && |
| 56 ReadParam(m, iter, &p->width) && |
| 57 ReadParam(m, iter, &p->height); |
| 58 } |
| 59 static void Log(const param_type& p, std::wstring* l) { |
| 60 l->append(L"("); |
| 61 LogParam(p.x, l); |
| 62 l->append(L", "); |
| 63 LogParam(p.y, l); |
| 64 l->append(L", "); |
| 65 LogParam(p.width, l); |
| 66 l->append(L", "); |
| 67 LogParam(p.height, l); |
| 68 l->append(L")"); |
| 69 } |
53 }; | 70 }; |
54 | 71 |
55 template <> | 72 template <> |
56 struct ParamTraits<WebKit::WebScreenInfo> { | 73 struct ParamTraits<WebKit::WebScreenInfo> { |
57 typedef WebKit::WebScreenInfo param_type; | 74 typedef WebKit::WebScreenInfo param_type; |
58 static void Write(Message* m, const param_type& p); | 75 static void Write(Message* m, const param_type& p) { |
59 static bool Read(const Message* m, void** iter, param_type* p); | 76 WriteParam(m, p.depth); |
60 static void Log(const param_type& p, std::wstring* l); | 77 WriteParam(m, p.depthPerComponent); |
| 78 WriteParam(m, p.isMonochrome); |
| 79 WriteParam(m, p.rect); |
| 80 WriteParam(m, p.availableRect); |
| 81 } |
| 82 static bool Read(const Message* m, void** iter, param_type* p) { |
| 83 return |
| 84 ReadParam(m, iter, &p->depth) && |
| 85 ReadParam(m, iter, &p->depthPerComponent) && |
| 86 ReadParam(m, iter, &p->isMonochrome) && |
| 87 ReadParam(m, iter, &p->rect) && |
| 88 ReadParam(m, iter, &p->availableRect); |
| 89 } |
| 90 static void Log(const param_type& p, std::wstring* l) { |
| 91 l->append(L"("); |
| 92 LogParam(p.depth, l); |
| 93 l->append(L", "); |
| 94 LogParam(p.depthPerComponent, l); |
| 95 l->append(L", "); |
| 96 LogParam(p.isMonochrome, l); |
| 97 l->append(L", "); |
| 98 LogParam(p.rect, l); |
| 99 l->append(L", "); |
| 100 LogParam(p.availableRect, l); |
| 101 l->append(L")"); |
| 102 } |
61 }; | 103 }; |
62 | 104 |
63 template <> | 105 template <> |
64 struct ParamTraits<WebKit::WebConsoleMessage::Level> { | 106 struct ParamTraits<WebKit::WebConsoleMessage::Level> { |
65 typedef WebKit::WebConsoleMessage::Level param_type; | 107 typedef WebKit::WebConsoleMessage::Level param_type; |
66 static void Write(Message* m, const param_type& p) { | 108 static void Write(Message* m, const param_type& p) { |
67 WriteParam(m, static_cast<int>(p)); | 109 WriteParam(m, static_cast<int>(p)); |
68 } | 110 } |
69 static bool Read(const Message* m, void** iter, param_type* r) { | 111 static bool Read(const Message* m, void** iter, param_type* r) { |
70 int value; | 112 int value; |
(...skipping 21 matching lines...) Expand all Loading... |
92 return true; | 134 return true; |
93 } | 135 } |
94 static void Log(const param_type& p, std::wstring* l) { | 136 static void Log(const param_type& p, std::wstring* l) { |
95 LogParam(static_cast<int>(p), l); | 137 LogParam(static_cast<int>(p), l); |
96 } | 138 } |
97 }; | 139 }; |
98 | 140 |
99 template <> | 141 template <> |
100 struct ParamTraits<WebKit::WebFindOptions> { | 142 struct ParamTraits<WebKit::WebFindOptions> { |
101 typedef WebKit::WebFindOptions param_type; | 143 typedef WebKit::WebFindOptions param_type; |
102 static void Write(Message* m, const param_type& p); | 144 static void Write(Message* m, const param_type& p) { |
103 static bool Read(const Message* m, void** iter, param_type* p); | 145 WriteParam(m, p.forward); |
104 static void Log(const param_type& p, std::wstring* l); | 146 WriteParam(m, p.matchCase); |
| 147 WriteParam(m, p.findNext); |
| 148 } |
| 149 static bool Read(const Message* m, void** iter, param_type* p) { |
| 150 return |
| 151 ReadParam(m, iter, &p->forward) && |
| 152 ReadParam(m, iter, &p->matchCase) && |
| 153 ReadParam(m, iter, &p->findNext); |
| 154 } |
| 155 static void Log(const param_type& p, std::wstring* l) { |
| 156 l->append(L"("); |
| 157 LogParam(p.forward, l); |
| 158 l->append(L", "); |
| 159 LogParam(p.matchCase, l); |
| 160 l->append(L", "); |
| 161 LogParam(p.findNext, l); |
| 162 l->append(L")"); |
| 163 } |
105 }; | 164 }; |
106 | 165 |
107 template <> | 166 template <> |
108 struct ParamTraits<WebKit::WebInputEvent::Type> { | 167 struct ParamTraits<WebKit::WebInputEvent::Type> { |
109 typedef WebKit::WebInputEvent::Type param_type; | 168 typedef WebKit::WebInputEvent::Type param_type; |
110 static void Write(Message* m, const param_type& p) { | 169 static void Write(Message* m, const param_type& p) { |
111 m->WriteInt(p); | 170 m->WriteInt(p); |
112 } | 171 } |
113 static bool Read(const Message* m, void** iter, param_type* p) { | 172 static bool Read(const Message* m, void** iter, param_type* p) { |
114 int type; | 173 int type; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 int temp; | 371 int temp; |
313 bool res = m->ReadInt(iter, &temp); | 372 bool res = m->ReadInt(iter, &temp); |
314 *r = static_cast<param_type>(temp); | 373 *r = static_cast<param_type>(temp); |
315 return res; | 374 return res; |
316 } | 375 } |
317 }; | 376 }; |
318 | 377 |
319 template <> | 378 template <> |
320 struct ParamTraits<WebKit::WebCompositionUnderline> { | 379 struct ParamTraits<WebKit::WebCompositionUnderline> { |
321 typedef WebKit::WebCompositionUnderline param_type; | 380 typedef WebKit::WebCompositionUnderline param_type; |
322 static void Write(Message* m, const param_type& p); | 381 static void Write(Message* m, const param_type& p) { |
323 static bool Read(const Message* m, void** iter, param_type* p); | 382 WriteParam(m, p.startOffset); |
324 static void Log(const param_type& p, std::wstring* l); | 383 WriteParam(m, p.endOffset); |
| 384 WriteParam(m, p.color); |
| 385 WriteParam(m, p.thick); |
| 386 } |
| 387 static bool Read(const Message* m, void** iter, param_type* p) { |
| 388 return |
| 389 ReadParam(m, iter, &p->startOffset) && |
| 390 ReadParam(m, iter, &p->endOffset) && |
| 391 ReadParam(m, iter, &p->color) && |
| 392 ReadParam(m, iter, &p->thick); |
| 393 } |
| 394 static void Log(const param_type& p, std::wstring* l) { |
| 395 l->append(L"("); |
| 396 LogParam(p.startOffset, l); |
| 397 l->append(L","); |
| 398 LogParam(p.endOffset, l); |
| 399 l->append(L":"); |
| 400 LogParam(p.color, l); |
| 401 l->append(L":"); |
| 402 LogParam(p.thick, l); |
| 403 l->append(L")"); |
| 404 } |
325 }; | 405 }; |
326 | 406 |
327 template <> | 407 template <> |
328 struct ParamTraits<WebKit::WebTextInputType> { | 408 struct ParamTraits<WebKit::WebTextInputType> { |
329 typedef WebKit::WebTextInputType param_type; | 409 typedef WebKit::WebTextInputType param_type; |
330 static void Write(Message* m, const param_type& p) { | 410 static void Write(Message* m, const param_type& p) { |
331 m->WriteInt(p); | 411 m->WriteInt(p); |
332 } | 412 } |
333 static bool Read(const Message* m, void** iter, param_type* p) { | 413 static bool Read(const Message* m, void** iter, param_type* p) { |
334 int type; | 414 int type; |
(...skipping 19 matching lines...) Expand all Loading... |
354 control = L"UNKNOWN"; | 434 control = L"UNKNOWN"; |
355 break; | 435 break; |
356 } | 436 } |
357 LogParam(control, l); | 437 LogParam(control, l); |
358 } | 438 } |
359 }; | 439 }; |
360 | 440 |
361 } // namespace IPC | 441 } // namespace IPC |
362 | 442 |
363 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 443 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
OLD | NEW |