| 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" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 LocalInputMonitorWin::Core::~Core() { | 121 LocalInputMonitorWin::Core::~Core() { |
| 122 DCHECK(!window_); | 122 DCHECK(!window_); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void LocalInputMonitorWin::Core::StartOnUiThread() { | 125 void LocalInputMonitorWin::Core::StartOnUiThread() { |
| 126 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 126 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 127 | 127 |
| 128 window_.reset(new base::win::MessageWindow()); | 128 window_.reset(new base::win::MessageWindow()); |
| 129 if (!window_->Create(base::Bind(&Core::HandleMessage, | 129 if (!window_->Create(base::Bind(&Core::HandleMessage, |
| 130 base::Unretained(this)))) { | 130 base::Unretained(this)))) { |
| 131 LOG_GETLASTERROR(ERROR) << "Failed to create the raw input window"; | 131 PLOG(ERROR) << "Failed to create the raw input window"; |
| 132 window_.reset(); | 132 window_.reset(); |
| 133 | 133 |
| 134 // If the local input cannot be monitored, the remote user can take over | 134 // If the local input cannot be monitored, the remote user can take over |
| 135 // the session. Disconnect the session now to prevent this. | 135 // the session. Disconnect the session now to prevent this. |
| 136 caller_task_runner_->PostTask( | 136 caller_task_runner_->PostTask( |
| 137 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, | 137 FROM_HERE, base::Bind(&ClientSessionControl::DisconnectSession, |
| 138 client_session_control_)); | 138 client_session_control_)); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 161 DCHECK(ui_task_runner_->BelongsToCurrentThread()); | 161 DCHECK(ui_task_runner_->BelongsToCurrentThread()); |
| 162 | 162 |
| 163 // Get the size of the input record. | 163 // Get the size of the input record. |
| 164 UINT size = 0; | 164 UINT size = 0; |
| 165 UINT result = GetRawInputData(input_handle, | 165 UINT result = GetRawInputData(input_handle, |
| 166 RID_INPUT, | 166 RID_INPUT, |
| 167 NULL, | 167 NULL, |
| 168 &size, | 168 &size, |
| 169 sizeof(RAWINPUTHEADER)); | 169 sizeof(RAWINPUTHEADER)); |
| 170 if (result == -1) { | 170 if (result == -1) { |
| 171 LOG_GETLASTERROR(ERROR) << "GetRawInputData() failed"; | 171 PLOG(ERROR) << "GetRawInputData() failed"; |
| 172 return 0; | 172 return 0; |
| 173 } | 173 } |
| 174 | 174 |
| 175 // Retrieve the input record itself. | 175 // Retrieve the input record itself. |
| 176 scoped_ptr<uint8[]> buffer(new uint8[size]); | 176 scoped_ptr<uint8[]> buffer(new uint8[size]); |
| 177 RAWINPUT* input = reinterpret_cast<RAWINPUT*>(buffer.get()); | 177 RAWINPUT* input = reinterpret_cast<RAWINPUT*>(buffer.get()); |
| 178 result = GetRawInputData(input_handle, | 178 result = GetRawInputData(input_handle, |
| 179 RID_INPUT, | 179 RID_INPUT, |
| 180 buffer.get(), | 180 buffer.get(), |
| 181 &size, | 181 &size, |
| 182 sizeof(RAWINPUTHEADER)); | 182 sizeof(RAWINPUTHEADER)); |
| 183 if (result == -1) { | 183 if (result == -1) { |
| 184 LOG_GETLASTERROR(ERROR) << "GetRawInputData() failed"; | 184 PLOG(ERROR) << "GetRawInputData() failed"; |
| 185 return 0; | 185 return 0; |
| 186 } | 186 } |
| 187 | 187 |
| 188 // Notify the observer about mouse events generated locally. Remote (injected) | 188 // Notify the observer about mouse events generated locally. Remote (injected) |
| 189 // mouse events do not specify a device handle (based on observed behavior). | 189 // mouse events do not specify a device handle (based on observed behavior). |
| 190 if (input->header.dwType == RIM_TYPEMOUSE && | 190 if (input->header.dwType == RIM_TYPEMOUSE && |
| 191 input->header.hDevice != NULL) { | 191 input->header.hDevice != NULL) { |
| 192 POINT position; | 192 POINT position; |
| 193 if (!GetCursorPos(&position)) { | 193 if (!GetCursorPos(&position)) { |
| 194 position.x = 0; | 194 position.x = 0; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 210 case WM_CREATE: { | 210 case WM_CREATE: { |
| 211 // Register to receive raw mouse input. | 211 // Register to receive raw mouse input. |
| 212 RAWINPUTDEVICE device = {0}; | 212 RAWINPUTDEVICE device = {0}; |
| 213 device.dwFlags = RIDEV_INPUTSINK; | 213 device.dwFlags = RIDEV_INPUTSINK; |
| 214 device.usUsagePage = kGenericDesktopPage; | 214 device.usUsagePage = kGenericDesktopPage; |
| 215 device.usUsage = kMouseUsage; | 215 device.usUsage = kMouseUsage; |
| 216 device.hwndTarget = window_->hwnd(); | 216 device.hwndTarget = window_->hwnd(); |
| 217 if (RegisterRawInputDevices(&device, 1, sizeof(device))) { | 217 if (RegisterRawInputDevices(&device, 1, sizeof(device))) { |
| 218 *result = 0; | 218 *result = 0; |
| 219 } else { | 219 } else { |
| 220 LOG_GETLASTERROR(ERROR) << "RegisterRawInputDevices() failed"; | 220 PLOG(ERROR) << "RegisterRawInputDevices() failed"; |
| 221 *result = -1; | 221 *result = -1; |
| 222 } | 222 } |
| 223 return true; | 223 return true; |
| 224 } | 224 } |
| 225 | 225 |
| 226 case WM_INPUT: | 226 case WM_INPUT: |
| 227 *result = OnInput(reinterpret_cast<HRAWINPUT>(lparam)); | 227 *result = OnInput(reinterpret_cast<HRAWINPUT>(lparam)); |
| 228 return true; | 228 return true; |
| 229 | 229 |
| 230 default: | 230 default: |
| 231 return false; | 231 return false; |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 } // namespace | 235 } // namespace |
| 236 | 236 |
| 237 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( | 237 scoped_ptr<LocalInputMonitor> LocalInputMonitor::Create( |
| 238 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, | 238 scoped_refptr<base::SingleThreadTaskRunner> caller_task_runner, |
| 239 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 239 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 240 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, | 240 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, |
| 241 base::WeakPtr<ClientSessionControl> client_session_control) { | 241 base::WeakPtr<ClientSessionControl> client_session_control) { |
| 242 return scoped_ptr<LocalInputMonitor>( | 242 return scoped_ptr<LocalInputMonitor>( |
| 243 new LocalInputMonitorWin(caller_task_runner, | 243 new LocalInputMonitorWin(caller_task_runner, |
| 244 ui_task_runner, | 244 ui_task_runner, |
| 245 client_session_control)); | 245 client_session_control)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace remoting | 248 } // namespace remoting |
| OLD | NEW |