blob: 24440d8ad6f9849b1e064c0c6bee56bc5d54e3d3 [file] [log] [blame]
[email protected]91e4b7f62012-01-25 23:23:021// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]44f60762011-03-23 12:13:352// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef REMOTING_HOST_CLIENT_SESSION_H_
6#define REMOTING_HOST_CLIENT_SESSION_H_
7
joedow4fa09d92016-06-27 21:26:178#include <cstdint>
9#include <memory>
[email protected]a5d181f2013-04-19 14:55:3710#include <string>
[email protected]c78669c92011-06-13 22:42:3811
avic5960f32015-12-22 22:49:4812#include "base/macros.h"
[email protected]170cba42012-09-12 22:28:3913#include "base/memory/ref_counted.h"
[email protected]ce404ca2013-01-16 17:23:5314#include "base/memory/weak_ptr.h"
gabbf77513a2017-06-01 14:35:3415#include "base/sequence_checker.h"
[email protected]fb441962013-05-08 05:35:2416#include "base/sequenced_task_runner_helpers.h"
[email protected]5d7eb862013-06-28 15:21:2417#include "base/time/time.h"
18#include "base/timer/timer.h"
[email protected]231316a2013-03-25 06:01:1219#include "remoting/host/client_session_control.h"
joedow4fa09d92016-06-27 21:26:1720#include "remoting/host/client_session_details.h"
zijiehe4aa6ea42016-11-12 01:28:1621#include "remoting/host/desktop_environment_options.h"
zijiehef38c9722017-02-08 02:05:2922#include "remoting/host/host_experiment_session_plugin.h"
[email protected]1b478ba2014-07-31 12:51:4323#include "remoting/host/host_extension_session_manager.h"
[email protected]86cbe6b2012-04-03 00:56:1824#include "remoting/host/remote_input_filter.h"
[email protected]ff3761a12012-05-22 22:29:2425#include "remoting/protocol/clipboard_echo_filter.h"
[email protected]34df2ab2012-08-19 06:54:2326#include "remoting/protocol/clipboard_filter.h"
[email protected]e265ad72012-03-16 17:28:0327#include "remoting/protocol/clipboard_stub.h"
[email protected]44f60762011-03-23 12:13:3528#include "remoting/protocol/connection_to_client.h"
29#include "remoting/protocol/host_stub.h"
[email protected]86cbe6b2012-04-03 00:56:1830#include "remoting/protocol/input_event_tracker.h"
31#include "remoting/protocol/input_filter.h"
32#include "remoting/protocol/input_stub.h"
sergeyua609b7a2015-11-30 06:25:3933#include "remoting/protocol/mouse_input_filter.h"
[email protected]88356922013-06-04 06:26:0134#include "remoting/protocol/pairing_registry.h"
sergeyuad51be82016-06-22 06:04:3935#include "remoting/protocol/video_stream.h"
[email protected]8c83a71c2013-12-16 18:02:5836#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
[email protected]44f60762011-03-23 12:13:3537
[email protected]44f60762011-03-23 12:13:3538namespace remoting {
39
sergeyucd16e2062016-09-12 19:28:3540class AudioStream;
[email protected]170cba42012-09-12 22:28:3941class DesktopEnvironment;
[email protected]81904792012-10-18 04:16:2842class DesktopEnvironmentFactory;
[email protected]b0b72f112013-03-24 03:42:4243class InputInjector;
sergeyu1afb35a12015-02-13 18:45:3044class MouseShapePump;
[email protected]231316a2013-03-25 06:01:1245class ScreenControls;
sergeyu4d208002015-11-23 22:27:4346
sergeyu9102cff2016-04-07 19:14:0147namespace protocol {
48class VideoLayout;
49} // namespace protocol
50
[email protected]44f60762011-03-23 12:13:3551// A ClientSession keeps a reference to a connection to a client, and maintains
52// per-client state.
gabbf77513a2017-06-01 14:35:3453class ClientSession : public protocol::HostStub,
sergeyu9102cff2016-04-07 19:14:0154 public protocol::ConnectionToClient::EventHandler,
sergeyuad51be82016-06-22 06:04:3955 public protocol::VideoStream::Observer,
joedow4fa09d92016-06-27 21:26:1756 public ClientSessionControl,
57 public ClientSessionDetails {
[email protected]44f60762011-03-23 12:13:3558 public:
59 // Callback interface for passing events to the ChromotingHost.
60 class EventHandler {
61 public:
[email protected]064128c2014-04-07 22:33:2862 // Called after authentication has started.
63 virtual void OnSessionAuthenticating(ClientSession* client) = 0;
64
sergeyu21c899e2015-11-24 16:39:5565 // Called after authentication has finished successfully.
66 virtual void OnSessionAuthenticated(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5967
[email protected]cba6f812012-03-27 01:01:5068 // Called after we've finished connecting all channels.
69 virtual void OnSessionChannelsConnected(ClientSession* client) = 0;
70
[email protected]1f249e22011-11-29 20:19:5971 // Called after authentication has failed. Must not tear down this
72 // object. OnSessionClosed() is notified after this handler
73 // returns.
74 virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
75
76 // Called after connection has failed or after the client closed it.
[email protected]ee910fd2011-11-10 18:23:3177 virtual void OnSessionClosed(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5978
[email protected]91e4b7f62012-01-25 23:23:0279 // Called on notification of a route change event, when a channel is
80 // connected.
[email protected]17af2ab2012-02-02 04:07:5281 virtual void OnSessionRouteChange(
82 ClientSession* client,
83 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:4784 const protocol::TransportRoute& route) = 0;
[email protected]512d03f2012-06-26 01:06:0685
86 protected:
87 virtual ~EventHandler() {}
[email protected]44f60762011-03-23 12:13:3588 };
89
[email protected]233bb942013-03-15 07:18:1790 // |event_handler| and |desktop_environment_factory| must outlive |this|.
[email protected]1b478ba2014-07-31 12:51:4391 // All |HostExtension|s in |extensions| must outlive |this|.
sergeyu85df3c482016-02-15 05:59:0892 ClientSession(EventHandler* event_handler,
dcheng0765c492016-04-06 22:41:5393 std::unique_ptr<protocol::ConnectionToClient> connection,
sergeyu85df3c482016-02-15 05:59:0894 DesktopEnvironmentFactory* desktop_environment_factory,
zijiehe4aa6ea42016-11-12 01:28:1695 const DesktopEnvironmentOptions& desktop_environment_options,
sergeyu85df3c482016-02-15 05:59:0896 const base::TimeDelta& max_duration,
97 scoped_refptr<protocol::PairingRegistry> pairing_registry,
98 const std::vector<HostExtension*>& extensions);
dcheng562aba52014-10-21 12:30:1499 ~ClientSession() override;
[email protected]44f60762011-03-23 12:13:35100
[email protected]1b478ba2014-07-31 12:51:43101 // Returns the set of capabilities negotiated between client and host.
102 const std::string& capabilities() const { return capabilities_; }
[email protected]399b4f62014-05-30 20:13:15103
[email protected]f2b9cf32012-04-27 00:13:43104 // protocol::HostStub interface.
dcheng562aba52014-10-21 12:30:14105 void NotifyClientResolution(
mostynb11d989c2014-10-08 16:58:09106 const protocol::ClientResolution& resolution) override;
dcheng562aba52014-10-21 12:30:14107 void ControlVideo(const protocol::VideoControl& video_control) override;
108 void ControlAudio(const protocol::AudioControl& audio_control) override;
109 void SetCapabilities(const protocol::Capabilities& capabilities) override;
110 void RequestPairing(
mostynb11d989c2014-10-08 16:58:09111 const remoting::protocol::PairingRequest& pairing_request) override;
dcheng562aba52014-10-21 12:30:14112 void DeliverClientMessage(const protocol::ExtensionMessage& message) override;
[email protected]f2b9cf32012-04-27 00:13:43113
[email protected]ee910fd2011-11-10 18:23:31114 // protocol::ConnectionToClient::EventHandler interface.
sergeyu4e1f4cd2016-09-27 00:42:52115 void OnConnectionAuthenticating() override;
116 void OnConnectionAuthenticated() override;
117 void CreateMediaStreams() override;
118 void OnConnectionChannelsConnected() override;
119 void OnConnectionClosed(protocol::ErrorCode error) override;
sergeyu4e1f4cd2016-09-27 00:42:52120 void OnRouteChange(const std::string& channel_name,
dcheng562aba52014-10-21 12:30:14121 const protocol::TransportRoute& route) override;
[email protected]44f60762011-03-23 12:13:35122
[email protected]231316a2013-03-25 06:01:12123 // ClientSessionControl interface.
dcheng562aba52014-10-21 12:30:14124 const std::string& client_jid() const override;
sergeyuec77d8542015-11-03 22:31:00125 void DisconnectSession(protocol::ErrorCode error) override;
dcheng562aba52014-10-21 12:30:14126 void OnLocalMouseMoved(const webrtc::DesktopVector& position) override;
127 void SetDisableInputs(bool disable_inputs) override;
[email protected]1ce457a2011-05-19 19:59:48128
joedow4fa09d92016-06-27 21:26:17129 // ClientSessionDetails interface.
130 uint32_t desktop_session_id() const override;
131 ClientSessionControl* session_control() override;
132
sergeyu6ad12dc2016-04-02 00:01:32133 protocol::ConnectionToClient* connection() const { return connection_.get(); }
[email protected]44f60762011-03-23 12:13:35134
sergeyu6ad12dc2016-04-02 00:01:32135 bool is_authenticated() { return is_authenticated_; }
[email protected]dda4da3b2012-05-22 00:51:26136
[email protected]399b4f62014-05-30 20:13:15137 const std::string* client_capabilities() const {
138 return client_capabilities_.get();
139 }
140
sergeyub047307a2016-10-18 17:19:29141 void SetEventTimestampsSourceForTests(
142 scoped_refptr<protocol::InputEventTimestampsSource>
143 event_timestamp_source);
144
[email protected]170cba42012-09-12 22:28:39145 private:
[email protected]7f44ba42012-05-31 20:26:29146 // Creates a proxy for sending clipboard events to the client.
dcheng0765c492016-04-06 22:41:53147 std::unique_ptr<protocol::ClipboardStub> CreateClipboardProxy();
[email protected]7f44ba42012-05-31 20:26:29148
sergeyuad51be82016-06-22 06:04:39149 // protocol::VideoStream::Observer implementation.
150 void OnVideoSizeChanged(protocol::VideoStream* stream,
151 const webrtc::DesktopSize& size,
152 const webrtc::DesktopVector& dpi) override;
sergeyua609b7a2015-11-30 06:25:39153
[email protected]44f60762011-03-23 12:13:35154 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06155
[email protected]4ea2c7c2011-03-31 14:20:06156 // The connection to the client.
dcheng0765c492016-04-06 22:41:53157 std::unique_ptr<protocol::ConnectionToClient> connection_;
[email protected]44f60762011-03-23 12:13:35158
[email protected]ce404ca2013-01-16 17:23:53159 std::string client_jid_;
160
[email protected]233bb942013-03-15 07:18:17161 // Used to create a DesktopEnvironment instance for this session.
162 DesktopEnvironmentFactory* desktop_environment_factory_;
[email protected]170cba42012-09-12 22:28:39163
zijiehe4aa6ea42016-11-12 01:28:16164 // The DesktopEnvironmentOptions used to initialize DesktopEnvironment.
165 DesktopEnvironmentOptions desktop_environment_options_;
166
[email protected]231316a2013-03-25 06:01:12167 // The DesktopEnvironment instance for this session.
dcheng0765c492016-04-06 22:41:53168 std::unique_ptr<DesktopEnvironment> desktop_environment_;
[email protected]231316a2013-03-25 06:01:12169
[email protected]eccc2d42013-01-10 19:35:14170 // Filter used as the final element in the input pipeline.
171 protocol::InputFilter host_input_filter_;
[email protected]4ea2c7c2011-03-31 14:20:06172
[email protected]86cbe6b2012-04-03 00:56:18173 // Tracker used to release pressed keys and buttons when disconnecting.
174 protocol::InputEventTracker input_tracker_;
175
176 // Filter used to disable remote inputs during local input activity.
177 RemoteInputFilter remote_input_filter_;
178
[email protected]f5d62e362012-04-30 20:54:37179 // Filter used to clamp mouse events to the current display dimensions.
sergeyua609b7a2015-11-30 06:25:39180 protocol::MouseInputFilter mouse_clamping_filter_;
[email protected]f5d62e362012-04-30 20:54:37181
[email protected]750ae6b2012-08-20 22:52:40182 // Filter to used to stop clipboard items sent from the client being echoed
[email protected]eccc2d42013-01-10 19:35:14183 // back to it. It is the final element in the clipboard (client -> host)
184 // pipeline.
[email protected]750ae6b2012-08-20 22:52:40185 protocol::ClipboardEchoFilter clipboard_echo_filter_;
186
[email protected]34df2ab2012-08-19 06:54:23187 // Filters used to manage enabling & disabling of input & clipboard.
[email protected]86cbe6b2012-04-03 00:56:18188 protocol::InputFilter disable_input_filter_;
[email protected]34df2ab2012-08-19 06:54:23189 protocol::ClipboardFilter disable_clipboard_filter_;
[email protected]86cbe6b2012-04-03 00:56:18190
[email protected]7f44ba42012-05-31 20:26:29191 // Factory for weak pointers to the client clipboard stub.
192 // This must appear after |clipboard_echo_filter_|, so that it won't outlive
193 // it.
[email protected]34df2ab2012-08-19 06:54:23194 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_;
[email protected]7f44ba42012-05-31 20:26:29195
[email protected]5dc5b12a2012-06-23 01:05:14196 // The maximum duration of this session.
197 // There is no maximum if this value is <= 0.
198 base::TimeDelta max_duration_;
199
200 // A timer that triggers a disconnect when the maximum session duration
201 // is reached.
danakj8c3eb802015-09-24 07:53:00202 base::OneShotTimer max_duration_timer_;
[email protected]5dc5b12a2012-06-23 01:05:14203
sergeyua609b7a2015-11-30 06:25:39204 // Objects responsible for sending video, audio and mouse shape.
dcheng0765c492016-04-06 22:41:53205 std::unique_ptr<protocol::VideoStream> video_stream_;
sergeyucd16e2062016-09-12 19:28:35206 std::unique_ptr<protocol::AudioStream> audio_stream_;
dcheng0765c492016-04-06 22:41:53207 std::unique_ptr<MouseShapePump> mouse_shape_pump_;
[email protected]170cba42012-09-12 22:28:39208
[email protected]a5d181f2013-04-19 14:55:37209 // The set of all capabilities supported by the client.
dcheng0765c492016-04-06 22:41:53210 std::unique_ptr<std::string> client_capabilities_;
[email protected]a5d181f2013-04-19 14:55:37211
212 // The set of all capabilities supported by the host.
213 std::string host_capabilities_;
214
[email protected]1b478ba2014-07-31 12:51:43215 // The set of all capabilities negotiated between client and host.
216 std::string capabilities_;
217
[email protected]b0b72f112013-03-24 03:42:42218 // Used to inject mouse and keyboard input and handle clipboard events.
dcheng0765c492016-04-06 22:41:53219 std::unique_ptr<InputInjector> input_injector_;
[email protected]170cba42012-09-12 22:28:39220
[email protected]6f526ce2013-03-18 04:38:56221 // Used to apply client-requested changes in screen resolution.
dcheng0765c492016-04-06 22:41:53222 std::unique_ptr<ScreenControls> screen_controls_;
[email protected]61cfdc52013-03-09 03:04:56223
[email protected]88356922013-06-04 06:26:01224 // The pairing registry for PIN-less authentication.
225 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
226
[email protected]1b478ba2014-07-31 12:51:43227 // Used to manage extension functionality.
dcheng0765c492016-04-06 22:41:53228 std::unique_ptr<HostExtensionSessionManager> extension_manager_;
[email protected]1b478ba2014-07-31 12:51:43229
sergeyu1f8cd502015-02-13 21:45:53230 // Set to true if the client was authenticated successfully.
sergeyu9102cff2016-04-07 19:14:01231 bool is_authenticated_ = false;
232
233 // Set to true after all data channels have been connected.
234 bool channels_connected_ = false;
sergeyu1f8cd502015-02-13 21:45:53235
[email protected]1b478ba2014-07-31 12:51:43236 // Used to store video channel pause & lossless parameters.
sergeyu9102cff2016-04-07 19:14:01237 bool pause_video_ = false;
238 bool lossless_video_encode_ = false;
239 bool lossless_video_color_ = false;
240
241 // VideoLayout is sent only after the control channel is connected. Until
242 // then it's stored in |pending_video_layout_message_|.
243 std::unique_ptr<protocol::VideoLayout> pending_video_layout_message_;
[email protected]399b4f62014-05-30 20:13:15244
sergeyub047307a2016-10-18 17:19:29245 scoped_refptr<protocol::InputEventTimestampsSource>
246 event_timestamp_source_for_tests_;
247
zijiehef38c9722017-02-08 02:05:29248 HostExperimentSessionPlugin host_experiment_session_plugin_;
249
gabbf77513a2017-06-01 14:35:34250 SEQUENCE_CHECKER(sequence_checker_);
251
kulkarni.a933aeaf2014-09-20 13:19:17252 // Used to disable callbacks to |this| once DisconnectSession() has been
253 // called.
254 base::WeakPtrFactory<ClientSessionControl> weak_factory_;
255
[email protected]44f60762011-03-23 12:13:35256 DISALLOW_COPY_AND_ASSIGN(ClientSession);
257};
258
[email protected]44f60762011-03-23 12:13:35259} // namespace remoting
260
261#endif // REMOTING_HOST_CLIENT_SESSION_H_