blob: bd616f3dca158923bfef8239435df9479008c0a6 [file] [log] [blame]
[email protected]da816272013-05-15 21:31:171// Copyright (c) 2013 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_PLUGIN_PARAM_TRAITS_H_
15#define CONTENT_COMMON_PLUGIN_PARAM_TRAITS_H_
16
17#include <string>
18#include "ipc/ipc_message.h"
19#include "ipc/ipc_param_traits.h"
20#include "webkit/glue/npruntime_util.h"
21
22namespace content {
23
24// Define the NPVariant_Param struct and its enum here since it needs manual
25// serialization code.
26enum NPVariant_ParamEnum {
27 NPVARIANT_PARAM_VOID,
28 NPVARIANT_PARAM_NULL,
29 NPVARIANT_PARAM_BOOL,
30 NPVARIANT_PARAM_INT,
31 NPVARIANT_PARAM_DOUBLE,
32 NPVARIANT_PARAM_STRING,
33 // Used when when the NPObject is running in the caller's process, so we
34 // create an NPObjectProxy in the other process.
35 NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
36 // Used when the NPObject we're sending is running in the callee's process
37 // (i.e. we have an NPObjectProxy for it). In that case we want the callee
38 // to just use the raw pointer.
39 NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
40};
41
42struct NPVariant_Param {
43 NPVariant_Param();
44 ~NPVariant_Param();
45
46 NPVariant_ParamEnum type;
47 bool bool_value;
48 int int_value;
49 double double_value;
50 std::string string_value;
51 int npobject_routing_id;
52};
53
54struct NPIdentifier_Param {
55 NPIdentifier_Param();
56 ~NPIdentifier_Param();
57
58 NPIdentifier identifier;
59};
60
61} // namespace content
62
63namespace IPC {
64
65template <>
66struct ParamTraits<content::NPVariant_Param> {
67 typedef content::NPVariant_Param param_type;
68 static void Write(Message* m, const param_type& p);
69 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
70 static void Log(const param_type& p, std::string* l);
71};
72
73template <>
74struct ParamTraits<content::NPIdentifier_Param> {
75 typedef content::NPIdentifier_Param param_type;
76 static void Write(Message* m, const param_type& p);
77 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
78 static void Log(const param_type& p, std::string* l);
79};
80
81} // namespace IPC
82
83#endif // CONTENT_COMMON_CONTENT_PARAM_TRAITS_H_