| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 void HandleMessage(PP_Instance instance, PP_Var message_data) { | 23 void HandleMessage(PP_Instance instance, PP_Var message_data) { |
| 24 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 24 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 25 if (!dispatcher || (message_data.type == PP_VARTYPE_OBJECT)) { | 25 if (!dispatcher || (message_data.type == PP_VARTYPE_OBJECT)) { |
| 26 // The dispatcher should always be valid, and the browser should never send | 26 // The dispatcher should always be valid, and the browser should never send |
| 27 // an 'object' var over PPP_Messaging. | 27 // an 'object' var over PPP_Messaging. |
| 28 NOTREACHED(); | 28 NOTREACHED(); |
| 29 return; | 29 return; |
| 30 } | 30 } |
| 31 | 31 |
| 32 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( | 32 dispatcher->Send(new PpapiMsg_PPPMessaging_HandleMessage( |
| 33 INTERFACE_ID_PPP_MESSAGING, | 33 API_ID_PPP_MESSAGING, |
| 34 instance, | 34 instance, |
| 35 SerializedVarSendInput(dispatcher, message_data))); | 35 SerializedVarSendInput(dispatcher, message_data))); |
| 36 } | 36 } |
| 37 | 37 |
| 38 static const PPP_Messaging messaging_interface = { | 38 static const PPP_Messaging messaging_interface = { |
| 39 &HandleMessage | 39 &HandleMessage |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher) { | 42 InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher) { |
| 43 return new PPP_Messaging_Proxy(dispatcher); | 43 return new PPP_Messaging_Proxy(dispatcher); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 55 } | 55 } |
| 56 | 56 |
| 57 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { | 57 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { |
| 58 } | 58 } |
| 59 | 59 |
| 60 // static | 60 // static |
| 61 const InterfaceProxy::Info* PPP_Messaging_Proxy::GetInfo() { | 61 const InterfaceProxy::Info* PPP_Messaging_Proxy::GetInfo() { |
| 62 static const Info info = { | 62 static const Info info = { |
| 63 &messaging_interface, | 63 &messaging_interface, |
| 64 PPP_MESSAGING_INTERFACE, | 64 PPP_MESSAGING_INTERFACE, |
| 65 INTERFACE_ID_PPP_MESSAGING, | 65 API_ID_PPP_MESSAGING, |
| 66 false, | 66 false, |
| 67 &CreateMessagingProxy, | 67 &CreateMessagingProxy, |
| 68 }; | 68 }; |
| 69 return &info; | 69 return &info; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { | 72 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 73 bool handled = true; | 73 bool handled = true; |
| 74 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) | 74 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) |
| 75 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, | 75 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, |
| 76 OnMsgHandleMessage) | 76 OnMsgHandleMessage) |
| 77 IPC_MESSAGE_UNHANDLED(handled = false) | 77 IPC_MESSAGE_UNHANDLED(handled = false) |
| 78 IPC_END_MESSAGE_MAP() | 78 IPC_END_MESSAGE_MAP() |
| 79 return handled; | 79 return handled; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void PPP_Messaging_Proxy::OnMsgHandleMessage( | 82 void PPP_Messaging_Proxy::OnMsgHandleMessage( |
| 83 PP_Instance instance, SerializedVarReceiveInput message_data) { | 83 PP_Instance instance, SerializedVarReceiveInput message_data) { |
| 84 PP_Var received_var(message_data.Get(dispatcher())); | 84 PP_Var received_var(message_data.Get(dispatcher())); |
| 85 // SerializedVarReceiveInput will decrement the reference count, but we want | 85 // SerializedVarReceiveInput will decrement the reference count, but we want |
| 86 // to give the recipient a reference. | 86 // to give the recipient a reference. |
| 87 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); | 87 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); |
| 88 ppp_messaging_impl_->HandleMessage(instance, received_var); | 88 ppp_messaging_impl_->HandleMessage(instance, received_var); |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace proxy | 91 } // namespace proxy |
| 92 } // namespace ppapi | 92 } // namespace ppapi |
| OLD | NEW |