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"
22 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher
* dispatcher
)
23 : InterfaceProxy(dispatcher
),
24 ppp_messaging_impl_(NULL
) {
25 if (dispatcher
->IsPlugin()) {
26 ppp_messaging_impl_
= static_cast<const PPP_Messaging
*>(
27 dispatcher
->local_get_interface()(PPP_MESSAGING_INTERFACE
));
31 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() {
34 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message
& msg
) {
35 if (!dispatcher()->IsPlugin())
39 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy
, msg
)
40 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage
,
42 IPC_MESSAGE_UNHANDLED(handled
= false)
47 void PPP_Messaging_Proxy::OnMsgHandleMessage(
48 PP_Instance instance
, SerializedVarReceiveInput message_data
) {
49 PP_Var
received_var(message_data
.GetForInstance(dispatcher(), instance
));
50 // SerializedVarReceiveInput will decrement the reference count, but we want
51 // to give the recipient a reference.
52 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var
);
53 CallWhileUnlocked(ppp_messaging_impl_
->HandleMessage
,