| 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/win/session_input_injector.h" | 5 #include "remoting/host/win/session_input_injector.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/win/windows_version.h" | 15 #include "base/win/windows_version.h" |
| 16 #include "remoting/host/sas_injector.h" | 16 #include "remoting/host/sas_injector.h" |
| 17 #include "remoting/proto/event.pb.h" | 17 #include "remoting/proto/event.pb.h" |
| 18 #include "remoting/protocol/usb_key_codes.h" | |
| 19 #include "third_party/webrtc/modules/desktop_capture/win/desktop.h" | 18 #include "third_party/webrtc/modules/desktop_capture/win/desktop.h" |
| 20 #include "third_party/webrtc/modules/desktop_capture/win/scoped_thread_desktop.h
" | 19 #include "third_party/webrtc/modules/desktop_capture/win/scoped_thread_desktop.h
" |
| 20 #include "ui/events/keycodes/dom/dom_code.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 bool CheckCtrlAndAltArePressed(const std::set<uint32>& pressed_keys) { | 24 bool CheckCtrlAndAltArePressed(const std::set<ui::DomCode>& pressed_keys) { |
| 25 size_t ctrl_keys = pressed_keys.count(kUsbLeftControl) + | 25 size_t ctrl_keys = pressed_keys.count(ui::DomCode::CONTROL_LEFT) + |
| 26 pressed_keys.count(kUsbRightControl); | 26 pressed_keys.count(ui::DomCode::CONTROL_RIGHT); |
| 27 size_t alt_keys = pressed_keys.count(kUsbLeftAlt) + | 27 size_t alt_keys = pressed_keys.count(ui::DomCode::ALT_LEFT) + |
| 28 pressed_keys.count(kUsbRightAlt); | 28 pressed_keys.count(ui::DomCode::ALT_RIGHT); |
| 29 return ctrl_keys != 0 && alt_keys != 0 && | 29 return ctrl_keys != 0 && alt_keys != 0 && |
| 30 (ctrl_keys + alt_keys == pressed_keys.size()); | 30 (ctrl_keys + alt_keys == pressed_keys.size()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 namespace remoting { | 35 namespace remoting { |
| 36 | 36 |
| 37 using protocol::ClipboardEvent; | 37 using protocol::ClipboardEvent; |
| 38 using protocol::KeyEvent; | 38 using protocol::KeyEvent; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 webrtc::ScopedThreadDesktop desktop_; | 80 webrtc::ScopedThreadDesktop desktop_; |
| 81 | 81 |
| 82 // Used to inject Secure Attention Sequence on Vista+. | 82 // Used to inject Secure Attention Sequence on Vista+. |
| 83 base::Closure inject_sas_; | 83 base::Closure inject_sas_; |
| 84 | 84 |
| 85 // Used to inject Secure Attention Sequence on XP. | 85 // Used to inject Secure Attention Sequence on XP. |
| 86 scoped_ptr<SasInjector> sas_injector_; | 86 scoped_ptr<SasInjector> sas_injector_; |
| 87 | 87 |
| 88 // Keys currently pressed by the client, used to detect Ctrl-Alt-Del. | 88 // Keys currently pressed by the client, used to detect Ctrl-Alt-Del. |
| 89 std::set<uint32> pressed_keys_; | 89 std::set<ui::DomCode> pressed_keys_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(Core); | 91 DISALLOW_COPY_AND_ASSIGN(Core); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 SessionInputInjectorWin::Core::Core( | 94 SessionInputInjectorWin::Core::Core( |
| 95 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, | 95 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
| 96 scoped_ptr<InputInjector> nested_executor, | 96 scoped_ptr<InputInjector> nested_executor, |
| 97 scoped_refptr<base::SingleThreadTaskRunner> inject_sas_task_runner, | 97 scoped_refptr<base::SingleThreadTaskRunner> inject_sas_task_runner, |
| 98 const base::Closure& inject_sas) | 98 const base::Closure& inject_sas) |
| 99 : input_task_runner_(input_task_runner), | 99 : input_task_runner_(input_task_runner), |
| (...skipping 29 matching lines...) Expand all Loading... |
| 129 if (!input_task_runner_->BelongsToCurrentThread()) { | 129 if (!input_task_runner_->BelongsToCurrentThread()) { |
| 130 input_task_runner_->PostTask( | 130 input_task_runner_->PostTask( |
| 131 FROM_HERE, base::Bind(&Core::InjectKeyEvent, this, event)); | 131 FROM_HERE, base::Bind(&Core::InjectKeyEvent, this, event)); |
| 132 return; | 132 return; |
| 133 } | 133 } |
| 134 | 134 |
| 135 // HostEventDispatcher should drop events lacking the pressed field. | 135 // HostEventDispatcher should drop events lacking the pressed field. |
| 136 DCHECK(event.has_pressed()); | 136 DCHECK(event.has_pressed()); |
| 137 | 137 |
| 138 if (event.has_usb_keycode()) { | 138 if (event.has_usb_keycode()) { |
| 139 ui::DomCode dom_code = static_cast<ui::DomCode>(event.usb_keycode()); |
| 139 if (event.pressed()) { | 140 if (event.pressed()) { |
| 140 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. | 141 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. |
| 141 if (event.usb_keycode() == kUsbDelete && | 142 if (dom_code == ui::DomCode::DEL && |
| 142 CheckCtrlAndAltArePressed(pressed_keys_)) { | 143 CheckCtrlAndAltArePressed(pressed_keys_)) { |
| 143 VLOG(3) << "Sending Secure Attention Sequence to the session"; | 144 VLOG(3) << "Sending Secure Attention Sequence to the session"; |
| 144 | 145 |
| 145 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 146 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 146 if (!sas_injector_) | 147 if (!sas_injector_) |
| 147 sas_injector_ = SasInjector::Create(); | 148 sas_injector_ = SasInjector::Create(); |
| 148 if (!sas_injector_->InjectSas()) | 149 if (!sas_injector_->InjectSas()) |
| 149 LOG(ERROR) << "Failed to inject Secure Attention Sequence."; | 150 LOG(ERROR) << "Failed to inject Secure Attention Sequence."; |
| 150 } else { | 151 } else { |
| 151 inject_sas_task_runner_->PostTask(FROM_HERE, inject_sas_); | 152 inject_sas_task_runner_->PostTask(FROM_HERE, inject_sas_); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 155 pressed_keys_.insert(event.usb_keycode()); | 156 pressed_keys_.insert(dom_code); |
| 156 } else { | 157 } else { |
| 157 pressed_keys_.erase(event.usb_keycode()); | 158 pressed_keys_.erase(dom_code); |
| 158 } | 159 } |
| 159 } | 160 } |
| 160 | 161 |
| 161 SwitchToInputDesktop(); | 162 SwitchToInputDesktop(); |
| 162 nested_executor_->InjectKeyEvent(event); | 163 nested_executor_->InjectKeyEvent(event); |
| 163 } | 164 } |
| 164 | 165 |
| 165 void SessionInputInjectorWin::Core::InjectTextEvent(const TextEvent& event) { | 166 void SessionInputInjectorWin::Core::InjectTextEvent(const TextEvent& event) { |
| 166 if (!input_task_runner_->BelongsToCurrentThread()) { | 167 if (!input_task_runner_->BelongsToCurrentThread()) { |
| 167 input_task_runner_->PostTask( | 168 input_task_runner_->PostTask( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const protocol::MouseEvent& event) { | 246 const protocol::MouseEvent& event) { |
| 246 core_->InjectMouseEvent(event); | 247 core_->InjectMouseEvent(event); |
| 247 } | 248 } |
| 248 | 249 |
| 249 void SessionInputInjectorWin::InjectTouchEvent( | 250 void SessionInputInjectorWin::InjectTouchEvent( |
| 250 const protocol::TouchEvent& event) { | 251 const protocol::TouchEvent& event) { |
| 251 core_->InjectTouchEvent(event); | 252 core_->InjectTouchEvent(event); |
| 252 } | 253 } |
| 253 | 254 |
| 254 } // namespace remoting | 255 } // namespace remoting |
| OLD | NEW |