blob: 4c32a622478899150f2bb16b6dc266bc02b57a1f [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"
Jamie Walch044a8cd382020-02-04 00:27:4021#include "remoting/host/desktop_and_cursor_conditional_composer.h"
Gary Kacmarcikebe85a812019-01-23 20:11:5422#include "remoting/host/desktop_display_info.h"
zijiehe4aa6ea42016-11-12 01:28:1623#include "remoting/host/desktop_environment_options.h"
zijiehef38c9722017-02-08 02:05:2924#include "remoting/host/host_experiment_session_plugin.h"
[email protected]1b478ba2014-07-31 12:51:4325#include "remoting/host/host_extension_session_manager.h"
Jamie Walchc3b6126f2020-01-27 22:34:5026#include "remoting/host/pointer_lock_detector.h"
[email protected]86cbe6b2012-04-03 00:56:1827#include "remoting/host/remote_input_filter.h"
Joe Downingb511e4a92018-11-16 21:10:1328#include "remoting/proto/action.pb.h"
[email protected]ff3761a12012-05-22 22:29:2429#include "remoting/protocol/clipboard_echo_filter.h"
[email protected]34df2ab2012-08-19 06:54:2330#include "remoting/protocol/clipboard_filter.h"
[email protected]e265ad72012-03-16 17:28:0331#include "remoting/protocol/clipboard_stub.h"
[email protected]44f60762011-03-23 12:13:3532#include "remoting/protocol/connection_to_client.h"
Joseph Arhar5f69f392017-07-01 00:33:2033#include "remoting/protocol/data_channel_manager.h"
Gary Kacmarcikfe08e312019-09-13 23:04:0434#include "remoting/protocol/display_size.h"
[email protected]44f60762011-03-23 12:13:3535#include "remoting/protocol/host_stub.h"
[email protected]86cbe6b2012-04-03 00:56:1836#include "remoting/protocol/input_event_tracker.h"
37#include "remoting/protocol/input_filter.h"
38#include "remoting/protocol/input_stub.h"
sergeyua609b7a2015-11-30 06:25:3939#include "remoting/protocol/mouse_input_filter.h"
[email protected]88356922013-06-04 06:26:0140#include "remoting/protocol/pairing_registry.h"
sergeyuad51be82016-06-22 06:04:3941#include "remoting/protocol/video_stream.h"
Gary Kacmarcikebe85a812019-01-23 20:11:5442#include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h"
[email protected]8c83a71c2013-12-16 18:02:5843#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
Jamie Walch758a02d92020-01-28 01:32:1344#include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
Jamie Walchc3b6126f2020-01-27 22:34:5045#include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
Jamie Walch6e3a42292019-05-03 02:19:2146#include "ui/events/event.h"
[email protected]44f60762011-03-23 12:13:3547
48namespace remoting {
49
sergeyucd16e2062016-09-12 19:28:3550class AudioStream;
[email protected]170cba42012-09-12 22:28:3951class DesktopEnvironment;
[email protected]81904792012-10-18 04:16:2852class DesktopEnvironmentFactory;
[email protected]b0b72f112013-03-24 03:42:4253class InputInjector;
Erik Jensenb8876672019-12-03 04:30:0554class KeyboardLayoutMonitor;
sergeyu1afb35a12015-02-13 18:45:3055class MouseShapePump;
[email protected]231316a2013-03-25 06:01:1256class ScreenControls;
sergeyu4d208002015-11-23 22:27:4357
sergeyu9102cff2016-04-07 19:14:0158namespace protocol {
59class VideoLayout;
60} // namespace protocol
61
[email protected]44f60762011-03-23 12:13:3562// A ClientSession keeps a reference to a connection to a client, and maintains
63// per-client state.
gabbf77513a2017-06-01 14:35:3464class ClientSession : public protocol::HostStub,
sergeyu9102cff2016-04-07 19:14:0165 public protocol::ConnectionToClient::EventHandler,
sergeyuad51be82016-06-22 06:04:3966 public protocol::VideoStream::Observer,
joedow4fa09d92016-06-27 21:26:1767 public ClientSessionControl,
Jamie Walchc3b6126f2020-01-27 22:34:5068 public ClientSessionDetails,
Jamie Walch758a02d92020-01-28 01:32:1369 public PointerLockDetector::EventHandler,
70 public webrtc::MouseCursorMonitor::Callback {
[email protected]44f60762011-03-23 12:13:3571 public:
72 // Callback interface for passing events to the ChromotingHost.
73 class EventHandler {
74 public:
[email protected]064128c2014-04-07 22:33:2875 // Called after authentication has started.
76 virtual void OnSessionAuthenticating(ClientSession* client) = 0;
77
sergeyu21c899e2015-11-24 16:39:5578 // Called after authentication has finished successfully.
79 virtual void OnSessionAuthenticated(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5980
[email protected]cba6f812012-03-27 01:01:5081 // Called after we've finished connecting all channels.
82 virtual void OnSessionChannelsConnected(ClientSession* client) = 0;
83
[email protected]1f249e22011-11-29 20:19:5984 // Called after authentication has failed. Must not tear down this
85 // object. OnSessionClosed() is notified after this handler
86 // returns.
87 virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
88
89 // Called after connection has failed or after the client closed it.
[email protected]ee910fd2011-11-10 18:23:3190 virtual void OnSessionClosed(ClientSession* client) = 0;
[email protected]1f249e22011-11-29 20:19:5991
[email protected]91e4b7f62012-01-25 23:23:0292 // Called on notification of a route change event, when a channel is
93 // connected.
[email protected]17af2ab2012-02-02 04:07:5294 virtual void OnSessionRouteChange(
95 ClientSession* client,
96 const std::string& channel_name,
[email protected]be451c82012-03-20 22:24:4797 const protocol::TransportRoute& route) = 0;
[email protected]512d03f2012-06-26 01:06:0698
99 protected:
100 virtual ~EventHandler() {}
[email protected]44f60762011-03-23 12:13:35101 };
102
[email protected]233bb942013-03-15 07:18:17103 // |event_handler| and |desktop_environment_factory| must outlive |this|.
[email protected]1b478ba2014-07-31 12:51:43104 // All |HostExtension|s in |extensions| must outlive |this|.
Joseph Arhar5f69f392017-07-01 00:33:20105 ClientSession(
106 EventHandler* event_handler,
107 std::unique_ptr<protocol::ConnectionToClient> connection,
108 DesktopEnvironmentFactory* desktop_environment_factory,
109 const DesktopEnvironmentOptions& desktop_environment_options,
110 const base::TimeDelta& max_duration,
111 scoped_refptr<protocol::PairingRegistry> pairing_registry,
zijieheb7da62422017-07-11 01:17:15112 const std::vector<HostExtension*>& extensions);
dcheng562aba52014-10-21 12:30:14113 ~ClientSession() override;
[email protected]44f60762011-03-23 12:13:35114
[email protected]1b478ba2014-07-31 12:51:43115 // Returns the set of capabilities negotiated between client and host.
116 const std::string& capabilities() const { return capabilities_; }
[email protected]399b4f62014-05-30 20:13:15117
[email protected]f2b9cf32012-04-27 00:13:43118 // protocol::HostStub interface.
dcheng562aba52014-10-21 12:30:14119 void NotifyClientResolution(
mostynb11d989c2014-10-08 16:58:09120 const protocol::ClientResolution& resolution) override;
dcheng562aba52014-10-21 12:30:14121 void ControlVideo(const protocol::VideoControl& video_control) override;
122 void ControlAudio(const protocol::AudioControl& audio_control) override;
123 void SetCapabilities(const protocol::Capabilities& capabilities) override;
124 void RequestPairing(
mostynb11d989c2014-10-08 16:58:09125 const remoting::protocol::PairingRequest& pairing_request) override;
dcheng562aba52014-10-21 12:30:14126 void DeliverClientMessage(const protocol::ExtensionMessage& message) override;
Gary Kacmarcik0c56fda2019-01-17 03:10:12127 void SelectDesktopDisplay(
128 const protocol::SelectDesktopDisplayRequest& select_display) override;
Yuwei Huangef530072020-06-19 02:33:44129 void ControlPeerConnection(
130 const protocol::PeerConnectionParameters& parameters) override;
[email protected]f2b9cf32012-04-27 00:13:43131
[email protected]ee910fd2011-11-10 18:23:31132 // protocol::ConnectionToClient::EventHandler interface.
sergeyu4e1f4cd2016-09-27 00:42:52133 void OnConnectionAuthenticating() override;
134 void OnConnectionAuthenticated() override;
135 void CreateMediaStreams() override;
136 void OnConnectionChannelsConnected() override;
137 void OnConnectionClosed(protocol::ErrorCode error) override;
Yuwei Huangcf7fdff2020-05-04 19:46:43138 void OnTransportProtocolChange(const std::string& protocol) override;
sergeyu4e1f4cd2016-09-27 00:42:52139 void OnRouteChange(const std::string& channel_name,
dcheng562aba52014-10-21 12:30:14140 const protocol::TransportRoute& route) override;
Joseph Arhar5f69f392017-07-01 00:33:20141 void OnIncomingDataChannel(
142 const std::string& channel_name,
143 std::unique_ptr<protocol::MessagePipe> pipe) override;
[email protected]44f60762011-03-23 12:13:35144
[email protected]231316a2013-03-25 06:01:12145 // ClientSessionControl interface.
dcheng562aba52014-10-21 12:30:14146 const std::string& client_jid() const override;
sergeyuec77d8542015-11-03 22:31:00147 void DisconnectSession(protocol::ErrorCode error) override;
Jamie Walchf297c512019-08-20 21:09:11148 void OnLocalKeyPressed(uint32_t usb_keycode) override;
Jamie Walch6e3a42292019-05-03 02:19:21149 void OnLocalPointerMoved(const webrtc::DesktopVector& position,
150 ui::EventType type) override;
dcheng562aba52014-10-21 12:30:14151 void SetDisableInputs(bool disable_inputs) override;
Gary Kacmarcik91f5ed42018-11-29 22:24:14152 void OnDesktopDisplayChanged(
153 std::unique_ptr<protocol::VideoLayout> layout) override;
[email protected]1ce457a2011-05-19 19:59:48154
joedow4fa09d92016-06-27 21:26:17155 // ClientSessionDetails interface.
156 uint32_t desktop_session_id() const override;
157 ClientSessionControl* session_control() override;
158
Jamie Walchc3b6126f2020-01-27 22:34:50159 // PointerLockDetector::EventHandler interface
160 void OnPointerLockChanged(bool active) override;
161
Jamie Walch758a02d92020-01-28 01:32:13162 // webrtc::MouseCursorMonitor::Callback implementation.
163 void OnMouseCursor(webrtc::MouseCursor* mouse_cursor) override;
164 void OnMouseCursorPosition(const webrtc::DesktopVector& position) override;
165
sergeyu6ad12dc2016-04-02 00:01:32166 protocol::ConnectionToClient* connection() const { return connection_.get(); }
[email protected]44f60762011-03-23 12:13:35167
sergeyu6ad12dc2016-04-02 00:01:32168 bool is_authenticated() { return is_authenticated_; }
[email protected]dda4da3b2012-05-22 00:51:26169
[email protected]399b4f62014-05-30 20:13:15170 const std::string* client_capabilities() const {
171 return client_capabilities_.get();
172 }
173
zijieheb7da62422017-07-11 01:17:15174 // Registers a DataChannelManager callback for testing.
175 void RegisterCreateHandlerCallbackForTesting(
176 const std::string& prefix,
177 protocol::DataChannelManager::CreateHandlerCallback constructor);
178
sergeyub047307a2016-10-18 17:19:29179 void SetEventTimestampsSourceForTests(
180 scoped_refptr<protocol::InputEventTimestampsSource>
181 event_timestamp_source);
182
Gary Kacmarcik72307922019-05-22 02:48:47183 // Public for tests.
184 void UpdateMouseClampingFilterOffset();
185
[email protected]170cba42012-09-12 22:28:39186 private:
[email protected]7f44ba42012-05-31 20:26:29187 // Creates a proxy for sending clipboard events to the client.
dcheng0765c492016-04-06 22:41:53188 std::unique_ptr<protocol::ClipboardStub> CreateClipboardProxy();
[email protected]7f44ba42012-05-31 20:26:29189
Gary Kacmarcikfe08e312019-09-13 23:04:04190 void SetMouseClampingFilter(const DisplaySize& size);
Gary Kacmarcik72307922019-05-22 02:48:47191
sergeyuad51be82016-06-22 06:04:39192 // protocol::VideoStream::Observer implementation.
193 void OnVideoSizeChanged(protocol::VideoStream* stream,
194 const webrtc::DesktopSize& size,
195 const webrtc::DesktopVector& dpi) override;
sergeyua609b7a2015-11-30 06:25:39196
Joe Downingb511e4a92018-11-16 21:10:13197 void CreateActionMessageHandler(
198 std::vector<protocol::ActionRequest::Action> capabilities,
199 const std::string& channel_name,
200 std::unique_ptr<protocol::MessagePipe> pipe);
201
Joseph Arhar91537d52017-08-14 22:31:10202 void CreateFileTransferMessageHandler(
203 const std::string& channel_name,
204 std::unique_ptr<protocol::MessagePipe> pipe);
205
[email protected]44f60762011-03-23 12:13:35206 EventHandler* event_handler_;
[email protected]4ea2c7c2011-03-31 14:20:06207
[email protected]233bb942013-03-15 07:18:17208 // Used to create a DesktopEnvironment instance for this session.
209 DesktopEnvironmentFactory* desktop_environment_factory_;
[email protected]170cba42012-09-12 22:28:39210
zijiehe4aa6ea42016-11-12 01:28:16211 // The DesktopEnvironmentOptions used to initialize DesktopEnvironment.
212 DesktopEnvironmentOptions desktop_environment_options_;
213
[email protected]231316a2013-03-25 06:01:12214 // The DesktopEnvironment instance for this session.
dcheng0765c492016-04-06 22:41:53215 std::unique_ptr<DesktopEnvironment> desktop_environment_;
[email protected]231316a2013-03-25 06:01:12216
[email protected]eccc2d42013-01-10 19:35:14217 // Filter used as the final element in the input pipeline.
218 protocol::InputFilter host_input_filter_;
[email protected]4ea2c7c2011-03-31 14:20:06219
[email protected]86cbe6b2012-04-03 00:56:18220 // Tracker used to release pressed keys and buttons when disconnecting.
221 protocol::InputEventTracker input_tracker_;
222
223 // Filter used to disable remote inputs during local input activity.
224 RemoteInputFilter remote_input_filter_;
225
[email protected]f5d62e362012-04-30 20:54:37226 // Filter used to clamp mouse events to the current display dimensions.
sergeyua609b7a2015-11-30 06:25:39227 protocol::MouseInputFilter mouse_clamping_filter_;
[email protected]f5d62e362012-04-30 20:54:37228
Jamie Walchc3b6126f2020-01-27 22:34:50229 // Filter used to detect transitions into and out of client-side pointer lock.
230 PointerLockDetector pointer_lock_detector_;
231
[email protected]750ae6b2012-08-20 22:52:40232 // Filter to used to stop clipboard items sent from the client being echoed
[email protected]eccc2d42013-01-10 19:35:14233 // back to it. It is the final element in the clipboard (client -> host)
234 // pipeline.
[email protected]750ae6b2012-08-20 22:52:40235 protocol::ClipboardEchoFilter clipboard_echo_filter_;
236
[email protected]34df2ab2012-08-19 06:54:23237 // Filters used to manage enabling & disabling of input & clipboard.
[email protected]86cbe6b2012-04-03 00:56:18238 protocol::InputFilter disable_input_filter_;
[email protected]34df2ab2012-08-19 06:54:23239 protocol::ClipboardFilter disable_clipboard_filter_;
[email protected]86cbe6b2012-04-03 00:56:18240
[email protected]7f44ba42012-05-31 20:26:29241 // Factory for weak pointers to the client clipboard stub.
242 // This must appear after |clipboard_echo_filter_|, so that it won't outlive
243 // it.
[email protected]34df2ab2012-08-19 06:54:23244 base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_;
[email protected]7f44ba42012-05-31 20:26:29245
[email protected]5dc5b12a2012-06-23 01:05:14246 // The maximum duration of this session.
247 // There is no maximum if this value is <= 0.
248 base::TimeDelta max_duration_;
249
250 // A timer that triggers a disconnect when the maximum session duration
251 // is reached.
danakj8c3eb802015-09-24 07:53:00252 base::OneShotTimer max_duration_timer_;
[email protected]5dc5b12a2012-06-23 01:05:14253
Erik Jensenc08ecf112019-12-19 00:29:49254 // Objects responsible for sending video, audio.
dcheng0765c492016-04-06 22:41:53255 std::unique_ptr<protocol::VideoStream> video_stream_;
sergeyucd16e2062016-09-12 19:28:35256 std::unique_ptr<protocol::AudioStream> audio_stream_;
[email protected]170cba42012-09-12 22:28:39257
[email protected]a5d181f2013-04-19 14:55:37258 // The set of all capabilities supported by the client.
dcheng0765c492016-04-06 22:41:53259 std::unique_ptr<std::string> client_capabilities_;
[email protected]a5d181f2013-04-19 14:55:37260
261 // The set of all capabilities supported by the host.
262 std::string host_capabilities_;
263
[email protected]1b478ba2014-07-31 12:51:43264 // The set of all capabilities negotiated between client and host.
265 std::string capabilities_;
266
[email protected]b0b72f112013-03-24 03:42:42267 // Used to inject mouse and keyboard input and handle clipboard events.
dcheng0765c492016-04-06 22:41:53268 std::unique_ptr<InputInjector> input_injector_;
[email protected]170cba42012-09-12 22:28:39269
[email protected]6f526ce2013-03-18 04:38:56270 // Used to apply client-requested changes in screen resolution.
dcheng0765c492016-04-06 22:41:53271 std::unique_ptr<ScreenControls> screen_controls_;
[email protected]61cfdc52013-03-09 03:04:56272
Gary Kacmarcikebe85a812019-01-23 20:11:54273 // Contains the most recently gathered info about the desktop displays;
274 DesktopDisplayInfo desktop_display_info_;
275
Gary Kacmarcike555ea6f2019-05-15 17:19:56276 // Default DPI values to use if a display reports 0 for DPI.
277 int default_x_dpi_;
278 int default_y_dpi_;
279
Gary Kacmarcikebe85a812019-01-23 20:11:54280 // The id of the desktop display to show to the user.
Gary Kacmarcik5dac99c2020-03-05 22:55:40281 // Default is webrtc::kInvalidScreenScreenId because we need to perform
282 // an initial capture to determine if the current setup support capturing
283 // the entire desktop or if it is restricted to a single display.
284 webrtc::ScreenId show_display_id_ = webrtc::kInvalidScreenId;
285
286 // The initial video size captured by WebRTC.
287 // This will be the full desktop unless webrtc cannot capture the entire
288 // desktop (e.g., because the DPIs don't match). In that case, it will
289 // be equal to the dimensions of the default display.
290 DisplaySize default_webrtc_desktop_size_;
291
292 // The current size of the area being captured by webrtc. This will be
293 // equal to the size of the entire desktop, or to a single display.
294 DisplaySize webrtc_capture_size_;
295
296 // Set to true if the current display configuration supports capturing the
297 // entire desktop.
298 bool can_capture_full_desktop_ = true;
Gary Kacmarcikebe85a812019-01-23 20:11:54299
[email protected]88356922013-06-04 06:26:01300 // The pairing registry for PIN-less authentication.
301 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
302
Joseph Arhar5f69f392017-07-01 00:33:20303 // Used to dispatch new data channels to factory methods.
304 protocol::DataChannelManager data_channel_manager_;
305
sergeyu1f8cd502015-02-13 21:45:53306 // Set to true if the client was authenticated successfully.
sergeyu9102cff2016-04-07 19:14:01307 bool is_authenticated_ = false;
308
309 // Set to true after all data channels have been connected.
310 bool channels_connected_ = false;
sergeyu1f8cd502015-02-13 21:45:53311
[email protected]1b478ba2014-07-31 12:51:43312 // Used to store video channel pause & lossless parameters.
sergeyu9102cff2016-04-07 19:14:01313 bool pause_video_ = false;
314 bool lossless_video_encode_ = false;
315 bool lossless_video_color_ = false;
316
317 // VideoLayout is sent only after the control channel is connected. Until
318 // then it's stored in |pending_video_layout_message_|.
319 std::unique_ptr<protocol::VideoLayout> pending_video_layout_message_;
[email protected]399b4f62014-05-30 20:13:15320
sergeyub047307a2016-10-18 17:19:29321 scoped_refptr<protocol::InputEventTimestampsSource>
322 event_timestamp_source_for_tests_;
323
zijiehef38c9722017-02-08 02:05:29324 HostExperimentSessionPlugin host_experiment_session_plugin_;
325
Erik Jensenc08ecf112019-12-19 00:29:49326 // The connection to the client.
327 std::unique_ptr<protocol::ConnectionToClient> connection_;
328
329 std::string client_jid_;
330
331 // Used to manage extension functionality.
332 std::unique_ptr<HostExtensionSessionManager> extension_manager_;
333
334 // Objects to monitor and send updates for mouse shape and keyboard layout.
335 std::unique_ptr<MouseShapePump> mouse_shape_pump_;
336 std::unique_ptr<KeyboardLayoutMonitor> keyboard_layout_monitor_;
337
Jamie Walch044a8cd382020-02-04 00:27:40338 base::WeakPtr<DesktopAndCursorConditionalComposer>
339 desktop_and_cursor_composer_;
Jamie Walch758a02d92020-01-28 01:32:13340
gabbf77513a2017-06-01 14:35:34341 SEQUENCE_CHECKER(sequence_checker_);
342
kulkarni.a933aeaf2014-09-20 13:19:17343 // Used to disable callbacks to |this| once DisconnectSession() has been
344 // called.
Jeremy Roman7c5cfabd2019-08-12 15:45:27345 base::WeakPtrFactory<ClientSessionControl> weak_factory_{this};
kulkarni.a933aeaf2014-09-20 13:19:17346
[email protected]44f60762011-03-23 12:13:35347 DISALLOW_COPY_AND_ASSIGN(ClientSession);
348};
349
[email protected]44f60762011-03-23 12:13:35350} // namespace remoting
351
352#endif // REMOTING_HOST_CLIENT_SESSION_H_