| Index: remoting/host/client_session.cc
|
| diff --git a/remoting/host/client_session.cc b/remoting/host/client_session.cc
|
| index 0848078cd6c7fb885a85b9481fbd1e3d943729fa..b85017265cfe95746284d41964bfb80ab2558096 100644
|
| --- a/remoting/host/client_session.cc
|
| +++ b/remoting/host/client_session.cc
|
| @@ -10,16 +10,6 @@
|
| #include "remoting/host/capturer.h"
|
| #include "remoting/proto/event.pb.h"
|
|
|
| -// The number of remote mouse events to record for the purpose of eliminating
|
| -// "echoes" detected by the local input detector. The value should be large
|
| -// enough to cope with the fact that multiple events might be injected before
|
| -// any echoes are detected.
|
| -static const unsigned int kNumRemoteMousePositions = 50;
|
| -
|
| -// The number of milliseconds for which to block remote input when local input
|
| -// is received.
|
| -static const int64 kRemoteBlockTimeoutMillis = 2000;
|
| -
|
| namespace remoting {
|
|
|
| using protocol::KeyEvent;
|
| @@ -34,11 +24,9 @@ ClientSession::ClientSession(
|
| connection_(connection.Pass()),
|
| client_jid_(connection_->session()->jid()),
|
| host_event_stub_(host_event_stub),
|
| - capturer_(capturer),
|
| - authenticated_(false),
|
| - connected_(false),
|
| - awaiting_continue_approval_(false),
|
| - remote_mouse_button_state_(0) {
|
| + input_tracker_(host_event_stub),
|
| + remote_input_filter_(&input_tracker_),
|
| + capturer_(capturer) {
|
| connection_->SetEventHandler(this);
|
|
|
| // TODO(sergeyu): Currently ConnectionToClient expects stubs to be
|
| @@ -46,7 +34,7 @@ ClientSession::ClientSession(
|
| // later and set them only when connection is authenticated.
|
| connection_->set_clipboard_stub(this);
|
| connection_->set_host_stub(this);
|
| - connection_->set_input_stub(this);
|
| + connection_->set_input_stub(&auth_input_filter_);
|
| }
|
|
|
| ClientSession::~ClientSession() {
|
| @@ -56,56 +44,45 @@ void ClientSession::InjectClipboardEvent(
|
| const protocol::ClipboardEvent& event) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| - if (connected_) {
|
| - host_event_stub_->InjectClipboardEvent(event);
|
| - }
|
| + // TODO(wez): Disable clipboard in both directions on local activity, and
|
| + // replace these tests with a HostInputFilter (or ClipboardFilter).
|
| + if (auth_input_filter_.input_stub() == NULL)
|
| + return;
|
| + if (disable_input_filter_.input_stub() == NULL)
|
| + return;
|
| +
|
| + host_event_stub_->InjectClipboardEvent(event);
|
| }
|
|
|
| void ClientSession::InjectKeyEvent(const KeyEvent& event) {
|
| DCHECK(CalledOnValidThread());
|
| -
|
| - if (connected_ && !ShouldIgnoreRemoteKeyboardInput(event)) {
|
| - RecordKeyEvent(event);
|
| - host_event_stub_->InjectKeyEvent(event);
|
| - }
|
| + auth_input_filter_.InjectKeyEvent(event);
|
| }
|
|
|
| void ClientSession::InjectMouseEvent(const MouseEvent& event) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| - if (connected_ && !ShouldIgnoreRemoteMouseInput(event)) {
|
| - RecordMouseButtonState(event);
|
| - MouseEvent event_to_inject = event;
|
| - if (event.has_x() && event.has_y()) {
|
| - // In case the client sends events with off-screen coordinates, modify
|
| - // the event to lie within the current screen area. This is better than
|
| - // simply discarding the event, which might lose a button-up event at the
|
| - // end of a drag'n'drop (or cause other related problems).
|
| - SkIPoint pos(SkIPoint::Make(event.x(), event.y()));
|
| - const SkISize& screen = capturer_->size_most_recent();
|
| - pos.setX(std::max(0, std::min(screen.width() - 1, pos.x())));
|
| - pos.setY(std::max(0, std::min(screen.height() - 1, pos.y())));
|
| - event_to_inject.set_x(pos.x());
|
| - event_to_inject.set_y(pos.y());
|
| -
|
| - // Record the mouse position so we can use it if we need to inject
|
| - // fake mouse button events. Note that we need to do this after we
|
| - // clamp the values to the screen area.
|
| - remote_mouse_pos_ = pos;
|
| -
|
| - injected_mouse_positions_.push_back(pos);
|
| - if (injected_mouse_positions_.size() > kNumRemoteMousePositions) {
|
| - VLOG(1) << "Injected mouse positions queue full.";
|
| - injected_mouse_positions_.pop_front();
|
| - }
|
| - }
|
| - host_event_stub_->InjectMouseEvent(event_to_inject);
|
| + MouseEvent event_to_inject = event;
|
| + if (event.has_x() && event.has_y()) {
|
| + // In case the client sends events with off-screen coordinates, modify
|
| + // the event to lie within the current screen area. This is better than
|
| + // simply discarding the event, which might lose a button-up event at the
|
| + // end of a drag'n'drop (or cause other related problems).
|
| + SkIPoint pos(SkIPoint::Make(event.x(), event.y()));
|
| + const SkISize& screen = capturer_->size_most_recent();
|
| + pos.setX(std::max(0, std::min(screen.width() - 1, pos.x())));
|
| + pos.setY(std::max(0, std::min(screen.height() - 1, pos.y())));
|
| + event_to_inject.set_x(pos.x());
|
| + event_to_inject.set_y(pos.y());
|
| }
|
| + auth_input_filter_.InjectMouseEvent(event_to_inject);
|
| }
|
|
|
| void ClientSession::OnConnectionAuthenticated(
|
| protocol::ConnectionToClient* connection) {
|
| - authenticated_ = true;
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK_EQ(connection_.get(), connection);
|
| + auth_input_filter_.set_input_stub(&disable_input_filter_);
|
| event_handler_->OnSessionAuthenticated(this);
|
| }
|
|
|
| @@ -113,7 +90,7 @@ void ClientSession::OnConnectionChannelsConnected(
|
| protocol::ConnectionToClient* connection) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK_EQ(connection_.get(), connection);
|
| - connected_ = true;
|
| + SetDisableInputs(false);
|
| event_handler_->OnSessionChannelsConnected(this);
|
| }
|
|
|
| @@ -122,8 +99,13 @@ void ClientSession::OnConnectionClosed(
|
| protocol::ErrorCode error) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK_EQ(connection_.get(), connection);
|
| - if (!authenticated_)
|
| + if (!auth_input_filter_.input_stub())
|
| event_handler_->OnSessionAuthenticationFailed(this);
|
| + auth_input_filter_.set_input_stub(NULL);
|
| +
|
| + // Ensure that any pressed keys or buttons are released.
|
| + input_tracker_.ReleaseAll();
|
| +
|
| // TODO(sergeyu): Log failure reason?
|
| event_handler_->OnSessionClosed(this);
|
| }
|
| @@ -147,126 +129,26 @@ void ClientSession::OnRouteChange(
|
| void ClientSession::Disconnect() {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(connection_.get());
|
| - connected_ = false;
|
| - RestoreEventState();
|
|
|
| - // This triggers OnSessionClosed() and the session may be destroyed
|
| + // This triggers OnConnectionClosed(), and the session may be destroyed
|
| // as the result, so this call must be the last in this method.
|
| connection_->Disconnect();
|
| }
|
|
|
| void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) {
|
| DCHECK(CalledOnValidThread());
|
| -
|
| - // If this is a genuine local input event (rather than an echo of a remote
|
| - // input event that we've just injected), then ignore remote inputs for a
|
| - // short time.
|
| - std::list<SkIPoint>::iterator found_position =
|
| - std::find(injected_mouse_positions_.begin(),
|
| - injected_mouse_positions_.end(), mouse_pos);
|
| - if (found_position != injected_mouse_positions_.end()) {
|
| - // Remove it from the list, and any positions that were added before it,
|
| - // if any. This is because the local input monitor is assumed to receive
|
| - // injected mouse position events in the order in which they were injected
|
| - // (if at all). If the position is found somewhere other than the front of
|
| - // the queue, this would be because the earlier positions weren't
|
| - // successfully injected (or the local input monitor might have skipped over
|
| - // some positions), and not because the events were out-of-sequence. These
|
| - // spurious positions should therefore be discarded.
|
| - injected_mouse_positions_.erase(injected_mouse_positions_.begin(),
|
| - ++found_position);
|
| - } else {
|
| - latest_local_input_time_ = base::Time::Now();
|
| - }
|
| -}
|
| -
|
| -bool ClientSession::ShouldIgnoreRemoteMouseInput(
|
| - const protocol::MouseEvent& event) const {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - // If the last remote input event was a click or a drag, then it's not safe
|
| - // to block remote mouse events. For example, it might result in the host
|
| - // missing the mouse-up event and being stuck with the button pressed.
|
| - if (remote_mouse_button_state_ != 0)
|
| - return false;
|
| - // Otherwise, if the host user has not yet approved the continuation of the
|
| - // connection, then ignore remote mouse events.
|
| - if (awaiting_continue_approval_)
|
| - return true;
|
| - // Otherwise, ignore remote mouse events if the local mouse moved recently.
|
| - int64 millis = (base::Time::Now() - latest_local_input_time_)
|
| - .InMilliseconds();
|
| - if (millis < kRemoteBlockTimeoutMillis)
|
| - return true;
|
| - return false;
|
| + remote_input_filter_.LocalMouseMoved(mouse_pos);
|
| }
|
|
|
| -bool ClientSession::ShouldIgnoreRemoteKeyboardInput(
|
| - const KeyEvent& event) const {
|
| +void ClientSession::SetDisableInputs(bool disable_inputs) {
|
| DCHECK(CalledOnValidThread());
|
|
|
| - // If the host user has not yet approved the continuation of the connection,
|
| - // then all remote keyboard input is ignored, except to release keys that
|
| - // were already pressed.
|
| - if (awaiting_continue_approval_) {
|
| - return event.pressed() ||
|
| - (pressed_keys_.find(event.keycode()) == pressed_keys_.end());
|
| - }
|
| - return false;
|
| -}
|
| -
|
| -void ClientSession::RecordKeyEvent(const KeyEvent& event) {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - if (event.pressed()) {
|
| - pressed_keys_.insert(event.keycode());
|
| + if (disable_inputs) {
|
| + disable_input_filter_.set_input_stub(NULL);
|
| + input_tracker_.ReleaseAll();
|
| } else {
|
| - pressed_keys_.erase(event.keycode());
|
| - }
|
| -}
|
| -
|
| -void ClientSession::RecordMouseButtonState(const MouseEvent& event) {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - if (event.has_button() && event.has_button_down()) {
|
| - // Button values are defined in remoting/proto/event.proto.
|
| - if (event.button() >= 1 && event.button() < MouseEvent::BUTTON_MAX) {
|
| - uint32 button_change = 1 << (event.button() - 1);
|
| - if (event.button_down()) {
|
| - remote_mouse_button_state_ |= button_change;
|
| - } else {
|
| - remote_mouse_button_state_ &= ~button_change;
|
| - }
|
| - }
|
| - }
|
| -}
|
| -
|
| -void ClientSession::RestoreEventState() {
|
| - DCHECK(CalledOnValidThread());
|
| -
|
| - // Undo any currently pressed keys.
|
| - std::set<int>::iterator i;
|
| - for (i = pressed_keys_.begin(); i != pressed_keys_.end(); ++i) {
|
| - KeyEvent key;
|
| - key.set_keycode(*i);
|
| - key.set_pressed(false);
|
| - host_event_stub_->InjectKeyEvent(key);
|
| - }
|
| - pressed_keys_.clear();
|
| -
|
| - // Undo any currently pressed mouse buttons.
|
| - for (int i = 1; i < MouseEvent::BUTTON_MAX; i++) {
|
| - if (remote_mouse_button_state_ & (1 << (i - 1))) {
|
| - MouseEvent mouse;
|
| - // TODO(wez): Shouldn't [need to] set position here.
|
| - mouse.set_x(remote_mouse_pos_.x());
|
| - mouse.set_y(remote_mouse_pos_.y());
|
| - mouse.set_button((MouseEvent::MouseButton)i);
|
| - mouse.set_button_down(false);
|
| - host_event_stub_->InjectMouseEvent(mouse);
|
| - }
|
| + disable_input_filter_.set_input_stub(&remote_input_filter_);
|
| }
|
| - remote_mouse_button_state_ = 0;
|
| }
|
|
|
| } // namespace remoting
|
|
|