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

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

Issue 6682033: Move plugin messages to content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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/browser/plugin_service.cc ('k') | content/common/common_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')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 is used to define IPC::ParamTraits<> specializations for a number 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<> 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 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 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 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 10 // manual serialization code. This is usually because they're not structs with
11 // public members.. 11 // public members..
12 12
13 #ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ 13 #ifndef CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
14 #define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ 14 #define CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
15 #pragma once 15 #pragma once
16 16
17 #include "app/surface/transport_dib.h"
17 #include "base/platform_file.h" 18 #include "base/platform_file.h"
18 #include "base/ref_counted.h" 19 #include "base/ref_counted.h"
20 #include "base/string_number_conversions.h"
19 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
20 #include "ipc/ipc_message_utils.h" 22 #include "ipc/ipc_message_utils.h"
21 #include "net/base/ip_endpoint.h" 23 #include "net/base/ip_endpoint.h"
22 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
23 // !!! WARNING: DO NOT ADD NEW WEBKIT DEPENDENCIES !!! 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
24
25 //
26 // That means don't add #includes to any file in 'webkit/' or
27 // 'third_party/WebKit/'. Chrome Frame and NACL build parts of base/ and
28 // content/common/ for a mini-library that doesn't depend on webkit.
29
30 // TODO(erg): The following headers are historical and only work because
31 // their definitions are inlined, which also needs to be fixed.
32 #include "ui/gfx/native_widget_types.h" 26 #include "ui/gfx/native_widget_types.h"
33 #include "webkit/blob/blob_data.h" 27 #include "webkit/blob/blob_data.h"
28 #include "webkit/glue/npruntime_util.h"
34 #include "webkit/glue/resource_type.h" 29 #include "webkit/glue/resource_type.h"
35 30 #include "webkit/glue/webcursor.h"
36 // Forward declarations.
37 class GURL;
38 31
39 namespace gfx { 32 namespace gfx {
40 class Point; 33 class Point;
41 class Rect; 34 class Rect;
42 class Size; 35 class Size;
43 } // namespace gfx 36 } // namespace gfx
44 37
45 namespace net { 38 namespace net {
46 class HttpResponseHeaders; 39 class HttpResponseHeaders;
47 class HostPortPair; 40 class HostPortPair;
48 class UploadData; 41 class UploadData;
49 } 42 }
50 43
51 namespace webkit_glue { 44 namespace webkit_glue {
52 struct ResourceDevToolsInfo; 45 struct ResourceDevToolsInfo;
53 struct ResourceLoadTimingInfo; 46 struct ResourceLoadTimingInfo;
54 } 47 }
55 48
49 // Define the NPVariant_Param struct and its enum here since it needs manual
50 // serialization code.
51 enum NPVariant_ParamEnum {
52 NPVARIANT_PARAM_VOID,
53 NPVARIANT_PARAM_NULL,
54 NPVARIANT_PARAM_BOOL,
55 NPVARIANT_PARAM_INT,
56 NPVARIANT_PARAM_DOUBLE,
57 NPVARIANT_PARAM_STRING,
58 // Used when when the NPObject is running in the caller's process, so we
59 // create an NPObjectProxy in the other process.
60 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
61 // Used when the NPObject we're sending is running in the callee's process
62 // (i.e. we have an NPObjectProxy for it). In that case we want the callee
63 // to just use the raw pointer.
64 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
65 };
66
67 struct NPVariant_Param {
68 NPVariant_Param();
69 ~NPVariant_Param();
70
71 NPVariant_ParamEnum type;
72 bool bool_value;
73 int int_value;
74 double double_value;
75 std::string string_value;
76 int npobject_routing_id;
77 };
78
79 struct NPIdentifier_Param {
80 NPIdentifier_Param();
81 ~NPIdentifier_Param();
82
83 NPIdentifier identifier;
84 };
85
56 namespace IPC { 86 namespace IPC {
57 87
58 template <> 88 template <>
59 struct ParamTraits<GURL> { 89 struct ParamTraits<GURL> {
60 typedef GURL param_type; 90 typedef GURL param_type;
61 static void Write(Message* m, const param_type& p); 91 static void Write(Message* m, const param_type& p);
62 static bool Read(const Message* m, void** iter, param_type* p); 92 static bool Read(const Message* m, void** iter, param_type* p);
63 static void Log(const param_type& p, std::string* l); 93 static void Log(const param_type& p, std::string* l);
64 }; 94 };
65 95
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 }; 227 };
198 228
199 template <> 229 template <>
200 struct ParamTraits<scoped_refptr<webkit_blob::BlobData > > { 230 struct ParamTraits<scoped_refptr<webkit_blob::BlobData > > {
201 typedef scoped_refptr<webkit_blob::BlobData> param_type; 231 typedef scoped_refptr<webkit_blob::BlobData> param_type;
202 static void Write(Message* m, const param_type& p); 232 static void Write(Message* m, const param_type& p);
203 static bool Read(const Message* m, void** iter, param_type* r); 233 static bool Read(const Message* m, void** iter, param_type* r);
204 static void Log(const param_type& p, std::string* l); 234 static void Log(const param_type& p, std::string* l);
205 }; 235 };
206 236
237 template <>
238 struct ParamTraits<NPVariant_Param> {
239 typedef NPVariant_Param param_type;
240 static void Write(Message* m, const param_type& p);
241 static bool Read(const Message* m, void** iter, param_type* r);
242 static void Log(const param_type& p, std::string* l);
243 };
244
245 template <>
246 struct ParamTraits<NPIdentifier_Param> {
247 typedef NPIdentifier_Param param_type;
248 static void Write(Message* m, const param_type& p);
249 static bool Read(const Message* m, void** iter, param_type* r);
250 static void Log(const param_type& p, std::string* l);
251 };
252
253 template <>
254 struct ParamTraits<WebCursor> {
255 typedef WebCursor param_type;
256 static void Write(Message* m, const param_type& p) {
257 p.Serialize(m);
258 }
259 static bool Read(const Message* m, void** iter, param_type* r) {
260 return r->Deserialize(m, iter);
261 }
262 static void Log(const param_type& p, std::string* l) {
263 l->append("<WebCursor>");
264 }
265 };
266
267
268 template <>
269 struct ParamTraits<WebKit::WebInputEvent::Type> {
270 typedef WebKit::WebInputEvent::Type param_type;
271 static void Write(Message* m, const param_type& p) {
272 m->WriteInt(p);
273 }
274 static bool Read(const Message* m, void** iter, param_type* p) {
275 int type;
276 if (!m->ReadInt(iter, &type))
277 return false;
278 *p = static_cast<WebKit::WebInputEvent::Type>(type);
279 return true;
280 }
281 static void Log(const param_type& p, std::string* l) {
282 const char* type;
283 switch (p) {
284 case WebKit::WebInputEvent::MouseDown:
285 type = "MouseDown";
286 break;
287 case WebKit::WebInputEvent::MouseUp:
288 type = "MouseUp";
289 break;
290 case WebKit::WebInputEvent::MouseMove:
291 type = "MouseMove";
292 break;
293 case WebKit::WebInputEvent::MouseLeave:
294 type = "MouseLeave";
295 break;
296 case WebKit::WebInputEvent::MouseEnter:
297 type = "MouseEnter";
298 break;
299 case WebKit::WebInputEvent::MouseWheel:
300 type = "MouseWheel";
301 break;
302 case WebKit::WebInputEvent::RawKeyDown:
303 type = "RawKeyDown";
304 break;
305 case WebKit::WebInputEvent::KeyDown:
306 type = "KeyDown";
307 break;
308 case WebKit::WebInputEvent::KeyUp:
309 type = "KeyUp";
310 break;
311 default:
312 type = "None";
313 break;
314 }
315 LogParam(std::string(type), l);
316 }
317 };
318
319 typedef const WebKit::WebInputEvent* WebInputEventPointer;
320 template <>
321 struct ParamTraits<WebInputEventPointer> {
322 typedef WebInputEventPointer param_type;
323 static void Write(Message* m, const param_type& p) {
324 m->WriteData(reinterpret_cast<const char*>(p), p->size);
325 }
326 // Note: upon read, the event has the lifetime of the message.
327 static bool Read(const Message* m, void** iter, param_type* r) {
328 const char* data;
329 int data_length;
330 if (!m->ReadData(iter, &data, &data_length)) {
331 NOTREACHED();
332 return false;
333 }
334 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) {
335 NOTREACHED();
336 return false;
337 }
338 param_type event = reinterpret_cast<param_type>(data);
339 // Check that the data size matches that of the event (we check the latter
340 // in the delegate).
341 if (data_length != static_cast<int>(event->size)) {
342 NOTREACHED();
343 return false;
344 }
345 *r = event;
346 return true;
347 }
348 static void Log(const param_type& p, std::string* l) {
349 l->append("(");
350 LogParam(p->size, l);
351 l->append(", ");
352 LogParam(p->type, l);
353 l->append(", ");
354 LogParam(p->timeStampSeconds, l);
355 l->append(")");
356 }
357 };
358
359 #if defined(OS_WIN)
360 template<>
361 struct ParamTraits<TransportDIB::Id> {
362 typedef TransportDIB::Id param_type;
363 static void Write(Message* m, const param_type& p) {
364 WriteParam(m, p.handle);
365 WriteParam(m, p.sequence_num);
366 }
367 static bool Read(const Message* m, void** iter, param_type* r) {
368 return (ReadParam(m, iter, &r->handle) &&
369 ReadParam(m, iter, &r->sequence_num));
370 }
371 static void Log(const param_type& p, std::string* l) {
372 l->append("TransportDIB(");
373 LogParam(p.handle, l);
374 l->append(", ");
375 LogParam(p.sequence_num, l);
376 l->append(")");
377 }
378 };
379 #endif
380
207 } // namespace IPC 381 } // namespace IPC
208 382
209 #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_ 383 #endif // CONTENT_COMMON_COMMON_PARAM_TRAITS_H_
OLDNEW
« no previous file with comments | « content/browser/plugin_service.cc ('k') | content/common/common_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698