content_param_traits.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This file is used to define IPC::ParamTraits<> specializations for a number 6// of types so that they can be serialized over IPC. IPC::ParamTraits<> 7// specializations for basic types (like int and std::string) and types in the 8// 'base' project can be found in ipc/ipc_message_utils.h. This file contains 9// specializations for types that are used by the content code, and which need 10// manual serialization code. This is usually because they're not structs with 11// public members, or because the same type is being used in multiple 12// *_messages.h headers. 13 14#ifndef CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_ 15#define CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_ 16 17#include "content/common/content_param_traits_macros.h" 18#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 19#include "webkit/glue/npruntime_util.h" 20#include "webkit/glue/webcursor.h" 21 22namespace net { 23class IPEndPoint; 24} 25 26namespace ui { 27class Range; 28} 29 30namespace content { 31 32// Define the NPVariant_Param struct and its enum here since it needs manual 33// serialization code. 34enum NPVariant_ParamEnum { 35 NPVARIANT_PARAM_VOID, 36 NPVARIANT_PARAM_NULL, 37 NPVARIANT_PARAM_BOOL, 38 NPVARIANT_PARAM_INT, 39 NPVARIANT_PARAM_DOUBLE, 40 NPVARIANT_PARAM_STRING, 41 // Used when when the NPObject is running in the caller's process, so we 42 // create an NPObjectProxy in the other process. 43 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID, 44 // Used when the NPObject we're sending is running in the callee's process 45 // (i.e. we have an NPObjectProxy for it). In that case we want the callee 46 // to just use the raw pointer. 47 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID, 48}; 49 50struct NPVariant_Param { 51 NPVariant_Param(); 52 ~NPVariant_Param(); 53 54 NPVariant_ParamEnum type; 55 bool bool_value; 56 int int_value; 57 double double_value; 58 std::string string_value; 59 int npobject_routing_id; 60}; 61 62struct NPIdentifier_Param { 63 NPIdentifier_Param(); 64 ~NPIdentifier_Param(); 65 66 NPIdentifier identifier; 67}; 68 69} // namespace content 70 71namespace IPC { 72 73template <> 74struct ParamTraits<net::IPEndPoint> { 75 typedef net::IPEndPoint param_type; 76 static void Write(Message* m, const param_type& p); 77 static bool Read(const Message* m, PickleIterator* iter, param_type* p); 78 static void Log(const param_type& p, std::string* l); 79}; 80 81template <> 82struct ParamTraits<content::NPVariant_Param> { 83 typedef content::NPVariant_Param param_type; 84 static void Write(Message* m, const param_type& p); 85 static bool Read(const Message* m, PickleIterator* iter, param_type* r); 86 static void Log(const param_type& p, std::string* l); 87}; 88 89template <> 90struct ParamTraits<content::NPIdentifier_Param> { 91 typedef content::NPIdentifier_Param param_type; 92 static void Write(Message* m, const param_type& p); 93 static bool Read(const Message* m, PickleIterator* iter, param_type* r); 94 static void Log(const param_type& p, std::string* l); 95}; 96 97template <> 98struct ParamTraits<ui::Range> { 99 typedef ui::Range param_type; 100 static void Write(Message* m, const param_type& p); 101 static bool Read(const Message* m, PickleIterator* iter, param_type* r); 102 static void Log(const param_type& p, std::string* l); 103}; 104 105template <> 106struct ParamTraits<WebCursor> { 107 typedef WebCursor param_type; 108 static void Write(Message* m, const param_type& p) { 109 p.Serialize(m); 110 } 111 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { 112 return r->Deserialize(iter); 113 } 114 static void Log(const param_type& p, std::string* l) { 115 l->append("<WebCursor>"); 116 } 117}; 118 119typedef const WebKit::WebInputEvent* WebInputEventPointer; 120template <> 121struct ParamTraits<WebInputEventPointer> { 122 typedef WebInputEventPointer param_type; 123 static void Write(Message* m, const param_type& p); 124 // Note: upon read, the event has the lifetime of the message. 125 static bool Read(const Message* m, PickleIterator* iter, param_type* r); 126 static void Log(const param_type& p, std::string* l); 127}; 128 129} // namespace IPC 130 131#endif // CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_ 132