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