#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
#include <memory>
#include <string>
#include <vector>
#include "base/containers/span.h"
#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/time/time.h"
#include "content/common/content_export.h"
#include "content/public/browser/devtools_agent_host_client.h"
#include "content/public/browser/devtools_agent_host_observer.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/network_context.mojom-forward.h"
#include "services/network/public/mojom/url_loader_factory.mojom-forward.h"
#include "url/gurl.h"
namespace base {
class RefCountedMemory;
class SingleThreadTaskRunner;
}
namespace net {
class ServerSocket;
}
namespace content {
class BrowserContext;
class DevToolsExternalAgentProxyDelegate;
class DevToolsSocketFactory;
class RenderFrameHost;
class WebContents;
class RenderProcessHost;
class ServiceWorkerContext;
class CONTENT_EXPORT DevToolsAgentHost
: public base::RefCounted<DevToolsAgentHost> {
public:
static const char kTypeTab[];
static const char kTypePage[];
static const char kTypeFrame[];
static const char kTypeDedicatedWorker[];
static const char kTypeSharedWorker[];
static const char kTypeServiceWorker[];
static const char kTypeBrowser[];
static const char kTypeGuest[];
static const char kTypeOther[];
static const char kTypeAuctionWorklet[];
static std::string GetProtocolVersion();
static bool IsSupportedProtocolVersion(const std::string& version);
static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id);
static scoped_refptr<DevToolsAgentHost> GetOrCreateFor(
WebContents* web_contents);
static scoped_refptr<DevToolsAgentHost> GetForTab(WebContents* web_contents);
static scoped_refptr<DevToolsAgentHost> GetOrCreateForTab(
WebContents* web_contents);
static bool HasFor(WebContents* web_contents);
static scoped_refptr<DevToolsAgentHost> GetForServiceWorker(
ServiceWorkerContext* context,
int64_t version_id);
static scoped_refptr<DevToolsAgentHost> Forward(
const std::string& id,
std::unique_ptr<DevToolsExternalAgentProxyDelegate> delegate);
using CreateServerSocketCallback =
base::RepeatingCallback<std::unique_ptr<net::ServerSocket>(std::string*)>;
static scoped_refptr<DevToolsAgentHost> CreateForBrowser(
scoped_refptr<base::SingleThreadTaskRunner> tethering_task_runner,
const CreateServerSocketCallback& socket_callback);
static scoped_refptr<DevToolsAgentHost> CreateForDiscovery();
static bool IsDebuggerAttached(WebContents* web_contents);
using List = std::vector<scoped_refptr<DevToolsAgentHost>>;
static List GetAll();
static List GetOrCreateAll();
static void StartRemoteDebuggingServer(
std::unique_ptr<DevToolsSocketFactory> server_socket_factory,
const base::FilePath& active_port_output_directory,
const base::FilePath& debug_frontend_dir);
static void StopRemoteDebuggingServer();
static void StartRemoteDebuggingPipeHandler(base::OnceClosure on_disconnect);
static void StopRemoteDebuggingPipeHandler();
static void AddObserver(DevToolsAgentHostObserver*);
static void RemoveObserver(DevToolsAgentHostObserver*);
virtual std::string CreateIOStreamFromData(
scoped_refptr<base::RefCountedMemory>) = 0;
virtual bool AttachClient(DevToolsAgentHostClient* client) = 0;
virtual bool AttachClientWithoutWakeLock(DevToolsAgentHostClient* client) = 0;
virtual bool DetachClient(DevToolsAgentHostClient* client) = 0;
virtual bool IsAttached() = 0;
virtual void DispatchProtocolMessage(DevToolsAgentHostClient* client,
base::span<const uint8_t> message) = 0;
virtual void InspectElement(RenderFrameHost* frame_host, int x, int y) = 0;
virtual std::string GetId() = 0;
virtual std::string GetParentId() = 0;
virtual std::string GetOpenerId() = 0;
virtual bool CanAccessOpener() = 0;
virtual std::string GetOpenerFrameId() = 0;
virtual WebContents* GetWebContents() = 0;
virtual BrowserContext* GetBrowserContext() = 0;
virtual void DisconnectWebContents() = 0;
virtual void ConnectWebContents(WebContents* web_contents) = 0;
virtual std::string GetType() = 0;
virtual std::string GetTitle() = 0;
virtual std::string GetDescription() = 0;
virtual GURL GetURL() = 0;
virtual GURL GetFaviconURL() = 0;
virtual std::string GetFrontendURL() = 0;
virtual bool Activate() = 0;
virtual void Reload() = 0;
virtual bool Close() = 0;
virtual base::TimeTicks GetLastActivityTime() = 0;
virtual void ForceDetachAllSessions() = 0;
static void DetachAllClients();
virtual RenderProcessHost* GetProcessHost() = 0;
protected:
friend class base::RefCounted<DevToolsAgentHost>;
virtual ~DevToolsAgentHost() {}
};
}
#endif