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_event_executor.h" | 5 #include "remoting/host/win/session_event_executor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 namespace remoting { | 37 namespace remoting { |
38 | 38 |
39 using protocol::ClipboardEvent; | 39 using protocol::ClipboardEvent; |
40 using protocol::MouseEvent; | 40 using protocol::MouseEvent; |
41 using protocol::KeyEvent; | 41 using protocol::KeyEvent; |
42 | 42 |
43 SessionEventExecutorWin::SessionEventExecutorWin( | 43 SessionEventExecutorWin::SessionEventExecutorWin( |
44 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 44 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, |
45 scoped_ptr<EventExecutor> nested_executor) | 45 scoped_ptr<EventExecutor> nested_executor, |
| 46 scoped_refptr<base::SingleThreadTaskRunner> inject_sas_task_runner, |
| 47 const base::Closure& inject_sas) |
46 : nested_executor_(nested_executor.Pass()), | 48 : nested_executor_(nested_executor.Pass()), |
47 task_runner_(main_task_runner), | 49 input_task_runner_(input_task_runner), |
| 50 inject_sas_task_runner_(inject_sas_task_runner), |
| 51 inject_sas_(inject_sas), |
48 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 52 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
49 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { | 53 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
50 // Let |weak_ptr_| be used on the |task_runner_| thread. | 54 // Let |weak_ptr_| be used on the |input_task_runner_| thread. |
51 // |weak_ptr_| and |weak_ptr_factory_| share a ThreadChecker, so the | 55 // |weak_ptr_| and |weak_ptr_factory_| share a ThreadChecker, so the |
52 // following line affects both of them. | 56 // following line affects both of them. |
53 weak_ptr_factory_.DetachFromThread(); | 57 weak_ptr_factory_.DetachFromThread(); |
54 } | 58 } |
55 | 59 |
56 SessionEventExecutorWin::~SessionEventExecutorWin() { | 60 SessionEventExecutorWin::~SessionEventExecutorWin() { |
57 } | 61 } |
58 | 62 |
59 void SessionEventExecutorWin::Start( | 63 void SessionEventExecutorWin::Start( |
60 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 64 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
61 if (!task_runner_->BelongsToCurrentThread()) { | 65 if (!input_task_runner_->BelongsToCurrentThread()) { |
62 task_runner_->PostTask( | 66 input_task_runner_->PostTask( |
63 FROM_HERE, | 67 FROM_HERE, |
64 base::Bind(&SessionEventExecutorWin::Start, | 68 base::Bind(&SessionEventExecutorWin::Start, |
65 weak_ptr_, base::Passed(&client_clipboard))); | 69 weak_ptr_, base::Passed(&client_clipboard))); |
66 return; | 70 return; |
67 } | 71 } |
68 | 72 |
69 nested_executor_->Start(client_clipboard.Pass()); | 73 nested_executor_->Start(client_clipboard.Pass()); |
70 } | 74 } |
71 | 75 |
72 void SessionEventExecutorWin::StopAndDelete() { | 76 void SessionEventExecutorWin::StopAndDelete() { |
73 if (!task_runner_->BelongsToCurrentThread()) { | 77 if (!input_task_runner_->BelongsToCurrentThread()) { |
74 task_runner_->PostTask( | 78 input_task_runner_->PostTask( |
75 FROM_HERE, | 79 FROM_HERE, |
76 base::Bind(&SessionEventExecutorWin::StopAndDelete, | 80 base::Bind(&SessionEventExecutorWin::StopAndDelete, |
77 weak_ptr_)); | 81 weak_ptr_)); |
78 return; | 82 return; |
79 } | 83 } |
80 | 84 |
81 nested_executor_.release()->StopAndDelete(); | 85 nested_executor_.release()->StopAndDelete(); |
82 delete this; | 86 delete this; |
83 } | 87 } |
84 | 88 |
85 void SessionEventExecutorWin::InjectClipboardEvent( | 89 void SessionEventExecutorWin::InjectClipboardEvent( |
86 const ClipboardEvent& event) { | 90 const ClipboardEvent& event) { |
87 if (!task_runner_->BelongsToCurrentThread()) { | 91 if (!input_task_runner_->BelongsToCurrentThread()) { |
88 task_runner_->PostTask( | 92 input_task_runner_->PostTask( |
89 FROM_HERE, | 93 FROM_HERE, |
90 base::Bind(&SessionEventExecutorWin::InjectClipboardEvent, | 94 base::Bind(&SessionEventExecutorWin::InjectClipboardEvent, |
91 weak_ptr_, event)); | 95 weak_ptr_, event)); |
92 return; | 96 return; |
93 } | 97 } |
94 | 98 |
95 nested_executor_->InjectClipboardEvent(event); | 99 nested_executor_->InjectClipboardEvent(event); |
96 } | 100 } |
97 | 101 |
98 void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) { | 102 void SessionEventExecutorWin::InjectKeyEvent(const KeyEvent& event) { |
99 if (!task_runner_->BelongsToCurrentThread()) { | 103 if (!input_task_runner_->BelongsToCurrentThread()) { |
100 task_runner_->PostTask( | 104 input_task_runner_->PostTask( |
101 FROM_HERE, | 105 FROM_HERE, |
102 base::Bind(&SessionEventExecutorWin::InjectKeyEvent, | 106 base::Bind(&SessionEventExecutorWin::InjectKeyEvent, |
103 weak_ptr_, event)); | 107 weak_ptr_, event)); |
104 return; | 108 return; |
105 } | 109 } |
106 | 110 |
107 // HostEventDispatcher should drop events lacking the pressed field. | 111 // HostEventDispatcher should drop events lacking the pressed field. |
108 DCHECK(event.has_pressed()); | 112 DCHECK(event.has_pressed()); |
109 | 113 |
110 if (event.has_usb_keycode()) { | 114 if (event.has_usb_keycode()) { |
111 if (event.pressed()) { | 115 if (event.pressed()) { |
112 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. | 116 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. |
113 if (event.usb_keycode() == kUsbDelete && | 117 if (event.usb_keycode() == kUsbDelete && |
114 CheckCtrlAndAltArePressed(pressed_keys_)) { | 118 CheckCtrlAndAltArePressed(pressed_keys_)) { |
115 VLOG(3) << "Sending Secure Attention Sequence to console"; | 119 VLOG(3) << "Sending Secure Attention Sequence to console"; |
116 | 120 |
117 if (sas_injector_.get() == NULL) | 121 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
118 sas_injector_ = SasInjector::Create(); | 122 if (!sas_injector_) |
119 sas_injector_->InjectSas(); | 123 sas_injector_ = SasInjector::Create(); |
| 124 if (!sas_injector_->InjectSas()) |
| 125 LOG(ERROR) << "Failed to inject Secure Attention Sequence."; |
| 126 } else { |
| 127 inject_sas_task_runner_->PostTask(FROM_HERE, inject_sas_); |
| 128 } |
120 } | 129 } |
121 | 130 |
122 pressed_keys_.insert(event.usb_keycode()); | 131 pressed_keys_.insert(event.usb_keycode()); |
123 } else { | 132 } else { |
124 pressed_keys_.erase(event.usb_keycode()); | 133 pressed_keys_.erase(event.usb_keycode()); |
125 } | 134 } |
126 } | 135 } |
127 | 136 |
128 SwitchToInputDesktop(); | 137 SwitchToInputDesktop(); |
129 nested_executor_->InjectKeyEvent(event); | 138 nested_executor_->InjectKeyEvent(event); |
130 } | 139 } |
131 | 140 |
132 void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) { | 141 void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) { |
133 if (!task_runner_->BelongsToCurrentThread()) { | 142 if (!input_task_runner_->BelongsToCurrentThread()) { |
134 task_runner_->PostTask( | 143 input_task_runner_->PostTask( |
135 FROM_HERE, | 144 FROM_HERE, |
136 base::Bind(&SessionEventExecutorWin::InjectMouseEvent, | 145 base::Bind(&SessionEventExecutorWin::InjectMouseEvent, |
137 weak_ptr_, event)); | 146 weak_ptr_, event)); |
138 return; | 147 return; |
139 } | 148 } |
140 | 149 |
141 SwitchToInputDesktop(); | 150 SwitchToInputDesktop(); |
142 nested_executor_->InjectMouseEvent(event); | 151 nested_executor_->InjectMouseEvent(event); |
143 } | 152 } |
144 | 153 |
145 void SessionEventExecutorWin::SwitchToInputDesktop() { | 154 void SessionEventExecutorWin::SwitchToInputDesktop() { |
146 // Switch to the desktop receiving user input if different from the current | 155 // Switch to the desktop receiving user input if different from the current |
147 // one. | 156 // one. |
148 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop(); | 157 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop(); |
149 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { | 158 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { |
150 // If SetThreadDesktop() fails, the thread is still assigned a desktop. | 159 // If SetThreadDesktop() fails, the thread is still assigned a desktop. |
151 // So we can continue capture screen bits, just from a diffected desktop. | 160 // So we can continue capture screen bits, just from a diffected desktop. |
152 desktop_.SetThreadDesktop(input_desktop.Pass()); | 161 desktop_.SetThreadDesktop(input_desktop.Pass()); |
153 } | 162 } |
154 } | 163 } |
155 | 164 |
156 } // namespace remoting | 165 } // namespace remoting |
OLD | NEW |