| 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 "remoting/host/local_input_monitor.h" | 5 #include "remoting/host/local_input_monitor.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/win/message_window.h" |
| 14 #include "remoting/host/client_session_control.h" | 15 #include "remoting/host/client_session_control.h" |
| 15 #include "remoting/host/win/message_window.h" | |
| 16 #include "third_party/skia/include/core/SkPoint.h" | 16 #include "third_party/skia/include/core/SkPoint.h" |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const wchar_t kWindowClassFormat[] = L"Chromoting_LocalInputMonitorWin_%p"; | 22 const wchar_t kWindowClassFormat[] = L"Chromoting_LocalInputMonitorWin_%p"; |
| 23 | 23 |
| 24 // From the HID Usage Tables specification. | 24 // From the HID Usage Tables specification. |
| 25 const USHORT kGenericDesktopPage = 1; | 25 const USHORT kGenericDesktopPage = 1; |
| 26 const USHORT kMouseUsage = 2; | 26 const USHORT kMouseUsage = 2; |
| 27 | 27 |
| 28 class LocalInputMonitorWin : public base::NonThreadSafe, | 28 class LocalInputMonitorWin : public base::NonThreadSafe, |
| 29 public LocalInputMonitor { | 29 public LocalInputMonitor { |
| 30 public: | 30 public: |
| 31 LocalInputMonitorWin( | 31 LocalInputMonitorWin( |
| 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 32 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 33 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 33 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 34 base::WeakPtr<ClientSessionControl> client_session_control); | 34 base::WeakPtr<ClientSessionControl> client_session_control); |
| 35 ~LocalInputMonitorWin(); | 35 ~LocalInputMonitorWin(); |
| 36 | 36 |
| 37 private: | 37 private: |
| 38 // The actual implementation resides in LocalInputMonitorWin::Core class. | 38 // The actual implementation resides in LocalInputMonitorWin::Core class. |
| 39 class Core : public base::RefCountedThreadSafe<Core>, | 39 class Core : public base::RefCountedThreadSafe<Core>, |
| 40 public win::MessageWindow::Delegate { | 40 public base::win::MessageWindow::Delegate { |
| 41 public: | 41 public: |
| 42 Core(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 42 Core(scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 43 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 43 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 44 base::WeakPtr<ClientSessionControl> client_session_control); | 44 base::WeakPtr<ClientSessionControl> client_session_control); |
| 45 | 45 |
| 46 void Start(); | 46 void Start(); |
| 47 void Stop(); | 47 void Stop(); |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class base::RefCountedThreadSafe<Core>; | 50 friend class base::RefCountedThreadSafe<Core>; |
| 51 virtual ~Core(); | 51 virtual ~Core(); |
| 52 | 52 |
| 53 void StartOnUiThread(); | 53 void StartOnUiThread(); |
| 54 void StopOnUiThread(); | 54 void StopOnUiThread(); |
| 55 | 55 |
| 56 // Handles WM_INPUT messages. | 56 // Handles WM_INPUT messages. |
| 57 LRESULT OnInput(HRAWINPUT input_handle); | 57 LRESULT OnInput(HRAWINPUT input_handle); |
| 58 | 58 |
| 59 // win::MessageWindow::Delegate interface. | 59 // base::win::MessageWindow::Delegate interface. |
| 60 virtual bool HandleMessage(HWND hwnd, | 60 virtual bool HandleMessage(HWND hwnd, |
| 61 UINT message, | 61 UINT message, |
| 62 WPARAM wparam, | 62 WPARAM wparam, |
| 63 LPARAM lparam, | 63 LPARAM lparam, |
| 64 LRESULT* result) OVERRIDE; | 64 LRESULT* result) OVERRIDE; |
| 65 | 65 |
| 66 // Task runner on which public methods of this class must be called. | 66 // Task runner on which public methods of this class must be called. |
| 67 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; | 67 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner_; |
| 68 | 68 |
| 69 // Task runner on which |window_| is created. | 69 // Task runner on which |window_| is created. |
| 70 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 70 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 71 | 71 |
| 72 // Used to receive raw input. | 72 // Used to receive raw input. |
| 73 scoped_ptr<win::MessageWindow> window_; | 73 scoped_ptr<base::win::MessageWindow> window_; |
| 74 | 74 |
| 75 // Points to the object receiving mouse event notifications. | 75 // Points to the object receiving mouse event notifications. |
| 76 base::WeakPtr<ClientSessionControl> client_session_control_; | 76 base::WeakPtr<ClientSessionControl> client_session_control_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(Core); | 78 DISALLOW_COPY_AND_ASSIGN(Core); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 scoped_refptr<Core> core_; | 81 scoped_refptr<Core> core_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorWin); | 83 DISALLOW_COPY_AND_ASSIGN(LocalInputMonitorWin); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 ui_task_runner_->PostTask(FROM_HERE, base::Bind(&Core::StopOnUiThread, this)); | 120 ui_task_runner_->PostTask(FROM_HERE, base::Bind(&Core::StopOnUiThread, this)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 LocalInputMonitorWin::Core::~Core() { | 123 LocalInputMonitorWin::Core::~Core() { |
| 124 DCHECK(!window_); | 124 DCHECK(!window_); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void LocalInputMonitorWin::Core::StartOnUiThread() { | 127 void LocalInputMonitorWin::Core::StartOnUiThread() { |
| 128 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 128 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 129 | 129 |
| 130 window_.reset(new win::MessageWindow()); | 130 window_.reset(new base::win::MessageWindow()); |
| 131 if (!window_->Create(this)) { | 131 if (!window_->Create(this)) { |
| 132 LOG_GETLASTERROR(ERROR) << "Failed to create the raw input window"; | 132 LOG_GETLASTERROR(ERROR) << "Failed to create the raw input window"; |
| 133 window_.reset(); | 133 window_.reset(); |
| 134 | 134 |
| 135 // If the local input cannot be monitored, the remote user can take over | 135 // If the local input cannot be monitored, the remote user can take over |
| 136 // the session. Disconnect the session now to prevent this. | 136 // the session. Disconnect the session now to prevent this. |
| 137 caller_task_runner_->PostTask( | 137 caller_task_runner_->PostTask( |
| 138 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, | 138 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, |
| 139 client_session_control_)); | 139 client_session_control_)); |
| 140 } | 140 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 240 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 241 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 241 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 242 base::WeakPtr<ClientSessionControl> client_session_control) { | 242 base::WeakPtr<ClientSessionControl> client_session_control) { |
| 243 return scoped_ptr<LocalInputMonitor>( | 243 return scoped_ptr<LocalInputMonitor>( |
| 244 new LocalInputMonitorWin(caller_task_runner, | 244 new LocalInputMonitorWin(caller_task_runner, |
| 245 ui_task_runner, | 245 ui_task_runner, |
| 246 client_session_control)); | 246 client_session_control)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 } // namespace remoting | 249 } // namespace remoting |
| OLD | NEW |