#include "remoting/host/client_session.h"
#include <algorithm>
#include <map>
#include <memory>
#include <optional>
#include <utility>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "remoting/base/capabilities.h"
#include "remoting/base/constants.h"
#include "remoting/base/errors.h"
#include "remoting/base/logging.h"
#include "remoting/base/session_options.h"
#include "remoting/base/session_policies.h"
#include "remoting/host/action_executor.h"
#include "remoting/host/action_message_handler.h"
#include "remoting/host/active_display_monitor.h"
#include "remoting/host/audio_capturer.h"
#include "remoting/host/base/screen_controls.h"
#include "remoting/host/base/screen_resolution.h"
#include "remoting/host/desktop_display_info_monitor.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/file_transfer/file_transfer_message_handler.h"
#include "remoting/host/file_transfer/rtc_log_file_operations.h"
#include "remoting/host/host_extension_session.h"
#include "remoting/host/input_injector.h"
#include "remoting/host/keyboard_layout_monitor.h"
#include "remoting/host/mouse_shape_pump.h"
#include "remoting/host/remote_open_url/remote_open_url_constants.h"
#include "remoting/host/remote_open_url/remote_open_url_message_handler.h"
#include "remoting/host/remote_open_url/remote_open_url_util.h"
#include "remoting/host/remote_open_url/url_forwarder_configurator.h"
#include "remoting/host/remote_open_url/url_forwarder_control_message_handler.h"
#include "remoting/host/security_key/security_key_extension.h"
#include "remoting/host/security_key/security_key_extension_session.h"
#include "remoting/host/webauthn/remote_webauthn_constants.h"
#include "remoting/host/webauthn/remote_webauthn_message_handler.h"
#include "remoting/host/webauthn/remote_webauthn_state_change_notifier.h"
#include "remoting/proto/control.pb.h"
#include "remoting/proto/event.pb.h"
#include "remoting/protocol/audio_stream.h"
#include "remoting/protocol/capability_names.h"
#include "remoting/protocol/client_stub.h"
#include "remoting/protocol/clipboard_thread_proxy.h"
#include "remoting/protocol/network_settings.h"
#include "remoting/protocol/pairing_registry.h"
#include "remoting/protocol/peer_connection_controls.h"
#include "remoting/protocol/session.h"
#include "remoting/protocol/session_config.h"
#include "remoting/protocol/video_frame_pump.h"
#include "remoting/protocol/webrtc_video_stream.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
#if defined(WEBRTC_USE_GIO)
#include "third_party/webrtc/modules/portal/xdg_desktop_portal_utils.h"
#endif
namespace {
constexpr char kRtcLogTransferDataChannelPrefix[] = …;
constexpr base::TimeDelta kDefaultBoostCaptureInterval = …;
constexpr base::TimeDelta kDefaultBoostDuration = …;
}
namespace remoting {
ActionRequest;
ClientSession::ClientSession(
EventHandler* event_handler,
std::unique_ptr<protocol::ConnectionToClient> connection,
DesktopEnvironmentFactory* desktop_environment_factory,
const DesktopEnvironmentOptions& desktop_environment_options,
scoped_refptr<protocol::PairingRegistry> pairing_registry,
const std::vector<raw_ptr<HostExtension, VectorExperimental>>& extensions,
const LocalSessionPoliciesProvider* local_session_policies_provider)
: … { … }
ClientSession::~ClientSession() { … }
void ClientSession::NotifyClientResolution(
const protocol::ClientResolution& resolution) { … }
void ClientSession::ControlVideo(const protocol::VideoControl& video_control) { … }
void ClientSession::ControlAudio(const protocol::AudioControl& audio_control) { … }
void ClientSession::SetCapabilities(
const protocol::Capabilities& capabilities) { … }
void ClientSession::RequestPairing(
const protocol::PairingRequest& pairing_request) { … }
void ClientSession::DeliverClientMessage(
const protocol::ExtensionMessage& message) { … }
void ClientSession::SelectDesktopDisplay(
const protocol::SelectDesktopDisplayRequest& select_display) { … }
void ClientSession::ControlPeerConnection(
const protocol::PeerConnectionParameters& parameters) { … }
void ClientSession::SetVideoLayout(const protocol::VideoLayout& video_layout) { … }
void ClientSession::OnConnectionAuthenticating() { … }
void ClientSession::OnConnectionAuthenticated() { … }
void ClientSession::CreateMediaStreams() { … }
void ClientSession::CreatePerMonitorVideoStreams() { … }
void ClientSession::OnConnectionChannelsConnected() { … }
void ClientSession::OnConnectionClosed(protocol::ErrorCode error) { … }
void ClientSession::OnTransportProtocolChange(const std::string& protocol) { … }
void ClientSession::OnRouteChange(const std::string& channel_name,
const protocol::TransportRoute& route) { … }
void ClientSession::OnIncomingDataChannel(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
const std::string& ClientSession::client_jid() const { … }
void ClientSession::DisconnectSession(protocol::ErrorCode error) { … }
void ClientSession::OnLocalKeyPressed(uint32_t usb_keycode) { … }
void ClientSession::OnLocalPointerMoved(const webrtc::DesktopVector& position,
ui::EventType type) { … }
void ClientSession::SetDisableInputs(bool disable_inputs) { … }
uint32_t ClientSession::desktop_session_id() const { … }
ClientSessionControl* ClientSession::session_control() { … }
void ClientSession::SetComposeEnabled(bool enabled) { … }
void ClientSession::OnMouseCursor(webrtc::MouseCursor* mouse_cursor) { … }
void ClientSession::OnMouseCursorPosition(
const webrtc::DesktopVector& position) { … }
void ClientSession::BindReceiver(
mojo::PendingReceiver<mojom::ChromotingSessionServices> receiver) { … }
void ClientSession::BindWebAuthnProxy(
mojo::PendingReceiver<mojom::WebAuthnProxy> receiver) { … }
void ClientSession::BindRemoteUrlOpener(
mojo::PendingReceiver<mojom::RemoteUrlOpener> receiver) { … }
#if BUILDFLAG(IS_WIN)
void ClientSession::BindSecurityKeyForwarder(
mojo::PendingReceiver<mojom::SecurityKeyForwarder> receiver) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto* extension_session = reinterpret_cast<SecurityKeyExtensionSession*>(
extension_manager_->FindExtensionSession(
SecurityKeyExtension::kCapability));
if (!extension_session) {
LOG(WARNING) << "Security key extension not found. "
<< "Binding request rejected.";
return;
}
extension_session->BindSecurityKeyForwarder(std::move(receiver));
}
#endif
void ClientSession::RegisterCreateHandlerCallbackForTesting(
const std::string& prefix,
protocol::DataChannelManager::CreateHandlerCallback constructor) { … }
void ClientSession::SetEventTimestampsSourceForTests(
scoped_refptr<protocol::InputEventTimestampsSource>
event_timestamp_source) { … }
std::unique_ptr<protocol::ClipboardStub> ClientSession::CreateClipboardProxy() { … }
void ClientSession::SetMouseClampingFilter(const DisplaySize& size) { … }
void ClientSession::UpdateMouseClampingFilterOffset() { … }
void ClientSession::OnLocalSessionPoliciesChanged(
const SessionPolicies& new_policies) { … }
void ClientSession::OnVideoSizeChanged(protocol::VideoStream* video_stream,
const webrtc::DesktopSize& size_px,
const webrtc::DesktopVector& dpi) { … }
void ClientSession::OnDesktopDisplayChanged(
std::unique_ptr<protocol::VideoLayout> displays) { … }
void ClientSession::OnDesktopAttached(uint32_t session_id) { … }
void ClientSession::OnDesktopDetached() { … }
void ClientSession::CreateFileTransferMessageHandler(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
void ClientSession::CreateRtcLogTransferMessageHandler(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
void ClientSession::CreateActionMessageHandler(
std::vector<ActionRequest::Action> capabilities,
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
void ClientSession::CreateRemoteOpenUrlMessageHandler(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
void ClientSession::CreateUrlForwarderControlMessageHandler(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
void ClientSession::CreateRemoteWebAuthnMessageHandler(
const std::string& channel_name,
std::unique_ptr<protocol::MessagePipe> pipe) { … }
bool ClientSession::IsValidDisplayIndex(webrtc::ScreenId index) const { … }
void ClientSession::BoostFramerateOnInput(
base::TimeDelta capture_interval,
base::TimeDelta boost_duration,
bool& mouse_button_down,
protocol::ObservingInputFilter::Event event) { … }
void ClientSession::OnActiveDisplayChanged(webrtc::ScreenId display) { … }
void ClientSession::UpdateFractionalFilterFallback() { … }
}