diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 16:56:34 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-08 16:56:34 +0000 |
commit | 18d871ff3cc3d59c58d479dbe82373a1f0a232b5 (patch) | |
tree | 30eea5317dcfea1cc965792c1e9691767b30f485 /ppapi | |
parent | 25bd71ae5f7770990ac30c5ad5ca8745a952e1c0 (diff) | |
download | chromium_src-18d871ff3cc3d59c58d479dbe82373a1f0a232b5.zip chromium_src-18d871ff3cc3d59c58d479dbe82373a1f0a232b5.tar.gz chromium_src-18d871ff3cc3d59c58d479dbe82373a1f0a232b5.tar.bz2 |
Introduce a new Pepper interface: PPB/PPP_MouseLock.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/7828019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100166 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
49 files changed, 1082 insertions, 3 deletions
diff --git a/ppapi/api/dev/ppb_mouse_lock_dev.idl b/ppapi/api/dev/ppb_mouse_lock_dev.idl new file mode 100755 index 0000000..7898994 --- /dev/null +++ b/ppapi/api/dev/ppb_mouse_lock_dev.idl @@ -0,0 +1,57 @@ +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * This file defines the <code>PPB_MouseLock_Dev</code> interface. + */ + +label Chrome { + M15 = 0.1 +}; + +/** + * The <code>PPB_MouseLock_Dev</code> interface is implemented by the browser. + * It provides a way of locking the target of mouse events to a single plugin + * instance and removing the cursor from view. This is a useful input mode for + * certain classes of applications, especially first person perspective 3D + * applications and 3D modelling software. + */ +interface PPB_MouseLock_Dev { + /** + * Requests the mouse to be locked. The browser will permit mouse lock only + * while the tab is in fullscreen mode. + * + * While the mouse is locked, the cursor is implicitly hidden from the user. + * Any movement of the mouse will generate a + * <code>PP_INPUTEVENT_TYPE_MOUSEMOVE</code>. The <code>GetPosition</code> of + * <code>PPB_MouseInputEvent</code> reports the last known mouse position just + * as mouse lock was entered; while the <code>GetMovement</code> provides + * relative movement information, which indicates what the change in position + * of the mouse would be had it not been locked. + * + * The browser may revoke mouse lock for reasons including but not limited to + * the user pressing the ESC key, the user activating another program via a + * reserved keystroke (e.g., ALT+TAB), or some other system event. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon + * completion. + * + * @return An int32_t containing an error code from <code>pp_errors.h</code>. + */ + int32_t LockMouse([in] PP_Instance instance, + [in] PP_CompletionCallback callback); + + /** + * Causes the mouse to be unlocked, allowing it to track user movement again. + * This is an asynchronous operation. The plugin instance will be notified via + * the <code>PPP_MouseLock</code> interface when it has lost the mouse lock. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + */ + void UnlockMouse([in] PP_Instance instance); +}; diff --git a/ppapi/api/dev/ppp_mouse_lock_dev.idl b/ppapi/api/dev/ppp_mouse_lock_dev.idl new file mode 100755 index 0000000..0ebeb97 --- /dev/null +++ b/ppapi/api/dev/ppp_mouse_lock_dev.idl @@ -0,0 +1,28 @@ +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/** + * This file defines the <code>PPP_MouseLock_Dev</code> interface. + */ + +label Chrome { + M15 = 0.1 +}; + +/** + * The <code>PPP_MouseLock_Dev</code> interface contains pointers to functions + * that you must implement to receive mouse lock events from the browser. + */ +interface PPP_MouseLock_Dev { + /** + * Called when the instance loses the mouse lock, e.g. because the user + * pressed the ESC key. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + */ + void MouseLockLost([in] PP_Instance instance); +}; + diff --git a/ppapi/c/dev/ppb_mouse_lock_dev.h b/ppapi/c/dev/ppb_mouse_lock_dev.h new file mode 100755 index 0000000..f5e2a884 --- /dev/null +++ b/ppapi/c/dev/ppb_mouse_lock_dev.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* From dev/ppb_mouse_lock_dev.idl modified Tue Sep 6 16:06:47 2011. */ + +#ifndef PPAPI_C_DEV_PPB_MOUSE_LOCK_DEV_H_ +#define PPAPI_C_DEV_PPB_MOUSE_LOCK_DEV_H_ + +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_stdint.h" + +#define PPB_MOUSELOCK_DEV_INTERFACE_0_1 "PPB_MouseLock(Dev);0.1" +#define PPB_MOUSELOCK_DEV_INTERFACE PPB_MOUSELOCK_DEV_INTERFACE_0_1 + +/** + * @file + * This file defines the <code>PPB_MouseLock_Dev</code> interface. + */ + + +/** + * @addtogroup Interfaces + * @{ + */ +/** + * The <code>PPB_MouseLock_Dev</code> interface is implemented by the browser. + * It provides a way of locking the target of mouse events to a single plugin + * instance and removing the cursor from view. This is a useful input mode for + * certain classes of applications, especially first person perspective 3D + * applications and 3D modelling software. + */ +struct PPB_MouseLock_Dev { + /** + * Requests the mouse to be locked. The browser will permit mouse lock only + * while the tab is in fullscreen mode. + * + * While the mouse is locked, the cursor is implicitly hidden from the user. + * Any movement of the mouse will generate a + * <code>PP_INPUTEVENT_TYPE_MOUSEMOVE</code>. The <code>GetPosition</code> of + * <code>PPB_MouseInputEvent</code> reports the last known mouse position just + * as mouse lock was entered; while the <code>GetMovement</code> provides + * relative movement information, which indicates what the change in position + * of the mouse would be had it not been locked. + * + * The browser may revoke mouse lock for reasons including but not limited to + * the user pressing the ESC key, the user activating another program via a + * reserved keystroke (e.g., ALT+TAB), or some other system event. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon + * completion. + * + * @return An int32_t containing an error code from <code>pp_errors.h</code>. + */ + int32_t (*LockMouse)(PP_Instance instance, + struct PP_CompletionCallback callback); + /** + * Causes the mouse to be unlocked, allowing it to track user movement again. + * This is an asynchronous operation. The plugin instance will be notified via + * the <code>PPP_MouseLock</code> interface when it has lost the mouse lock. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + */ + void (*UnlockMouse)(PP_Instance instance); +}; +/** + * @} + */ + +#endif /* PPAPI_C_DEV_PPB_MOUSE_LOCK_DEV_H_ */ + diff --git a/ppapi/c/dev/ppp_mouse_lock_dev.h b/ppapi/c/dev/ppp_mouse_lock_dev.h new file mode 100755 index 0000000..fee1ce7 --- /dev/null +++ b/ppapi/c/dev/ppp_mouse_lock_dev.h @@ -0,0 +1,47 @@ +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* From dev/ppp_mouse_lock_dev.idl modified Tue Sep 6 16:07:16 2011. */ + +#ifndef PPAPI_C_DEV_PPP_MOUSE_LOCK_DEV_H_ +#define PPAPI_C_DEV_PPP_MOUSE_LOCK_DEV_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_macros.h" +#include "ppapi/c/pp_stdint.h" + +#define PPP_MOUSELOCK_DEV_INTERFACE_0_1 "PPP_MouseLock(Dev);0.1" +#define PPP_MOUSELOCK_DEV_INTERFACE PPP_MOUSELOCK_DEV_INTERFACE_0_1 + +/** + * @file + * This file defines the <code>PPP_MouseLock_Dev</code> interface. + */ + + +/** + * @addtogroup Interfaces + * @{ + */ +/** + * The <code>PPP_MouseLock_Dev</code> interface contains pointers to functions + * that you must implement to receive mouse lock events from the browser. + */ +struct PPP_MouseLock_Dev { + /** + * Called when the instance loses the mouse lock, e.g. because the user + * pressed the ESC key. + * + * @param[in] instance A <code>PP_Instance</code> identifying one instance + * of a module. + */ + void (*MouseLockLost)(PP_Instance instance); +}; +/** + * @} + */ + +#endif /* PPAPI_C_DEV_PPP_MOUSE_LOCK_DEV_H_ */ + diff --git a/ppapi/cpp/dev/mouse_lock_dev.cc b/ppapi/cpp/dev/mouse_lock_dev.cc new file mode 100755 index 0000000..57b724d --- /dev/null +++ b/ppapi/cpp/dev/mouse_lock_dev.cc @@ -0,0 +1,63 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/cpp/dev/mouse_lock_dev.h" + +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/cpp/instance.h" +#include "ppapi/cpp/module.h" +#include "ppapi/cpp/module_impl.h" + +namespace pp { + +namespace { + +static const char kPPPMouseLockInterface[] = PPP_MOUSELOCK_DEV_INTERFACE; + +void MouseLockLost(PP_Instance instance) { + void* object = + pp::Instance::GetPerInstanceObject(instance, kPPPMouseLockInterface); + if (!object) + return; + static_cast<MouseLock_Dev*>(object)->MouseLockLost(); +} + +const PPP_MouseLock_Dev ppp_mouse_lock = { + &MouseLockLost +}; + +template <> const char* interface_name<PPB_MouseLock_Dev>() { + return PPB_MOUSELOCK_DEV_INTERFACE; +} + +} // namespace + +MouseLock_Dev::MouseLock_Dev(Instance* instance) + : associated_instance_(instance) { + pp::Module::Get()->AddPluginInterface(kPPPMouseLockInterface, + &ppp_mouse_lock); + associated_instance_->AddPerInstanceObject(kPPPMouseLockInterface, this); +} + +MouseLock_Dev::~MouseLock_Dev() { + associated_instance_->RemovePerInstanceObject(kPPPMouseLockInterface, this); +} + +int32_t MouseLock_Dev::LockMouse(const CompletionCallback& cc) { + if (!has_interface<PPB_MouseLock_Dev>()) + return cc.MayForce(PP_ERROR_NOINTERFACE); + return get_interface<PPB_MouseLock_Dev>()->LockMouse( + associated_instance_->pp_instance(), cc.pp_completion_callback()); +} + +void MouseLock_Dev::UnlockMouse() { + if (has_interface<PPB_MouseLock_Dev>()) { + get_interface<PPB_MouseLock_Dev>()->UnlockMouse( + associated_instance_->pp_instance()); + } +} + +} // namespace pp diff --git a/ppapi/cpp/dev/mouse_lock_dev.h b/ppapi/cpp/dev/mouse_lock_dev.h new file mode 100755 index 0000000..7585de0 --- /dev/null +++ b/ppapi/cpp/dev/mouse_lock_dev.h @@ -0,0 +1,57 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_DEV_MOUSE_LOCK_DEV_H_ +#define PPAPI_CPP_DEV_MOUSE_LOCK_DEV_H_ + +#include "ppapi/c/pp_stdint.h" + +namespace pp { + +class CompletionCallback; +class Instance; + +// This class allows you to associate the PPP_MouseLock_Dev and +// PPB_MouseLock_Dev C-based interfaces with an object. It associates itself +// with the given instance, and registers as the global handler for handling the +// PPP_MouseLock_Dev interface that the browser calls. +// +// You would typically use this either via inheritance on your instance: +// class MyInstance : public pp::Instance, public pp::MouseLock_Dev { +// class MyInstance() : pp::MouseLock_Dev(this) { +// } +// ... +// }; +// +// or by composition: +// class MyMouseLock : public pp::MouseLock_Dev { +// ... +// }; +// +// class MyInstance : public pp::Instance { +// MyInstance() : mouse_lock_(this) { +// } +// +// MyMouseLock mouse_lock_; +// }; +class MouseLock_Dev { + public: + explicit MouseLock_Dev(Instance* instance); + virtual ~MouseLock_Dev(); + + // PPP_MouseLock_Dev functions exposed as virtual functions for you to + // override. + virtual void MouseLockLost() = 0; + + // PPB_MouseLock_Dev functions for you to call. + int32_t LockMouse(const CompletionCallback& cc); + void UnlockMouse(); + + private: + Instance* associated_instance_; +}; + +} // namespace pp + +#endif // PPAPI_CPP_DEV_MOUSE_LOCK_DEV_H_ diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc index 1ac2a5f..830e7bf 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.cc @@ -363,6 +363,13 @@ const PPB_Fullscreen_Dev* PPBFullscreenInterface() { return ppb; } +const PPB_MouseLock_Dev* PPBMouseLockInterface() { + static const PPB_MouseLock_Dev* ppb = + static_cast<const PPB_MouseLock_Dev*>( + GetBrowserInterfaceSafe(PPB_MOUSELOCK_DEV_INTERFACE)); + return ppb; +} + const PPB_Scrollbar_Dev* PPBScrollbarInterface() { static const PPB_Scrollbar_Dev* ppb = static_cast<const PPB_Scrollbar_Dev*>( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h index e118e6a..66e311b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_globals.h @@ -10,6 +10,7 @@ #include "ppapi/c/dev/ppb_font_dev.h" #include "ppapi/c/dev/ppb_fullscreen_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" @@ -115,6 +116,7 @@ const PPB_KeyboardInputEvent* PPBKeyboardInputEventInterface(); const PPB_Memory_Dev* PPBMemoryInterface(); // shared const PPB_MouseInputEvent* PPBMouseInputEventInterface(); const PPB_Messaging* PPBMessagingInterface(); +const PPB_MouseLock_Dev* PPBMouseLockInterface(); const PPB_PDF* PPBPDFInterface(); const PPB_Scrollbar_Dev* PPBScrollbarInterface(); const PPB_Testing_Dev* PPBTestingInterface(); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_mouse_lock_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_mouse_lock_rpc_server.cc new file mode 100755 index 0000000..b85bf09 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppb_mouse_lock_rpc_server.cc @@ -0,0 +1,54 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// SRPC-abstraction wrappers around PPB_MouseLock_Dev functions. + +#include "native_client/src/include/nacl_macros.h" +#include "native_client/src/include/nacl_scoped_ptr.h" +#include "native_client/src/include/portability.h" +#include "native_client/src/shared/ppapi_proxy/browser_callback.h" +#include "native_client/src/shared/ppapi_proxy/browser_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "native_client/src/trusted/desc/nacl_desc_wrapper.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" +#include "ppapi/c/pp_errors.h" +#include "srpcgen/ppb_rpc.h" + +using ppapi_proxy::DebugPrintf; +using ppapi_proxy::DeleteRemoteCallbackInfo; +using ppapi_proxy::MakeRemoteCompletionCallback; +using ppapi_proxy::PPBMouseLockInterface; + +void PpbMouseLockRpcServer::PPB_MouseLock_LockMouse( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + int32_t callback_id, + int32_t* pp_error) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + + PP_CompletionCallback remote_callback = MakeRemoteCompletionCallback( + rpc->channel, callback_id); + if (NULL == remote_callback.func) + return; + + *pp_error = PPBMouseLockInterface()->LockMouse(instance, remote_callback); + DebugPrintf("PPB_MouseLock::LockMouse: pp_error=%"NACL_PRId32"\n", *pp_error); + CHECK(*pp_error != PP_OK); // LockMouse should not complete synchronously. + + if (*pp_error != PP_OK_COMPLETIONPENDING) + DeleteRemoteCallbackInfo(remote_callback); + rpc->result = NACL_SRPC_RESULT_OK; +} + +void PpbMouseLockRpcServer::PPB_MouseLock_UnlockMouse( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance) { + NaClSrpcClosureRunner runner(done); + rpc->result = NACL_SRPC_RESULT_OK; + DebugPrintf("PPB_MouseLock::UnlockMouse\n"); + PPBMouseLockInterface()->UnlockMouse(instance); +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp.cc index 18928b8..683e45b0 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Native Client Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,6 +13,7 @@ #include "native_client/src/shared/ppapi_proxy/browser_ppp_find.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp_input_event.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp_instance.h" +#include "native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp_messaging.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp_printing.h" #include "native_client/src/shared/ppapi_proxy/browser_ppp_scrollbar.h" @@ -27,6 +28,7 @@ #include "native_client/src/trusted/plugin/plugin.h" #include "ppapi/c/ppp_input_event.h" #include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_scrollbar_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -161,6 +163,9 @@ const void* BrowserPpp::GetPluginInterface(const char* interface_name) { } else if (strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0) { ppp_interface = reinterpret_cast<const void*>(BrowserMessaging::GetInterface()); + } else if (strcmp(interface_name, PPP_MOUSELOCK_DEV_INTERFACE) == 0) { + ppp_interface = + reinterpret_cast<const void*>(BrowserMouseLock::GetInterface()); } else if (strcmp(interface_name, PPP_INPUT_EVENT_INTERFACE) == 0) { ppp_interface = reinterpret_cast<const void*>(BrowserInputEvent::GetInterface()); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.cc b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.cc new file mode 100755 index 0000000..75cc38c --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.cc @@ -0,0 +1,40 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.h" + +#include "native_client/src/include/portability.h" +#include "native_client/src/shared/ppapi_proxy/browser_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/pp_instance.h" +#include "srpcgen/ppp_rpc.h" + +namespace ppapi_proxy { + +namespace { + +void MouseLockLost(PP_Instance instance) { + DebugPrintf("PPP_MouseLock::MouseLockLost: instance=%"NACL_PRIu32"\n", + instance); + + NaClSrpcError srpc_result = + PppMouseLockRpcClient::PPP_MouseLock_MouseLockLost( + GetMainSrpcChannel(instance), + instance); + + DebugPrintf("PPP_MouseLock::MouseLockLost: %s\n", + NaClSrpcErrorString(srpc_result)); +} + +} // namespace + +const PPP_MouseLock_Dev* BrowserMouseLock::GetInterface() { + static const PPP_MouseLock_Dev mouse_lock_interface = { + MouseLockLost + }; + return &mouse_lock_interface; +} + +} // namespace ppapi_proxy + diff --git a/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.h b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.h new file mode 100755 index 0000000..94ffffc --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/browser_ppp_mouse_lock.h @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_MOUSE_LOCK_H_ +#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_MOUSE_LOCK_H_ + +#include "native_client/src/include/nacl_macros.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" + +namespace ppapi_proxy { + +// Implements the trusted side of the PPP_MouseLock_Dev interface. +class BrowserMouseLock { + public: + static const PPP_MouseLock_Dev* GetInterface(); + + private: + NACL_DISALLOW_COPY_AND_ASSIGN(BrowserMouseLock); +}; + +} // namespace ppapi_proxy + +#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_BROWSER_PPP_MOUSE_LOCK_H_ + diff --git a/ppapi/native_client/src/shared/ppapi_proxy/build.scons b/ppapi/native_client/src/shared/ppapi_proxy/build.scons index 1e6158c..508b790 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/build.scons +++ b/ppapi/native_client/src/shared/ppapi_proxy/build.scons @@ -47,6 +47,7 @@ env.TrustedSrpc(is_client=True, 'ppp_input_event.srpc', 'ppp_instance.srpc', 'ppp_messaging.srpc', + 'ppp_mouse_lock.srpc', 'ppp_printing.srpc', 'ppp_scrollbar.srpc', 'ppp_selection.srpc', @@ -77,6 +78,7 @@ env.TrustedSrpc(is_client=False, 'ppb_input_event.srpc', 'ppb_instance.srpc', 'ppb_messaging.srpc', + 'ppb_mouse_lock.srpc', 'ppb_pdf.srpc', 'ppb_scrollbar.srpc', 'ppb_testing.srpc', @@ -121,6 +123,7 @@ env.DualLibrary('ppapi_browser', 'browser_ppb_input_event_rpc_server.cc', 'browser_ppb_instance_rpc_server.cc', 'browser_ppb_messaging_rpc_server.cc', + 'browser_ppb_mouse_lock_rpc_server.cc', 'browser_ppb_pdf_rpc_server.cc', 'browser_ppb_rpc_server.cc', 'browser_ppb_scrollbar_rpc_server.cc', @@ -134,6 +137,7 @@ env.DualLibrary('ppapi_browser', 'browser_ppp_input_event.cc', 'browser_ppp_instance.cc', 'browser_ppp_messaging.cc', + 'browser_ppp_mouse_lock.cc', 'browser_ppp_printing.cc', 'browser_ppp_scrollbar.cc', 'browser_ppp_selection.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons b/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons index 8078536..5093c7a 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons +++ b/ppapi/native_client/src/shared/ppapi_proxy/nacl.scons @@ -33,6 +33,7 @@ env.UntrustedSrpc(is_client=False, 'ppp_input_event.srpc', 'ppp_instance.srpc', 'ppp_messaging.srpc', + 'ppp_mouse_lock.srpc', 'ppp_printing.srpc', 'ppp_scrollbar.srpc', 'ppp_selection.srpc', @@ -63,6 +64,7 @@ env.UntrustedSrpc(is_client=True, 'ppb_input_event.srpc', 'ppb_instance.srpc', 'ppb_messaging.srpc', + 'ppb_mouse_lock.srpc', 'ppb_pdf.srpc', 'ppb_scrollbar.srpc', 'ppb_testing.srpc', @@ -137,6 +139,7 @@ libppruntime = env.NaClSdkLibrary( 'plugin_ppb_instance.cc', 'plugin_ppb_memory.cc', 'plugin_ppb_messaging.cc', + 'plugin_ppb_mouse_lock.cc', 'plugin_ppb_pdf.cc', 'plugin_ppb_scrollbar.cc', 'plugin_ppb_testing.cc', @@ -150,6 +153,7 @@ libppruntime = env.NaClSdkLibrary( 'plugin_ppp_input_event_rpc_server.cc', 'plugin_ppp_instance_rpc_server.cc', 'plugin_ppp_messaging_rpc_server.cc', + 'plugin_ppp_mouse_lock_rpc_server.cc', 'plugin_ppp_printing_rpc_server.cc', 'plugin_ppp_scrollbar_rpc_server.cc', 'plugin_ppp_selection_rpc_server.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc index cd018a40..7281bb9 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Native Client Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -122,6 +122,11 @@ const PPP_Messaging* PPPMessagingInterface() { return static_cast<const PPP_Messaging*>(ppp); } +const PPP_MouseLock_Dev* PPPMouseLockInterface() { + static const void* ppp = GetPluginInterfaceSafe(PPP_MOUSELOCK_DEV_INTERFACE); + return static_cast<const PPP_MouseLock_Dev*>(ppp); +} + const PPP_Printing_Dev* PPPPrintingInterface() { static const void* ppp = GetPluginInterfaceSafe(PPP_PRINTING_DEV_INTERFACE); return static_cast<const PPP_Printing_Dev*>(ppp); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h index 915ef10..c3a4665 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_globals.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Native Client Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,7 @@ #include "ppapi/c/dev/ppb_memory_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_scrollbar_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -62,6 +63,7 @@ const PPP_Find_Dev* PPPFindInterface(); const PPP_InputEvent* PPPInputEventInterface(); const PPP_Instance* PPPInstanceInterface(); const PPP_Messaging* PPPMessagingInterface(); +const PPP_MouseLock_Dev* PPPMouseLockInterface(); const PPP_Printing_Dev* PPPPrintingInterface(); const PPP_Scrollbar_Dev* PPPScrollbarInterface(); const PPP_Selection_Dev* PPPSelectionInterface(); diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc index 8db868e..faff8e5 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb.cc @@ -25,6 +25,7 @@ #include "native_client/src/shared/ppapi_proxy/plugin_ppb_instance.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_memory.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_messaging.h" +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_pdf.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_scrollbar.h" #include "native_client/src/shared/ppapi_proxy/plugin_ppb_testing.h" @@ -73,6 +74,7 @@ InterfaceMapElement interface_map[] = { PluginInputEvent::GetMouseInterface1_0(), true }, { PPB_MOUSE_INPUT_EVENT_INTERFACE_1_1, PluginInputEvent::GetMouseInterface1_1(), true }, + { PPB_MOUSELOCK_DEV_INTERFACE, PluginMouseLock::GetInterface(), true }, { PPB_OPENGLES2_INTERFACE, PluginGraphics3D::GetOpenGLESInterface(), true }, { PPB_PDF_INTERFACE, PluginPDF::GetInterface(), true }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.cc new file mode 100755 index 0000000..f528813 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h" + +#include "native_client/src/include/portability.h" +#include "native_client/src/shared/ppapi_proxy/plugin_callback.h" +#include "native_client/src/shared/ppapi_proxy/plugin_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_errors.h" +#include "srpcgen/ppb_rpc.h" + +namespace ppapi_proxy { + +namespace { + +int32_t LockMouse(PP_Instance instance, PP_CompletionCallback callback) { + DebugPrintf("PPB_MouseLock::LockMouse: " + "instance=%"NACL_PRIu32"\n", instance); + + int32_t callback_id = + CompletionCallbackTable::Get()->AddCallback(callback); + if (callback_id == 0) + return PP_ERROR_BADARGUMENT; + + int32_t pp_error = PP_ERROR_FAILED; + NaClSrpcError srpc_result = + PpbMouseLockRpcClient::PPB_MouseLock_LockMouse( + GetMainSrpcChannel(), + instance, + callback_id, + &pp_error); + + DebugPrintf("PPB_MouseLock::LockMouse: %s\n", + NaClSrpcErrorString(srpc_result)); + + if (srpc_result != NACL_SRPC_RESULT_OK) + pp_error = PP_ERROR_FAILED; + return MayForceCallback(callback, pp_error); +} + +void UnlockMouse(PP_Instance instance) { + DebugPrintf("PPB_MouseLock::UnlockMouse: " + "instance=%"NACL_PRIu32"\n", instance); + + NaClSrpcError srpc_result = + PpbMouseLockRpcClient::PPB_MouseLock_UnlockMouse( + GetMainSrpcChannel(), + instance); + + DebugPrintf("PPB_MouseLock::UnlockMouse: %s\n", + NaClSrpcErrorString(srpc_result)); +} + +} // namespace + +const PPB_MouseLock_Dev* PluginMouseLock::GetInterface() { + static const PPB_MouseLock_Dev mouse_lock_interface = { + LockMouse, + UnlockMouse + }; + return &mouse_lock_interface; +} + +} // namespace ppapi_proxy + + diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h new file mode 100755 index 0000000..bb64a72 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppb_mouse_lock.h @@ -0,0 +1,26 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_MOUSE_LOCK_H_ +#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_MOUSE_LOCK_H_ + +#include "native_client/src/include/nacl_macros.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" + +namespace ppapi_proxy { + +// Implements the untrusted side of the PPB_MouseLock_Dev interface. +class PluginMouseLock { + public: + PluginMouseLock(); + static const PPB_MouseLock_Dev* GetInterface(); + + private: + NACL_DISALLOW_COPY_AND_ASSIGN(PluginMouseLock); +}; + +} // namespace ppapi_proxy + +#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_PLUGIN_PPB_MOUSE_LOCK_H_ + diff --git a/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppp_mouse_lock_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppp_mouse_lock_rpc_server.cc new file mode 100755 index 0000000..9d5a6dc --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/plugin_ppp_mouse_lock_rpc_server.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// SRPC-abstraction wrappers around PPP_MouseLock_Dev functions. + +#include "native_client/src/include/portability.h" +#include "native_client/src/include/portability_process.h" +#include "native_client/src/shared/ppapi_proxy/plugin_globals.h" +#include "native_client/src/shared/ppapi_proxy/utility.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" +#include "srpcgen/ppp_rpc.h" + +using ppapi_proxy::DebugPrintf; +using ppapi_proxy::PPPMouseLockInterface; + +void PppMouseLockRpcServer::PPP_MouseLock_MouseLockLost( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + // inputs + PP_Instance instance) { + rpc->result = NACL_SRPC_RESULT_APP_ERROR; + NaClSrpcClosureRunner runner(done); + + PPPMouseLockInterface()->MouseLockLost(instance); + + DebugPrintf("PPP_MouseLock::MouseLockLost"); + rpc->result = NACL_SRPC_RESULT_OK; +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp index 186cfea..88e682e 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppapi_proxy.gyp @@ -30,6 +30,7 @@ 'browser_ppb_input_event_rpc_server.cc', 'browser_ppb_instance_rpc_server.cc', 'browser_ppb_messaging_rpc_server.cc', + 'browser_ppb_mouse_lock_rpc_server.cc', 'browser_ppb_pdf_rpc_server.cc', 'browser_ppb_rpc_server.cc', 'browser_ppb_scrollbar_rpc_server.cc', @@ -43,6 +44,7 @@ 'browser_ppp_input_event.cc', 'browser_ppp_instance.cc', 'browser_ppp_messaging.cc', + 'browser_ppp_mouse_lock.cc', 'browser_ppp_printing.cc', 'browser_ppp_scrollbar.cc', 'browser_ppp_selection.cc', diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_mouse_lock.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_mouse_lock.srpc new file mode 100755 index 0000000..715c748 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_mouse_lock.srpc @@ -0,0 +1,24 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# RPC methods used to implement PPB_MouseLock_Dev calls from the plugin. +# See ppapi/c/dev/ppb_mouse_lock_dev.h for interface details. + +{ + 'name': 'PpbMouseLockRpc', + 'rpcs': [ + {'name': 'PPB_MouseLock_LockMouse', + 'inputs': [['instance', 'PP_Instance'], # PP_Instance + ['callback_id', 'int32_t'], # PP_CompletionCallback + ], + 'outputs': [['pp_error', 'int32_t'], + ] + }, + {'name': 'PPB_MouseLock_UnlockMouse', + 'inputs': [['instance', 'PP_Instance'], # PP_Instance + ], + 'outputs': [] + }, + ] +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc index 4729260..a5b0c93 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_client.cc @@ -1899,6 +1899,40 @@ NaClSrpcError PpbMessagingRpcClient::PPB_Messaging_PostMessage( return retval; } +NaClSrpcError PpbMouseLockRpcClient::PPB_MouseLock_LockMouse( + NaClSrpcChannel* channel, + PP_Instance instance, + int32_t callback_id, + int32_t* pp_error) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_MouseLock_LockMouse:ii:i", + instance, + callback_id, + pp_error + ); + return retval; +} + +NaClSrpcError PpbMouseLockRpcClient::PPB_MouseLock_UnlockMouse( + NaClSrpcChannel* channel, + PP_Instance instance) { + VCHECK(ppapi_proxy::PPBCoreInterface()->IsMainThread(), + ("%s: PPAPI calls are not supported off the main thread\n", + __FUNCTION__)); + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPB_MouseLock_UnlockMouse:i:", + instance + ); + return retval; +} + NaClSrpcError PpbPdfRpcClient::PPB_PDF_GetLocalizedString( NaClSrpcChannel* channel, PP_Instance instance, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc index 4d05e2d..abf8010 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppb_rpc_server.cc @@ -1515,6 +1515,35 @@ static void PPB_Messaging_PostMessageDispatcher( ); } +static void PPB_MouseLock_LockMouseDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + PpbMouseLockRpcServer::PPB_MouseLock_LockMouse( + rpc, + done, + inputs[0]->u.ival, + inputs[1]->u.ival, + &(outputs[0]->u.ival) + ); +} + +static void PPB_MouseLock_UnlockMouseDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + UNREFERENCED_PARAMETER(outputs); + PpbMouseLockRpcServer::PPB_MouseLock_UnlockMouse( + rpc, + done, + inputs[0]->u.ival + ); +} + static void PPB_PDF_GetLocalizedStringDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -2363,6 +2392,8 @@ NaClSrpcHandlerDesc PpbRpcs::srpc_methods[] = { { "PPB_Instance_BindGraphics:ii:i", PPB_Instance_BindGraphicsDispatcher }, { "PPB_Instance_IsFullFrame:i:i", PPB_Instance_IsFullFrameDispatcher }, { "PPB_Messaging_PostMessage:iC:", PPB_Messaging_PostMessageDispatcher }, + { "PPB_MouseLock_LockMouse:ii:i", PPB_MouseLock_LockMouseDispatcher }, + { "PPB_MouseLock_UnlockMouse:i:", PPB_MouseLock_UnlockMouseDispatcher }, { "PPB_PDF_GetLocalizedString:ii:C", PPB_PDF_GetLocalizedStringDispatcher }, { "PPB_PDF_GetResourceImage:ii:i", PPB_PDF_GetResourceImageDispatcher }, { "PPB_PDF_GetFontFileWithFallback:iCCi:i", PPB_PDF_GetFontFileWithFallbackDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppp_mouse_lock.srpc b/ppapi/native_client/src/shared/ppapi_proxy/ppp_mouse_lock.srpc new file mode 100755 index 0000000..da370a5 --- /dev/null +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppp_mouse_lock.srpc @@ -0,0 +1,16 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# RPC methods used to implement PPP_MouseLock_Dev calls to the plugin. +# See ppapi/c/dev/ppp_mouse_lock_dev.h for interface details. +{ + 'name': 'PppMouseLockRpc', + 'rpcs': [ + {'name': 'PPP_MouseLock_MouseLockLost', + 'inputs': [['instance', 'PP_Instance'], # PP_Instance + ], + 'outputs': [] + }, + ] +} diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_client.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_client.cc index 2e7def5..83a5940 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_client.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_client.cc @@ -280,6 +280,20 @@ NaClSrpcError PppMessagingRpcClient::PPP_Messaging_HandleMessage( return retval; } +NaClSrpcError PppMouseLockRpcClient::PPP_MouseLock_MouseLockLost( + NaClSrpcChannel* channel, + PP_Instance instance) { + NaClSrpcError retval; + retval = NaClSrpcInvokeBySignature( + channel, + "PPP_MouseLock_MouseLockLost:i:", + instance + ); + if (retval == NACL_SRPC_RESULT_INTERNAL) + ppapi_proxy::CleanUpAfterDeadNexe(instance); + return retval; +} + NaClSrpcError PppPrintingRpcClient::PPP_Printing_QuerySupportedFormats( NaClSrpcChannel* channel, PP_Instance instance, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_server.cc b/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_server.cc index 7e53e75..5275ffb 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_server.cc +++ b/ppapi/native_client/src/shared/ppapi_proxy/ppp_rpc_server.cc @@ -256,6 +256,20 @@ static void PPP_Messaging_HandleMessageDispatcher( ); } +static void PPP_MouseLock_MouseLockLostDispatcher( + NaClSrpcRpc* rpc, + NaClSrpcArg** inputs, + NaClSrpcArg** outputs, + NaClSrpcClosure* done +) { + UNREFERENCED_PARAMETER(outputs); + PppMouseLockRpcServer::PPP_MouseLock_MouseLockLost( + rpc, + done, + inputs[0]->u.ival + ); +} + static void PPP_Printing_QuerySupportedFormatsDispatcher( NaClSrpcRpc* rpc, NaClSrpcArg** inputs, @@ -412,6 +426,7 @@ NaClSrpcHandlerDesc PppRpcs::srpc_methods[] = { { "PPP_Instance_DidChangeFocus:ib:", PPP_Instance_DidChangeFocusDispatcher }, { "PPP_Instance_HandleDocumentLoad:ii:i", PPP_Instance_HandleDocumentLoadDispatcher }, { "PPP_Messaging_HandleMessage:iC:", PPP_Messaging_HandleMessageDispatcher }, + { "PPP_MouseLock_MouseLockLost:i:", PPP_MouseLock_MouseLockLostDispatcher }, { "PPP_Printing_QuerySupportedFormats:i:i", PPP_Printing_QuerySupportedFormatsDispatcher }, { "PPP_Printing_Begin:iC:i", PPP_Printing_BeginDispatcher }, { "PPP_Printing_PrintPages:iCi:i", PPP_Printing_PrintPagesDispatcher }, diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h index 26d37b5..4cb598b 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppb_rpc.h @@ -782,6 +782,25 @@ class PpbMessagingRpcServer { void operator=(const PpbMessagingRpcServer); }; // class PpbMessagingRpcServer +class PpbMouseLockRpcServer { + public: + static void PPB_MouseLock_LockMouse( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance, + int32_t callback_id, + int32_t* pp_error); + static void PPB_MouseLock_UnlockMouse( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance); + + private: + PpbMouseLockRpcServer(); + PpbMouseLockRpcServer(const PpbMouseLockRpcServer&); + void operator=(const PpbMouseLockRpcServer); +}; // class PpbMouseLockRpcServer + class PpbPdfRpcServer { public: static void PPB_PDF_GetLocalizedString( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h index 94c9c3d..05ce4a2 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/trusted/srpcgen/ppp_rpc.h @@ -155,6 +155,18 @@ class PppMessagingRpcClient { void operator=(const PppMessagingRpcClient); }; // class PppMessagingRpcClient +class PppMouseLockRpcClient { + public: + static NaClSrpcError PPP_MouseLock_MouseLockLost( + NaClSrpcChannel* channel, + PP_Instance instance); + + private: + PppMouseLockRpcClient(); + PppMouseLockRpcClient(const PppMouseLockRpcClient&); + void operator=(const PppMouseLockRpcClient); +}; // class PppMouseLockRpcClient + class PppPrintingRpcClient { public: static NaClSrpcError PPP_Printing_QuerySupportedFormats( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h index 7c58187..3446a97 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppb_rpc.h @@ -685,6 +685,23 @@ class PpbMessagingRpcClient { void operator=(const PpbMessagingRpcClient); }; // class PpbMessagingRpcClient +class PpbMouseLockRpcClient { + public: + static NaClSrpcError PPB_MouseLock_LockMouse( + NaClSrpcChannel* channel, + PP_Instance instance, + int32_t callback_id, + int32_t* pp_error); + static NaClSrpcError PPB_MouseLock_UnlockMouse( + NaClSrpcChannel* channel, + PP_Instance instance); + + private: + PpbMouseLockRpcClient(); + PpbMouseLockRpcClient(const PpbMouseLockRpcClient&); + void operator=(const PpbMouseLockRpcClient); +}; // class PpbMouseLockRpcClient + class PpbPdfRpcClient { public: static NaClSrpcError PPB_PDF_GetLocalizedString( diff --git a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h index adee80b..0d42db3 100644 --- a/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h +++ b/ppapi/native_client/src/shared/ppapi_proxy/untrusted/srpcgen/ppp_rpc.h @@ -170,6 +170,19 @@ class PppMessagingRpcServer { void operator=(const PppMessagingRpcServer); }; // class PppMessagingRpcServer +class PppMouseLockRpcServer { + public: + static void PPP_MouseLock_MouseLockLost( + NaClSrpcRpc* rpc, + NaClSrpcClosure* done, + PP_Instance instance); + + private: + PppMouseLockRpcServer(); + PppMouseLockRpcServer(const PppMouseLockRpcServer&); + void operator=(const PppMouseLockRpcServer); +}; // class PppMouseLockRpcServer + class PppPrintingRpcServer { public: static void PPP_Printing_QuerySupportedFormats( diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 55ec739..a676c32 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -53,6 +53,7 @@ #include "native_client/src/trusted/service_runtime/nacl_error_code.h" #include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_scrollbar_dev.h" #include "ppapi/c/dev/ppp_selection_dev.h" @@ -63,6 +64,7 @@ #include "ppapi/c/ppp_instance.h" #include "ppapi/c/private/ppb_uma_private.h" #include "ppapi/cpp/dev/find_dev.h" +#include "ppapi/cpp/dev/mouse_lock_dev.h" #include "ppapi/cpp/dev/printing_dev.h" #include "ppapi/cpp/dev/scrollbar_dev.h" #include "ppapi/cpp/dev/selection_dev.h" @@ -295,6 +297,32 @@ class FindAdapter : public pp::Find_Dev { }; +// Derive a class from pp::MouseLock_Dev to forward PPP_MouseLock_Dev calls to +// the plugin. +class MouseLockAdapter : public pp::MouseLock_Dev { + public: + explicit MouseLockAdapter(Plugin* plugin) + : pp::MouseLock_Dev(plugin), + plugin_(plugin) { + BrowserPpp* proxy = plugin_->ppapi_proxy(); + CHECK(proxy != NULL); + ppp_mouse_lock_ = static_cast<const PPP_MouseLock_Dev*>( + proxy->GetPluginInterface(PPP_MOUSELOCK_DEV_INTERFACE)); + } + + void MouseLockLost() { + if (ppp_mouse_lock_ != NULL) + ppp_mouse_lock_->MouseLockLost(plugin_->pp_instance()); + } + + private: + Plugin* plugin_; + const PPP_MouseLock_Dev* ppp_mouse_lock_; + + NACL_DISALLOW_COPY_AND_ASSIGN(MouseLockAdapter); +}; + + // Derive a class from pp::Printing_Dev to forward PPP_Printing_Dev calls to // the plugin. class PrintingAdapter : public pp::Printing_Dev { @@ -1273,6 +1301,7 @@ bool Plugin::StartProxiedExecution(NaClSrpcChannel* srpc_channel, // Create PPP* interface adapters to forward calls to .nexe. find_adapter_.reset(new(std::nothrow) FindAdapter(this)); + mouse_lock_adapter_.reset(new(std::nothrow) MouseLockAdapter(this)); printing_adapter_.reset(new(std::nothrow) PrintingAdapter(this)); selection_adapter_.reset(new(std::nothrow) SelectionAdapter(this)); widget_client_adapter_.reset(new(std::nothrow) WidgetClientAdapter(this)); diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index b4e76cf..3918aff 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -42,6 +42,7 @@ class DescWrapperFactory; namespace pp { class Find_Dev; +class MouseLock_Dev; class Printing_Dev; class Selection_Dev; class URLLoader; @@ -494,6 +495,7 @@ class Plugin : public pp::InstancePrivate { // Adapter class constructors require a reference to 'this', so we can't // contain them directly. nacl::scoped_ptr<pp::Find_Dev> find_adapter_; + nacl::scoped_ptr<pp::MouseLock_Dev> mouse_lock_adapter_; nacl::scoped_ptr<pp::Printing_Dev> printing_adapter_; nacl::scoped_ptr<pp::Selection_Dev> selection_adapter_; nacl::scoped_ptr<pp::WidgetClient_Dev> widget_client_adapter_; diff --git a/ppapi/native_client/tests/ppapi_browser/ppb_dev/ppapi_ppb_dev.cc b/ppapi/native_client/tests/ppapi_browser/ppb_dev/ppapi_ppb_dev.cc index d1e6d6a..efa544e 100644 --- a/ppapi/native_client/tests/ppapi_browser/ppb_dev/ppapi_ppb_dev.cc +++ b/ppapi/native_client/tests/ppapi_browser/ppb_dev/ppapi_ppb_dev.cc @@ -31,6 +31,7 @@ #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_surface_3d_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" @@ -67,6 +68,7 @@ void TestGetDevInterfaces() { PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE) == NULL); CHECK(GetBrowserInterface(PPB_LAYER_COMPOSITOR_DEV_INTERFACE) == NULL); CHECK(GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE) == NULL); + CHECK(GetBrowserInterface(PPB_MOUSELOCK_DEV_INTERFACE) == NULL); CHECK(GetBrowserInterface(PPB_SCROLLBAR_DEV_INTERFACE) == NULL); CHECK(GetBrowserInterface(PPB_SURFACE_3D_DEV_INTERFACE) == NULL); CHECK(GetBrowserInterface(PPB_TESTING_DEV_INTERFACE) == NULL); diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi index 3c01319..a943a4b 100644 --- a/ppapi/ppapi_cpp.gypi +++ b/ppapi/ppapi_cpp.gypi @@ -68,6 +68,7 @@ 'c/dev/ppb_font_dev.h', 'c/dev/ppb_fullscreen_dev.h', 'c/dev/ppb_memory_dev.h', + 'c/dev/ppb_mouse_lock_dev.h', 'c/dev/ppb_query_policy_dev.h', 'c/dev/ppb_scrollbar_dev.h', 'c/dev/ppb_surface_3d_dev.h', @@ -78,6 +79,7 @@ 'c/dev/ppb_zoom_dev.h', 'c/dev/ppp_cursor_control_dev.h', 'c/dev/ppp_find_dev.h', + 'c/dev/ppp_mouse_lock_dev.h', 'c/dev/ppp_network_state_dev.h', 'c/dev/ppp_policy_update_dev.h', 'c/dev/ppp_printing_dev.h', @@ -203,6 +205,8 @@ 'cpp/dev/fullscreen_dev.h', 'cpp/dev/memory_dev.cc', 'cpp/dev/memory_dev.h', + 'cpp/dev/mouse_lock_dev.cc', + 'cpp/dev/mouse_lock_dev.h', 'cpp/dev/printing_dev.cc', 'cpp/dev/printing_dev.h', 'cpp/dev/scrollbar_dev.cc', diff --git a/ppapi/ppapi_proxy.gypi b/ppapi/ppapi_proxy.gypi index 35b0a03..02a2420 100644 --- a/ppapi/ppapi_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -141,6 +141,8 @@ 'proxy/ppp_instance_proxy.h', 'proxy/ppp_messaging_proxy.cc', 'proxy/ppp_messaging_proxy.h', + 'proxy/ppp_mouse_lock_proxy.cc', + 'proxy/ppp_mouse_lock_proxy.h', 'proxy/ppp_video_decoder_proxy.cc', 'proxy/ppp_video_decoder_proxy.h', 'proxy/proxy_channel.cc', diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi index 1f8453e..714a512 100644 --- a/ppapi/ppapi_shared.gypi +++ b/ppapi/ppapi_shared.gypi @@ -142,6 +142,7 @@ 'thunk/ppb_layer_compositor_api.h', 'thunk/ppb_layer_compositor_thunk.cc', 'thunk/ppb_messaging_thunk.cc', + 'thunk/ppb_mouse_lock_thunk.cc', 'thunk/ppb_pdf_api.h', 'thunk/ppb_query_policy_thunk.cc', 'thunk/ppb_scrollbar_api.h', diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index 7c099a7..d77c905 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -88,6 +88,7 @@ #include "ppapi/proxy/ppp_instance_private_proxy.h" #include "ppapi/proxy/ppp_instance_proxy.h" #include "ppapi/proxy/ppp_messaging_proxy.h" +#include "ppapi/proxy/ppp_mouse_lock_proxy.h" #include "ppapi/proxy/ppp_video_decoder_proxy.h" #include "ppapi/proxy/var_serialization_rules.h" @@ -154,6 +155,7 @@ InterfaceList::InterfaceList() { AddPPB(PPB_Instance_Proxy::GetInfo1_0()); AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); AddPPB(PPB_Instance_Proxy::GetInfoMessaging()); + AddPPB(PPB_Instance_Proxy::GetInfoMouseLock()); AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); AddPPB(PPB_Memory_Proxy::GetInfo()); AddPPB(PPB_OpenGLES2_Proxy::GetInfo()); @@ -180,6 +182,7 @@ InterfaceList::InterfaceList() { AddPPP(PPP_Instance_Private_Proxy::GetInfo()); AddPPP(PPP_Instance_Proxy::GetInfo1_0()); AddPPP(PPP_Messaging_Proxy::GetInfo()); + AddPPP(PPP_MouseLock_Proxy::GetInfo()); AddPPP(PPP_VideoCapture_Proxy::GetInfo()); AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); } diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index 595b2c8..277f964 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -60,6 +60,7 @@ enum InterfaceID { INTERFACE_ID_PPP_INSTANCE, INTERFACE_ID_PPP_INSTANCE_PRIVATE, INTERFACE_ID_PPP_MESSAGING, + INTERFACE_ID_PPP_MOUSE_LOCK_DEV, INTERFACE_ID_PPP_VIDEO_CAPTURE_DEV, INTERFACE_ID_PPP_VIDEO_DECODER_DEV, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index f8559b3..4611a4f 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -374,6 +374,10 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPPMessaging_HandleMessage, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* message */) +// PPP_MouseLock_Dev. +IPC_MESSAGE_ROUTED1(PpapiMsg_PPPMouseLock_MouseLockLost, + PP_Instance /* instance */) + // PPB_URLLoader // (Messages from browser to plugin to notify it of changes in state.) IPC_MESSAGE_ROUTED1( @@ -838,6 +842,11 @@ IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_ClearInputEvents, IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_PostMessage, PP_Instance /* instance */, ppapi::proxy::SerializedVar /* message */) +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBInstance_LockMouse, + PP_Instance /* instance */, + uint32_t /* serialized_callback */) +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBInstance_UnlockMouse, + PP_Instance /* instance */) IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBPDF_GetFontFileWithFallback, diff --git a/ppapi/proxy/ppb_instance_proxy.cc b/ppapi/proxy/ppb_instance_proxy.cc index 3c02807..10464c6 100644 --- a/ppapi/proxy/ppb_instance_proxy.cc +++ b/ppapi/proxy/ppb_instance_proxy.cc @@ -5,6 +5,8 @@ #include "ppapi/proxy/ppb_instance_proxy.h" #include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" +#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_var.h" #include "ppapi/c/ppb_instance.h" #include "ppapi/c/ppb_messaging.h" @@ -82,6 +84,18 @@ const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoMessaging() { } // static +const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoMouseLock() { + static const Info info = { + ppapi::thunk::GetPPB_MouseLock_Thunk(), + PPB_MOUSELOCK_DEV_INTERFACE, + INTERFACE_ID_NONE, // 1_0 is the canonical one. + false, + &CreateInstanceProxy, + }; + return &info; +} + +// static const InterfaceProxy::Info* PPB_Instance_Proxy::GetInfoPrivate() { static const Info info = { ppapi::thunk::GetPPB_Instance_Private_Thunk(), @@ -134,6 +148,10 @@ bool PPB_Instance_Proxy::OnMessageReceived(const IPC::Message& msg) { OnMsgRequestInputEvents) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_ClearInputEvents, OnMsgClearInputEvents) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_LockMouse, + OnMsgLockMouse) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBInstance_UnlockMouse, + OnMsgUnlockMouse) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -269,6 +287,21 @@ void PPB_Instance_Proxy::PostMessage(PP_Instance instance, instance, SerializedVarSendInput(dispatcher(), message))); } +int32_t PPB_Instance_Proxy::LockMouse(PP_Instance instance, + PP_CompletionCallback callback) { + if (!callback.func) + return PP_ERROR_BADARGUMENT; + + dispatcher()->Send(new PpapiHostMsg_PPBInstance_LockMouse( + INTERFACE_ID_PPB_INSTANCE, instance, SendCallback(callback))); + return PP_OK_COMPLETIONPENDING; +} + +void PPB_Instance_Proxy::UnlockMouse(PP_Instance instance) { + dispatcher()->Send(new PpapiHostMsg_PPBInstance_UnlockMouse( + INTERFACE_ID_PPB_INSTANCE, instance)); +} + void PPB_Instance_Proxy::OnMsgGetWindowObject( PP_Instance instance, SerializedVarReturnValue result) { @@ -366,5 +399,22 @@ void PPB_Instance_Proxy::OnMsgPostMessage(PP_Instance instance, enter.functions()->PostMessage(instance, message.Get(dispatcher())); } +void PPB_Instance_Proxy::OnMsgLockMouse(PP_Instance instance, + uint32_t serialized_callback) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.failed()) + return; + PP_CompletionCallback callback = ReceiveCallback(serialized_callback); + int32_t result = enter.functions()->LockMouse(instance, callback); + if (result != PP_OK_COMPLETIONPENDING) + PP_RunCompletionCallback(&callback, result); +} + +void PPB_Instance_Proxy::OnMsgUnlockMouse(PP_Instance instance) { + EnterFunctionNoLock<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.succeeded()) + enter.functions()->UnlockMouse(instance); +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/ppb_instance_proxy.h b/ppapi/proxy/ppb_instance_proxy.h index a7dd6e6..d0ec32b 100644 --- a/ppapi/proxy/ppb_instance_proxy.h +++ b/ppapi/proxy/ppb_instance_proxy.h @@ -32,6 +32,7 @@ class PPB_Instance_Proxy : public InterfaceProxy, static const Info* GetInfo0_5(); static const Info* GetInfo1_0(); static const Info* GetInfoMessaging(); + static const Info* GetInfoMouseLock(); static const Info* GetInfoPrivate(); static const Info* GetInfoFullscreen(); @@ -66,6 +67,9 @@ class PPB_Instance_Proxy : public InterfaceProxy, double maximium_factor) OVERRIDE; virtual void SubscribeToPolicyUpdates(PP_Instance instance) OVERRIDE; virtual void PostMessage(PP_Instance instance, PP_Var message) OVERRIDE; + virtual int32_t LockMouse(PP_Instance instance, + PP_CompletionCallback callback) OVERRIDE; + virtual void UnlockMouse(PP_Instance instance) OVERRIDE; private: // Message handlers. @@ -94,6 +98,9 @@ class PPB_Instance_Proxy : public InterfaceProxy, uint32_t event_classes); void OnMsgPostMessage(PP_Instance instance, SerializedVarReceiveInput message); + void OnMsgLockMouse(PP_Instance instance, + uint32_t serialized_callback); + void OnMsgUnlockMouse(PP_Instance instance); }; } // namespace proxy diff --git a/ppapi/proxy/ppp_mouse_lock_proxy.cc b/ppapi/proxy/ppp_mouse_lock_proxy.cc new file mode 100755 index 0000000..8980bcf --- /dev/null +++ b/ppapi/proxy/ppp_mouse_lock_proxy.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppp_mouse_lock_proxy.h" + +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" +#include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/ppapi_messages.h" + +namespace ppapi { +namespace proxy { + +namespace { + +void MouseLockLost(PP_Instance instance) { + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); + if (!dispatcher) { + // The dispatcher should always be valid. + NOTREACHED(); + return; + } + + dispatcher->Send(new PpapiMsg_PPPMouseLock_MouseLockLost( + INTERFACE_ID_PPP_MOUSE_LOCK_DEV, instance)); +} + +static const PPP_MouseLock_Dev mouse_lock_interface = { + &MouseLockLost +}; + +InterfaceProxy* CreateMouseLockProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPP_MouseLock_Proxy(dispatcher, target_interface); +} + +} // namespace + +PPP_MouseLock_Proxy::PPP_MouseLock_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPP_MouseLock_Proxy::~PPP_MouseLock_Proxy() { +} + +// static +const InterfaceProxy::Info* PPP_MouseLock_Proxy::GetInfo() { + static const Info info = { + &mouse_lock_interface, + PPP_MOUSELOCK_DEV_INTERFACE, + INTERFACE_ID_PPP_MOUSE_LOCK_DEV, + false, + &CreateMouseLockProxy, + }; + return &info; +} + +bool PPP_MouseLock_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPP_MouseLock_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiMsg_PPPMouseLock_MouseLockLost, + OnMsgMouseLockLost) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void PPP_MouseLock_Proxy::OnMsgMouseLockLost(PP_Instance instance) { + if (ppp_mouse_lock_target()) + ppp_mouse_lock_target()->MouseLockLost(instance); +} + +} // namespace proxy +} // namespace ppapi diff --git a/ppapi/proxy/ppp_mouse_lock_proxy.h b/ppapi/proxy/ppp_mouse_lock_proxy.h new file mode 100755 index 0000000..cfd451c --- /dev/null +++ b/ppapi/proxy/ppp_mouse_lock_proxy.h @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PROXY_PPP_MOUSE_LOCK_PROXY_H_ +#define PPAPI_PROXY_PPP_MOUSE_LOCK_PROXY_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" + +struct PPP_MouseLock_Dev; + +namespace ppapi { +namespace proxy { + +class PPP_MouseLock_Proxy : public InterfaceProxy { + public: + PPP_MouseLock_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPP_MouseLock_Proxy(); + + static const Info* GetInfo(); + + const PPP_MouseLock_Dev* ppp_mouse_lock_target() const { + return static_cast<const PPP_MouseLock_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; + + private: + // Message handlers. + void OnMsgMouseLockLost(PP_Instance instance); +}; + +} // namespace proxy +} // namespace ppapi + +#endif // PPAPI_PROXY_PPP_MOUSE_LOCK_PROXY_H_ diff --git a/ppapi/tests/all_c_includes.h b/ppapi/tests/all_c_includes.h index e924d13..269472d 100644 --- a/ppapi/tests/all_c_includes.h +++ b/ppapi/tests/all_c_includes.h @@ -25,6 +25,7 @@ #include "ppapi/c/dev/ppb_fullscreen_dev.h" #include "ppapi/c/dev/ppb_layer_compositor_dev.h" #include "ppapi/c/dev/ppb_memory_dev.h" +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" #include "ppapi/c/dev/ppb_query_policy_dev.h" #include "ppapi/c/dev/ppb_scrollbar_dev.h" #include "ppapi/c/dev/ppb_surface_3d_dev.h" @@ -39,6 +40,7 @@ #include "ppapi/c/dev/ppp_class_deprecated.h" #include "ppapi/c/dev/ppp_cursor_control_dev.h" #include "ppapi/c/dev/ppp_find_dev.h" +#include "ppapi/c/dev/ppp_mouse_lock_dev.h" #include "ppapi/c/dev/ppp_policy_update_dev.h" #include "ppapi/c/dev/ppp_printing_dev.h" #include "ppapi/c/dev/ppp_scrollbar_dev.h" diff --git a/ppapi/tests/all_cpp_includes.h b/ppapi/tests/all_cpp_includes.h index 511bea9..719e94e 100644 --- a/ppapi/tests/all_cpp_includes.h +++ b/ppapi/tests/all_cpp_includes.h @@ -21,6 +21,7 @@ #include "ppapi/cpp/dev/font_dev.h" #include "ppapi/cpp/dev/fullscreen_dev.h" #include "ppapi/cpp/dev/memory_dev.h" +#include "ppapi/cpp/dev/mouse_lock_dev.h" #include "ppapi/cpp/dev/printing_dev.h" #include "ppapi/cpp/dev/scriptable_object_deprecated.h" #include "ppapi/cpp/dev/scrollbar_dev.h" diff --git a/ppapi/thunk/ppb_instance_api.h b/ppapi/thunk/ppb_instance_api.h index dcf100dc..e9cacef 100644 --- a/ppapi/thunk/ppb_instance_api.h +++ b/ppapi/thunk/ppb_instance_api.h @@ -5,6 +5,7 @@ #ifndef PPAPI_THUNK_INSTANCE_API_H_ #define PPAPI_THUNK_INSTANCE_API_H_ +#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/ppb_instance.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_size.h" @@ -44,6 +45,11 @@ class PPB_Instance_FunctionAPI { // Messaging. virtual void PostMessage(PP_Instance instance, PP_Var message) = 0; + // MouseLock. + virtual int32_t LockMouse(PP_Instance instance, + PP_CompletionCallback callback) = 0; + virtual void UnlockMouse(PP_Instance instance) = 0; + // Zoom. virtual void ZoomChanged(PP_Instance instance, double factor) = 0; virtual void ZoomLimitsChanged(PP_Instance instance, diff --git a/ppapi/thunk/ppb_mouse_lock_thunk.cc b/ppapi/thunk/ppb_mouse_lock_thunk.cc new file mode 100755 index 0000000..d9116b0 --- /dev/null +++ b/ppapi/thunk/ppb_mouse_lock_thunk.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/dev/ppb_mouse_lock_dev.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/common.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_instance_api.h" +#include "ppapi/thunk/thunk.h" + +namespace ppapi { +namespace thunk { + +namespace { + +int32_t LockMouse(PP_Instance instance, PP_CompletionCallback callback) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.failed()) + return MayForceCallback(callback, PP_ERROR_BADARGUMENT); + int32_t result = enter.functions()->LockMouse(instance, callback); + return MayForceCallback(callback, result); +} + +void UnlockMouse(PP_Instance instance) { + EnterFunction<PPB_Instance_FunctionAPI> enter(instance, true); + if (enter.failed()) + return; + enter.functions()->UnlockMouse(instance); +} + +const PPB_MouseLock_Dev g_ppb_mouse_lock_thunk = { + &LockMouse, + &UnlockMouse +}; + +} // namespace + +const PPB_MouseLock_Dev* GetPPB_MouseLock_Thunk() { + return &g_ppb_mouse_lock_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index a6d1dd9..94c31a7 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -43,6 +43,7 @@ struct PPB_LayerCompositor_Dev; struct PPB_Messaging; struct PPB_MouseInputEvent_1_0; struct PPB_MouseInputEvent; +struct PPB_MouseLock_Dev; struct PPB_QueryPolicy_Dev; struct PPB_Scrollbar_0_5_Dev; struct PPB_Surface3D_Dev; @@ -109,6 +110,7 @@ PPAPI_THUNK_EXPORT const PPB_MouseInputEvent_1_0* GetPPB_MouseInputEvent_1_0_Thunk(); PPAPI_THUNK_EXPORT const PPB_MouseInputEvent* GetPPB_MouseInputEvent_1_1_Thunk(); +PPAPI_THUNK_EXPORT const PPB_MouseLock_Dev* GetPPB_MouseLock_Thunk(); PPAPI_THUNK_EXPORT const PPB_Scrollbar_0_5_Dev* GetPPB_Scrollbar_Thunk(); PPAPI_THUNK_EXPORT const PPB_Surface3D_Dev* GetPPB_Surface3D_Thunk(); PPAPI_THUNK_EXPORT const PPB_Transport_Dev* GetPPB_Transport_Thunk(); |