| 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: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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/WebDragOperation.h" |
| 31 #include "webkit/api/public/WebFindOptions.h" | 31 #include "webkit/api/public/WebFindOptions.h" |
| 32 #include "webkit/api/public/WebInputEvent.h" | 32 #include "webkit/api/public/WebInputEvent.h" |
| 33 #include "webkit/api/public/WebMediaPlayerAction.h" |
| 33 #include "webkit/api/public/WebScreenInfo.h" | 34 #include "webkit/api/public/WebScreenInfo.h" |
| 34 #include "webkit/api/public/WebTextDirection.h" | 35 #include "webkit/api/public/WebTextDirection.h" |
| 35 | 36 |
| 36 namespace IPC { | 37 namespace IPC { |
| 37 | 38 |
| 38 template <> | 39 template <> |
| 39 struct ParamTraits<WebKit::WebRect> { | 40 struct ParamTraits<WebKit::WebRect> { |
| 40 typedef WebKit::WebRect param_type; | 41 typedef WebKit::WebRect param_type; |
| 41 static void Write(Message* m, const param_type& p) { | 42 static void Write(Message* m, const param_type& p) { |
| 42 WriteParam(m, p.x); | 43 WriteParam(m, p.x); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return false; | 298 return false; |
| 298 *r = static_cast<param_type>(value); | 299 *r = static_cast<param_type>(value); |
| 299 return true; | 300 return true; |
| 300 } | 301 } |
| 301 static void Log(const param_type& p, std::wstring* l) { | 302 static void Log(const param_type& p, std::wstring* l) { |
| 302 LogParam(static_cast<int>(p), l); | 303 LogParam(static_cast<int>(p), l); |
| 303 } | 304 } |
| 304 }; | 305 }; |
| 305 | 306 |
| 306 template <> | 307 template <> |
| 307 struct ParamTraits<WebKit::WebDragOperation> { | 308 struct ParamTraits<WebKit::WebDragOperation> { |
| 308 typedef WebKit::WebDragOperation param_type; | 309 typedef WebKit::WebDragOperation param_type; |
| 309 static void Write(Message* m, const param_type& p) { | 310 static void Write(Message* m, const param_type& p) { |
| 310 m->WriteInt(p); | 311 m->WriteInt(p); |
| 311 } | 312 } |
| 312 static bool Read(const Message* m, void** iter, param_type* r) { | 313 static bool Read(const Message* m, void** iter, param_type* r) { |
| 313 int temp; | 314 int temp; |
| 314 bool res = m->ReadInt(iter, &temp); | 315 bool res = m->ReadInt(iter, &temp); |
| 315 *r = static_cast<param_type>(temp); | 316 *r = static_cast<param_type>(temp); |
| 316 return res; | 317 return res; |
| 317 } | 318 } |
| 318 static void Log(const param_type& p, std::wstring* l) { | 319 static void Log(const param_type& p, std::wstring* l) { |
| 319 l->append(StringPrintf(L"%d", p)); | 320 l->append(StringPrintf(L"%d", p)); |
| 320 } | 321 } |
| 321 }; | 322 }; |
| 322 | 323 |
| 324 template <> |
| 325 struct ParamTraits<WebKit::WebMediaPlayerAction> { |
| 326 typedef WebKit::WebMediaPlayerAction param_type; |
| 327 static void Write(Message* m, const param_type& p) { |
| 328 WriteParam(m, static_cast<int>(p.type)); |
| 329 WriteParam(m, p.enable); |
| 330 } |
| 331 static bool Read(const Message* m, void** iter, param_type* r) { |
| 332 int temp; |
| 333 if (!ReadParam(m, iter, &temp)) |
| 334 return false; |
| 335 r->type = static_cast<param_type::Type>(temp); |
| 336 return ReadParam(m, iter, &r->enable); |
| 337 } |
| 338 static void Log(const param_type& p, std::wstring* l) { |
| 339 l->append(L"("); |
| 340 switch (p.type) { |
| 341 case WebKit::WebMediaPlayerAction::Play: |
| 342 l->append(L"Play"); |
| 343 break; |
| 344 case WebKit::WebMediaPlayerAction::Mute: |
| 345 l->append(L"Mute"); |
| 346 break; |
| 347 case WebKit::WebMediaPlayerAction::Loop: |
| 348 l->append(L"Loop"); |
| 349 break; |
| 350 default: |
| 351 l->append(L"Unknown"); |
| 352 break; |
| 353 } |
| 354 l->append(L", "); |
| 355 LogParam(p.enable, l); |
| 356 l->append(L")"); |
| 357 } |
| 358 }; |
| 359 |
| 323 } // namespace IPC | 360 } // namespace IPC |
| 324 | 361 |
| 325 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ | 362 #endif // CHROME_COMMON_WEBKIT_PARAM_TRAITS_H_ |
| OLD | NEW |