• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 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_CHILD_PLUGIN_PARAM_TRAITS_H_
15 #define CONTENT_CHILD_PLUGIN_PARAM_TRAITS_H_
16 
17 #include <string>
18 
19 #include "content/child/npapi/npruntime_util.h"
20 #include "ipc/ipc_message.h"
21 #include "ipc/ipc_param_traits.h"
22 
23 namespace content {
24 
25 // Define the NPVariant_Param struct and its enum here since it needs manual
26 // serialization code.
27 enum NPVariant_ParamEnum {
28   NPVARIANT_PARAM_VOID,
29   NPVARIANT_PARAM_NULL,
30   NPVARIANT_PARAM_BOOL,
31   NPVARIANT_PARAM_INT,
32   NPVARIANT_PARAM_DOUBLE,
33   NPVARIANT_PARAM_STRING,
34   // Used when when the NPObject is running in the caller's process, so we
35   // create an NPObjectProxy in the other process. To support object ownership
36   // tracking the routing-Id of the NPObject's owning plugin instance is
37   // passed alongside that of the object itself.
38   NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
39   // Used when the NPObject we're sending is running in the callee's process
40   // (i.e. we have an NPObjectProxy for it).  In that case we want the callee
41   // to just use the raw pointer.
42   NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
43 };
44 
45 struct NPVariant_Param {
46   NPVariant_Param();
47   ~NPVariant_Param();
48 
49   NPVariant_ParamEnum type;
50   bool bool_value;
51   int int_value;
52   double double_value;
53   std::string string_value;
54   int npobject_routing_id;
55   int npobject_owner_id;
56 };
57 
58 struct NPIdentifier_Param {
59   NPIdentifier_Param();
60   ~NPIdentifier_Param();
61 
62   NPIdentifier identifier;
63 };
64 
65 }  // namespace content
66 
67 namespace IPC {
68 
69 template <>
70 struct ParamTraits<content::NPVariant_Param> {
71   typedef content::NPVariant_Param param_type;
72   static void Write(Message* m, const param_type& p);
73   static bool Read(const Message* m, PickleIterator* iter, param_type* r);
74   static void Log(const param_type& p, std::string* l);
75 };
76 
77 template <>
78 struct ParamTraits<content::NPIdentifier_Param> {
79   typedef content::NPIdentifier_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 }  // namespace IPC
86 
87 #endif  // CONTENT_CHILD_PLUGIN_PARAM_TRAITS_H_
88