Chromium Code Reviews| Index: ppapi/proxy/ppp_messaging_proxy.cc |
| diff --git a/ppapi/proxy/ppp_messaging_proxy.cc b/ppapi/proxy/ppp_messaging_proxy.cc |
| index ba83ca7432b88fc829528ccc5c4abf754984f557..a262de23ca178975bf8795a4de1570b96f6bc357 100644 |
| --- a/ppapi/proxy/ppp_messaging_proxy.cc |
| +++ b/ppapi/proxy/ppp_messaging_proxy.cc |
| @@ -8,17 +8,39 @@ |
| #include "ppapi/c/ppp_messaging.h" |
| #include "ppapi/proxy/host_dispatcher.h" |
| +#include "ppapi/proxy/message_handler.h" |
| +#include "ppapi/proxy/plugin_dispatcher.h" |
| #include "ppapi/proxy/plugin_resource_tracker.h" |
| #include "ppapi/proxy/plugin_var_tracker.h" |
| #include "ppapi/proxy/ppapi_messages.h" |
| #include "ppapi/proxy/serialized_var.h" |
| #include "ppapi/shared_impl/ppapi_globals.h" |
| #include "ppapi/shared_impl/proxy_lock.h" |
| +#include "ppapi/shared_impl/scoped_pp_var.h" |
| #include "ppapi/shared_impl/var_tracker.h" |
| namespace ppapi { |
| namespace proxy { |
| +namespace { |
| + |
| +MessageHandler* GetMessageHandler(Dispatcher* dispatcher, |
| + PP_Instance instance) { |
| + if (!dispatcher) |
| + return NULL; |
| + if (!dispatcher->IsPlugin()) |
| + return NULL; |
| + PluginDispatcher* plugin_dispatcher = |
| + static_cast<PluginDispatcher*>(dispatcher); |
| + InstanceData* instance_data = plugin_dispatcher->GetInstanceData(instance); |
| + if (!instance_data) |
| + return NULL; |
| + |
| + return instance_data->message_handler.get(); |
| +} |
| + |
| +} |
| + |
| PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) |
| : InterfaceProxy(dispatcher), |
| ppp_messaging_impl_(NULL) { |
| @@ -39,6 +61,9 @@ bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) |
| IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, |
| OnMsgHandleMessage) |
| + IPC_MESSAGE_HANDLER_DELAY_REPLY( |
| + PpapiMsg_PPPMessageHandler_HandleBlockingMessage, |
| + OnMsgHandleBlockingMessage) |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP() |
| return handled; |
| @@ -47,13 +72,39 @@ bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| void PPP_Messaging_Proxy::OnMsgHandleMessage( |
| PP_Instance instance, SerializedVarReceiveInput message_data) { |
| PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); |
| - // SerializedVarReceiveInput will decrement the reference count, but we want |
| - // to give the recipient a reference. |
| - PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); |
| - CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, |
| - instance, |
| - received_var); |
| + MessageHandler* message_handler = GetMessageHandler(dispatcher(), instance); |
| + if (message_handler) { |
| + message_handler->HandleMessage(ScopedPPVar(received_var)); |
| + } else { |
|
raymes
2014/06/06 06:38:17
nit: there's double space here before the {
|
| + // SerializedVarReceiveInput will decrement the reference count, but we want |
| + // to give the recipient a reference in the legacy API. |
| + PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); |
| + CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, |
| + instance, |
| + received_var); |
| + } |
| +} |
| + |
| +void PPP_Messaging_Proxy::OnMsgHandleBlockingMessage( |
| + PP_Instance instance, |
| + SerializedVarReceiveInput message_data, |
| + IPC::Message* reply_msg) { |
| + PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); |
|
raymes
2014/06/10 04:50:47
Should this be in a ScopedPPVar?
dmichael (off chromium)
2014/06/13 22:01:26
I guess I just copied from an existing use of Seri
|
| + MessageHandler* message_handler = GetMessageHandler(dispatcher(), instance); |
| + if (message_handler) { |
| + message_handler->HandleBlockingMessage(ScopedPPVar(received_var), |
| + scoped_ptr<IPC::Message>(reply_msg)); |
| + return; |
| + } |
| + // We have no handler, but we still need to respond to unblock the renderer |
| + // and inform the JavaScript caller. |
| + PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( |
| + reply_msg, |
| + SerializedVarReturnValue::Convert(dispatcher(), PP_MakeUndefined()), |
| + false /* was_handled */); |
| + dispatcher()->Send(reply_msg); |
| } |
| + |
| } // namespace proxy |
| } // namespace ppapi |