1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file.
490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// This file is used to define IPC::ParamTraits<> specializations for a number
690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// of types so that they can be serialized over IPC.  IPC::ParamTraits<>
790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// specializations for basic types (like int and std::string) and types in the
890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 'base' project can be found in ipc/ipc_message_utils.h.  This file contains
990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// specializations for types that are used by the content code, and which need
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// manual serialization code.  This is usually because they're not structs with
1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// public members, or because the same type is being used in multiple
1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// *_messages.h headers.
1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#ifndef CONTENT_CHILD_PLUGIN_PARAM_TRAITS_H_
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#define CONTENT_CHILD_PLUGIN_PARAM_TRAITS_H_
1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string>
18ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch
19ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "content/child/npapi/npruntime_util.h"
2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ipc/ipc_message.h"
2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ipc/ipc_param_traits.h"
2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace content {
2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Define the NPVariant_Param struct and its enum here since it needs manual
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// serialization code.
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)enum NPVariant_ParamEnum {
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_VOID,
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_NULL,
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_BOOL,
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_INT,
3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_DOUBLE,
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_STRING,
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Used when when the NPObject is running in the caller's process, so we
35eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // create an NPObjectProxy in the other process. To support object ownership
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // tracking the routing-Id of the NPObject's owning plugin instance is
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // passed alongside that of the object itself.
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID,
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Used when the NPObject we're sending is running in the callee's process
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // (i.e. we have an NPObjectProxy for it).  In that case we want the callee
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // to just use the raw pointer.
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID,
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct NPVariant_Param {
4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVariant_Param();
4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ~NPVariant_Param();
4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPVariant_ParamEnum type;
5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool bool_value;
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int int_value;
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  double double_value;
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  std::string string_value;
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  int npobject_routing_id;
55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  int npobject_owner_id;
5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct NPIdentifier_Param {
5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPIdentifier_Param();
6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ~NPIdentifier_Param();
6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NPIdentifier identifier;
6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace content
6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace IPC {
6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <>
7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ParamTraits<content::NPVariant_Param> {
7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef content::NPVariant_Param param_type;
7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void Write(Message* m, const param_type& p);
7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static bool Read(const Message* m, PickleIterator* iter, param_type* r);
7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void Log(const param_type& p, std::string* l);
7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)template <>
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct ParamTraits<content::NPIdentifier_Param> {
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  typedef content::NPIdentifier_Param param_type;
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void Write(Message* m, const param_type& p);
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static bool Read(const Message* m, PickleIterator* iter, param_type* r);
8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  static void Log(const param_type& p, std::string* l);
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)};
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace IPC
8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif  // CONTENT_CHILD_PLUGIN_PARAM_TRAITS_H_
88