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/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 15 matching lines...) Expand all Loading... | |
| 374 void ClientSession::OnConnectionClosed( | 368 void ClientSession::OnConnectionClosed( |
| 375 protocol::ConnectionToClient* connection, | 369 protocol::ConnectionToClient* connection, |
| 376 protocol::ErrorCode error) { | 370 protocol::ErrorCode error) { |
| 377 DCHECK(CalledOnValidThread()); | 371 DCHECK(CalledOnValidThread()); |
| 378 DCHECK_EQ(connection_.get(), connection); | 372 DCHECK_EQ(connection_.get(), connection); |
| 379 | 373 |
| 380 // Ignore any further callbacks. | 374 // Ignore any further callbacks. |
| 381 weak_factory_.InvalidateWeakPtrs(); | 375 weak_factory_.InvalidateWeakPtrs(); |
| 382 | 376 |
| 383 // If the client never authenticated then the session failed. | 377 // If the client never authenticated then the session failed. |
| 384 if (!auth_input_filter_.enabled()) | 378 if (!is_authenticated_) |
| 385 event_handler_->OnSessionAuthenticationFailed(this); | 379 event_handler_->OnSessionAuthenticationFailed(this); |
| 386 | 380 |
| 387 // Block any further input events from the client. | |
| 388 // TODO(wez): Fix ChromotingHost::OnSessionClosed not to check our | |
| 389 // is_authenticated(), so that we can disable |auth_*_filter_| here. | |
| 390 disable_input_filter_.set_enabled(false); | |
| 391 disable_clipboard_filter_.set_enabled(false); | |
|
Wez
2015/02/07 00:40:43
Why remove these? The ensure that we don't proces
Sergey Ulanov
2015/02/13 19:40:20
InputInjector is deleted 5 lines later so these ar
| |
| 392 | |
| 393 // Ensure that any pressed keys or buttons are released. | 381 // Ensure that any pressed keys or buttons are released. |
| 394 input_tracker_.ReleaseAll(); | 382 input_tracker_.ReleaseAll(); |
| 395 | 383 |
| 396 // Stop components access the client, audio or video stubs, which are no | 384 // Stop components access the client, audio or video stubs, which are no |
| 397 // longer valid once ConnectionToClient calls OnConnectionClosed(). | 385 // longer valid once ConnectionToClient calls OnConnectionClosed(). |
| 398 audio_pump_.reset(); | 386 audio_pump_.reset(); |
| 399 video_frame_pump_.reset(); | 387 video_frame_pump_.reset(); |
| 400 mouse_shape_pump_.reset(); | 388 mouse_shape_pump_.reset(); |
| 401 client_clipboard_factory_.InvalidateWeakPtrs(); | 389 client_clipboard_factory_.InvalidateWeakPtrs(); |
| 402 input_injector_.reset(); | 390 input_injector_.reset(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 | 492 |
| 505 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { | 493 scoped_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { |
| 506 DCHECK(CalledOnValidThread()); | 494 DCHECK(CalledOnValidThread()); |
| 507 | 495 |
| 508 return make_scoped_ptr( | 496 return make_scoped_ptr( |
| 509 new protocol::ClipboardThreadProxy(client_clipboard_factory_.GetWeakPtr(), | 497 new protocol::ClipboardThreadProxy(client_clipboard_factory_.GetWeakPtr(), |
| 510 base::MessageLoopProxy::current())); | 498 base::MessageLoopProxy::current())); |
| 511 } | 499 } |
| 512 | 500 |
| 513 } // namespace remoting | 501 } // namespace remoting |
| OLD | NEW |