Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: content/common/content_param_traits.h

Issue 10980010: Cleanup the IPC param traits structure (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix android Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/content_message_generator.h ('k') | content/common/content_param_traits.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
22 namespace net {
23 class IPEndPoint;
24 }
25
26 namespace ui {
27 class Range;
28 }
29
30 // Define the NPVariant_Param struct and its enum here since it needs manual
31 // serialization code.
32 enum NPVariant_ParamEnum {
33 NPVARIANT_PARAM_VOID,
34 NPVARIANT_PARAM_NULL,
35 NPVARIANT_PARAM_BOOL,
36 NPVARIANT_PARAM_INT,
37 NPVARIANT_PARAM_DOUBLE,
38 NPVARIANT_PARAM_STRING,
39 // Used when when the NPObject is running in the caller's process, so we
40 // create an NPObjectProxy in the other process.
41 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
42 // Used when the NPObject we're sending is running in the callee's process
43 // (i.e. we have an NPObjectProxy for it). In that case we want the callee
44 // to just use the raw pointer.
45 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
46 };
47
48 struct NPVariant_Param {
49 NPVariant_Param();
50 ~NPVariant_Param();
51
52 NPVariant_ParamEnum type;
53 bool bool_value;
54 int int_value;
55 double double_value;
56 std::string string_value;
57 int npobject_routing_id;
58 };
59
60 struct NPIdentifier_Param {
61 NPIdentifier_Param();
62 ~NPIdentifier_Param();
63
64 NPIdentifier identifier;
65 };
66
67 namespace IPC {
68
69 template <>
70 struct ParamTraits<net::IPEndPoint> {
71 typedef net::IPEndPoint param_type;
72 static void Write(Message* m, const param_type& p);
73 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
74 static void Log(const param_type& p, std::string* l);
75 };
76
77 template <>
78 struct ParamTraits<NPVariant_Param> {
79 typedef NPVariant_Param param_type;
80 static void Write(Message* m, const param_type& p);
81 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
82 static void Log(const param_type& p, std::string* l);
83 };
84
85 template <>
86 struct ParamTraits<NPIdentifier_Param> {
87 typedef NPIdentifier_Param param_type;
88 static void Write(Message* m, const param_type& p);
89 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
90 static void Log(const param_type& p, std::string* l);
91 };
92
93 template <>
94 struct ParamTraits<ui::Range> {
95 typedef ui::Range param_type;
96 static void Write(Message* m, const param_type& p);
97 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
98 static void Log(const param_type& p, std::string* l);
99 };
100
101 template <>
102 struct ParamTraits<WebCursor> {
103 typedef WebCursor param_type;
104 static void Write(Message* m, const param_type& p) {
105 p.Serialize(m);
106 }
107 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
108 return r->Deserialize(iter);
109 }
110 static void Log(const param_type& p, std::string* l) {
111 l->append("<WebCursor>");
112 }
113 };
114
115 typedef const WebKit::WebInputEvent* WebInputEventPointer;
116 template <>
117 struct ParamTraits<WebInputEventPointer> {
118 typedef WebInputEventPointer param_type;
119 static void Write(Message* m, const param_type& p) {
120 m->WriteData(reinterpret_cast<const char*>(p), p->size);
121 }
122 // Note: upon read, the event has the lifetime of the message.
123 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
124 const char* data;
125 int data_length;
126 if (!m->ReadData(iter, &data, &data_length)) {
127 NOTREACHED();
128 return false;
129 }
130 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) {
131 NOTREACHED();
132 return false;
133 }
134 param_type event = reinterpret_cast<param_type>(data);
135 // Check that the data size matches that of the event (we check the latter
136 // in the delegate).
137 if (data_length != static_cast<int>(event->size)) {
138 NOTREACHED();
139 return false;
140 }
141 *r = event;
142 return true;
143 }
144 static void Log(const param_type& p, std::string* l) {
145 l->append("(");
146 LogParam(p->size, l);
147 l->append(", ");
148 LogParam(p->type, l);
149 l->append(", ");
150 LogParam(p->timeStampSeconds, l);
151 l->append(")");
152 }
153 };
154
155 } // namespace IPC
156
157 #endif // CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_
OLDNEW
« no previous file with comments | « content/common/content_message_generator.h ('k') | content/common/content_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698