Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: remoting/host/client_session.cc

Issue 301453003: Host extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_session.h"
21 #include "remoting/host/input_injector.h" 22 #include "remoting/host/input_injector.h"
22 #include "remoting/host/screen_controls.h" 23 #include "remoting/host/screen_controls.h"
23 #include "remoting/host/screen_resolution.h" 24 #include "remoting/host/screen_resolution.h"
24 #include "remoting/host/video_scheduler.h" 25 #include "remoting/host/video_scheduler.h"
25 #include "remoting/proto/control.pb.h" 26 #include "remoting/proto/control.pb.h"
26 #include "remoting/proto/event.pb.h" 27 #include "remoting/proto/event.pb.h"
27 #include "remoting/protocol/client_stub.h" 28 #include "remoting/protocol/client_stub.h"
28 #include "remoting/protocol/clipboard_thread_proxy.h" 29 #include "remoting/protocol/clipboard_thread_proxy.h"
29 #include "remoting/protocol/pairing_registry.h" 30 #include "remoting/protocol/pairing_registry.h"
30 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h" 31 #include "third_party/webrtc/modules/desktop_capture/screen_capturer.h"
31 32
32 // Default DPI to assume for old clients that use notifyClientDimensions. 33 // Default DPI to assume for old clients that use notifyClientDimensions.
33 const int kDefaultDPI = 96; 34 const int kDefaultDPI = 96;
34 35
35 namespace remoting { 36 namespace remoting {
36 37
37 ClientSession::ClientSession( 38 ClientSession::ClientSession(
38 EventHandler* event_handler, 39 EventHandler* event_handler,
39 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner, 40 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner,
40 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner, 41 scoped_refptr<base::SingleThreadTaskRunner> input_task_runner,
41 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner, 42 scoped_refptr<base::SingleThreadTaskRunner> video_capture_task_runner,
42 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, 43 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner,
43 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner, 44 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
44 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, 45 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
45 scoped_ptr<protocol::ConnectionToClient> connection, 46 scoped_ptr<protocol::ConnectionToClient> connection,
46 DesktopEnvironmentFactory* desktop_environment_factory, 47 DesktopEnvironmentFactory* desktop_environment_factory,
47 const base::TimeDelta& max_duration, 48 const base::TimeDelta& max_duration,
48 scoped_refptr<protocol::PairingRegistry> pairing_registry) 49 scoped_refptr<protocol::PairingRegistry> pairing_registry,
50 const ExtensionList* extensions)
49 : event_handler_(event_handler), 51 : event_handler_(event_handler),
50 connection_(connection.Pass()), 52 connection_(connection.Pass()),
51 client_jid_(connection_->session()->jid()), 53 client_jid_(connection_->session()->jid()),
52 control_factory_(this), 54 control_factory_(this),
53 desktop_environment_factory_(desktop_environment_factory), 55 desktop_environment_factory_(desktop_environment_factory),
54 input_tracker_(&host_input_filter_), 56 input_tracker_(&host_input_filter_),
55 remote_input_filter_(&input_tracker_), 57 remote_input_filter_(&input_tracker_),
56 mouse_clamping_filter_(&remote_input_filter_), 58 mouse_clamping_filter_(&remote_input_filter_),
57 disable_input_filter_(mouse_clamping_filter_.input_filter()), 59 disable_input_filter_(mouse_clamping_filter_.input_filter()),
58 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()), 60 disable_clipboard_filter_(clipboard_echo_filter_.host_filter()),
59 auth_input_filter_(&disable_input_filter_), 61 auth_input_filter_(&disable_input_filter_),
60 auth_clipboard_filter_(&disable_clipboard_filter_), 62 auth_clipboard_filter_(&disable_clipboard_filter_),
61 client_clipboard_factory_(clipboard_echo_filter_.client_filter()), 63 client_clipboard_factory_(clipboard_echo_filter_.client_filter()),
62 max_duration_(max_duration), 64 max_duration_(max_duration),
63 audio_task_runner_(audio_task_runner), 65 audio_task_runner_(audio_task_runner),
64 input_task_runner_(input_task_runner), 66 input_task_runner_(input_task_runner),
65 video_capture_task_runner_(video_capture_task_runner), 67 video_capture_task_runner_(video_capture_task_runner),
66 video_encode_task_runner_(video_encode_task_runner), 68 video_encode_task_runner_(video_encode_task_runner),
67 network_task_runner_(network_task_runner), 69 network_task_runner_(network_task_runner),
68 ui_task_runner_(ui_task_runner), 70 ui_task_runner_(ui_task_runner),
69 pairing_registry_(pairing_registry) { 71 pairing_registry_(pairing_registry),
72 extensions_(extensions) {
70 connection_->SetEventHandler(this); 73 connection_->SetEventHandler(this);
71 74
72 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be 75 // TODO(sergeyu): Currently ConnectionToClient expects stubs to be
73 // set before channels are connected. Make it possible to set stubs 76 // set before channels are connected. Make it possible to set stubs
74 // later and set them only when connection is authenticated. 77 // later and set them only when connection is authenticated.
75 connection_->set_clipboard_stub(&auth_clipboard_filter_); 78 connection_->set_clipboard_stub(&auth_clipboard_filter_);
76 connection_->set_host_stub(this); 79 connection_->set_host_stub(this);
77 connection_->set_input_stub(&auth_input_filter_); 80 connection_->set_input_stub(&auth_input_filter_);
78 81
79 // |auth_*_filter_|'s states reflect whether the session is authenticated. 82 // |auth_*_filter_|'s states reflect whether the session is authenticated.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 LOG(WARNING) << "protocol::Capabilities has been received already."; 165 LOG(WARNING) << "protocol::Capabilities has been received already.";
163 return; 166 return;
164 } 167 }
165 168
166 client_capabilities_ = make_scoped_ptr(new std::string()); 169 client_capabilities_ = make_scoped_ptr(new std::string());
167 if (capabilities.has_capabilities()) 170 if (capabilities.has_capabilities())
168 *client_capabilities_ = capabilities.capabilities(); 171 *client_capabilities_ = capabilities.capabilities();
169 172
170 VLOG(1) << "Client capabilities: " << *client_capabilities_; 173 VLOG(1) << "Client capabilities: " << *client_capabilities_;
171 174
175 CreateExtensionSessions();
Wez 2014/05/28 01:05:59 Why are we doing this here *and* in OnConnectionAu
dcaiafa 2014/05/28 22:44:58 They are the two sites where client_capabilities_
176
172 // Calculate the set of capabilities enabled by both client and host and 177 // Calculate the set of capabilities enabled by both client and host and
173 // pass it to the desktop environment if it is available. 178 // pass it to the desktop environment if it is available.
174 desktop_environment_->SetCapabilities( 179 desktop_environment_->SetCapabilities(
175 IntersectCapabilities(*client_capabilities_, host_capabilities_)); 180 IntersectCapabilities(*client_capabilities_, host_capabilities_));
176 } 181 }
177 182
178 void ClientSession::RequestPairing( 183 void ClientSession::RequestPairing(
179 const protocol::PairingRequest& pairing_request) { 184 const protocol::PairingRequest& pairing_request) {
180 if (pairing_registry_ && pairing_request.has_client_name()) { 185 if (pairing_registry_ && pairing_request.has_client_name()) {
181 protocol::PairingRegistry::Pairing pairing = 186 protocol::PairingRegistry::Pairing pairing =
(...skipping 15 matching lines...) Expand all
197 reply.set_data(message.data().substr(0, 16)); 202 reply.set_data(message.data().substr(0, 16));
198 connection_->client_stub()->DeliverHostMessage(reply); 203 connection_->client_stub()->DeliverHostMessage(reply);
199 return; 204 return;
200 } else if (message.type() == "gnubby-auth") { 205 } else if (message.type() == "gnubby-auth") {
201 if (gnubby_auth_handler_) { 206 if (gnubby_auth_handler_) {
202 gnubby_auth_handler_->DeliverClientMessage(message.data()); 207 gnubby_auth_handler_->DeliverClientMessage(message.data());
203 } else { 208 } else {
204 HOST_LOG << "gnubby auth is not enabled"; 209 HOST_LOG << "gnubby auth is not enabled";
205 } 210 }
206 return; 211 return;
212 } else {
213 for(ExtensionSessionList::iterator it = extension_sessions_.begin();
214 it != extension_sessions_.end(); ++it) {
215 // Extension returns |true| to indicate that the message was handled.
216 if ((*it)->OnExtensionMessage(this, message))
217 return;
218 }
207 } 219 }
208 } 220 }
209 HOST_LOG << "Unexpected message received: " 221 HOST_LOG << "Unexpected message received: "
210 << message.type() << ": " << message.data(); 222 << message.type() << ": " << message.data();
211 } 223 }
212 224
213 void ClientSession::OnConnectionAuthenticating( 225 void ClientSession::OnConnectionAuthenticating(
214 protocol::ConnectionToClient* connection) { 226 protocol::ConnectionToClient* connection) {
215 event_handler_->OnSessionAuthenticating(this); 227 event_handler_->OnSessionAuthenticating(this);
216 } 228 }
(...skipping 29 matching lines...) Expand all
246 258
247 // Create the desktop environment. Drop the connection if it could not be 259 // Create the desktop environment. Drop the connection if it could not be
248 // created for any reason (for instance the curtain could not initialize). 260 // created for any reason (for instance the curtain could not initialize).
249 desktop_environment_ = 261 desktop_environment_ =
250 desktop_environment_factory_->Create(control_factory_.GetWeakPtr()); 262 desktop_environment_factory_->Create(control_factory_.GetWeakPtr());
251 if (!desktop_environment_) { 263 if (!desktop_environment_) {
252 DisconnectSession(); 264 DisconnectSession();
253 return; 265 return;
254 } 266 }
255 267
268 // Compile a list of capabilities from the desktop environment and the
269 // extensions. It is formatted as a space-separated list of words.
256 host_capabilities_ = desktop_environment_->GetCapabilities(); 270 host_capabilities_ = desktop_environment_->GetCapabilities();
271 for (ExtensionList::const_iterator extension = extensions_->begin();
272 extension != extensions_->end(); ++extension) {
273 std::string extension_capabilities = (*extension)->GetCapabilities();
274 if (!extension_capabilities.empty()) {
275 if (!host_capabilities_.empty())
276 host_capabilities_.append(" ");
277
278 host_capabilities_.append(extension_capabilities);
279 }
280 }
257 281
258 // Ignore protocol::Capabilities messages from the client if it does not 282 // Ignore protocol::Capabilities messages from the client if it does not
259 // support any capabilities. 283 // support any capabilities.
260 if (!connection_->session()->config().SupportsCapabilities()) { 284 if (!connection_->session()->config().SupportsCapabilities()) {
261 VLOG(1) << "The client does not support any capabilities."; 285 VLOG(1) << "The client does not support any capabilities.";
262 286
263 client_capabilities_ = make_scoped_ptr(new std::string()); 287 client_capabilities_ = make_scoped_ptr(new std::string());
288 CreateExtensionSessions();
Wez 2014/05/28 01:05:59 Could you have the ChromotingHost add the extensio
dcaiafa 2014/05/28 22:44:58 Done.
289
264 desktop_environment_->SetCapabilities(*client_capabilities_); 290 desktop_environment_->SetCapabilities(*client_capabilities_);
265 } 291 }
266 292
267 // Create the object that controls the screen resolution. 293 // Create the object that controls the screen resolution.
268 screen_controls_ = desktop_environment_->CreateScreenControls(); 294 screen_controls_ = desktop_environment_->CreateScreenControls();
269 295
270 // Create the event executor. 296 // Create the event executor.
271 input_injector_ = desktop_environment_->CreateInputInjector(); 297 input_injector_ = desktop_environment_->CreateInputInjector();
272 298
273 // Connect the host clipboard and input stubs. 299 // Connect the host clipboard and input stubs.
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 if (audio_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) { 491 if (audio_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
466 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim()); 492 return scoped_ptr<AudioEncoder>(new AudioEncoderVerbatim());
467 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { 493 } else if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) {
468 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus()); 494 return scoped_ptr<AudioEncoder>(new AudioEncoderOpus());
469 } 495 }
470 496
471 NOTREACHED(); 497 NOTREACHED();
472 return scoped_ptr<AudioEncoder>(); 498 return scoped_ptr<AudioEncoder>();
473 } 499 }
474 500
501 void ClientSession::CreateExtensionSessions() {
502 DCHECK(extension_sessions_.empty());
503
504 for (ExtensionList::const_iterator extension = extensions_->begin();
505 extension != extensions_->end(); ++extension) {
506 extension_sessions_.push_back(
507 (*extension)->CreateExtensionSession(this).release());
508 }
509 }
510
475 } // namespace remoting 511 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698