#include "components/ui_devtools/devtools_server.h"
#include <memory>
#include <string_view>
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/not_fatal_until.h"
#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/thread_annotations.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "components/ui_devtools/switches.h"
#include "net/base/net_errors.h"
#include "net/log/net_log.h"
#include "net/server/http_server.h"
#include "net/server/http_server_request_info.h"
#include "net/socket/tcp_server_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace ui_devtools {
namespace {
const char kChromeDeveloperToolsPrefix[] = …;
const base::FilePath::CharType kUIDevToolsActivePortFileName[] = …);
void WriteUIDevtoolsPortToFile(base::FilePath output_dir, int port) { … }
}
UiDevToolsServer* UiDevToolsServer::devtools_server_ = …;
const net::NetworkTrafficAnnotationTag UiDevToolsServer::kUIDevtoolsServerTag = …;
class UiDevToolsServer::IOThreadData : public net::HttpServer::Delegate { … };
UiDevToolsServer::IOThreadData::IOThreadData(
base::WeakPtr<UiDevToolsServer> owner,
net::NetworkTrafficAnnotationTag tag)
: … { … }
void UiDevToolsServer::IOThreadData::MakeServer(
int port,
base::FilePath active_port_output_directory) { … }
void UiDevToolsServer::IOThreadData::OnConnect(int connection_id) { … }
void UiDevToolsServer::IOThreadData::OnHttpRequest(
int connection_id,
const net::HttpServerRequestInfo& info) { … }
void UiDevToolsServer::IOThreadData::OnWebSocketRequest(
int connection_id,
const net::HttpServerRequestInfo& info) { … }
void UiDevToolsServer::IOThreadData::OnWebSocketMessage(int connection_id,
std::string data) { … }
void UiDevToolsServer::IOThreadData::OnClose(int connection_id) { … }
void UiDevToolsServer::ServerCreated(int port) { … }
void UiDevToolsServer::IOThreadData::AcceptWebSocket(
int connection_id,
const net::HttpServerRequestInfo& request) { … }
void UiDevToolsServer::IOThreadData::SendOverWebSocket(int connection_id,
std::string data) { … }
UiDevToolsServer::UiDevToolsServer(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
int port,
net::NetworkTrafficAnnotationTag tag,
const base::FilePath& active_port_output_directory)
: … { … }
UiDevToolsServer::~UiDevToolsServer() { … }
std::unique_ptr<UiDevToolsServer> UiDevToolsServer::CreateForViews(
scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner,
int port,
const base::FilePath& active_port_output_directory) { … }
void UiDevToolsServer::SetOnSocketConnectedForTesting(
base::OnceClosure on_socket_connected) { … }
void UiDevToolsServer::OnWebSocketRequestForTesting(
int connection_id,
net::HttpServerRequestInfo info) { … }
std::vector<UiDevToolsServer::NameUrlPair>
UiDevToolsServer::GetClientNamesAndUrls() { … }
bool UiDevToolsServer::IsUiDevToolsEnabled(const char* enable_devtools_flag) { … }
int UiDevToolsServer::GetUiDevToolsPort(const char* enable_devtools_flag,
int default_port) { … }
void UiDevToolsServer::AttachClient(std::unique_ptr<UiDevToolsClient> client) { … }
void UiDevToolsServer::SendOverWebSocket(int connection_id,
std::string_view message) { … }
void UiDevToolsServer::SetOnSessionEnded(base::OnceClosure callback) const { … }
void UiDevToolsServer::OnWebSocketRequest(int connection_id,
net::HttpServerRequestInfo info) { … }
void UiDevToolsServer::OnWebSocketMessage(int connection_id, std::string data) { … }
void UiDevToolsServer::OnClose(int connection_id) { … }
}