OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/message_handler.h" | 5 #include "ppapi/proxy/message_handler.h" |
6 | 6 |
7 #include "ipc/ipc_message.h" | 7 #include "ipc/ipc_message.h" |
8 #include "ppapi/proxy/plugin_dispatcher.h" | 8 #include "ppapi/proxy/plugin_dispatcher.h" |
9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
10 #include "ppapi/proxy/ppb_message_loop_proxy.h" | 10 #include "ppapi/proxy/ppb_message_loop_proxy.h" |
11 #include "ppapi/shared_impl/proxy_lock.h" | 11 #include "ppapi/shared_impl/proxy_lock.h" |
12 #include "ppapi/shared_impl/scoped_pp_var.h" | 12 #include "ppapi/shared_impl/scoped_pp_var.h" |
13 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
14 | 14 |
15 namespace ppapi { | 15 namespace ppapi { |
16 namespace proxy { | 16 namespace proxy { |
17 namespace { | 17 namespace { |
18 | 18 |
19 typedef void (*HandleMessageFunc)(PP_Instance, void*, PP_Var); | 19 typedef void (*HandleMessageFunc)(PP_Instance, void*, const PP_Var*); |
20 typedef PP_Var (*HandleBlockingMessageFunc)(PP_Instance, void*, PP_Var); | 20 typedef void (*HandleBlockingMessageFunc)( |
21 PP_Instance, void*, const PP_Var*, PP_Var*); | |
21 | 22 |
22 void HandleMessageWrapper(HandleMessageFunc function, | 23 void HandleMessageWrapper(HandleMessageFunc function, |
23 PP_Instance instance, | 24 PP_Instance instance, |
24 void* user_data, | 25 void* user_data, |
25 ScopedPPVar message_data) { | 26 ScopedPPVar message_data) { |
26 CallWhileUnlocked(function, instance, user_data, message_data.get()); | 27 CallWhileUnlocked(function, instance, user_data, |
28 const_cast<const PP_Var*>(&message_data.get())); | |
teravest
2014/09/11 15:42:41
As discussed off-thread, the const_cast<> here loo
| |
27 } | 29 } |
28 | 30 |
29 void HandleBlockingMessageWrapper(HandleBlockingMessageFunc function, | 31 void HandleBlockingMessageWrapper(HandleBlockingMessageFunc function, |
30 PP_Instance instance, | 32 PP_Instance instance, |
31 void* user_data, | 33 void* user_data, |
32 ScopedPPVar message_data, | 34 ScopedPPVar message_data, |
33 scoped_ptr<IPC::Message> reply_msg) { | 35 scoped_ptr<IPC::Message> reply_msg) { |
34 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 36 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
35 if (!dispatcher) | 37 if (!dispatcher) |
36 return; | 38 return; |
37 PP_Var return_value = CallWhileUnlocked(function, | 39 PP_Var result = PP_MakeUndefined(); |
38 instance, | 40 CallWhileUnlocked(function, instance, user_data, |
39 user_data, | 41 const_cast<const PP_Var*>(&message_data.get()), &result); |
40 message_data.get()); | |
41 PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( | 42 PpapiMsg_PPPMessageHandler_HandleBlockingMessage::WriteReplyParams( |
42 reply_msg.get(), | 43 reply_msg.get(), |
43 SerializedVarReturnValue::Convert(dispatcher, return_value), | 44 SerializedVarReturnValue::Convert(dispatcher, result), |
44 true /* was_handled */); | 45 true /* was_handled */); |
45 dispatcher->Send(reply_msg.release()); | 46 dispatcher->Send(reply_msg.release()); |
46 } | 47 } |
47 | 48 |
48 } // namespace | 49 } // namespace |
49 | 50 |
50 // static | 51 // static |
51 scoped_ptr<MessageHandler> MessageHandler::Create( | 52 scoped_ptr<MessageHandler> MessageHandler::Create( |
52 PP_Instance instance, | 53 PP_Instance instance, |
53 const PPP_MessageHandler_0_1* handler_if, | 54 const PPP_MessageHandler_0_2* handler_if, |
54 void* user_data, | 55 void* user_data, |
55 PP_Resource message_loop, | 56 PP_Resource message_loop, |
56 int32_t* error) { | 57 int32_t* error) { |
57 scoped_ptr<MessageHandler> result; | 58 scoped_ptr<MessageHandler> result; |
58 // The interface and all function pointers must be valid. | 59 // The interface and all function pointers must be valid. |
59 if (!handler_if || | 60 if (!handler_if || |
60 !handler_if->HandleMessage || | 61 !handler_if->HandleMessage || |
61 !handler_if->HandleBlockingMessage || | 62 !handler_if->HandleBlockingMessage || |
62 !handler_if->Destroy) { | 63 !handler_if->Destroy) { |
63 *error = PP_ERROR_BADARGUMENT; | 64 *error = PP_ERROR_BADARGUMENT; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 RunWhileLocked(base::Bind(&HandleBlockingMessageWrapper, | 115 RunWhileLocked(base::Bind(&HandleBlockingMessageWrapper, |
115 handler_if_->HandleBlockingMessage, | 116 handler_if_->HandleBlockingMessage, |
116 instance_, | 117 instance_, |
117 user_data_, | 118 user_data_, |
118 var, | 119 var, |
119 base::Passed(reply_msg.Pass())))); | 120 base::Passed(reply_msg.Pass())))); |
120 } | 121 } |
121 | 122 |
122 MessageHandler::MessageHandler( | 123 MessageHandler::MessageHandler( |
123 PP_Instance instance, | 124 PP_Instance instance, |
124 const PPP_MessageHandler_0_1* handler_if, | 125 const PPP_MessageHandler_0_2* handler_if, |
125 void* user_data, | 126 void* user_data, |
126 scoped_refptr<MessageLoopResource> message_loop) | 127 scoped_refptr<MessageLoopResource> message_loop) |
127 : instance_(instance), | 128 : instance_(instance), |
128 handler_if_(handler_if), | 129 handler_if_(handler_if), |
129 user_data_(user_data), | 130 user_data_(user_data), |
130 message_loop_(message_loop) { | 131 message_loop_(message_loop) { |
131 } | 132 } |
132 | 133 |
133 } // namespace proxy | 134 } // namespace proxy |
134 } // namespace ppapi | 135 } // namespace ppapi |
OLD | NEW |