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.
5 #include "ppapi/proxy/ppp_messaging_proxy.h"
9 #include "ppapi/c/ppp_messaging.h"
10 #include "ppapi/proxy/host_dispatcher.h"
11 #include "ppapi/proxy/plugin_resource_tracker.h"
12 #include "ppapi/proxy/plugin_var_tracker.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/serialized_var.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/proxy_lock.h"
17 #include "ppapi/shared_impl/var_tracker.h"
25 void HandleMessage(PP_Instance instance
, PP_Var message_data
) {
26 HostDispatcher
* dispatcher
= HostDispatcher::GetForInstance(instance
);
27 if (!dispatcher
|| (message_data
.type
== PP_VARTYPE_OBJECT
)) {
28 // The dispatcher should always be valid, and the browser should never send
29 // an 'object' var over PPP_Messaging.
34 dispatcher
->Send(new PpapiMsg_PPPMessaging_HandleMessage(
37 SerializedVarSendInputShmem(dispatcher
, message_data
, instance
)));
40 static const PPP_Messaging messaging_interface
= {
44 // The NaCl plugin doesn't need the host side interface - stub it out.
45 static const PPP_Messaging messaging_interface
= {};
46 #endif // !defined(OS_NACL)
50 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher
* dispatcher
)
51 : InterfaceProxy(dispatcher
),
52 ppp_messaging_impl_(NULL
) {
53 if (dispatcher
->IsPlugin()) {
54 ppp_messaging_impl_
= static_cast<const PPP_Messaging
*>(
55 dispatcher
->local_get_interface()(PPP_MESSAGING_INTERFACE
));
59 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() {
63 const PPP_Messaging
* PPP_Messaging_Proxy::GetProxyInterface() {
64 return &messaging_interface
;
67 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
68 if (!dispatcher()->IsPlugin())
72 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy
, msg
)
73 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage
,
75 IPC_MESSAGE_UNHANDLED(handled
= false)
80 void PPP_Messaging_Proxy::OnMsgHandleMessage(
81 PP_Instance instance
, SerializedVarReceiveInput message_data
) {
82 PP_Var
received_var(message_data
.GetForInstance(dispatcher(), instance
));
83 // SerializedVarReceiveInput will decrement the reference count, but we want
84 // to give the recipient a reference.
85 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var
);
86 CallWhileUnlocked(ppp_messaging_impl_
->HandleMessage
,