123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434 |
- // Copyright (c) 2012 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef REMOTING_HOST_CLIENT_SESSION_H_
- #define REMOTING_HOST_CLIENT_SESSION_H_
- #include <cstdint>
- #include <map>
- #include <memory>
- #include <string>
- #include <vector>
- #include "base/memory/raw_ptr.h"
- #include "base/memory/ref_counted.h"
- #include "base/memory/weak_ptr.h"
- #include "base/sequence_checker.h"
- #include "base/task/sequenced_task_runner_helpers.h"
- #include "base/time/time.h"
- #include "base/timer/timer.h"
- #include "mojo/public/cpp/bindings/pending_receiver.h"
- #include "mojo/public/cpp/bindings/receiver_set.h"
- #include "remoting/host/base/desktop_environment_options.h"
- #include "remoting/host/client_session_control.h"
- #include "remoting/host/client_session_details.h"
- #include "remoting/host/client_session_events.h"
- #include "remoting/host/desktop_and_cursor_composer_notifier.h"
- #include "remoting/host/desktop_and_cursor_conditional_composer.h"
- #include "remoting/host/desktop_display_info.h"
- #include "remoting/host/host_experiment_session_plugin.h"
- #include "remoting/host/host_extension_session_manager.h"
- #include "remoting/host/mojom/chromoting_host_services.mojom.h"
- #include "remoting/host/mojom/webauthn_proxy.mojom.h"
- #include "remoting/host/remote_input_filter.h"
- #include "remoting/proto/action.pb.h"
- #include "remoting/protocol/clipboard_echo_filter.h"
- #include "remoting/protocol/clipboard_filter.h"
- #include "remoting/protocol/clipboard_stub.h"
- #include "remoting/protocol/connection_to_client.h"
- #include "remoting/protocol/data_channel_manager.h"
- #include "remoting/protocol/display_size.h"
- #include "remoting/protocol/host_stub.h"
- #include "remoting/protocol/input_event_tracker.h"
- #include "remoting/protocol/input_filter.h"
- #include "remoting/protocol/input_stub.h"
- #include "remoting/protocol/mouse_input_filter.h"
- #include "remoting/protocol/pairing_registry.h"
- #include "remoting/protocol/video_stream.h"
- #include "third_party/webrtc/modules/desktop_capture/desktop_capture_metadata.h"
- #include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h"
- #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
- #include "third_party/webrtc/modules/desktop_capture/mouse_cursor.h"
- #include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
- #include "ui/events/event.h"
- namespace remoting {
- class AudioStream;
- class DesktopEnvironment;
- class DesktopEnvironmentFactory;
- class InputInjector;
- class KeyboardLayoutMonitor;
- class MouseShapePump;
- class RemoteOpenUrlMessageHandler;
- class RemoteWebAuthnMessageHandler;
- class ScreenControls;
- namespace protocol {
- class VideoLayout;
- } // namespace protocol
- // A ClientSession keeps a reference to a connection to a client, and maintains
- // per-client state.
- class ClientSession : public protocol::HostStub,
- public protocol::ConnectionToClient::EventHandler,
- public protocol::VideoStream::Observer,
- public ClientSessionControl,
- public ClientSessionDetails,
- public ClientSessionEvents,
- public DesktopAndCursorComposerNotifier::EventHandler,
- public webrtc::MouseCursorMonitor::Callback,
- public mojom::ChromotingSessionServices {
- public:
- // Callback interface for passing events to the ChromotingHost.
- class EventHandler {
- public:
- // Called after authentication has started.
- virtual void OnSessionAuthenticating(ClientSession* client) = 0;
- // Called after authentication has finished successfully.
- virtual void OnSessionAuthenticated(ClientSession* client) = 0;
- // Called after we've finished connecting all channels.
- virtual void OnSessionChannelsConnected(ClientSession* client) = 0;
- // Called after authentication has failed. Must not tear down this
- // object. OnSessionClosed() is notified after this handler
- // returns.
- virtual void OnSessionAuthenticationFailed(ClientSession* client) = 0;
- // Called after connection has failed or after the client closed it.
- virtual void OnSessionClosed(ClientSession* client) = 0;
- // Called on notification of a route change event, when a channel is
- // connected.
- virtual void OnSessionRouteChange(
- ClientSession* client,
- const std::string& channel_name,
- const protocol::TransportRoute& route) = 0;
- protected:
- virtual ~EventHandler() {}
- };
- // |event_handler| and |desktop_environment_factory| must outlive |this|.
- // All |HostExtension|s in |extensions| must outlive |this|.
- ClientSession(
- EventHandler* event_handler,
- std::unique_ptr<protocol::ConnectionToClient> connection,
- DesktopEnvironmentFactory* desktop_environment_factory,
- const DesktopEnvironmentOptions& desktop_environment_options,
- const base::TimeDelta& max_duration,
- scoped_refptr<protocol::PairingRegistry> pairing_registry,
- const std::vector<HostExtension*>& extensions);
- ClientSession(const ClientSession&) = delete;
- ClientSession& operator=(const ClientSession&) = delete;
- ~ClientSession() override;
- // Returns the set of capabilities negotiated between client and host.
- const std::string& capabilities() const { return capabilities_; }
- // protocol::HostStub interface.
- void NotifyClientResolution(
- const protocol::ClientResolution& resolution) override;
- void ControlVideo(const protocol::VideoControl& video_control) override;
- void ControlAudio(const protocol::AudioControl& audio_control) override;
- void SetCapabilities(const protocol::Capabilities& capabilities) override;
- void RequestPairing(
- const remoting::protocol::PairingRequest& pairing_request) override;
- void DeliverClientMessage(const protocol::ExtensionMessage& message) override;
- void SelectDesktopDisplay(
- const protocol::SelectDesktopDisplayRequest& select_display) override;
- void ControlPeerConnection(
- const protocol::PeerConnectionParameters& parameters) override;
- // protocol::ConnectionToClient::EventHandler interface.
- void OnConnectionAuthenticating() override;
- void OnConnectionAuthenticated() override;
- void CreateMediaStreams() override;
- void OnConnectionChannelsConnected() override;
- void OnConnectionClosed(protocol::ErrorCode error) override;
- void OnTransportProtocolChange(const std::string& protocol) override;
- void OnRouteChange(const std::string& channel_name,
- const protocol::TransportRoute& route) override;
- void OnIncomingDataChannel(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe) override;
- // ClientSessionControl interface.
- const std::string& client_jid() const override;
- void DisconnectSession(protocol::ErrorCode error) override;
- void OnLocalKeyPressed(uint32_t usb_keycode) override;
- void OnLocalPointerMoved(const webrtc::DesktopVector& position,
- ui::EventType type) override;
- void SetDisableInputs(bool disable_inputs) override;
- void OnDesktopDisplayChanged(
- std::unique_ptr<protocol::VideoLayout> layout) override;
- // ClientSessionEvents interface.
- void OnDesktopAttached(uint32_t session_id) override;
- void OnDesktopDetached() override;
- // ClientSessionDetails interface.
- uint32_t desktop_session_id() const override;
- ClientSessionControl* session_control() override;
- // DesktopAndCursorComposerNotifier::EventHandler interface
- void SetComposeEnabled(bool enabled) override;
- // webrtc::MouseCursorMonitor::Callback implementation.
- void OnMouseCursor(webrtc::MouseCursor* mouse_cursor) override;
- void OnMouseCursorPosition(const webrtc::DesktopVector& position) override;
- // mojom::ChromotingSessionServices implementation.
- void BindWebAuthnProxy(
- mojo::PendingReceiver<mojom::WebAuthnProxy> receiver) override;
- void BindRemoteUrlOpener(
- mojo::PendingReceiver<mojom::RemoteUrlOpener> receiver) override;
- void BindReceiver(
- mojo::PendingReceiver<mojom::ChromotingSessionServices> receiver);
- protocol::ConnectionToClient* connection() const { return connection_.get(); }
- bool is_authenticated() const { return is_authenticated_; }
- bool channels_connected() const { return channels_connected_; }
- const std::string* client_capabilities() const {
- return client_capabilities_.get();
- }
- // Registers a DataChannelManager callback for testing.
- void RegisterCreateHandlerCallbackForTesting(
- const std::string& prefix,
- protocol::DataChannelManager::CreateHandlerCallback constructor);
- void SetEventTimestampsSourceForTests(
- scoped_refptr<protocol::InputEventTimestampsSource>
- event_timestamp_source);
- // Public for tests.
- void UpdateMouseClampingFilterOffset();
- private:
- // Struct for associating an optional DesktopAndCursorConditionalComposer
- // with each VideoStream.
- struct VideoStreamWithComposer {
- VideoStreamWithComposer();
- VideoStreamWithComposer(VideoStreamWithComposer&&);
- VideoStreamWithComposer& operator=(VideoStreamWithComposer&&);
- ~VideoStreamWithComposer();
- std::unique_ptr<protocol::VideoStream> stream;
- base::WeakPtr<DesktopAndCursorConditionalComposer> composer;
- };
- // Creates a proxy for sending clipboard events to the client.
- std::unique_ptr<protocol::ClipboardStub> CreateClipboardProxy();
- void SetMouseClampingFilter(const DisplaySize& size);
- // protocol::VideoStream::Observer implementation.
- void OnVideoSizeChanged(protocol::VideoStream* stream,
- const webrtc::DesktopSize& size,
- const webrtc::DesktopVector& dpi) override;
- void CreateActionMessageHandler(
- std::vector<protocol::ActionRequest::Action> capabilities,
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreateFileTransferMessageHandler(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreateRtcLogTransferMessageHandler(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreateRemoteOpenUrlMessageHandler(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreateUrlForwarderControlMessageHandler(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreateRemoteWebAuthnMessageHandler(
- const std::string& channel_name,
- std::unique_ptr<protocol::MessagePipe> pipe);
- void CreatePerMonitorVideoStreams();
- // True if |index| corresponds with an existing display (or the combined
- // display).
- bool IsValidDisplayIndex(webrtc::ScreenId index) const;
- #if defined(WEBRTC_USE_GIO)
- void ExtractAndSetInputInjectorMetadata(
- webrtc::DesktopCaptureMetadata capture_metadata);
- #endif
- raw_ptr<EventHandler> event_handler_;
- // Used to create a DesktopEnvironment instance for this session.
- raw_ptr<DesktopEnvironmentFactory> desktop_environment_factory_;
- // The DesktopEnvironmentOptions used to initialize DesktopEnvironment.
- DesktopEnvironmentOptions desktop_environment_options_;
- // The DesktopEnvironment instance for this session.
- std::unique_ptr<DesktopEnvironment> desktop_environment_;
- // Filter used as the final element in the input pipeline.
- protocol::InputFilter host_input_filter_;
- // Tracker used to release pressed keys and buttons when disconnecting.
- protocol::InputEventTracker input_tracker_;
- // Filter used to disable remote inputs during local input activity.
- RemoteInputFilter remote_input_filter_;
- // Filter used to clamp mouse events to the current display dimensions.
- protocol::MouseInputFilter mouse_clamping_filter_;
- // Filter used to detect transitions into and out of client-side pointer lock,
- // and to monitor local input to determine whether or not to include the mouse
- // cursor in the desktop image.
- DesktopAndCursorComposerNotifier desktop_and_cursor_composer_notifier_;
- // Filter to used to stop clipboard items sent from the client being echoed
- // back to it. It is the final element in the clipboard (client -> host)
- // pipeline.
- protocol::ClipboardEchoFilter clipboard_echo_filter_;
- // Filters used to manage enabling & disabling of input.
- protocol::InputFilter disable_input_filter_;
- // Used to enable/disable clipboard sync and to restrict payload size.
- protocol::ClipboardFilter host_clipboard_filter_;
- protocol::ClipboardFilter client_clipboard_filter_;
- // Factory for weak pointers to the client clipboard stub.
- // This must appear after |clipboard_echo_filter_|, so that it won't outlive
- // it.
- base::WeakPtrFactory<protocol::ClipboardStub> client_clipboard_factory_;
- // The maximum duration of this session.
- // There is no maximum if this value is <= 0.
- base::TimeDelta max_duration_;
- // A timer that triggers a disconnect when the maximum session duration
- // is reached.
- base::OneShotTimer max_duration_timer_;
- // Objects responsible for sending video, audio.
- std::map<webrtc::ScreenId, VideoStreamWithComposer> video_streams_;
- std::unique_ptr<protocol::AudioStream> audio_stream_;
- // The set of all capabilities supported by the client.
- std::unique_ptr<std::string> client_capabilities_;
- // The set of all capabilities supported by the host.
- std::string host_capabilities_;
- // The set of all capabilities negotiated between client and host.
- std::string capabilities_;
- // Used to inject mouse and keyboard input and handle clipboard events.
- std::unique_ptr<InputInjector> input_injector_;
- // Used to apply client-requested changes in screen resolution.
- std::unique_ptr<ScreenControls> screen_controls_;
- // Contains the most recently gathered info about the desktop displays;
- DesktopDisplayInfo desktop_display_info_;
- // Default DPI values to use if a display reports 0 for DPI.
- int default_x_dpi_;
- int default_y_dpi_;
- // The index of the desktop display to show to the user.
- // Default is webrtc::kInvalidScreenScreenId because we need to perform
- // an initial capture to determine if the current setup support capturing
- // the entire desktop or if it is restricted to a single display.
- // This value is either an index into |desktop_display_info_| or one of
- // the special values webrtc::kInvalidScreenId, webrtc::kFullDesktopScreenId.
- webrtc::ScreenId selected_display_index_ = webrtc::kInvalidScreenId;
- // The initial video size captured by WebRTC.
- // This will be the full desktop unless webrtc cannot capture the entire
- // desktop (e.g., because the DPIs don't match). In that case, it will
- // be equal to the dimensions of the default display.
- DisplaySize default_webrtc_desktop_size_;
- // The current size of the area being captured by webrtc. This will be
- // equal to the size of the entire desktop, or to a single display.
- DisplaySize webrtc_capture_size_;
- // Set to true if the current display configuration supports capturing the
- // entire desktop.
- bool can_capture_full_desktop_ = true;
- // The pairing registry for PIN-less authentication.
- scoped_refptr<protocol::PairingRegistry> pairing_registry_;
- // Used to dispatch new data channels to factory methods.
- protocol::DataChannelManager data_channel_manager_;
- // Set to true if the client was authenticated successfully.
- bool is_authenticated_ = false;
- // Set to true after all data channels have been connected.
- bool channels_connected_ = false;
- // Used to store video channel pause & lossless parameters.
- bool pause_video_ = false;
- bool lossless_video_encode_ = false;
- bool lossless_video_color_ = false;
- // VideoLayout is sent only after the control channel is connected. Until
- // then it's stored in |pending_video_layout_message_|.
- std::unique_ptr<protocol::VideoLayout> pending_video_layout_message_;
- scoped_refptr<protocol::InputEventTimestampsSource>
- event_timestamp_source_for_tests_;
- HostExperimentSessionPlugin host_experiment_session_plugin_;
- // The connection to the client.
- std::unique_ptr<protocol::ConnectionToClient> connection_;
- std::string client_jid_;
- // Used to manage extension functionality.
- std::unique_ptr<HostExtensionSessionManager> extension_manager_;
- // Objects to monitor and send updates for mouse shape and keyboard layout.
- std::unique_ptr<MouseShapePump> mouse_shape_pump_;
- std::unique_ptr<KeyboardLayoutMonitor> keyboard_layout_monitor_;
- base::WeakPtr<RemoteWebAuthnMessageHandler> remote_webauthn_message_handler_;
- base::WeakPtr<RemoteOpenUrlMessageHandler> remote_open_url_message_handler_;
- mojo::ReceiverSet<mojom::ChromotingSessionServices>
- session_services_receivers_;
- SEQUENCE_CHECKER(sequence_checker_);
- // Used to disable callbacks to |this| once DisconnectSession() has been
- // called.
- base::WeakPtrFactory<ClientSessionControl>
- client_session_control_weak_factory_{this};
- base::WeakPtrFactory<ClientSessionEvents> client_session_events_weak_factory_{
- this};
- };
- } // namespace remoting
- #endif // REMOTING_HOST_CLIENT_SESSION_H_
|