#include "content/browser/devtools/devtools_agent_host_impl.h"
#include <map>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "base/strings/string_split.h"
#include "content/browser/devtools/auction_worklet_devtools_agent_host.h"
#include "content/browser/devtools/devtools_http_handler.h"
#include "content/browser/devtools/devtools_manager.h"
#include "content/browser/devtools/devtools_pipe_handler.h"
#include "content/browser/devtools/devtools_stream_file.h"
#include "content/browser/devtools/forwarding_agent_host.h"
#include "content/browser/devtools/mojom_devtools_agent_host.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_manager.h"
#include "content/browser/devtools/shared_storage_worklet_devtools_manager.h"
#include "content/browser/devtools/shared_worker_devtools_agent_host.h"
#include "content/browser/devtools/shared_worker_devtools_manager.h"
#include "content/browser/devtools/web_contents_devtools_agent_host.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/devtools_external_agent_proxy_delegate.h"
#include "content/public/browser/devtools_socket_factory.h"
#include "content/public/browser/mojom_devtools_agent_host_delegate.h"
#include "content/public/common/content_switches.h"
#include "services/network/public/mojom/network_context.mojom.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include <fcntl.h>
#include <io.h>
#endif
namespace content {
namespace {
DevToolsMap;
DevToolsMap& GetDevtoolsInstances() { … }
base::ObserverList<DevToolsAgentHostObserver>::Unchecked&
GetDevtoolsObservers() { … }
void SetDevToolsHttpHandler(std::unique_ptr<DevToolsHttpHandler> handler) { … }
void SetDevToolsPipeHandler(std::unique_ptr<DevToolsPipeHandler> handler) { … }
#if BUILDFLAG(IS_WIN)
int AdoptHandle(const std::string& serialized_pipe, int flags) {
uint32_t handle_as_uint32;
if (!base::StringToUint(serialized_pipe, &handle_as_uint32)) {
return -1;
}
HANDLE handle = base::win::Uint32ToHandle(handle_as_uint32);
if (GetFileType(handle) != FILE_TYPE_PIPE) {
return -1;
}
return _open_osfhandle(reinterpret_cast<intptr_t>(handle), flags);
}
bool AdoptPipes(const std::string& io_pipes, int& read_fd, int& write_fd) {
std::vector<std::string> pipe_names = base::SplitString(
io_pipes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (pipe_names.size() != 2) {
return false;
}
const std::string& in_pipe = pipe_names[0];
const std::string& out_pipe = pipe_names[1];
int tmp_write_fd = AdoptHandle(out_pipe, 0);
if (tmp_write_fd < 0) {
return false;
}
int tmp_read_fd = AdoptHandle(in_pipe, _O_RDONLY);
if (tmp_read_fd < 0) {
_close(tmp_write_fd);
return false;
}
read_fd = tmp_read_fd;
write_fd = tmp_write_fd;
return true;
}
#endif
}
const char DevToolsAgentHost::kTypeTab[] = …;
const char DevToolsAgentHost::kTypePage[] = …;
const char DevToolsAgentHost::kTypeFrame[] = …;
const char DevToolsAgentHost::kTypeDedicatedWorker[] = …;
const char DevToolsAgentHost::kTypeSharedWorker[] = …;
const char DevToolsAgentHost::kTypeServiceWorker[] = …;
const char DevToolsAgentHost::kTypeWorklet[] = …;
const char DevToolsAgentHost::kTypeSharedStorageWorklet[] = …;
const char DevToolsAgentHost::kTypeBrowser[] = …;
const char DevToolsAgentHost::kTypeGuest[] = …;
const char DevToolsAgentHost::kTypeOther[] = …;
const char DevToolsAgentHost::kTypeAuctionWorklet[] = …;
const char DevToolsAgentHost::kTypeAssistiveTechnology[] = …;
int DevToolsAgentHostImpl::s_force_creation_count_ = …;
std::string DevToolsAgentHost::GetProtocolVersion() { … }
bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) { … }
DevToolsAgentHost::List DevToolsAgentHost::GetAll() { … }
DevToolsAgentHost::List DevToolsAgentHost::GetOrCreateAll() { … }
void DevToolsAgentHost::StartRemoteDebuggingServer(
std::unique_ptr<DevToolsSocketFactory> server_socket_factory,
const base::FilePath& active_port_output_directory,
const base::FilePath& debug_frontend_dir) { … }
void DevToolsAgentHost::StartRemoteDebuggingPipeHandler(
base::OnceClosure on_disconnect) { … }
void DevToolsAgentHost::StopRemoteDebuggingServer() { … }
void DevToolsAgentHost::StopRemoteDebuggingPipeHandler() { … }
DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
: … { … }
DevToolsAgentHostImpl::~DevToolsAgentHostImpl() { … }
scoped_refptr<DevToolsAgentHostImpl> DevToolsAgentHostImpl::GetForId(
const std::string& id) { … }
scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId(
const std::string& id) { … }
scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Forward(
const std::string& id,
std::unique_ptr<DevToolsExternalAgentProxyDelegate> delegate) { … }
scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::CreateForMojomDelegate(
const std::string& id,
std::unique_ptr<MojomDevToolsAgentHostDelegate> delegate) { … }
DevToolsSession* DevToolsAgentHostImpl::SessionByClient(
DevToolsAgentHostClient* client) { … }
bool DevToolsAgentHostImpl::AttachInternal(
std::unique_ptr<DevToolsSession> session_owned) { … }
bool DevToolsAgentHostImpl::AttachInternal(
std::unique_ptr<DevToolsSession> session_owned,
bool acquire_wake_lock) { … }
bool DevToolsAgentHostImpl::AttachClient(DevToolsAgentHostClient* client) { … }
bool DevToolsAgentHostImpl::AttachClientWithoutWakeLock(
content::DevToolsAgentHostClient* client) { … }
bool DevToolsAgentHostImpl::DetachClient(DevToolsAgentHostClient* client) { … }
void DevToolsAgentHostImpl::DispatchProtocolMessage(
DevToolsAgentHostClient* client,
base::span<const uint8_t> message) { … }
void DevToolsAgentHostImpl::DetachInternal(DevToolsSession* session) { … }
bool DevToolsAgentHostImpl::IsAttached() { … }
void DevToolsAgentHostImpl::InspectElement(RenderFrameHost* frame_host,
int x,
int y) { … }
std::string DevToolsAgentHostImpl::GetId() { … }
std::string DevToolsAgentHostImpl::CreateIOStreamFromData(
scoped_refptr<base::RefCountedMemory> data) { … }
std::string DevToolsAgentHostImpl::GetParentId() { … }
std::string DevToolsAgentHostImpl::GetOpenerId() { … }
std::string DevToolsAgentHostImpl::GetOpenerFrameId() { … }
bool DevToolsAgentHostImpl::CanAccessOpener() { … }
std::string DevToolsAgentHostImpl::GetDescription() { … }
GURL DevToolsAgentHostImpl::GetFaviconURL() { … }
std::string DevToolsAgentHostImpl::GetFrontendURL() { … }
base::TimeTicks DevToolsAgentHostImpl::GetLastActivityTime() { … }
BrowserContext* DevToolsAgentHostImpl::GetBrowserContext() { … }
WebContents* DevToolsAgentHostImpl::GetWebContents() { … }
void DevToolsAgentHostImpl::DisconnectWebContents() { … }
void DevToolsAgentHostImpl::ConnectWebContents(WebContents* wc) { … }
DevToolsSession::Mode DevToolsAgentHostImpl::GetSessionMode() { … }
bool DevToolsAgentHostImpl::Inspect() { … }
void DevToolsAgentHostImpl::ForceDetachAllSessions() { … }
scoped_refptr<DevToolsAgentHost>
DevToolsAgentHostImpl::ForceDetachAllSessionsImpl() { … }
void DevToolsAgentHostImpl::MainThreadDebuggerPaused() { … }
void DevToolsAgentHostImpl::MainThreadDebuggerResumed() { … }
void DevToolsAgentHostImpl::ForceDetachRestrictedSessions(
const std::vector<DevToolsSession*>& restricted_sessions) { … }
bool DevToolsAgentHostImpl::AttachSession(DevToolsSession* session,
bool acquire_wake_lock) { … }
void DevToolsAgentHostImpl::DetachSession(DevToolsSession* session) { … }
void DevToolsAgentHostImpl::UpdateRendererChannel(bool force) { … }
void DevToolsAgentHost::DetachAllClients() { … }
void DevToolsAgentHost::AddObserver(DevToolsAgentHostObserver* observer) { … }
void DevToolsAgentHost::RemoveObserver(DevToolsAgentHostObserver* observer) { … }
bool DevToolsAgentHostImpl::ShouldForceCreation() { … }
std::string DevToolsAgentHostImpl::GetSubtype() { … }
void DevToolsAgentHostImpl::NotifyCreated() { … }
void DevToolsAgentHostImpl::NotifyNavigated() { … }
void DevToolsAgentHostImpl::NotifyAttached() { … }
void DevToolsAgentHostImpl::NotifyDetached() { … }
void DevToolsAgentHostImpl::NotifyCrashed(base::TerminationStatus status) { … }
void DevToolsAgentHostImpl::NotifyDestroyed() { … }
void DevToolsAgentHostImpl::ProcessHostChanged() { … }
void DevToolsAgentHostImpl::SetProcessId(base::ProcessId process_id) { … }
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo::
NetworkLoaderFactoryParamsAndInfo() = default;
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo::
NetworkLoaderFactoryParamsAndInfo(
url::Origin origin,
net::SiteForCookies site_for_cookies,
network::mojom::URLLoaderFactoryParamsPtr factory_params)
: … { … }
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo::
NetworkLoaderFactoryParamsAndInfo(
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo&&) = default;
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo::
~NetworkLoaderFactoryParamsAndInfo() = default;
DevToolsAgentHostImpl::NetworkLoaderFactoryParamsAndInfo
DevToolsAgentHostImpl::CreateNetworkFactoryParamsForDevTools() { … }
RenderProcessHost* DevToolsAgentHostImpl::GetProcessHost() { … }
std::optional<network::CrossOriginEmbedderPolicy>
DevToolsAgentHostImpl::cross_origin_embedder_policy(const std::string& id) { … }
std::optional<network::CrossOriginOpenerPolicy>
DevToolsAgentHostImpl::cross_origin_opener_policy(const std::string& id) { … }
std::optional<std::vector<network::mojom::ContentSecurityPolicyHeader>>
DevToolsAgentHostImpl::content_security_policy(const std::string& id) { … }
protocol::TargetAutoAttacher* DevToolsAgentHostImpl::auto_attacher() { … }
}