OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppp_messaging_proxy.h" | 5 #include "ppapi/proxy/ppp_messaging_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ppapi/c/ppp_messaging.h" | 9 #include "ppapi/c/ppp_messaging.h" |
10 #include "ppapi/proxy/host_dispatcher.h" | 10 #include "ppapi/proxy/host_dispatcher.h" |
11 #include "ppapi/proxy/message_handler.h" | |
12 #include "ppapi/proxy/plugin_dispatcher.h" | |
11 #include "ppapi/proxy/plugin_resource_tracker.h" | 13 #include "ppapi/proxy/plugin_resource_tracker.h" |
12 #include "ppapi/proxy/plugin_var_tracker.h" | 14 #include "ppapi/proxy/plugin_var_tracker.h" |
13 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/serialized_var.h" | 16 #include "ppapi/proxy/serialized_var.h" |
15 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
16 #include "ppapi/shared_impl/proxy_lock.h" | 18 #include "ppapi/shared_impl/proxy_lock.h" |
19 #include "ppapi/shared_impl/scoped_pp_var.h" | |
17 #include "ppapi/shared_impl/var_tracker.h" | 20 #include "ppapi/shared_impl/var_tracker.h" |
18 | 21 |
19 namespace ppapi { | 22 namespace ppapi { |
20 namespace proxy { | 23 namespace proxy { |
21 | 24 |
25 namespace { | |
26 | |
27 MessageHandler* GetMessageHandler(Dispatcher* dispatcher, | |
28 PP_Instance instance) { | |
29 if (!dispatcher) | |
30 return NULL; | |
31 if (!dispatcher->IsPlugin()) | |
32 return NULL; | |
33 PluginDispatcher* plugin_dispatcher = | |
34 static_cast<PluginDispatcher*>(dispatcher); | |
35 InstanceData* instance_data = plugin_dispatcher->GetInstanceData(instance); | |
36 if (!instance_data) | |
37 return NULL; | |
38 | |
39 return instance_data->message_handler.get(); | |
40 } | |
41 | |
42 } | |
43 | |
22 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) | 44 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) |
23 : InterfaceProxy(dispatcher), | 45 : InterfaceProxy(dispatcher), |
24 ppp_messaging_impl_(NULL) { | 46 ppp_messaging_impl_(NULL) { |
25 if (dispatcher->IsPlugin()) { | 47 if (dispatcher->IsPlugin()) { |
26 ppp_messaging_impl_ = static_cast<const PPP_Messaging*>( | 48 ppp_messaging_impl_ = static_cast<const PPP_Messaging*>( |
27 dispatcher->local_get_interface()(PPP_MESSAGING_INTERFACE)); | 49 dispatcher->local_get_interface()(PPP_MESSAGING_INTERFACE)); |
28 } | 50 } |
29 } | 51 } |
30 | 52 |
31 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { | 53 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { |
32 } | 54 } |
33 | 55 |
34 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { | 56 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { |
35 if (!dispatcher()->IsPlugin()) | 57 if (!dispatcher()->IsPlugin()) |
36 return false; | 58 return false; |
37 | 59 |
38 bool handled = true; | 60 bool handled = true; |
39 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) | 61 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) |
40 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, | 62 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, |
41 OnMsgHandleMessage) | 63 OnMsgHandleMessage) |
64 IPC_MESSAGE_HANDLER_DELAY_REPLY( | |
65 PpapiMsg_PPPMessageHandler_HandleBlockingMessage, | |
66 OnMsgHandleBlockingMessage) | |
42 IPC_MESSAGE_UNHANDLED(handled = false) | 67 IPC_MESSAGE_UNHANDLED(handled = false) |
43 IPC_END_MESSAGE_MAP() | 68 IPC_END_MESSAGE_MAP() |
44 return handled; | 69 return handled; |
45 } | 70 } |
46 | 71 |
47 void PPP_Messaging_Proxy::OnMsgHandleMessage( | 72 void PPP_Messaging_Proxy::OnMsgHandleMessage( |
48 PP_Instance instance, SerializedVarReceiveInput message_data) { | 73 PP_Instance instance, SerializedVarReceiveInput message_data) { |
49 PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); | 74 PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); |
50 // SerializedVarReceiveInput will decrement the reference count, but we want | 75 MessageHandler* message_handler = GetMessageHandler(dispatcher(), instance); |
51 // to give the recipient a reference. | 76 if (message_handler) { |
52 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); | 77 message_handler->HandleMessage(ScopedPPVar(received_var)); |
53 CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, | 78 } else { |
raymes
2014/06/06 06:38:17
nit: there's double space here before the {
| |
54 instance, | 79 // SerializedVarReceiveInput will decrement the reference count, but we want |
55 received_var); | 80 // to give the recipient a reference in the legacy API. |
81 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); | |
82 CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, | |
83 instance, | |
84 received_var); | |
85 } | |
56 } | 86 } |
57 | 87 |
88 void PPP_Messaging_Proxy::OnMsgHandleBlockingMessage( | |
89 PP_Instance instance, | |
90 SerializedVarReceiveInput message_data, | |
91 IPC::Message* reply_msg) { | |
92 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
| |
93 MessageHandler* message_handler = GetMessageHandler(dispatcher(), instance); | |
94 if (message_handler) { | |
95 message_handler->HandleBlockingMessage(ScopedPPVar(received_var), | |
96 scoped_ptr<IPC::Message>(reply_msg)); | |
97 return; | |
98 } | |
99 // We have no handler, but we still need to respond to unblock the renderer | |
100 // and inform the JavaScript caller. | |
101 PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( | |
102 reply_msg, | |
103 SerializedVarReturnValue::Convert(dispatcher(), PP_MakeUndefined()), | |
104 false /* was_handled */); | |
105 dispatcher()->Send(reply_msg); | |
106 } | |
107 | |
108 | |
58 } // namespace proxy | 109 } // namespace proxy |
59 } // namespace ppapi | 110 } // namespace ppapi |
OLD | NEW |