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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 static const PPP_Messaging messaging_interface = { | 40 static const PPP_Messaging messaging_interface = { |
41 &HandleMessage | 41 &HandleMessage |
42 }; | 42 }; |
43 #else | 43 #else |
44 // The NaCl plugin doesn't need the host side interface - stub it out. | 44 // The NaCl plugin doesn't need the host side interface - stub it out. |
45 static const PPP_Messaging messaging_interface = {}; | 45 static const PPP_Messaging messaging_interface = {}; |
46 #endif // !defined(OS_NACL) | 46 #endif // !defined(OS_NACL) |
47 | 47 |
48 InterfaceProxy* CreateMessagingProxy(Dispatcher* dispatcher) { | |
49 return new PPP_Messaging_Proxy(dispatcher); | |
50 } | |
51 | |
52 } // namespace | 48 } // namespace |
53 | 49 |
54 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) | 50 PPP_Messaging_Proxy::PPP_Messaging_Proxy(Dispatcher* dispatcher) |
55 : InterfaceProxy(dispatcher), | 51 : InterfaceProxy(dispatcher), |
56 ppp_messaging_impl_(NULL) { | 52 ppp_messaging_impl_(NULL) { |
57 if (dispatcher->IsPlugin()) { | 53 if (dispatcher->IsPlugin()) { |
58 ppp_messaging_impl_ = static_cast<const PPP_Messaging*>( | 54 ppp_messaging_impl_ = static_cast<const PPP_Messaging*>( |
59 dispatcher->local_get_interface()(PPP_MESSAGING_INTERFACE)); | 55 dispatcher->local_get_interface()(PPP_MESSAGING_INTERFACE)); |
60 } | 56 } |
61 } | 57 } |
62 | 58 |
63 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { | 59 PPP_Messaging_Proxy::~PPP_Messaging_Proxy() { |
64 } | 60 } |
65 | 61 |
66 // static | 62 // static |
67 const InterfaceProxy::Info* PPP_Messaging_Proxy::GetInfo() { | 63 const PPP_Messaging* PPP_Messaging_Proxy::GetProxyInterface() { |
68 static const Info info = { | 64 return &messaging_interface; |
69 &messaging_interface, | |
70 PPP_MESSAGING_INTERFACE, | |
71 API_ID_PPP_MESSAGING, | |
72 false, | |
73 &CreateMessagingProxy, | |
74 }; | |
75 return &info; | |
76 } | 65 } |
77 | 66 |
78 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { | 67 bool PPP_Messaging_Proxy::OnMessageReceived(const IPC::Message& msg) { |
79 if (!dispatcher()->IsPlugin()) | 68 if (!dispatcher()->IsPlugin()) |
80 return false; | 69 return false; |
81 | 70 |
82 bool handled = true; | 71 bool handled = true; |
83 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) | 72 IPC_BEGIN_MESSAGE_MAP(PPP_Messaging_Proxy, msg) |
84 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, | 73 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMessaging_HandleMessage, |
85 OnMsgHandleMessage) | 74 OnMsgHandleMessage) |
86 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
87 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
88 return handled; | 77 return handled; |
89 } | 78 } |
90 | 79 |
91 void PPP_Messaging_Proxy::OnMsgHandleMessage( | 80 void PPP_Messaging_Proxy::OnMsgHandleMessage( |
92 PP_Instance instance, SerializedVarReceiveInput message_data) { | 81 PP_Instance instance, SerializedVarReceiveInput message_data) { |
93 PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); | 82 PP_Var received_var(message_data.GetForInstance(dispatcher(), instance)); |
94 // SerializedVarReceiveInput will decrement the reference count, but we want | 83 // SerializedVarReceiveInput will decrement the reference count, but we want |
95 // to give the recipient a reference. | 84 // to give the recipient a reference. |
96 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); | 85 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(received_var); |
97 CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, | 86 CallWhileUnlocked(ppp_messaging_impl_->HandleMessage, |
98 instance, | 87 instance, |
99 received_var); | 88 received_var); |
100 } | 89 } |
101 | 90 |
102 } // namespace proxy | 91 } // namespace proxy |
103 } // namespace ppapi | 92 } // namespace ppapi |
OLD | NEW |