| 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/client_session.h" | 5 #include "remoting/host/client_session.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "remoting/host/capturer.h" | 10 #include "remoting/host/capturer.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 static const int64 kRemoteBlockTimeoutMillis = 2000; | 21 static const int64 kRemoteBlockTimeoutMillis = 2000; |
| 22 | 22 |
| 23 namespace remoting { | 23 namespace remoting { |
| 24 | 24 |
| 25 using protocol::KeyEvent; | 25 using protocol::KeyEvent; |
| 26 using protocol::MouseEvent; | 26 using protocol::MouseEvent; |
| 27 | 27 |
| 28 ClientSession::ClientSession( | 28 ClientSession::ClientSession( |
| 29 EventHandler* event_handler, | 29 EventHandler* event_handler, |
| 30 protocol::ConnectionToClient* connection, | 30 protocol::ConnectionToClient* connection, |
| 31 protocol::InputStub* input_stub, | 31 protocol::HostEventStub* host_event_stub, |
| 32 Capturer* capturer) | 32 Capturer* capturer) |
| 33 : event_handler_(event_handler), | 33 : event_handler_(event_handler), |
| 34 connection_(connection), | 34 connection_(connection), |
| 35 client_jid_(connection->session()->jid()), | 35 client_jid_(connection->session()->jid()), |
| 36 input_stub_(input_stub), | 36 host_event_stub_(host_event_stub), |
| 37 capturer_(capturer), | 37 capturer_(capturer), |
| 38 authenticated_(false), | 38 authenticated_(false), |
| 39 awaiting_continue_approval_(false), | 39 awaiting_continue_approval_(false), |
| 40 remote_mouse_button_state_(0) { | 40 remote_mouse_button_state_(0) { |
| 41 connection_->SetEventHandler(this); | 41 connection_->SetEventHandler(this); |
| 42 | 42 |
| 43 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be | 43 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
| 44 // set before channels are connected. Make it possible to set stubs | 44 // set before channels are connected. Make it possible to set stubs |
| 45 // later and set them only when connection is authenticated. | 45 // later and set them only when connection is authenticated. |
| 46 connection_->set_clipboard_stub(this); |
| 46 connection_->set_host_stub(this); | 47 connection_->set_host_stub(this); |
| 47 connection_->set_input_stub(this); | 48 connection_->set_input_stub(this); |
| 48 } | 49 } |
| 49 | 50 |
| 50 ClientSession::~ClientSession() { | 51 ClientSession::~ClientSession() { |
| 51 } | 52 } |
| 52 | 53 |
| 54 void ClientSession::InjectClipboardEvent( |
| 55 const protocol::ClipboardEvent& event) { |
| 56 DCHECK(CalledOnValidThread()); |
| 57 |
| 58 if (authenticated_) { |
| 59 host_event_stub_->InjectClipboardEvent(event); |
| 60 } |
| 61 } |
| 62 |
| 53 void ClientSession::InjectKeyEvent(const KeyEvent& event) { | 63 void ClientSession::InjectKeyEvent(const KeyEvent& event) { |
| 54 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 55 | 65 |
| 56 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { | 66 if (authenticated_ && !ShouldIgnoreRemoteKeyboardInput(event)) { |
| 57 RecordKeyEvent(event); | 67 RecordKeyEvent(event); |
| 58 input_stub_->InjectKeyEvent(event); | 68 host_event_stub_->InjectKeyEvent(event); |
| 59 } | 69 } |
| 60 } | 70 } |
| 61 | 71 |
| 62 void ClientSession::InjectMouseEvent(const MouseEvent& event) { | 72 void ClientSession::InjectMouseEvent(const MouseEvent& event) { |
| 63 DCHECK(CalledOnValidThread()); | 73 DCHECK(CalledOnValidThread()); |
| 64 | 74 |
| 65 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { | 75 if (authenticated_ && !ShouldIgnoreRemoteMouseInput(event)) { |
| 66 RecordMouseButtonState(event); | 76 RecordMouseButtonState(event); |
| 67 MouseEvent event_to_inject = event; | 77 MouseEvent event_to_inject = event; |
| 68 if (event.has_x() && event.has_y()) { | 78 if (event.has_x() && event.has_y()) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 // fake mouse button events. Note that we need to do this after we | 91 // fake mouse button events. Note that we need to do this after we |
| 82 // clamp the values to the screen area. | 92 // clamp the values to the screen area. |
| 83 remote_mouse_pos_ = pos; | 93 remote_mouse_pos_ = pos; |
| 84 | 94 |
| 85 injected_mouse_positions_.push_back(pos); | 95 injected_mouse_positions_.push_back(pos); |
| 86 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { | 96 if (injected_mouse_positions_.size() > kNumRemoteMousePositions) { |
| 87 VLOG(1) << "Injected mouse positions queue full."; | 97 VLOG(1) << "Injected mouse positions queue full."; |
| 88 injected_mouse_positions_.pop_front(); | 98 injected_mouse_positions_.pop_front(); |
| 89 } | 99 } |
| 90 } | 100 } |
| 91 input_stub_->InjectMouseEvent(event_to_inject); | 101 host_event_stub_->InjectMouseEvent(event_to_inject); |
| 92 } | 102 } |
| 93 } | 103 } |
| 94 | 104 |
| 95 void ClientSession::OnConnectionOpened( | 105 void ClientSession::OnConnectionOpened( |
| 96 protocol::ConnectionToClient* connection) { | 106 protocol::ConnectionToClient* connection) { |
| 97 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
| 98 DCHECK_EQ(connection_.get(), connection); | 108 DCHECK_EQ(connection_.get(), connection); |
| 99 authenticated_ = true; | 109 authenticated_ = true; |
| 100 event_handler_->OnSessionAuthenticated(this); | 110 event_handler_->OnSessionAuthenticated(this); |
| 101 } | 111 } |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 245 |
| 236 void ClientSession::RestoreEventState() { | 246 void ClientSession::RestoreEventState() { |
| 237 DCHECK(CalledOnValidThread()); | 247 DCHECK(CalledOnValidThread()); |
| 238 | 248 |
| 239 // Undo any currently pressed keys. | 249 // Undo any currently pressed keys. |
| 240 std::set<int>::iterator i; | 250 std::set<int>::iterator i; |
| 241 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { | 251 for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) { |
| 242 KeyEvent key; | 252 KeyEvent key; |
| 243 key.set_keycode(*i); | 253 key.set_keycode(*i); |
| 244 key.set_pressed(false); | 254 key.set_pressed(false); |
| 245 input_stub_->InjectKeyEvent(key); | 255 host_event_stub_->InjectKeyEvent(key); |
| 246 } | 256 } |
| 247 pressed_keys_.clear(); | 257 pressed_keys_.clear(); |
| 248 | 258 |
| 249 // Undo any currently pressed mouse buttons. | 259 // Undo any currently pressed mouse buttons. |
| 250 for (int i = 1; i < MouseEvent::BUTTON_MAX; i++) { | 260 for (int i = 1; i < MouseEvent::BUTTON_MAX; i++) { |
| 251 if (remote_mouse_button_state_ & (1 << (i - 1))) { | 261 if (remote_mouse_button_state_ & (1 << (i - 1))) { |
| 252 MouseEvent mouse; | 262 MouseEvent mouse; |
| 253 // TODO(wez): Shouldn't [need to] set position here. | 263 // TODO(wez): Shouldn't [need to] set position here. |
| 254 mouse.set_x(remote_mouse_pos_.x()); | 264 mouse.set_x(remote_mouse_pos_.x()); |
| 255 mouse.set_y(remote_mouse_pos_.y()); | 265 mouse.set_y(remote_mouse_pos_.y()); |
| 256 mouse.set_button((MouseEvent::MouseButton)i); | 266 mouse.set_button((MouseEvent::MouseButton)i); |
| 257 mouse.set_button_down(false); | 267 mouse.set_button_down(false); |
| 258 input_stub_->InjectMouseEvent(mouse); | 268 host_event_stub_->InjectMouseEvent(mouse); |
| 259 } | 269 } |
| 260 } | 270 } |
| 261 remote_mouse_button_state_ = 0; | 271 remote_mouse_button_state_ = 0; |
| 262 } | 272 } |
| 263 | 273 |
| 264 } // namespace remoting | 274 } // namespace remoting |
| OLD | NEW |