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/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "remoting/base/capabilities.h" | 10 #include "remoting/base/capabilities.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const std::vector<HostExtension*>& extensions) | 87 const std::vector<HostExtension*>& extensions) |
88 : event_handler_(event_handler), | 88 : event_handler_(event_handler), |
89 connection_(connection.Pass()), | 89 connection_(connection.Pass()), |
90 client_jid_(connection_->session()->jid()), | 90 client_jid_(connection_->session()->jid()), |
91 desktop_environment_factory_(desktop_environment_factory), | 91 desktop_environment_factory_(desktop_environment_factory), |
92 input_tracker_(&host_input_filter_), | 92 input_tracker_(&host_input_filter_), |
93 remote_input_filter_(&input_tracker_), | 93 remote_input_filter_(&input_tracker_), |
94 mouse_clamping_filter_(&remote_input_filter_), | 94 mouse_clamping_filter_(&remote_input_filter_), |
95 disable_input_filter_(mouse_clamping_filter_.input_filter()), | 95 disable_input_filter_(mouse_clamping_filter_.input_filter()), |
96 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), | 96 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), |
97 auth_input_filter_(&disable_input_filter_), | |
98 auth_clipboard_filter_(&disable_clipboard_filter_), | |
99 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), | 97 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), |
100 max_duration_(max_duration), | 98 max_duration_(max_duration), |
101 audio_task_runner_(audio_task_runner), | 99 audio_task_runner_(audio_task_runner), |
102 input_task_runner_(input_task_runner), | 100 input_task_runner_(input_task_runner), |
103 video_capture_task_runner_(video_capture_task_runner), | 101 video_capture_task_runner_(video_capture_task_runner), |
104 video_encode_task_runner_(video_encode_task_runner), | 102 video_encode_task_runner_(video_encode_task_runner), |
105 network_task_runner_(network_task_runner), | 103 network_task_runner_(network_task_runner), |
106 ui_task_runner_(ui_task_runner), | 104 ui_task_runner_(ui_task_runner), |
107 pairing_registry_(pairing_registry), | 105 pairing_registry_(pairing_registry), |
| 106 is_authenticated_(false), |
108 pause_video_(false), | 107 pause_video_(false), |
109 lossless_video_encode_(false), | 108 lossless_video_encode_(false), |
110 lossless_video_color_(false), | 109 lossless_video_color_(false), |
111 weak_factory_(this) { | 110 weak_factory_(this) { |
112 connection_->SetEventHandler(this); | 111 connection_->SetEventHandler(this); |
113 | 112 |
114 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be | |
115 // set before channels are connected. Make it possible to set stubs | |
116 // later and set them only when connection is authenticated. | |
117 connection_->set_clipboard_stub(&auth_clipboard_filter_); | |
118 connection_->set_host_stub(this); | |
119 connection_->set_input_stub(&auth_input_filter_); | |
120 | |
121 // |auth_*_filter_|'s states reflect whether the session is authenticated. | |
122 auth_input_filter_.set_enabled(false); | |
123 auth_clipboard_filter_.set_enabled(false); | |
124 | |
125 // Create a manager for the configured extensions, if any. | 113 // Create a manager for the configured extensions, if any. |
126 extension_manager_.reset(new HostExtensionSessionManager(extensions, this)); | 114 extension_manager_.reset(new HostExtensionSessionManager(extensions, this)); |
127 | 115 |
128 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
129 // LocalInputMonitorWin filters out an echo of the injected input before it | 117 // LocalInputMonitorWin filters out an echo of the injected input before it |
130 // reaches |remote_input_filter_|. | 118 // reaches |remote_input_filter_|. |
131 remote_input_filter_.SetExpectLocalEcho(false); | 119 remote_input_filter_.SetExpectLocalEcho(false); |
132 #endif // defined(OS_WIN) | 120 #endif // defined(OS_WIN) |
133 } | 121 } |
134 | 122 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 void ClientSession::OnConnectionAuthenticated( | 270 void ClientSession::OnConnectionAuthenticated( |
283 protocol::ConnectionToClient* connection) { | 271 protocol::ConnectionToClient* connection) { |
284 DCHECK(CalledOnValidThread()); | 272 DCHECK(CalledOnValidThread()); |
285 DCHECK_EQ(connection_.get(), connection); | 273 DCHECK_EQ(connection_.get(), connection); |
286 DCHECK(!audio_pump_); | 274 DCHECK(!audio_pump_); |
287 DCHECK(!desktop_environment_); | 275 DCHECK(!desktop_environment_); |
288 DCHECK(!input_injector_); | 276 DCHECK(!input_injector_); |
289 DCHECK(!screen_controls_); | 277 DCHECK(!screen_controls_); |
290 DCHECK(!video_frame_pump_); | 278 DCHECK(!video_frame_pump_); |
291 | 279 |
292 auth_input_filter_.set_enabled(true); | 280 is_authenticated_ = true; |
293 auth_clipboard_filter_.set_enabled(true); | |
294 | |
295 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); | |
296 mouse_clamping_filter_.set_video_stub(connection_->video_stub()); | |
297 | 281 |
298 if (max_duration_ > base::TimeDelta()) { | 282 if (max_duration_ > base::TimeDelta()) { |
299 // TODO(simonmorris): Let Disconnect() tell the client that the | 283 // TODO(simonmorris): Let Disconnect() tell the client that the |
300 // disconnection was caused by the session exceeding its maximum duration. | 284 // disconnection was caused by the session exceeding its maximum duration. |
301 max_duration_timer_.Start(FROM_HERE, max_duration_, | 285 max_duration_timer_.Start(FROM_HERE, max_duration_, |
302 this, &ClientSession::DisconnectSession); | 286 this, &ClientSession::DisconnectSession); |
303 } | 287 } |
304 | 288 |
305 // Disconnect the session if the connection was rejected by the host. | 289 // Disconnect the session if the connection was rejected by the host. |
306 if (!event_handler_->OnSessionAuthenticated(this)) { | 290 if (!event_handler_->OnSessionAuthenticated(this)) { |
307 DisconnectSession(); | 291 DisconnectSession(); |
308 return; | 292 return; |
309 } | 293 } |
310 | 294 |
311 // Create the desktop environment. Drop the connection if it could not be | 295 // Create the desktop environment. Drop the connection if it could not be |
312 // created for any reason (for instance the curtain could not initialize). | 296 // created for any reason (for instance the curtain could not initialize). |
313 desktop_environment_ = | 297 desktop_environment_ = |
314 desktop_environment_factory_->Create(weak_factory_.GetWeakPtr()); | 298 desktop_environment_factory_->Create(weak_factory_.GetWeakPtr()); |
315 if (!desktop_environment_) { | 299 if (!desktop_environment_) { |
316 DisconnectSession(); | 300 DisconnectSession(); |
317 return; | 301 return; |
318 } | 302 } |
319 | 303 |
| 304 // Connect host stub. |
| 305 connection_->set_host_stub(this); |
| 306 |
| 307 // Connect video stub. |
| 308 mouse_clamping_filter_.set_video_stub(connection_->video_stub()); |
| 309 |
320 // Collate the set of capabilities to offer the client, if it supports them. | 310 // Collate the set of capabilities to offer the client, if it supports them. |
321 host_capabilities_ = desktop_environment_->GetCapabilities(); | 311 host_capabilities_ = desktop_environment_->GetCapabilities(); |
322 if (!host_capabilities_.empty()) | 312 if (!host_capabilities_.empty()) |
323 host_capabilities_.append(" "); | 313 host_capabilities_.append(" "); |
324 host_capabilities_.append(extension_manager_->GetCapabilities()); | 314 host_capabilities_.append(extension_manager_->GetCapabilities()); |
325 | 315 |
326 // Create the object that controls the screen resolution. | 316 // Create the object that controls the screen resolution. |
327 screen_controls_ = desktop_environment_->CreateScreenControls(); | 317 screen_controls_ = desktop_environment_->CreateScreenControls(); |
328 | 318 |
329 // Create the event executor. | 319 // Create the event executor. |
330 input_injector_ = desktop_environment_->CreateInputInjector(); | 320 input_injector_ = desktop_environment_->CreateInputInjector(); |
331 | 321 |
332 // Connect the host clipboard and input stubs. | 322 // Connect the host input stubs. |
| 323 connection_->set_input_stub(&disable_input_filter_); |
333 host_input_filter_.set_input_stub(input_injector_.get()); | 324 host_input_filter_.set_input_stub(input_injector_.get()); |
| 325 |
| 326 // Connect the clipboard stubs. |
| 327 connection_->set_clipboard_stub(&disable_clipboard_filter_); |
334 clipboard_echo_filter_.set_host_stub(input_injector_.get()); | 328 clipboard_echo_filter_.set_host_stub(input_injector_.get()); |
| 329 clipboard_echo_filter_.set_client_stub(connection_->client_stub()); |
335 | 330 |
336 // Create a GnubbyAuthHandler to proxy gnubbyd messages. | 331 // Create a GnubbyAuthHandler to proxy gnubbyd messages. |
337 gnubby_auth_handler_ = desktop_environment_->CreateGnubbyAuthHandler( | 332 gnubby_auth_handler_ = desktop_environment_->CreateGnubbyAuthHandler( |
338 connection_->client_stub()); | 333 connection_->client_stub()); |
339 } | 334 } |
340 | 335 |
341 void ClientSession::OnConnectionChannelsConnected( | 336 void ClientSession::OnConnectionChannelsConnected( |
342 protocol::ConnectionToClient* connection) { | 337 protocol::ConnectionToClient* connection) { |
343 DCHECK(CalledOnValidThread()); | 338 DCHECK(CalledOnValidThread()); |
344 DCHECK_EQ(connection_.get(), connection); | 339 DCHECK_EQ(connection_.get(), connection); |
345 | 340 |
346 // Negotiate capabilities with the client. | 341 // Negotiate capabilities with the client. |
347 VLOG(1) << "Host capabilities: " << host_capabilities_; | 342 VLOG(1) << "Host capabilities: " << host_capabilities_; |
348 | |
349 protocol::Capabilities capabilities; | 343 protocol::Capabilities capabilities; |
350 capabilities.set_capabilities(host_capabilities_); | 344 capabilities.set_capabilities(host_capabilities_); |
351 connection_->client_stub()->SetCapabilities(capabilities); | 345 connection_->client_stub()->SetCapabilities(capabilities); |
352 | 346 |
353 // Start the event executor. | 347 // Start the event executor. |
354 input_injector_->Start(CreateClipboardProxy()); | 348 input_injector_->Start(CreateClipboardProxy()); |
355 SetDisableInputs(false); | 349 SetDisableInputs(false); |
356 | 350 |
357 // Start recording video. | 351 // Start recording video. |
358 ResetVideoPipeline(); | 352 ResetVideoPipeline(); |
(...skipping 14 matching lines...) Expand all Loading... |
373 void ClientSession::OnConnectionClosed( | 367 void ClientSession::OnConnectionClosed( |
374 protocol::ConnectionToClient* connection, | 368 protocol::ConnectionToClient* connection, |
375 protocol::ErrorCode error) { | 369 protocol::ErrorCode error) { |
376 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
377 DCHECK_EQ(connection_.get(), connection); | 371 DCHECK_EQ(connection_.get(), connection); |
378 | 372 |
379 // Ignore any further callbacks. | 373 // Ignore any further callbacks. |
380 weak_factory_.InvalidateWeakPtrs(); | 374 weak_factory_.InvalidateWeakPtrs(); |
381 | 375 |
382 // If the client never authenticated then the session failed. | 376 // If the client never authenticated then the session failed. |
383 if (!auth_input_filter_.enabled()) | 377 if (!is_authenticated_) |
384 event_handler_->OnSessionAuthenticationFailed(this); | 378 event_handler_->OnSessionAuthenticationFailed(this); |
385 | 379 |
386 // Block any further input events from the client. | |
387 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our | |
388 // is_authenticated(), so that we can disable |auth_*_filter_| here. | |
389 disable_input_filter_.set_enabled(false); | |
390 disable_clipboard_filter_.set_enabled(false); | |
391 | |
392 // Ensure that any pressed keys or buttons are released. | 380 // Ensure that any pressed keys or buttons are released. |
393 input_tracker_.ReleaseAll(); | 381 input_tracker_.ReleaseAll(); |
394 | 382 |
395 // Stop components access the client, audio or video stubs, which are no | 383 // Stop components access the client, audio or video stubs, which are no |
396 // longer valid once ConnectionToClient calls OnConnectionClosed(). | 384 // longer valid once ConnectionToClient calls OnConnectionClosed(). |
397 audio_pump_.reset(); | 385 audio_pump_.reset(); |
398 video_frame_pump_.reset(); | 386 video_frame_pump_.reset(); |
399 mouse_shape_pump_.reset(); | 387 mouse_shape_pump_.reset(); |
400 client_clipboard_factory_.InvalidateWeakPtrs(); | 388 client_clipboard_factory_.InvalidateWeakPtrs(); |
401 input_injector_.reset(); | 389 input_injector_.reset(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 494 |
507 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { | 495 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
508 DCHECK(CalledOnValidThread()); | 496 DCHECK(CalledOnValidThread()); |
509 | 497 |
510 return make_scoped_ptr( | 498 return make_scoped_ptr( |
511 new protocol::ClipboardThreadProxy(client_clipboard_factory_.GetWeakPtr(), | 499 new protocol::ClipboardThreadProxy(client_clipboard_factory_.GetWeakPtr(), |
512 base::MessageLoopProxy::current())); | 500 base::MessageLoopProxy::current())); |
513 } | 501 } |
514 | 502 |
515 } // namespace remoting | 503 } // namespace remoting |
OLD | NEW |