Home | History | Annotate | Download | only in proxy
      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 
     17 namespace ppapi {
     18 namespace proxy {
     19 
     20 namespace {
     21 
     22 PP_Var GetInstanceObject(PP_Instance instance) {
     23   Dispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
     24   if (!dispatcher->permissions().HasPermission(PERMISSION_PRIVATE))
     25     return PP_MakeUndefined();
     26 
     27   ReceiveSerializedVarReturnValue result;
     28   dispatcher->Send(new PpapiMsg_PPPInstancePrivate_GetInstanceObject(
     29       API_ID_PPP_INSTANCE_PRIVATE, instance, &result));
     30   return result.Return(dispatcher);
     31 }
     32 
     33 static const PPP_Instance_Private instance_private_interface = {
     34   &GetInstanceObject
     35 };
     36 
     37 }  // namespace
     38 
     39 PPP_Instance_Private_Proxy::PPP_Instance_Private_Proxy(Dispatcher* dispatcher)
     40     : InterfaceProxy(dispatcher),
     41       ppp_instance_private_impl_(NULL) {
     42   if (dispatcher->IsPlugin()) {
     43     ppp_instance_private_impl_ = static_cast<const PPP_Instance_Private*>(
     44         dispatcher->local_get_interface()(PPP_INSTANCE_PRIVATE_INTERFACE));
     45   }
     46 }
     47 
     48 PPP_Instance_Private_Proxy::~PPP_Instance_Private_Proxy() {
     49 }
     50 
     51 // static
     52 const PPP_Instance_Private* PPP_Instance_Private_Proxy::GetProxyInterface() {
     53   return &instance_private_interface;
     54 }
     55 
     56 bool PPP_Instance_Private_Proxy::OnMessageReceived(const IPC::Message& msg) {
     57   if (!dispatcher()->IsPlugin())
     58     return false;
     59 
     60   bool handled = true;
     61   IPC_BEGIN_MESSAGE_MAP(PPP_Instance_Private_Proxy, msg)
     62     IPC_MESSAGE_HANDLER(PpapiMsg_PPPInstancePrivate_GetInstanceObject,
     63                         OnMsgGetInstanceObject)
     64     IPC_MESSAGE_UNHANDLED(handled = false)
     65   IPC_END_MESSAGE_MAP()
     66   return handled;
     67 }
     68 
     69 void PPP_Instance_Private_Proxy::OnMsgGetInstanceObject(
     70     PP_Instance instance,
     71     SerializedVarReturnValue result) {
     72   result.Return(dispatcher(),
     73                 CallWhileUnlocked(ppp_instance_private_impl_->GetInstanceObject,
     74                                   instance));
     75 }
     76 
     77 }  // namespace proxy
     78 }  // namespace ppapi
     79