chromium/content/browser/devtools/devtools_agent_host_impl.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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)
// Map handle to file descriptor
int AdoptHandle(const std::string& serialized_pipe, int flags) {
  // Deserialize the handle.
  // We use the fact that inherited handles in the child process have the same
  // value and access rights as in the parent process.
  // See:
  // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
  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;
  }
  // Map the handle to the file descriptor
  return _open_osfhandle(reinterpret_cast<intptr_t>(handle), flags);
}

// Transform the --remote-debugging-io-pipes switch value to file descriptors.
bool AdoptPipes(const std::string& io_pipes, int& read_fd, int& write_fd) {
  // The parent process is expected to serialize the input and the output pipe
  // handles as unsigned integers, concatenate them with comma and pass this
  // string to the browser via the --remote-debugging-io-pipes argument.
  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];
  // If adoption of the read_fd fails the already adopted write_fd signalizing
  // the remote end that the session is over.
  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

}  // namespace

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_ =;

// static
std::string DevToolsAgentHost::GetProtocolVersion() {}

// static
bool DevToolsAgentHost::IsSupportedProtocolVersion(const std::string& version) {}

// static
DevToolsAgentHost::List DevToolsAgentHost::GetAll() {}

// static
DevToolsAgentHost::List DevToolsAgentHost::GetOrCreateAll() {}

// static
void DevToolsAgentHost::StartRemoteDebuggingServer(
    std::unique_ptr<DevToolsSocketFactory> server_socket_factory,
    const base::FilePath& active_port_output_directory,
    const base::FilePath& debug_frontend_dir) {}

// static
void DevToolsAgentHost::StartRemoteDebuggingPipeHandler(
    base::OnceClosure on_disconnect) {}

// static
void DevToolsAgentHost::StopRemoteDebuggingServer() {}

// static
void DevToolsAgentHost::StopRemoteDebuggingPipeHandler() {}

DevToolsAgentHostImpl::DevToolsAgentHostImpl(const std::string& id)
    :{}

DevToolsAgentHostImpl::~DevToolsAgentHostImpl() {}

// static
scoped_refptr<DevToolsAgentHostImpl> DevToolsAgentHostImpl::GetForId(
    const std::string& id) {}

// static
scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForId(
    const std::string& id) {}

// static
scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::Forward(
    const std::string& id,
    std::unique_ptr<DevToolsExternalAgentProxyDelegate> delegate) {}

// static
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) {}

// static
void DevToolsAgentHost::DetachAllClients() {}

// static
void DevToolsAgentHost::AddObserver(DevToolsAgentHostObserver* observer) {}

// static
void DevToolsAgentHost::RemoveObserver(DevToolsAgentHostObserver* observer) {}

// static
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() {}

}  // namespace content