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" | |
30 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" | 29 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" |
31 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" | 30 #include "third_party/WebKit/WebKit/chromium/public/WebContextMenuData.h" |
32 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" | 31 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" |
33 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" | |
34 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 32 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
35 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" | 33 #include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayerAction.h" |
36 #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" | 34 #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" |
37 #include "third_party/WebKit/WebKit/chromium/public/WebScreenInfo.h" | |
38 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" | 35 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" |
40 | 37 |
| 38 namespace WebKit { |
| 39 struct WebCompositionUnderline; |
| 40 struct WebFindOptions; |
| 41 struct WebRect; |
| 42 struct WebScreenInfo; |
| 43 } |
| 44 |
41 namespace IPC { | 45 namespace IPC { |
42 | 46 |
43 template <> | 47 template <> |
44 struct ParamTraits<WebKit::WebRect> { | 48 struct ParamTraits<WebKit::WebRect> { |
45 typedef WebKit::WebRect param_type; | 49 typedef WebKit::WebRect param_type; |
46 static void Write(Message* m, const param_type& p) { | 50 static void Write(Message* m, const param_type& p); |
47 WriteParam(m, p.x); | 51 static bool Read(const Message* m, void** iter, param_type* p); |
48 WriteParam(m, p.y); | 52 static void Log(const param_type& p, std::wstring* l); |
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 } | |
70 }; | 53 }; |
71 | 54 |
72 template <> | 55 template <> |
73 struct ParamTraits<WebKit::WebScreenInfo> { | 56 struct ParamTraits<WebKit::WebScreenInfo> { |
74 typedef WebKit::WebScreenInfo param_type; | 57 typedef WebKit::WebScreenInfo param_type; |
75 static void Write(Message* m, const param_type& p) { | 58 static void Write(Message* m, const param_type& p); |
76 WriteParam(m, p.depth); | 59 static bool Read(const Message* m, void** iter, param_type* p); |
77 WriteParam(m, p.depthPerComponent); | 60 static void Log(const param_type& p, std::wstring* l); |
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 } | |
103 }; | 61 }; |
104 | 62 |
105 template <> | 63 template <> |
106 struct ParamTraits<WebKit::WebConsoleMessage::Level> { | 64 struct ParamTraits<WebKit::WebConsoleMessage::Level> { |
107 typedef WebKit::WebConsoleMessage::Level param_type; | 65 typedef WebKit::WebConsoleMessage::Level param_type; |
108 static void Write(Message* m, const param_type& p) { | 66 static void Write(Message* m, const param_type& p) { |
109 WriteParam(m, static_cast<int>(p)); | 67 WriteParam(m, static_cast<int>(p)); |
110 } | 68 } |
111 static bool Read(const Message* m, void** iter, param_type* r) { | 69 static bool Read(const Message* m, void** iter, param_type* r) { |
112 int value; | 70 int value; |
(...skipping 21 matching lines...) Expand all Loading... |
134 return true; | 92 return true; |
135 } | 93 } |
136 static void Log(const param_type& p, std::wstring* l) { | 94 static void Log(const param_type& p, std::wstring* l) { |
137 LogParam(static_cast<int>(p), l); | 95 LogParam(static_cast<int>(p), l); |
138 } | 96 } |
139 }; | 97 }; |
140 | 98 |
141 template <> | 99 template <> |
142 struct ParamTraits<WebKit::WebFindOptions> { | 100 struct ParamTraits<WebKit::WebFindOptions> { |
143 typedef WebKit::WebFindOptions param_type; | 101 typedef WebKit::WebFindOptions param_type; |
144 static void Write(Message* m, const param_type& p) { | 102 static void Write(Message* m, const param_type& p); |
145 WriteParam(m, p.forward); | 103 static bool Read(const Message* m, void** iter, param_type* p); |
146 WriteParam(m, p.matchCase); | 104 static void Log(const param_type& p, std::wstring* l); |
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 } | |
164 }; | 105 }; |
165 | 106 |
166 template <> | 107 template <> |
167 struct ParamTraits<WebKit::WebInputEvent::Type> { | 108 struct ParamTraits<WebKit::WebInputEvent::Type> { |
168 typedef WebKit::WebInputEvent::Type param_type; | 109 typedef WebKit::WebInputEvent::Type param_type; |
169 static void Write(Message* m, const param_type& p) { | 110 static void Write(Message* m, const param_type& p) { |
170 m->WriteInt(p); | 111 m->WriteInt(p); |
171 } | 112 } |
172 static bool Read(const Message* m, void** iter, param_type* p) { | 113 static bool Read(const Message* m, void** iter, param_type* p) { |
173 int type; | 114 int type; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 int temp; | 312 int temp; |
372 bool res = m->ReadInt(iter, &temp); | 313 bool res = m->ReadInt(iter, &temp); |
373 *r = static_cast<param_type>(temp); | 314 *r = static_cast<param_type>(temp); |
374 return res; | 315 return res; |
375 } | 316 } |
376 }; | 317 }; |
377 | 318 |
378 template <> | 319 template <> |
379 struct ParamTraits<WebKit::WebCompositionUnderline> { | 320 struct ParamTraits<WebKit::WebCompositionUnderline> { |
380 typedef WebKit::WebCompositionUnderline param_type; | 321 typedef WebKit::WebCompositionUnderline param_type; |
381 static void Write(Message* m, const param_type& p) { | 322 static void Write(Message* m, const param_type& p); |
382 WriteParam(m, p.startOffset); | 323 static bool Read(const Message* m, void** iter, param_type* p); |
383 WriteParam(m, p.endOffset); | 324 static void Log(const param_type& p, std::wstring* l); |
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 } | |
405 }; | 325 }; |
406 | 326 |
407 template <> | 327 template <> |
408 struct ParamTraits<WebKit::WebTextInputType> { | 328 struct ParamTraits<WebKit::WebTextInputType> { |
409 typedef WebKit::WebTextInputType param_type; | 329 typedef WebKit::WebTextInputType param_type; |
410 static void Write(Message* m, const param_type& p) { | 330 static void Write(Message* m, const param_type& p) { |
411 m->WriteInt(p); | 331 m->WriteInt(p); |
412 } | 332 } |
413 static bool Read(const Message* m, void** iter, param_type* p) { | 333 static bool Read(const Message* m, void** iter, param_type* p) { |
414 int type; | 334 int type; |
(...skipping 19 matching lines...) Expand all Loading... |
434 control = L"UNKNOWN"; | 354 control = L"UNKNOWN"; |
435 break; | 355 break; |
436 } | 356 } |
437 LogParam(control, l); | 357 LogParam(control, l); |
438 } | 358 } |
439 }; | 359 }; |
440 | 360 |
441 } // namespace IPC | 361 } // namespace IPC |
442 | 362 |
443 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 363 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
OLD | NEW |