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 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), |
| 35 auth_input_filter_(&disable_input_filter_), |
| 36 auth_clipboard_filter_(&disable_clipboard_filter_), |
34 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), | 37 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), |
35 capturer_(capturer), | 38 capturer_(capturer), |
36 max_duration_(max_duration) { | 39 max_duration_(max_duration) { |
37 connection_->SetEventHandler(this); | 40 connection_->SetEventHandler(this); |
38 | 41 |
39 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be | 42 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be |
40 // set before channels are connected. Make it possible to set stubs | 43 // set before channels are connected. Make it possible to set stubs |
41 // later and set them only when connection is authenticated. | 44 // later and set them only when connection is authenticated. |
42 connection_->set_clipboard_stub(&auth_clipboard_filter_); | 45 connection_->set_clipboard_stub(&auth_clipboard_filter_); |
43 connection_->set_host_stub(this); | 46 connection_->set_host_stub(this); |
44 connection_->set_input_stub(this); | 47 connection_->set_input_stub(this); |
45 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_); | 48 clipboard_echo_filter_.set_host_stub(host_clipboard_stub_); |
| 49 |
| 50 // |auth_*_filter_|'s states reflect whether the session is authenticated. |
| 51 auth_input_filter_.set_enabled(false); |
| 52 auth_clipboard_filter_.set_enabled(false); |
46 } | 53 } |
47 | 54 |
48 ClientSession::~ClientSession() { | 55 ClientSession::~ClientSession() { |
49 } | 56 } |
50 | 57 |
51 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { | 58 void ClientSession::InjectKeyEvent(const protocol::KeyEvent& event) { |
52 DCHECK(CalledOnValidThread()); | 59 DCHECK(CalledOnValidThread()); |
53 auth_input_filter_.InjectKeyEvent(event); | 60 auth_input_filter_.InjectKeyEvent(event); |
54 } | 61 } |
55 | 62 |
(...skipping 23 matching lines...) Expand all Loading... |
79 VLOG(1) << "Received VideoControl (enable=" | 86 VLOG(1) << "Received VideoControl (enable=" |
80 << video_control.enable() << ")"; | 87 << video_control.enable() << ")"; |
81 } | 88 } |
82 } | 89 } |
83 | 90 |
84 void ClientSession::OnConnectionAuthenticated( | 91 void ClientSession::OnConnectionAuthenticated( |
85 protocol::ConnectionToClient* connection) { | 92 protocol::ConnectionToClient* connection) { |
86 DCHECK(CalledOnValidThread()); | 93 DCHECK(CalledOnValidThread()); |
87 DCHECK_EQ(connection_.get(), connection); | 94 DCHECK_EQ(connection_.get(), connection); |
88 | 95 |
89 is_authenticated_ = true; | 96 auth_input_filter_.set_enabled(true); |
90 auth_input_filter_.set_input_stub(&disable_input_filter_); | 97 auth_clipboard_filter_.set_enabled(true); |
91 auth_clipboard_filter_.set_clipboard_stub(&disable_clipboard_filter_); | |
92 | 98 |
93 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); | 99 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); |
94 | 100 |
95 if (max_duration_ > base::TimeDelta()) { | 101 if (max_duration_ > base::TimeDelta()) { |
96 // TODO(simonmorris): Let Disconnect() tell the client that the | 102 // TODO(simonmorris): Let Disconnect() tell the client that the |
97 // disconnection was caused by the session exceeding its maximum duration. | 103 // disconnection was caused by the session exceeding its maximum duration. |
98 max_duration_timer_.Start(FROM_HERE, max_duration_, | 104 max_duration_timer_.Start(FROM_HERE, max_duration_, |
99 this, &ClientSession::Disconnect); | 105 this, &ClientSession::Disconnect); |
100 } | 106 } |
101 | 107 |
102 event_handler_->OnSessionAuthenticated(this); | 108 event_handler_->OnSessionAuthenticated(this); |
103 } | 109 } |
104 | 110 |
105 void ClientSession::OnConnectionChannelsConnected( | 111 void ClientSession::OnConnectionChannelsConnected( |
106 protocol::ConnectionToClient* connection) { | 112 protocol::ConnectionToClient* connection) { |
107 DCHECK(CalledOnValidThread()); | 113 DCHECK(CalledOnValidThread()); |
108 DCHECK_EQ(connection_.get(), connection); | 114 DCHECK_EQ(connection_.get(), connection); |
109 SetDisableInputs(false); | 115 SetDisableInputs(false); |
110 event_handler_->OnSessionChannelsConnected(this); | 116 event_handler_->OnSessionChannelsConnected(this); |
111 } | 117 } |
112 | 118 |
113 void ClientSession::OnConnectionClosed( | 119 void ClientSession::OnConnectionClosed( |
114 protocol::ConnectionToClient* connection, | 120 protocol::ConnectionToClient* connection, |
115 protocol::ErrorCode error) { | 121 protocol::ErrorCode error) { |
116 DCHECK(CalledOnValidThread()); | 122 DCHECK(CalledOnValidThread()); |
117 DCHECK_EQ(connection_.get(), connection); | 123 DCHECK_EQ(connection_.get(), connection); |
118 if (!is_authenticated_) | 124 |
| 125 if (!auth_input_filter_.enabled()) |
119 event_handler_->OnSessionAuthenticationFailed(this); | 126 event_handler_->OnSessionAuthenticationFailed(this); |
120 auth_input_filter_.set_input_stub(NULL); | 127 |
121 auth_clipboard_filter_.set_clipboard_stub(NULL); | 128 // Block any further input events from the client. |
| 129 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our |
| 130 // is_authenticated(), so that we can disable |auth_*_filter_| here. |
| 131 disable_input_filter_.set_enabled(false); |
| 132 disable_clipboard_filter_.set_enabled(false); |
122 | 133 |
123 // Ensure that any pressed keys or buttons are released. | 134 // Ensure that any pressed keys or buttons are released. |
124 input_tracker_.ReleaseAll(); | 135 input_tracker_.ReleaseAll(); |
125 | 136 |
126 // TODO(sergeyu): Log failure reason? | 137 // TODO(sergeyu): Log failure reason? |
127 event_handler_->OnSessionClosed(this); | 138 event_handler_->OnSessionClosed(this); |
128 } | 139 } |
129 | 140 |
130 void ClientSession::OnSequenceNumberUpdated( | 141 void ClientSession::OnSequenceNumberUpdated( |
131 protocol::ConnectionToClient* connection, int64 sequence_number) { | 142 protocol::ConnectionToClient* connection, int64 sequence_number) { |
(...skipping 22 matching lines...) Expand all Loading... |
154 } | 165 } |
155 | 166 |
156 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { | 167 void ClientSession::LocalMouseMoved(const SkIPoint& mouse_pos) { |
157 DCHECK(CalledOnValidThread()); | 168 DCHECK(CalledOnValidThread()); |
158 remote_input_filter_.LocalMouseMoved(mouse_pos); | 169 remote_input_filter_.LocalMouseMoved(mouse_pos); |
159 } | 170 } |
160 | 171 |
161 void ClientSession::SetDisableInputs(bool disable_inputs) { | 172 void ClientSession::SetDisableInputs(bool disable_inputs) { |
162 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
163 | 174 |
164 if (disable_inputs) { | 175 if (disable_inputs) |
165 disable_input_filter_.set_input_stub(NULL); | |
166 disable_clipboard_filter_.set_clipboard_stub(NULL); | |
167 input_tracker_.ReleaseAll(); | 176 input_tracker_.ReleaseAll(); |
168 } else { | 177 |
169 disable_input_filter_.set_input_stub(&mouse_input_filter_); | 178 disable_input_filter_.set_enabled(!disable_inputs); |
170 disable_clipboard_filter_.set_clipboard_stub( | 179 disable_clipboard_filter_.set_enabled(!disable_inputs); |
171 clipboard_echo_filter_.host_filter()); | |
172 } | |
173 } | 180 } |
174 | 181 |
175 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { | 182 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
176 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
177 | 184 |
178 return scoped_ptr<protocol::ClipboardStub>( | 185 return scoped_ptr<protocol::ClipboardStub>( |
179 new protocol::ClipboardThreadProxy( | 186 new protocol::ClipboardThreadProxy( |
180 client_clipboard_factory_.GetWeakPtr(), | 187 client_clipboard_factory_.GetWeakPtr(), |
181 base::MessageLoopProxy::current())); | 188 base::MessageLoopProxy::current())); |
182 } | 189 } |
183 | 190 |
184 } // namespace remoting | 191 } // namespace remoting |
OLD | NEW |