OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/event_executor.h" | 5 #include "remoting/host/event_executor.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "ipc/ipc_channel_proxy.h" |
12 #include "remoting/host/capturer.h" | 13 #include "remoting/host/capturer.h" |
13 #include "remoting/proto/event.pb.h" | 14 #include "remoting/proto/event.pb.h" |
14 #include "ui/base/keycodes/keyboard_codes.h" | 15 #include "ui/base/keycodes/keyboard_codes.h" |
15 | 16 |
| 17 #include "remoting/host/chromoting_session_messages.h" |
| 18 |
16 namespace remoting { | 19 namespace remoting { |
17 | 20 |
18 using protocol::MouseEvent; | 21 using protocol::MouseEvent; |
19 using protocol::KeyEvent; | 22 using protocol::KeyEvent; |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
| 26 // Name of the chromoting service IPC channel. |
| 27 const char kChromotingSessionChannelName[] = "chromoting_session"; |
| 28 |
23 // A class to generate events on Windows. | 29 // A class to generate events on Windows. |
24 class EventExecutorWin : public EventExecutor { | 30 class EventExecutorWin : public EventExecutor { |
25 public: | 31 public: |
26 EventExecutorWin(MessageLoop* message_loop, Capturer* capturer); | 32 EventExecutorWin(MessageLoop* message_loop, |
| 33 IPC::ChannelProxy* chromoting_session, |
| 34 Capturer* capturer); |
27 virtual ~EventExecutorWin() {} | 35 virtual ~EventExecutorWin() {} |
28 | 36 |
29 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; | 37 virtual void InjectKeyEvent(const KeyEvent& event) OVERRIDE; |
30 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; | 38 virtual void InjectMouseEvent(const MouseEvent& event) OVERRIDE; |
31 | 39 |
32 private: | 40 private: |
33 void HandleKey(const KeyEvent& event); | 41 void HandleKey(const KeyEvent& event); |
34 void HandleMouse(const MouseEvent& event); | 42 void HandleMouse(const MouseEvent& event); |
35 | 43 |
36 MessageLoop* message_loop_; | 44 MessageLoop* message_loop_; |
37 Capturer* capturer_; | 45 Capturer* capturer_; |
38 | 46 |
| 47 // IPC channel connecting the host with the chromoting service. |
| 48 IPC::ChannelProxy* chromoting_session_; |
| 49 |
| 50 bool scroll_pressed_; |
| 51 |
39 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); | 52 DISALLOW_COPY_AND_ASSIGN(EventExecutorWin); |
40 }; | 53 }; |
41 | 54 |
42 EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, | 55 EventExecutorWin::EventExecutorWin(MessageLoop* message_loop, |
| 56 IPC::ChannelProxy* chromoting_session, |
43 Capturer* capturer) | 57 Capturer* capturer) |
44 : message_loop_(message_loop), | 58 : message_loop_(message_loop), |
45 capturer_(capturer) { | 59 capturer_(capturer), |
| 60 chromoting_session_(chromoting_session), |
| 61 scroll_pressed_(false) { |
46 } | 62 } |
47 | 63 |
48 void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { | 64 void EventExecutorWin::InjectKeyEvent(const KeyEvent& event) { |
49 if (MessageLoop::current() != message_loop_) { | 65 if (MessageLoop::current() != message_loop_) { |
50 message_loop_->PostTask( | 66 message_loop_->PostTask( |
51 FROM_HERE, | 67 FROM_HERE, |
52 base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this), | 68 base::Bind(&EventExecutorWin::InjectKeyEvent, base::Unretained(this), |
53 event)); | 69 event)); |
54 return; | 70 return; |
55 } | 71 } |
56 | 72 |
| 73 // Poor man's Ctrl+Alt+Delete emulation: a double Scroll Lock is converted to |
| 74 // the security attention sequence. |
| 75 // TODO(alexeypa): replace this with proper SAS handling. |
| 76 if (chromoting_session_ != NULL && event.keycode() == VK_SCROLL) { |
| 77 if (event.pressed()) { |
| 78 if (scroll_pressed_) { |
| 79 chromoting_session_->Send(new ChromotingSessionMsg_SendSasToConsole()); |
| 80 scroll_pressed_ = false; |
| 81 } else { |
| 82 scroll_pressed_ = true; |
| 83 } |
| 84 } |
| 85 } else { |
| 86 scroll_pressed_ = false; |
| 87 } |
| 88 |
57 HandleKey(event); | 89 HandleKey(event); |
58 } | 90 } |
59 | 91 |
60 void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) { | 92 void EventExecutorWin::InjectMouseEvent(const MouseEvent& event) { |
61 if (MessageLoop::current() != message_loop_) { | 93 if (MessageLoop::current() != message_loop_) { |
62 message_loop_->PostTask( | 94 message_loop_->PostTask( |
63 FROM_HERE, | 95 FROM_HERE, |
64 base::Bind(&EventExecutorWin::InjectMouseEvent, base::Unretained(this), | 96 base::Bind(&EventExecutorWin::InjectMouseEvent, base::Unretained(this), |
65 event)); | 97 event)); |
66 return; | 98 return; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; | 193 down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP; |
162 } | 194 } |
163 | 195 |
164 SendInput(1, &button_event, sizeof(INPUT)); | 196 SendInput(1, &button_event, sizeof(INPUT)); |
165 } | 197 } |
166 } | 198 } |
167 | 199 |
168 } // namespace | 200 } // namespace |
169 | 201 |
170 EventExecutor* EventExecutor::Create(MessageLoop* message_loop, | 202 EventExecutor* EventExecutor::Create(MessageLoop* message_loop, |
| 203 IPC::ChannelProxy* chromoting_session, |
171 Capturer* capturer) { | 204 Capturer* capturer) { |
172 return new EventExecutorWin(message_loop, capturer); | 205 return new EventExecutorWin(message_loop, chromoting_session, capturer); |
173 } | 206 } |
174 | 207 |
175 } // namespace remoting | 208 } // namespace remoting |
OLD | NEW |