| 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" |
| 11 #include "remoting/base/logging.h" | 11 #include "remoting/base/logging.h" |
| 12 #include "remoting/codec/audio_encoder.h" | 12 #include "remoting/codec/audio_encoder.h" |
| 13 #include "remoting/codec/audio_encoder_opus.h" | 13 #include "remoting/codec/audio_encoder_opus.h" |
| 14 #include "remoting/codec/audio_encoder_verbatim.h" | 14 #include "remoting/codec/audio_encoder_verbatim.h" |
| 15 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
| 16 #include "remoting/codec/video_encoder_verbatim.h" | 16 #include "remoting/codec/video_encoder_verbatim.h" |
| 17 #include "remoting/codec/video_encoder_vpx.h" | 17 #include "remoting/codec/video_encoder_vpx.h" |
| 18 #include "remoting/host/audio_capturer.h" | 18 #include "remoting/host/audio_capturer.h" |
| 19 #include "remoting/host/audio_scheduler.h" | 19 #include "remoting/host/audio_scheduler.h" |
| 20 #include "remoting/host/desktop_environment.h" | 20 #include "remoting/host/desktop_environment.h" |
| 21 #include "remoting/host/host_extension_session.h" | |
| 22 #include "remoting/host/input_injector.h" | 21 #include "remoting/host/input_injector.h" |
| 23 #include "remoting/host/screen_controls.h" | 22 #include "remoting/host/screen_controls.h" |
| 24 #include "remoting/host/screen_resolution.h" | 23 #include "remoting/host/screen_resolution.h" |
| 25 #include "remoting/host/video_scheduler.h" | 24 #include "remoting/host/video_scheduler.h" |
| 26 #include "remoting/proto/control.pb.h" | 25 #include "remoting/proto/control.pb.h" |
| 27 #include "remoting/proto/event.pb.h" | 26 #include "remoting/proto/event.pb.h" |
| 28 #include "remoting/protocol/client_stub.h" | 27 #include "remoting/protocol/client_stub.h" |
| 29 #include "remoting/protocol/clipboard_thread_proxy.h" | 28 #include "remoting/protocol/clipboard_thread_proxy.h" |
| 30 #include "remoting/protocol/pairing_registry.h" | 29 #include "remoting/protocol/pairing_registry.h" |
| 31 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" | 30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
| 93 DCHECK(!audio_scheduler_.get()); | 92 DCHECK(!audio_scheduler_.get()); |
| 94 DCHECK(!desktop_environment_); | 93 DCHECK(!desktop_environment_); |
| 95 DCHECK(!input_injector_); | 94 DCHECK(!input_injector_); |
| 96 DCHECK(!screen_controls_); | 95 DCHECK(!screen_controls_); |
| 97 DCHECK(!video_scheduler_.get()); | 96 DCHECK(!video_scheduler_.get()); |
| 98 | 97 |
| 99 connection_.reset(); | 98 connection_.reset(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 void ClientSession::AddExtensionSession( | |
| 103 scoped_ptr<HostExtensionSession> extension_session) { | |
| 104 DCHECK(CalledOnValidThread()); | |
| 105 | |
| 106 extension_sessions_.push_back(extension_session.release()); | |
| 107 } | |
| 108 | |
| 109 void ClientSession::AddHostCapabilities(const std::string& capabilities) { | |
| 110 DCHECK(CalledOnValidThread()); | |
| 111 | |
| 112 if (capabilities.empty()) | |
| 113 return; | |
| 114 | |
| 115 if (!host_capabilities_.empty()) | |
| 116 host_capabilities_.append(" "); | |
| 117 | |
| 118 host_capabilities_.append(capabilities); | |
| 119 } | |
| 120 | |
| 121 void ClientSession::NotifyClientResolution( | 101 void ClientSession::NotifyClientResolution( |
| 122 const protocol::ClientResolution& resolution) { | 102 const protocol::ClientResolution& resolution) { |
| 123 DCHECK(CalledOnValidThread()); | 103 DCHECK(CalledOnValidThread()); |
| 124 | 104 |
| 125 // TODO(sergeyu): Move these checks to protocol layer. | 105 // TODO(sergeyu): Move these checks to protocol layer. |
| 126 if (!resolution.has_dips_width() || !resolution.has_dips_height() || | 106 if (!resolution.has_dips_width() || !resolution.has_dips_height() || |
| 127 resolution.dips_width() < 0 || resolution.dips_height() < 0 || | 107 resolution.dips_width() < 0 || resolution.dips_height() < 0 || |
| 128 resolution.width() <= 0 || resolution.height() <= 0) { | 108 resolution.width() <= 0 || resolution.height() <= 0) { |
| 129 LOG(ERROR) << "Received invalid ClientResolution message."; | 109 LOG(ERROR) << "Received invalid ClientResolution message."; |
| 130 return; | 110 return; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (client_capabilities_) { | 161 if (client_capabilities_) { |
| 182 LOG(WARNING) << "protocol::Capabilities has been received already."; | 162 LOG(WARNING) << "protocol::Capabilities has been received already."; |
| 183 return; | 163 return; |
| 184 } | 164 } |
| 185 | 165 |
| 186 client_capabilities_ = make_scoped_ptr(new std::string()); | 166 client_capabilities_ = make_scoped_ptr(new std::string()); |
| 187 if (capabilities.has_capabilities()) | 167 if (capabilities.has_capabilities()) |
| 188 *client_capabilities_ = capabilities.capabilities(); | 168 *client_capabilities_ = capabilities.capabilities(); |
| 189 | 169 |
| 190 VLOG(1) << "Client capabilities: " << *client_capabilities_; | 170 VLOG(1) << "Client capabilities: " << *client_capabilities_; |
| 191 event_handler_->OnSessionClientCapabilities(this); | |
| 192 | 171 |
| 193 // Calculate the set of capabilities enabled by both client and host and | 172 // Calculate the set of capabilities enabled by both client and host and |
| 194 // pass it to the desktop environment if it is available. | 173 // pass it to the desktop environment if it is available. |
| 195 desktop_environment_->SetCapabilities( | 174 desktop_environment_->SetCapabilities( |
| 196 IntersectCapabilities(*client_capabilities_, host_capabilities_)); | 175 IntersectCapabilities(*client_capabilities_, host_capabilities_)); |
| 197 } | 176 } |
| 198 | 177 |
| 199 void ClientSession::RequestPairing( | 178 void ClientSession::RequestPairing( |
| 200 const protocol::PairingRequest& pairing_request) { | 179 const protocol::PairingRequest& pairing_request) { |
| 201 if (pairing_registry_ && pairing_request.has_client_name()) { | 180 if (pairing_registry_ && pairing_request.has_client_name()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 218 reply.set_data(message.data().substr(0, 16)); | 197 reply.set_data(message.data().substr(0, 16)); |
| 219 connection_->client_stub()->DeliverHostMessage(reply); | 198 connection_->client_stub()->DeliverHostMessage(reply); |
| 220 return; | 199 return; |
| 221 } else if (message.type() == "gnubby-auth") { | 200 } else if (message.type() == "gnubby-auth") { |
| 222 if (gnubby_auth_handler_) { | 201 if (gnubby_auth_handler_) { |
| 223 gnubby_auth_handler_->DeliverClientMessage(message.data()); | 202 gnubby_auth_handler_->DeliverClientMessage(message.data()); |
| 224 } else { | 203 } else { |
| 225 HOST_LOG << "gnubby auth is not enabled"; | 204 HOST_LOG << "gnubby auth is not enabled"; |
| 226 } | 205 } |
| 227 return; | 206 return; |
| 228 } else { | |
| 229 for(HostExtensionSessionList::iterator it = extension_sessions_.begin(); | |
| 230 it != extension_sessions_.end(); ++it) { | |
| 231 // Extension returns |true| to indicate that the message was handled. | |
| 232 if ((*it)->OnExtensionMessage(this, message)) | |
| 233 return; | |
| 234 } | |
| 235 } | 207 } |
| 236 } | 208 } |
| 237 HOST_LOG << "Unexpected message received: " | 209 HOST_LOG << "Unexpected message received: " |
| 238 << message.type() << ": " << message.data(); | 210 << message.type() << ": " << message.data(); |
| 239 } | 211 } |
| 240 | 212 |
| 241 void ClientSession::OnConnectionAuthenticating( | 213 void ClientSession::OnConnectionAuthenticating( |
| 242 protocol::ConnectionToClient* connection) { | 214 protocol::ConnectionToClient* connection) { |
| 243 event_handler_->OnSessionAuthenticating(this); | 215 event_handler_->OnSessionAuthenticating(this); |
| 244 } | 216 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 274 | 246 |
| 275 // Create the desktop environment. Drop the connection if it could not be | 247 // Create the desktop environment. Drop the connection if it could not be |
| 276 // created for any reason (for instance the curtain could not initialize). | 248 // created for any reason (for instance the curtain could not initialize). |
| 277 desktop_environment_ = | 249 desktop_environment_ = |
| 278 desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); | 250 desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); |
| 279 if (!desktop_environment_) { | 251 if (!desktop_environment_) { |
| 280 DisconnectSession(); | 252 DisconnectSession(); |
| 281 return; | 253 return; |
| 282 } | 254 } |
| 283 | 255 |
| 284 AddHostCapabilities(desktop_environment_->GetCapabilities()); | 256 host_capabilities_ = desktop_environment_->GetCapabilities(); |
| 285 | 257 |
| 286 // Ignore protocol::Capabilities messages from the client if it does not | 258 // Ignore protocol::Capabilities messages from the client if it does not |
| 287 // support any capabilities. | 259 // support any capabilities. |
| 288 if (!connection_->session()->config().SupportsCapabilities()) { | 260 if (!connection_->session()->config().SupportsCapabilities()) { |
| 289 VLOG(1) << "The client does not support any capabilities."; | 261 VLOG(1) << "The client does not support any capabilities."; |
| 290 | 262 |
| 291 client_capabilities_ = make_scoped_ptr(new std::string()); | 263 client_capabilities_ = make_scoped_ptr(new std::string()); |
| 292 event_handler_->OnSessionClientCapabilities(this); | |
| 293 | |
| 294 desktop_environment_->SetCapabilities(*client_capabilities_); | 264 desktop_environment_->SetCapabilities(*client_capabilities_); |
| 295 } | 265 } |
| 296 | 266 |
| 297 // Create the object that controls the screen resolution. | 267 // Create the object that controls the screen resolution. |
| 298 screen_controls_ = desktop_environment_->CreateScreenControls(); | 268 screen_controls_ = desktop_environment_->CreateScreenControls(); |
| 299 | 269 |
| 300 // Create the event executor. | 270 // Create the event executor. |
| 301 input_injector_ = desktop_environment_->CreateInputInjector(); | 271 input_injector_ = desktop_environment_->CreateInputInjector(); |
| 302 | 272 |
| 303 // Connect the host clipboard and input stubs. | 273 // Connect the host clipboard and input stubs. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim()); | 466 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim()); |
| 497 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { | 467 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { |
| 498 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus()); | 468 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus()); |
| 499 } | 469 } |
| 500 | 470 |
| 501 NOTREACHED(); | 471 NOTREACHED(); |
| 502 return scoped_ptr<AudioEncoder>(); | 472 return scoped_ptr<AudioEncoder>(); |
| 503 } | 473 } |
| 504 | 474 |
| 505 } // namespace remoting | 475 } // namespace remoting |
| OLD | NEW |