summaryrefslogtreecommitdiffstats
path: root/remoting/host/local_input_monitor_win.cc
diff options
context:
space:
mode:
authoralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 18:00:06 +0000
committeralexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 18:00:06 +0000
commit2336afffa360213748a9019136332a4d2ed3987c (patch)
tree39e8685865766c7de680eabbed38c81cf29015ce /remoting/host/local_input_monitor_win.cc
parent59e5ceeb221400200926159da08e56e1f5507594 (diff)
downloadchromium_src-2336afffa360213748a9019136332a4d2ed3987c.zip
chromium_src-2336afffa360213748a9019136332a4d2ed3987c.tar.gz
chromium_src-2336afffa360213748a9019136332a4d2ed3987c.tar.bz2
Moved code implementing message-only windows to a dedicated class (Windows only).
This CL merges three implementations of message-only windows that we have in remoting into one class remoting::win::MessageWindow. Collateral changes: - The local input monitor now closes the connection if it cannot subscribe to the raw mouse input. Without this the remote user could potentially prevent the local user from closing the connection. - The clipboard window can be started only once, just like its owner. TEST=remoting_unittests.MessageWindowTest Review URL: https://chromiumcodereview.appspot.com/13142002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191532 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/host/local_input_monitor_win.cc')
-rw-r--r--remoting/host/local_input_monitor_win.cc132
1 files changed, 50 insertions, 82 deletions
diff --git a/remoting/host/local_input_monitor_win.cc b/remoting/host/local_input_monitor_win.cc
index 28deebc..b23b02c 100644
--- a/remoting/host/local_input_monitor_win.cc
+++ b/remoting/host/local_input_monitor_win.cc
@@ -11,8 +11,8 @@
#include "base/single_thread_task_runner.h"
#include "base/stringprintf.h"
#include "base/threading/non_thread_safe.h"
-#include "base/win/wrapped_window_proc.h"
#include "remoting/host/client_session_control.h"
+#include "remoting/host/win/message_window.h"
#include "third_party/skia/include/core/SkPoint.h"
namespace remoting {
@@ -36,7 +36,8 @@ class LocalInputMonitorWin : public base::NonThreadSafe,
private:
// The actual implementation resides in LocalInputMonitorWin::Core class.
- class Core : public base::RefCountedThreadSafe<Core> {
+ class Core : public base::RefCountedThreadSafe<Core>,
+ public win::MessageWindow::Delegate {
public:
Core(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
@@ -52,15 +53,15 @@ class LocalInputMonitorWin : public base::NonThreadSafe,
void StartOnUiThread();
void StopOnUiThread();
- // Handles WM_CREATE messages.
- LRESULT OnCreate(HWND hwnd);
-
// Handles WM_INPUT messages.
LRESULT OnInput(HRAWINPUT input_handle);
- // Window procedure invoked by the OS to process window messages.
- static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message,
- WPARAM wparam, LPARAM lparam);
+ // win::MessageWindow::Delegate interface.
+ virtual bool HandleMessage(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam,
+ LRESULT* result) OVERRIDE;
// Task runner on which public methods of this class must be called.
scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_;
@@ -68,14 +69,8 @@ class LocalInputMonitorWin : public base::NonThreadSafe,
// Task runner on which |window_| is created.
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_;
- // Atom representing the input window class.
- ATOM atom_;
-
- // Instance of the module containing the window procedure.
- HINSTANCE instance_;
-
- // Handle of the input window.
- HWND window_;
+ // Used to receive raw input.
+ scoped_ptr<win::MessageWindow> window_;
// Points to the object receiving mouse event notifications.
base::WeakPtr<ClientSessionControl> client_session_control_;
@@ -108,9 +103,6 @@ LocalInputMonitorWin::Core::Core(
base::WeakPtr<ClientSessionControl> client_session_control)
: caller_task_runner_(caller_task_runner),
ui_task_runner_(ui_task_runner),
- atom_(0),
- instance_(NULL),
- window_(NULL),
client_session_control_(client_session_control) {
DCHECK(client_session_control_);
}
@@ -129,68 +121,41 @@ void LocalInputMonitorWin::Core::Stop() {
}
LocalInputMonitorWin::Core::~Core() {
- DCHECK(!atom_);
- DCHECK(!instance_);
DCHECK(!window_);
}
void LocalInputMonitorWin::Core::StartOnUiThread() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- // Create a window for receiving raw input.
- string16 window_class_name = base::StringPrintf(kWindowClassFormat, this);
- WNDCLASSEX window_class;
- base::win::InitializeWindowClass(
- window_class_name.c_str(),
- &base::win::WrappedWindowProc<WindowProc>,
- 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
- &window_class);
- instance_ = window_class.hInstance;
- atom_ = RegisterClassEx(&window_class);
- if (atom_ == 0) {
- LOG_GETLASTERROR(ERROR)
- << "Failed to register the window class '" << window_class_name << "'";
- return;
- }
-
- window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
- instance_, this);
- if (window_ == NULL) {
+ window_.reset(new win::MessageWindow());
+ if (!window_->Create(this)) {
LOG_GETLASTERROR(ERROR) << "Failed to create the raw input window";
- return;
+ window_.reset();
+
+ // If the local input cannot be monitored, the remote user can take over
+ // the session. Disconnect the session now to prevent this.
+ caller_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession,
+ client_session_control_));
}
}
void LocalInputMonitorWin::Core::StopOnUiThread() {
DCHECK(ui_task_runner_->BelongsToCurrentThread());
- if (window_ != NULL) {
- DestroyWindow(window_);
- window_ = NULL;
- }
-
- if (atom_ != 0) {
- UnregisterClass(MAKEINTATOM(atom_), instance_);
- atom_ = 0;
- instance_ = NULL;
- }
-}
-
-LRESULT LocalInputMonitorWin::Core::OnCreate(HWND hwnd) {
- DCHECK(ui_task_runner_->BelongsToCurrentThread());
+ // Stop receiving raw mouse input.
+ if (window_) {
+ RAWINPUTDEVICE device = {0};
+ device.dwFlags = RIDEV_REMOVE;
+ device.usUsagePage = kGenericDesktopPage;
+ device.usUsage = kMouseUsage;
+ device.hwndTarget = window_->hwnd();
- // Register to receive raw mouse input.
- RAWINPUTDEVICE device = {0};
- device.dwFlags = RIDEV_INPUTSINK;
- device.usUsagePage = kGenericDesktopPage;
- device.usUsage = kMouseUsage;
- device.hwndTarget = hwnd;
- if (!RegisterRawInputDevices(&device, 1, sizeof(device))) {
- LOG_GETLASTERROR(ERROR) << "RegisterRawInputDevices() failed";
- return -1;
+ // The error is harmless, ignore it.
+ RegisterRawInputDevices(&device, 1, sizeof(device));
}
- return 0;
+ window_.reset();
}
LRESULT LocalInputMonitorWin::Core::OnInput(HRAWINPUT input_handle) {
@@ -240,28 +205,31 @@ LRESULT LocalInputMonitorWin::Core::OnInput(HRAWINPUT input_handle) {
return DefRawInputProc(&input, 1, sizeof(RAWINPUTHEADER));
}
-// static
-LRESULT CALLBACK LocalInputMonitorWin::Core::WindowProc(
- HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
- // Store |this| to the window's user data.
- if (message == WM_CREATE) {
- CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
- SetLastError(ERROR_SUCCESS);
- LONG_PTR result = SetWindowLongPtr(
- hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
- CHECK(result != 0 || GetLastError() == ERROR_SUCCESS);
- }
-
- Core* self = reinterpret_cast<Core*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
+bool LocalInputMonitorWin::Core::HandleMessage(
+ HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT* result) {
switch (message) {
- case WM_CREATE:
- return self->OnCreate(hwnd);
+ case WM_CREATE: {
+ // Register to receive raw mouse input.
+ RAWINPUTDEVICE device = {0};
+ device.dwFlags = RIDEV_INPUTSINK;
+ device.usUsagePage = kGenericDesktopPage;
+ device.usUsage = kMouseUsage;
+ device.hwndTarget = hwnd;
+ if (RegisterRawInputDevices(&device, 1, sizeof(device))) {
+ *result = 0;
+ } else {
+ LOG_GETLASTERROR(ERROR) << "RegisterRawInputDevices() failed";
+ *result = -1;
+ }
+ return true;
+ }
case WM_INPUT:
- return self->OnInput(reinterpret_cast<HRAWINPUT>(lparam));
+ *result = OnInput(reinterpret_cast<HRAWINPUT>(lparam));
+ return true;
default:
- return DefWindowProc(hwnd, message, wparam, lparam);
+ return false;
}
}