#include "remoting/client/chromoting_session.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "base/timer/timer.h"
#include "components/webrtc/thread_wrapper.h"
#include "net/socket/client_socket_factory.h"
#include "remoting/base/chromoting_event.h"
#include "remoting/base/service_urls.h"
#include "remoting/client/audio/audio_player.h"
#include "remoting/client/chromoting_client_runtime.h"
#include "remoting/client/client_telemetry_logger.h"
#include "remoting/client/input/native_device_keymap.h"
#include "remoting/protocol/chromium_port_allocator_factory.h"
#include "remoting/protocol/chromium_socket_factory.h"
#include "remoting/protocol/client_authentication_config.h"
#include "remoting/protocol/frame_consumer.h"
#include "remoting/protocol/host_stub.h"
#include "remoting/protocol/network_settings.h"
#include "remoting/protocol/performance_tracker.h"
#include "remoting/protocol/transport_context.h"
#include "remoting/protocol/video_renderer.h"
#include "remoting/signaling/ftl_client_uuid_device_id_provider.h"
#include "remoting/signaling/ftl_signal_strategy.h"
#include "remoting/signaling/server_log_entry.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
namespace remoting {
namespace {
const int kDefaultDPI = …;
const int kMinDimension = …;
constexpr base::TimeDelta kPerfStatsInterval = …;
constexpr base::TimeDelta kDestroySignalingDelay = …;
bool IsClientResolutionValid(int width_pixels, int height_pixels) { … }
void NormalizeClientResolution(protocol::ClientResolution* resolution) { … }
struct SessionContext { … };
}
class ChromotingSession::Core : public ClientUserInterface,
public protocol::ClipboardStub,
public protocol::KeyboardLayoutStub { … };
ChromotingSession::Core::Core(ChromotingClientRuntime* runtime,
std::unique_ptr<ClientTelemetryLogger> logger,
std::unique_ptr<SessionContext> session_context)
: … { … }
ChromotingSession::Core::~Core() { … }
void ChromotingSession::Core::RequestPairing(const std::string& device_name) { … }
void ChromotingSession::Core::SendMouseEvent(
int x,
int y,
protocol::MouseEvent_MouseButton button,
bool button_down) { … }
void ChromotingSession::Core::SendMouseWheelEvent(int delta_x, int delta_y) { … }
void ChromotingSession::Core::SendKeyEvent(int usb_key_code, bool key_down) { … }
void ChromotingSession::Core::SendTextEvent(const std::string& text) { … }
void ChromotingSession::Core::SendTouchEvent(
const protocol::TouchEvent& touch_event) { … }
void ChromotingSession::Core::SendClientResolution(int width_pixels,
int height_pixels,
float scale) { … }
void ChromotingSession::Core::EnableVideoChannel(bool enable) { … }
void ChromotingSession::Core::SendClientMessage(const std::string& type,
const std::string& data) { … }
std::unique_ptr<FeedbackData> ChromotingSession::Core::GetFeedbackData() { … }
void ChromotingSession::Core::Disconnect() { … }
void ChromotingSession::Core::OnConnectionState(
protocol::ConnectionToHost::State state,
protocol::ErrorCode error) { … }
void ChromotingSession::Core::OnConnectionReady(bool ready) { … }
void ChromotingSession::Core::OnRouteChanged(
const std::string& channel_name,
const protocol::TransportRoute& route) { … }
void ChromotingSession::Core::SetCapabilities(const std::string& capabilities) { … }
void ChromotingSession::Core::SetPairingResponse(
const protocol::PairingResponse& response) { … }
void ChromotingSession::Core::DeliverHostMessage(
const protocol::ExtensionMessage& message) { … }
void ChromotingSession::Core::SetDesktopSize(const webrtc::DesktopSize& size,
const webrtc::DesktopVector& dpi) { … }
protocol::ClipboardStub* ChromotingSession::Core::GetClipboardStub() { … }
protocol::CursorShapeStub* ChromotingSession::Core::GetCursorShapeStub() { … }
protocol::KeyboardLayoutStub* ChromotingSession::Core::GetKeyboardLayoutStub() { … }
void ChromotingSession::Core::InjectClipboardEvent(
const protocol::ClipboardEvent& event) { … }
void ChromotingSession::Core::SetKeyboardLayout(
const protocol::KeyboardLayout& layout) { … }
base::WeakPtr<ChromotingSession::Core> ChromotingSession::Core::GetWeakPtr() { … }
void ChromotingSession::Core::Invalidate() { … }
void ChromotingSession::Core::ConnectOnNetworkThread() { … }
void ChromotingSession::Core::LogPerfStats() { … }
void ChromotingSession::Core::FetchSecret(
bool pairing_supported,
const protocol::SecretFetchedCallback& secret_fetched_callback) { … }
void ChromotingSession::Core::HandleOnSecretFetched(
const protocol::SecretFetchedCallback& callback,
const std::string secret) { … }
ChromotingSession::ChromotingSession(
base::WeakPtr<ChromotingSession::Delegate> delegate,
std::unique_ptr<protocol::CursorShapeStub> cursor_shape_stub,
std::unique_ptr<protocol::VideoRenderer> video_renderer,
std::unique_ptr<protocol::AudioStub> audio_player,
const ConnectToHostInfo& info)
: … { … }
ChromotingSession::~ChromotingSession() { … }
void ChromotingSession::GetFeedbackData(
GetFeedbackDataCallback callback) const { … }
void ChromotingSession::RequestPairing(const std::string& device_name) { … }
void ChromotingSession::SendMouseEvent(int x,
int y,
protocol::MouseEvent_MouseButton button,
bool button_down) { … }
void ChromotingSession::SendMouseWheelEvent(int delta_x, int delta_y) { … }
bool ChromotingSession::SendKeyEvent(int scan_code,
int key_code,
bool key_down) { … }
void ChromotingSession::SendTextEvent(const std::string& text) { … }
void ChromotingSession::SendTouchEvent(
const protocol::TouchEvent& touch_event) { … }
void ChromotingSession::SendClientResolution(int width_pixels,
int height_pixels,
float scale) { … }
void ChromotingSession::EnableVideoChannel(bool enable) { … }
void ChromotingSession::SendClientMessage(const std::string& type,
const std::string& data) { … }
template <typename Functor, typename... Args>
void ChromotingSession::RunCoreTaskOnNetworkThread(
const base::Location& from_here,
Functor&& core_functor,
Args&&... args) { … }
}