12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string> 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <vector> 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/basictypes.h" 1203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "base/callback.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/common/content_export.h" 1503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "content/public/browser/devtools_agent_host_client.h" 161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "url/gurl.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content { 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class DevToolsExternalAgentProxyDelegate; 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WebContents; 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Describes interface for managing devtools agents from browser process. 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CONTENT_EXPORT DevToolsAgentHost 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : public base::RefCounted<DevToolsAgentHost> { 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci enum Type { 281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Agent host associated with WebContents. 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TYPE_WEB_CONTENTS, 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Agent host associated with shared worker. 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TYPE_SHARED_WORKER, 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Agent host associated with service worker. 351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TYPE_SERVICE_WORKER, 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Agent host associated with DevToolsExternalAgentProxyDelegate. 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci TYPE_EXTERNAL, 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci }; 401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 44effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. 45effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch // New DevToolsAgentHost will be created if it does not exist. 46effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( 47effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch WebContents* web_contents); 48effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch 496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Returns true iff an instance of DevToolsAgentHost for the |web_contents| 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // does exist. 516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) static bool HasFor(WebContents* web_contents); 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns DevToolsAgentHost that can be used for inspecting shared worker 542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // with given worker process host id and routing id. 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id, 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int worker_route_id); 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 58cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Creates DevToolsAgentHost that communicates to the target by means of 59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // provided |delegate|. |delegate| ownership is passed to the created agent 60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // host. 61cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static scoped_refptr<DevToolsAgentHost> Create( 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) DevToolsExternalAgentProxyDelegate* delegate); 63cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool IsDebuggerAttached(WebContents* web_contents); 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef std::vector<scoped_refptr<DevToolsAgentHost> > List; 671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns all possible DevToolsAgentHosts. 691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static List GetOrCreateAll(); 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Client attaches to this agent host to start debugging it. 7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void AttachClient(DevToolsAgentHostClient* client) = 0; 7303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 7403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Already attached client detaches from this agent host to stop debugging it. 7503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void DetachClient() = 0; 7603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Returns true if there is a client attached. 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) virtual bool IsAttached() = 0; 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 8003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Sends a message to the agent. 8103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) virtual void DispatchProtocolMessage(const std::string& message) = 0; 8203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Starts inspecting element at position (|x|, |y|) in the specified page. 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void InspectElement(int x, int y) = 0; 852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the unique id of the agent. 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual std::string GetId() = 0; 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 896e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // Returns web contents instance for this host if any. 906e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual WebContents* GetWebContents() = 0; 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Temporarily detaches render view host from this host. Must be followed by 936e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // a call to ConnectWebContents (may leak the host instance otherwise). 946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void DisconnectWebContents() = 0; 957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Attaches render view host to this host. 976e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void ConnectWebContents(WebContents* web_contents) = 0; 987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 99cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns true if DevToolsAgentHost is for worker. 100cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual bool IsWorker() const = 0; 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1021320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns agent host type. 1031320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual Type GetType() = 0; 1041320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns agent host title. 1061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual std::string GetTitle() = 0; 1071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1081320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Returns url associated with agent host. 1091320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual GURL GetURL() = 0; 1101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Activates agent host. Returns false if the operation failed. 1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool Activate() = 0; 1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Closes agent host. Returns false if the operation failed. 1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual bool Close() = 0; 1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 11703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Terminates all debugging sessions and detaches all clients. 11803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) static void DetachAllClients(); 11903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 12003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) typedef base::Callback<void(DevToolsAgentHost*, bool attached)> 12103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) AgentStateCallback; 12203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 12303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) static void AddAgentStateCallback(const AgentStateCallback& callback); 12403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) static void RemoveAgentStateCallback(const AgentStateCallback& callback); 12503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) friend class base::RefCounted<DevToolsAgentHost>; 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~DevToolsAgentHost() {} 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace content 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 134