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/session_event_executor_win.h" | 5 #include "remoting/host/session_event_executor_win.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | |
11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
12 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
13 #include "base/win/windows_version.h" | 12 #include "base/win/windows_version.h" |
14 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
15 #include "ipc/ipc_channel_proxy.h" | 14 #include "ipc/ipc_channel_proxy.h" |
16 #include "remoting/host/chromoting_messages.h" | 15 #include "remoting/host/chromoting_messages.h" |
17 #include "remoting/host/win/desktop.h" | 16 #include "remoting/host/win/desktop.h" |
18 #include "remoting/host/win/scoped_thread_desktop.h" | 17 #include "remoting/host/win/scoped_thread_desktop.h" |
19 #include "remoting/proto/event.pb.h" | 18 #include "remoting/proto/event.pb.h" |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 // The command line switch specifying the name of the Chromoting IPC channel. | |
24 const char kProcessChannelId[] = "chromoting-ipc"; | |
25 | |
26 const uint32 kUsbLeftControl = 0x0700e0; | 22 const uint32 kUsbLeftControl = 0x0700e0; |
27 const uint32 kUsbRightControl = 0x0700e4; | 23 const uint32 kUsbRightControl = 0x0700e4; |
28 const uint32 kUsbLeftAlt = 0x0700e2; | 24 const uint32 kUsbLeftAlt = 0x0700e2; |
29 const uint32 kUsbRightAlt = 0x0700e6; | 25 const uint32 kUsbRightAlt = 0x0700e6; |
30 const uint32 kUsbDelete = 0x07004c; | 26 const uint32 kUsbDelete = 0x07004c; |
31 | 27 |
32 bool CheckCtrlAndAltArePressed(const std::set<uint32>& pressed_keys) { | 28 bool CheckCtrlAndAltArePressed(const std::set<uint32>& pressed_keys) { |
33 size_t ctrl_keys = pressed_keys.count(kUsbLeftControl) + | 29 size_t ctrl_keys = pressed_keys.count(kUsbLeftControl) + |
34 pressed_keys.count(kUsbRightControl); | 30 pressed_keys.count(kUsbRightControl); |
35 size_t alt_keys = pressed_keys.count(kUsbLeftAlt) + | 31 size_t alt_keys = pressed_keys.count(kUsbLeftAlt) + |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } // namespace | 64 } // namespace |
69 | 65 |
70 namespace remoting { | 66 namespace remoting { |
71 | 67 |
72 using protocol::ClipboardEvent; | 68 using protocol::ClipboardEvent; |
73 using protocol::MouseEvent; | 69 using protocol::MouseEvent; |
74 using protocol::KeyEvent; | 70 using protocol::KeyEvent; |
75 | 71 |
76 SessionEventExecutorWin::SessionEventExecutorWin( | 72 SessionEventExecutorWin::SessionEventExecutorWin( |
77 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 73 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
78 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 74 IPC::ChannelProxy* daemon_channel, |
79 scoped_ptr<EventExecutor> nested_executor) | 75 scoped_ptr<EventExecutor> nested_executor) |
80 : nested_executor_(nested_executor.Pass()), | 76 : nested_executor_(nested_executor.Pass()), |
81 task_runner_(main_task_runner), | 77 task_runner_(main_task_runner), |
| 78 daemon_channel_(daemon_channel), |
82 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), | 79 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
83 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { | 80 weak_ptr_(weak_ptr_factory_.GetWeakPtr()) { |
84 // Let |weak_ptr_| be used on the |task_runner_| thread. | 81 // Let |weak_ptr_| be used on the |task_runner_| thread. |
85 // |weak_ptr_| and |weak_ptr_factory_| share a ThreadChecker, so the | 82 // |weak_ptr_| and |weak_ptr_factory_| share a ThreadChecker, so the |
86 // following line affects both of them. | 83 // following line affects both of them. |
87 weak_ptr_factory_.DetachFromThread(); | 84 weak_ptr_factory_.DetachFromThread(); |
88 | |
89 std::string channel_name = | |
90 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(kProcessChannelId); | |
91 | |
92 // Connect to the Chromoting IPC channel if the name was passed in the command | |
93 // line. | |
94 if (!channel_name.empty()) { | |
95 chromoting_channel_.reset(new IPC::ChannelProxy( | |
96 channel_name, IPC::Channel::MODE_CLIENT, this, io_task_runner)); | |
97 } | |
98 } | 85 } |
99 | 86 |
100 SessionEventExecutorWin::~SessionEventExecutorWin() { | 87 SessionEventExecutorWin::~SessionEventExecutorWin() { |
101 } | 88 } |
102 | 89 |
103 void SessionEventExecutorWin::OnSessionStarted( | 90 void SessionEventExecutorWin::OnSessionStarted( |
104 scoped_ptr<protocol::ClipboardStub> client_clipboard) { | 91 scoped_ptr<protocol::ClipboardStub> client_clipboard) { |
105 if (!task_runner_->BelongsToCurrentThread()) { | 92 if (!task_runner_->BelongsToCurrentThread()) { |
106 task_runner_->PostTask( | 93 task_runner_->PostTask( |
107 FROM_HERE, | 94 FROM_HERE, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 139 |
153 if (event.has_usb_keycode()) { | 140 if (event.has_usb_keycode()) { |
154 if (event.pressed()) { | 141 if (event.pressed()) { |
155 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. | 142 // Simulate secure attention sequence if Ctrl-Alt-Del was just pressed. |
156 if (event.usb_keycode() == kUsbDelete && | 143 if (event.usb_keycode() == kUsbDelete && |
157 CheckCtrlAndAltArePressed(pressed_keys_)) { | 144 CheckCtrlAndAltArePressed(pressed_keys_)) { |
158 VLOG(3) << "Sending Secure Attention Sequence to console"; | 145 VLOG(3) << "Sending Secure Attention Sequence to console"; |
159 | 146 |
160 if (base::win::GetVersion() == base::win::VERSION_XP) { | 147 if (base::win::GetVersion() == base::win::VERSION_XP) { |
161 EmulateSecureAttentionSequence(); | 148 EmulateSecureAttentionSequence(); |
162 } else if (chromoting_channel_.get()) { | 149 } else if (daemon_channel_ != NULL) { |
163 chromoting_channel_->Send(new ChromotingHostMsg_SendSasToConsole()); | 150 daemon_channel_->Send(new ChromotingHostMsg_SendSasToConsole()); |
164 } | 151 } |
165 } | 152 } |
166 | 153 |
167 pressed_keys_.insert(event.usb_keycode()); | 154 pressed_keys_.insert(event.usb_keycode()); |
168 } else { | 155 } else { |
169 pressed_keys_.erase(event.usb_keycode()); | 156 pressed_keys_.erase(event.usb_keycode()); |
170 } | 157 } |
171 } | 158 } |
172 | 159 |
173 SwitchToInputDesktop(); | 160 SwitchToInputDesktop(); |
174 nested_executor_->InjectKeyEvent(event); | 161 nested_executor_->InjectKeyEvent(event); |
175 } | 162 } |
176 | 163 |
177 void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) { | 164 void SessionEventExecutorWin::InjectMouseEvent(const MouseEvent& event) { |
178 if (!task_runner_->BelongsToCurrentThread()) { | 165 if (!task_runner_->BelongsToCurrentThread()) { |
179 task_runner_->PostTask( | 166 task_runner_->PostTask( |
180 FROM_HERE, | 167 FROM_HERE, |
181 base::Bind(&SessionEventExecutorWin::InjectMouseEvent, | 168 base::Bind(&SessionEventExecutorWin::InjectMouseEvent, |
182 weak_ptr_, event)); | 169 weak_ptr_, event)); |
183 return; | 170 return; |
184 } | 171 } |
185 | 172 |
186 SwitchToInputDesktop(); | 173 SwitchToInputDesktop(); |
187 nested_executor_->InjectMouseEvent(event); | 174 nested_executor_->InjectMouseEvent(event); |
188 } | 175 } |
189 | 176 |
190 bool SessionEventExecutorWin::OnMessageReceived(const IPC::Message& message) { | |
191 return false; | |
192 } | |
193 | |
194 void SessionEventExecutorWin::SwitchToInputDesktop() { | 177 void SessionEventExecutorWin::SwitchToInputDesktop() { |
195 // Switch to the desktop receiving user input if different from the current | 178 // Switch to the desktop receiving user input if different from the current |
196 // one. | 179 // one. |
197 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop(); | 180 scoped_ptr<Desktop> input_desktop = Desktop::GetInputDesktop(); |
198 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { | 181 if (input_desktop.get() != NULL && !desktop_.IsSame(*input_desktop)) { |
199 // If SetThreadDesktop() fails, the thread is still assigned a desktop. | 182 // If SetThreadDesktop() fails, the thread is still assigned a desktop. |
200 // So we can continue capture screen bits, just from a diffected desktop. | 183 // So we can continue capture screen bits, just from a diffected desktop. |
201 desktop_.SetThreadDesktop(input_desktop.Pass()); | 184 desktop_.SetThreadDesktop(input_desktop.Pass()); |
202 } | 185 } |
203 } | 186 } |
204 | 187 |
205 } // namespace remoting | 188 } // namespace remoting |
OLD | NEW |