ppp_instance_private_proxy.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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#include "ppapi/proxy/ppp_instance_private_proxy.h"
6
7#include <algorithm>
8
9#include "ppapi/c/pp_var.h"
10#include "ppapi/c/private/ppp_instance_private.h"
11#include "ppapi/proxy/host_dispatcher.h"
12#include "ppapi/proxy/plugin_dispatcher.h"
13#include "ppapi/proxy/plugin_resource_tracker.h"
14#include "ppapi/proxy/ppapi_messages.h"
15#include "ppapi/shared_impl/proxy_lock.h"
16
17namespace ppapi {
18namespace proxy {
19
20namespace {
21
22PP_Var GetInstanceObject(PP_Instance instance) {
23  Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
24  ReceiveSerializedVarReturnValue result;
25  dispatcher->Send(new PpapiMsg_PPPInstancePrivate_GetInstanceObject(
26      API_ID_PPP_INSTANCE_PRIVATE, instance, &result));
27  return result.Return(dispatcher);
28}
29
30static const PPP_Instance_Private instance_private_interface = {
31  &GetInstanceObject
32};
33
34InterfaceProxy* CreateInstancePrivateProxy(Dispatcher* dispatcher) {
35  return new PPP_Instance_Private_Proxy(dispatcher);
36}
37
38}  // namespace
39
40PPP_Instance_Private_Proxy::PPP_Instance_Private_Proxy(Dispatcher* dispatcher)
41    : InterfaceProxy(dispatcher),
42      ppp_instance_private_impl_(NULL) {
43  if (dispatcher->IsPlugin()) {
44    ppp_instance_private_impl_ = static_cast<const PPP_Instance_Private*>(
45        dispatcher->local_get_interface()(PPP_INSTANCE_PRIVATE_INTERFACE));
46  }
47}
48
49PPP_Instance_Private_Proxy::~PPP_Instance_Private_Proxy() {
50}
51
52// static
53const InterfaceProxy::Info* PPP_Instance_Private_Proxy::GetInfo() {
54  static const Info info = {
55    &instance_private_interface,
56    PPP_INSTANCE_PRIVATE_INTERFACE,
57    API_ID_PPP_INSTANCE_PRIVATE,
58    false,
59    &CreateInstancePrivateProxy,
60  };
61  return &info;
62}
63
64bool PPP_Instance_Private_Proxy::OnMessageReceived(const IPC::Message& msg) {
65  bool handled = true;
66  IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Private_Proxy, msg)
67    IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstancePrivate_GetInstanceObject,
68                        OnMsgGetInstanceObject)
69    IPC_MESSAGE_UNHANDLED(handled = false)
70  IPC_END_MESSAGE_MAP()
71  return handled;
72}
73
74void PPP_Instance_Private_Proxy::OnMsgGetInstanceObject(
75    PP_Instance instance,
76    SerializedVarReturnValue result) {
77  result.Return(dispatcher(),
78                CallWhileUnlocked(ppp_instance_private_impl_->GetInstanceObject,
79                                  instance));
80}
81
82}  // namespace proxy
83}  // namespace ppapi
84