#include "content/shell/browser/shell_devtools_manager_delegate.h"
#include <stdint.h>
#include <vector>
#include "base/atomicops.h"
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_agent_host_client_channel.h"
#include "content/public/browser/devtools_socket_factory.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/user_agent.h"
#include "content/shell/browser/protocol/shell_devtools_session.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_content_client.h"
#include "content/shell/common/shell_switches.h"
#include "content/shell/grit/shell_resources.h"
#include "net/base/net_errors.h"
#include "net/log/net_log_source.h"
#include "net/socket/tcp_server_socket.h"
#include "ui/base/resource/resource_bundle.h"
#if BUILDFLAG(IS_ANDROID)
#include "content/public/browser/android/devtools_auth.h"
#include "net/socket/unix_domain_server_socket_posix.h"
#endif
namespace content {
namespace {
const int kBackLog = …;
base::subtle::Atomic32 g_last_used_port;
#if BUILDFLAG(IS_ANDROID)
class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory {
public:
explicit UnixDomainServerSocketFactory(const std::string& socket_name)
: socket_name_(socket_name) {}
UnixDomainServerSocketFactory(const UnixDomainServerSocketFactory&) = delete;
UnixDomainServerSocketFactory& operator=(
const UnixDomainServerSocketFactory&) = delete;
private:
std::unique_ptr<net::ServerSocket> CreateForHttpServer() override {
std::unique_ptr<net::UnixDomainServerSocket> socket(
new net::UnixDomainServerSocket(
base::BindRepeating(&CanUserConnectToDevTools),
true ));
if (socket->BindAndListen(socket_name_, kBackLog) != net::OK)
return nullptr;
return std::move(socket);
}
std::unique_ptr<net::ServerSocket> CreateForTethering(
std::string* out_name) override {
return nullptr;
}
std::string socket_name_;
};
#else
class TCPServerSocketFactory : public content::DevToolsSocketFactory { … };
#endif
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() { … }
}
int ShellDevToolsManagerDelegate::GetHttpHandlerPort() { … }
void ShellDevToolsManagerDelegate::StartHttpHandler(
BrowserContext* browser_context) { … }
void ShellDevToolsManagerDelegate::StopHttpHandler() { … }
ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate(
BrowserContext* browser_context)
: … { … }
ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() { … }
BrowserContext* ShellDevToolsManagerDelegate::GetDefaultBrowserContext() { … }
void ShellDevToolsManagerDelegate::ClientAttached(
content::DevToolsAgentHostClientChannel* channel) { … }
void ShellDevToolsManagerDelegate::ClientDetached(
content::DevToolsAgentHostClientChannel* channel) { … }
void ShellDevToolsManagerDelegate::HandleCommand(
content::DevToolsAgentHostClientChannel* channel,
base::span<const uint8_t> message,
NotHandledCallback callback) { … }
scoped_refptr<DevToolsAgentHost> ShellDevToolsManagerDelegate::CreateNewTarget(
const GURL& url,
content::DevToolsManagerDelegate::TargetType target_type) { … }
std::string ShellDevToolsManagerDelegate::GetDiscoveryPageHTML() { … }
bool ShellDevToolsManagerDelegate::HasBundledFrontendResources() { … }
}