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 3 // found in the LICENSE file. 4 5 #include "ppapi/proxy/ppp_mouse_lock_proxy.h" 6 7 #include "ppapi/c/ppp_mouse_lock.h" 8 #include "ppapi/proxy/host_dispatcher.h" 9 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/shared_impl/proxy_lock.h" 11 12 namespace ppapi { 13 namespace proxy { 14 15 namespace { 16 17 #if !defined(OS_NACL) 18 void MouseLockLost(PP_Instance instance) { 19 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 20 if (!dispatcher) { 21 // The dispatcher should always be valid. 22 NOTREACHED(); 23 return; 24 } 25 26 dispatcher->Send(new PpapiMsg_PPPMouseLock_MouseLockLost( 27 API_ID_PPP_MOUSE_LOCK, instance)); 28 } 29 30 static const PPP_MouseLock mouse_lock_interface = { 31 &MouseLockLost 32 }; 33 #else 34 // The NaCl plugin doesn't need the host side interface - stub it out. 35 static const PPP_MouseLock mouse_lock_interface = {}; 36 #endif // !defined(OS_NACL) 37 38 InterfaceProxy* CreateMouseLockProxy(Dispatcher* dispatcher) { 39 return new PPP_MouseLock_Proxy(dispatcher); 40 } 41 42 } // namespace 43 44 PPP_MouseLock_Proxy::PPP_MouseLock_Proxy(Dispatcher* dispatcher) 45 : InterfaceProxy(dispatcher), 46 ppp_mouse_lock_impl_(NULL) { 47 if (dispatcher->IsPlugin()) { 48 ppp_mouse_lock_impl_ = static_cast<const PPP_MouseLock*>( 49 dispatcher->local_get_interface()(PPP_MOUSELOCK_INTERFACE)); 50 } 51 } 52 53 PPP_MouseLock_Proxy::~PPP_MouseLock_Proxy() { 54 } 55 56 // static 57 const InterfaceProxy::Info* PPP_MouseLock_Proxy::GetInfo() { 58 static const Info info = { 59 &mouse_lock_interface, 60 PPP_MOUSELOCK_INTERFACE, 61 API_ID_PPP_MOUSE_LOCK, 62 false, 63 &CreateMouseLockProxy, 64 }; 65 return &info; 66 } 67 68 bool PPP_MouseLock_Proxy::OnMessageReceived(const IPC::Message& msg) { 69 if (!dispatcher()->IsPlugin()) 70 return false; 71 72 bool handled = true; 73 IPC_BEGIN_MESSAGE_MAP(PPP_MouseLock_Proxy, msg) 74 IPC_MESSAGE_HANDLER(PpapiMsg_PPPMouseLock_MouseLockLost, 75 OnMsgMouseLockLost) 76 IPC_MESSAGE_UNHANDLED(handled = false) 77 IPC_END_MESSAGE_MAP() 78 return handled; 79 } 80 81 void PPP_MouseLock_Proxy::OnMsgMouseLockLost(PP_Instance instance) { 82 if (ppp_mouse_lock_impl_) 83 CallWhileUnlocked(ppp_mouse_lock_impl_->MouseLockLost, instance); 84 } 85 86 } // namespace proxy 87 } // namespace ppapi 88