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" | |
36 #include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h" | 33 #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" | 34 #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" |
39 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" | 35 #include "third_party/WebKit/WebKit/chromium/public/WebTextInputType.h" |
40 | 36 |
| 37 namespace WebKit { |
| 38 struct WebCompositionUnderline; |
| 39 struct WebFindOptions; |
| 40 struct WebMediaPlayerAction; |
| 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return res; | 262 return res; |
322 } | 263 } |
323 static void Log(const param_type& p, std::wstring* l) { | 264 static void Log(const param_type& p, std::wstring* l) { |
324 l->append(StringPrintf(L"%d", p)); | 265 l->append(StringPrintf(L"%d", p)); |
325 } | 266 } |
326 }; | 267 }; |
327 | 268 |
328 template <> | 269 template <> |
329 struct ParamTraits<WebKit::WebMediaPlayerAction> { | 270 struct ParamTraits<WebKit::WebMediaPlayerAction> { |
330 typedef WebKit::WebMediaPlayerAction param_type; | 271 typedef WebKit::WebMediaPlayerAction param_type; |
331 static void Write(Message* m, const param_type& p) { | 272 static void Write(Message* m, const param_type& p); |
332 WriteParam(m, static_cast<int>(p.type)); | 273 static bool Read(const Message* m, void** iter, param_type* r); |
333 WriteParam(m, p.enable); | 274 static void Log(const param_type& p, std::wstring* l); |
334 } | |
335 static bool Read(const Message* m, void** iter, param_type* r) { | |
336 int temp; | |
337 if (!ReadParam(m, iter, &temp)) | |
338 return false; | |
339 r->type = static_cast<param_type::Type>(temp); | |
340 return ReadParam(m, iter, &r->enable); | |
341 } | |
342 static void Log(const param_type& p, std::wstring* l) { | |
343 l->append(L"("); | |
344 switch (p.type) { | |
345 case WebKit::WebMediaPlayerAction::Play: | |
346 l->append(L"Play"); | |
347 break; | |
348 case WebKit::WebMediaPlayerAction::Mute: | |
349 l->append(L"Mute"); | |
350 break; | |
351 case WebKit::WebMediaPlayerAction::Loop: | |
352 l->append(L"Loop"); | |
353 break; | |
354 default: | |
355 l->append(L"Unknown"); | |
356 break; | |
357 } | |
358 l->append(L", "); | |
359 LogParam(p.enable, l); | |
360 l->append(L")"); | |
361 } | |
362 }; | 275 }; |
363 | 276 |
364 template <> | 277 template <> |
365 struct ParamTraits<WebKit::WebContextMenuData::MediaType> { | 278 struct ParamTraits<WebKit::WebContextMenuData::MediaType> { |
366 typedef WebKit::WebContextMenuData::MediaType param_type; | 279 typedef WebKit::WebContextMenuData::MediaType param_type; |
367 static void Write(Message* m, const param_type& p) { | 280 static void Write(Message* m, const param_type& p) { |
368 m->WriteInt(p); | 281 m->WriteInt(p); |
369 } | 282 } |
370 static bool Read(const Message* m, void** iter, param_type* r) { | 283 static bool Read(const Message* m, void** iter, param_type* r) { |
371 int temp; | 284 int temp; |
372 bool res = m->ReadInt(iter, &temp); | 285 bool res = m->ReadInt(iter, &temp); |
373 *r = static_cast<param_type>(temp); | 286 *r = static_cast<param_type>(temp); |
374 return res; | 287 return res; |
375 } | 288 } |
376 }; | 289 }; |
377 | 290 |
378 template <> | 291 template <> |
379 struct ParamTraits<WebKit::WebCompositionUnderline> { | 292 struct ParamTraits<WebKit::WebCompositionUnderline> { |
380 typedef WebKit::WebCompositionUnderline param_type; | 293 typedef WebKit::WebCompositionUnderline param_type; |
381 static void Write(Message* m, const param_type& p) { | 294 static void Write(Message* m, const param_type& p); |
382 WriteParam(m, p.startOffset); | 295 static bool Read(const Message* m, void** iter, param_type* p); |
383 WriteParam(m, p.endOffset); | 296 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 }; | 297 }; |
406 | 298 |
407 template <> | 299 template <> |
408 struct ParamTraits<WebKit::WebTextInputType> { | 300 struct ParamTraits<WebKit::WebTextInputType> { |
409 typedef WebKit::WebTextInputType param_type; | 301 typedef WebKit::WebTextInputType param_type; |
410 static void Write(Message* m, const param_type& p) { | 302 static void Write(Message* m, const param_type& p) { |
411 m->WriteInt(p); | 303 m->WriteInt(p); |
412 } | 304 } |
413 static bool Read(const Message* m, void** iter, param_type* p) { | 305 static bool Read(const Message* m, void** iter, param_type* p) { |
414 int type; | 306 int type; |
(...skipping 19 matching lines...) Expand all Loading... |
434 control = L"UNKNOWN"; | 326 control = L"UNKNOWN"; |
435 break; | 327 break; |
436 } | 328 } |
437 LogParam(control, l); | 329 LogParam(control, l); |
438 } | 330 } |
439 }; | 331 }; |
440 | 332 |
441 } // namespace IPC | 333 } // namespace IPC |
442 | 334 |
443 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 335 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
OLD | NEW |