Chromium Code Reviews| 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/video_frame_capturer.h" | 10 #include "remoting/host/video_frame_capturer.h" |
| 11 #include "remoting/proto/control.pb.h" | 11 #include "remoting/proto/control.pb.h" |
| 12 #include "remoting/proto/event.pb.h" | 12 #include "remoting/proto/event.pb.h" |
| 13 #include "remoting/protocol/client_stub.h" | 13 #include "remoting/protocol/client_stub.h" |
| 14 #include "remoting/protocol/clipboard_thread_proxy.h" | 14 #include "remoting/protocol/clipboard_thread_proxy.h" |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 ClientSession::ClientSession( | 18 ClientSession::ClientSession( |
| 19 EventHandler* event_handler, | 19 EventHandler* event_handler, |
| 20 scoped_ptr<protocol::ConnectionToClient> connection, | 20 scoped_ptr<protocol::ConnectionToClient> connection, |
| 21 protocol::ClipboardStub* host_clipboard_stub, | 21 protocol::ClipboardStub* host_clipboard_stub, |
| 22 protocol::InputStub* host_input_stub, | 22 protocol::InputStub* host_input_stub, |
| 23 VideoFrameCapturer* capturer, | 23 VideoFrameCapturer* capturer, |
| 24 const base::TimeDelta& max_duration) | 24 const base::TimeDelta& max_duration) |
| 25 : event_handler_(event_handler), | 25 : event_handler_(event_handler), |
| 26 connection_(connection.Pass()), | 26 connection_(connection.Pass()), |
| 27 client_jid_(connection_->session()->jid()), | 27 client_jid_(connection_->session()->jid()), |
| 28 is_authenticated_(false), | |
| 29 host_clipboard_stub_(host_clipboard_stub), | 28 host_clipboard_stub_(host_clipboard_stub), |
| 30 host_input_stub_(host_input_stub), | 29 host_input_stub_(host_input_stub), |
| 31 input_tracker_(host_input_stub_), | 30 input_tracker_(host_input_stub_), |
| 32 remote_input_filter_(&input_tracker_), | 31 remote_input_filter_(&input_tracker_), |
| 33 mouse_input_filter_(&remote_input_filter_), | 32 mouse_input_filter_(&remote_input_filter_), |
| 33 disable_input_filter_(&mouse_input_filter_), | |
| 34 auth_input_filter_(&disable_input_filter_), | |
| 34 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), | 35 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), |
| 35 capturer_(capturer), | 36 capturer_(capturer), |
| 36 max_duration_(max_duration) { | 37 max_duration_(max_duration) { |
| 37 connection_->SetEventHandler(this); | 38 connection_->SetEventHandler(this); |
| 38 | 39 |
| 39 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be | 40 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
| 40 // set before channels are connected. Make it possible to set stubs | 41 // set before channels are connected. Make it possible to set stubs |
| 41 // later and set them only when connection is authenticated. | 42 // later and set them only when connection is authenticated. |
| 42 connection_->set_clipboard_stub(this); | 43 connection_->set_clipboard_stub(this); |
| 43 connection_->set_host_stub(this); | 44 connection_->set_host_stub(this); |
| 44 connection_->set_input_stub(this); | 45 connection_->set_input_stub(this); |
| 45 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_); | 46 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_); |
| 47 | |
| 48 // |auth_input_filter|'s state reflects whether the session is authenticated. | |
|
simonmorris
2012/08/20 16:37:18
_ after "auth_input_filter".
Wez
2012/08/20 19:58:21
Done.
| |
| 49 auth_input_filter_.set_enabled(false); | |
| 46 } | 50 } |
| 47 | 51 |
| 48 ClientSession::~ClientSession() { | 52 ClientSession::~ClientSession() { |
| 49 } | 53 } |
| 50 | 54 |
| 51 void ClientSession::InjectClipboardEvent( | 55 void ClientSession::InjectClipboardEvent( |
| 52 const protocol::ClipboardEvent& event) { | 56 const protocol::ClipboardEvent& event) { |
| 53 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
| 54 | 58 |
| 55 // TODO(wez): Disable clipboard in both directions on local activity, and | 59 // TODO(wez): Disable clipboard in both directions on local activity, and |
| 56 // replace these tests with a HostInputFilter (or ClipboardFilter). | 60 // replace these tests with a HostInputFilter (or ClipboardFilter). |
| 57 if (auth_input_filter_.input_stub() == NULL) | 61 if (!auth_input_filter_.enabled()) |
| 58 return; | 62 return; |
| 59 if (disable_input_filter_.input_stub() == NULL) | 63 if (!disable_input_filter_.enabled()) |
| 60 return; | 64 return; |
| 61 | 65 |
| 62 clipboard_echo_filter_.host_filter()->InjectClipboardEvent(event); | 66 clipboard_echo_filter_.host_filter()->InjectClipboardEvent(event); |
| 63 } | 67 } |
| 64 | 68 |
| 65 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { | 69 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { |
| 66 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
| 67 auth_input_filter_.InjectKeyEvent(event); | 71 auth_input_filter_.InjectKeyEvent(event); |
| 68 } | 72 } |
| 69 | 73 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 92 if (video_control.has_enable()) { | 96 if (video_control.has_enable()) { |
| 93 VLOG(1) << "Received VideoControl (enable=" | 97 VLOG(1) << "Received VideoControl (enable=" |
| 94 << video_control.enable() << ")"; | 98 << video_control.enable() << ")"; |
| 95 } | 99 } |
| 96 } | 100 } |
| 97 | 101 |
| 98 void ClientSession::OnConnectionAuthenticated( | 102 void ClientSession::OnConnectionAuthenticated( |
| 99 protocol::ConnectionToClient* connection) { | 103 protocol::ConnectionToClient* connection) { |
| 100 DCHECK(CalledOnValidThread()); | 104 DCHECK(CalledOnValidThread()); |
| 101 DCHECK_EQ(connection_.get(), connection); | 105 DCHECK_EQ(connection_.get(), connection); |
| 102 is_authenticated_ = true; | 106 |
| 103 auth_input_filter_.set_input_stub(&disable_input_filter_); | 107 auth_input_filter_.set_enabled(true); |
| 108 | |
| 104 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); | 109 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); |
| 110 | |
| 105 if (max_duration_ > base::TimeDelta()) { | 111 if (max_duration_ > base::TimeDelta()) { |
| 106 // TODO(simonmorris): Let Disconnect() tell the client that the | 112 // TODO(simonmorris): Let Disconnect() tell the client that the |
| 107 // disconnection was caused by the session exceeding its maximum duration. | 113 // disconnection was caused by the session exceeding its maximum duration. |
| 108 max_duration_timer_.Start(FROM_HERE, max_duration_, | 114 max_duration_timer_.Start(FROM_HERE, max_duration_, |
| 109 this, &ClientSession::Disconnect); | 115 this, &ClientSession::Disconnect); |
| 110 } | 116 } |
| 117 | |
| 111 event_handler_->OnSessionAuthenticated(this); | 118 event_handler_->OnSessionAuthenticated(this); |
| 112 } | 119 } |
| 113 | 120 |
| 114 void ClientSession::OnConnectionChannelsConnected( | 121 void ClientSession::OnConnectionChannelsConnected( |
| 115 protocol::ConnectionToClient* connection) { | 122 protocol::ConnectionToClient* connection) { |
| 116 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
| 117 DCHECK_EQ(connection_.get(), connection); | 124 DCHECK_EQ(connection_.get(), connection); |
| 118 SetDisableInputs(false); | 125 SetDisableInputs(false); |
| 119 event_handler_->OnSessionChannelsConnected(this); | 126 event_handler_->OnSessionChannelsConnected(this); |
| 120 } | 127 } |
| 121 | 128 |
| 122 void ClientSession::OnConnectionClosed( | 129 void ClientSession::OnConnectionClosed( |
| 123 protocol::ConnectionToClient* connection, | 130 protocol::ConnectionToClient* connection, |
| 124 protocol::ErrorCode error) { | 131 protocol::ErrorCode error) { |
| 125 DCHECK(CalledOnValidThread()); | 132 DCHECK(CalledOnValidThread()); |
| 126 DCHECK_EQ(connection_.get(), connection); | 133 DCHECK_EQ(connection_.get(), connection); |
| 127 if (!is_authenticated_) | 134 |
| 135 if (!auth_input_filter_.enabled()) | |
| 128 event_handler_->OnSessionAuthenticationFailed(this); | 136 event_handler_->OnSessionAuthenticationFailed(this); |
| 129 auth_input_filter_.set_input_stub(NULL); | 137 |
| 138 // Block any further input events from the client. | |
| 139 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our | |
| 140 // is_authenticated(), so that we can disable |auth_input_filter_| here. | |
| 141 disable_input_filter_.set_enabled(false); | |
| 130 | 142 |
| 131 // Ensure that any pressed keys or buttons are released. | 143 // Ensure that any pressed keys or buttons are released. |
| 132 input_tracker_.ReleaseAll(); | 144 input_tracker_.ReleaseAll(); |
| 133 | 145 |
| 134 // TODO(sergeyu): Log failure reason? | 146 // TODO(sergeyu): Log failure reason? |
| 135 event_handler_->OnSessionClosed(this); | 147 event_handler_->OnSessionClosed(this); |
| 136 } | 148 } |
| 137 | 149 |
| 138 void ClientSession::OnSequenceNumberUpdated( | 150 void ClientSession::OnSequenceNumberUpdated( |
| 139 protocol::ConnectionToClient* connection, int64 sequence_number) { | 151 protocol::ConnectionToClient* connection, int64 sequence_number) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 } | 174 } |
| 163 | 175 |
| 164 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { | 176 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
| 165 DCHECK(CalledOnValidThread()); | 177 DCHECK(CalledOnValidThread()); |
| 166 remote_input_filter_.LocalMouseMoved(mouse_pos); | 178 remote_input_filter_.LocalMouseMoved(mouse_pos); |
| 167 } | 179 } |
| 168 | 180 |
| 169 void ClientSession::SetDisableInputs(bool disable_inputs) { | 181 void ClientSession::SetDisableInputs(bool disable_inputs) { |
| 170 DCHECK(CalledOnValidThread()); | 182 DCHECK(CalledOnValidThread()); |
| 171 | 183 |
| 172 if (disable_inputs) { | 184 if (disable_inputs) |
| 173 disable_input_filter_.set_input_stub(NULL); | |
| 174 input_tracker_.ReleaseAll(); | 185 input_tracker_.ReleaseAll(); |
| 175 } else { | 186 |
| 176 disable_input_filter_.set_input_stub(&mouse_input_filter_); | 187 disable_input_filter_.set_enabled(!disable_inputs); |
| 177 } | |
| 178 } | 188 } |
| 179 | 189 |
| 180 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { | 190 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
| 181 DCHECK(CalledOnValidThread()); | 191 DCHECK(CalledOnValidThread()); |
| 182 | 192 |
| 183 return scoped_ptr<protocol::ClipboardStub>( | 193 return scoped_ptr<protocol::ClipboardStub>( |
| 184 new protocol::ClipboardThreadProxy( | 194 new protocol::ClipboardThreadProxy( |
| 185 client_clipboard_factory_.GetWeakPtr(), | 195 client_clipboard_factory_.GetWeakPtr(), |
| 186 base::MessageLoopProxy::current())); | 196 base::MessageLoopProxy::current())); |
| 187 } | 197 } |
| 188 | 198 |
| 189 } // namespace remoting | 199 } // namespace remoting |
| OLD | NEW |