devtools_agent_host.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 6#define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 7 8#include <string> 9#include <vector> 10 11#include "base/basictypes.h" 12#include "base/callback.h" 13#include "base/memory/ref_counted.h" 14#include "content/common/content_export.h" 15#include "content/public/browser/devtools_agent_host_client.h" 16 17namespace content { 18 19class DevToolsExternalAgentProxyDelegate; 20class WebContents; 21 22// Describes interface for managing devtools agents from browser process. 23class CONTENT_EXPORT DevToolsAgentHost 24 : public base::RefCounted<DevToolsAgentHost> { 25 public: 26 // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. 27 static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); 28 29 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. 30 // New DevToolsAgentHost will be created if it does not exist. 31 static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( 32 WebContents* web_contents); 33 34 // Returns true iff an instance of DevToolsAgentHost for the |web_contents| 35 // does exist. 36 static bool HasFor(WebContents* web_contents); 37 38 // Returns DevToolsAgentHost that can be used for inspecting shared worker 39 // with given worker process host id and routing id. 40 static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id, 41 int worker_route_id); 42 43 // Creates DevToolsAgentHost that communicates to the target by means of 44 // provided |delegate|. |delegate| ownership is passed to the created agent 45 // host. 46 static scoped_refptr<DevToolsAgentHost> Create( 47 DevToolsExternalAgentProxyDelegate* delegate); 48 49 static bool IsDebuggerAttached(WebContents* web_contents); 50 51 // Returns a list of all existing WebContents that can be debugged. 52 static std::vector<WebContents*> GetInspectableWebContents(); 53 54 // Client attaches to this agent host to start debugging it. 55 virtual void AttachClient(DevToolsAgentHostClient* client) = 0; 56 57 // Already attached client detaches from this agent host to stop debugging it. 58 virtual void DetachClient() = 0; 59 60 // Returns true if there is a client attached. 61 virtual bool IsAttached() = 0; 62 63 // Sends a message to the agent. 64 virtual void DispatchProtocolMessage(const std::string& message) = 0; 65 66 // Starts inspecting element at position (|x|, |y|) in the specified page. 67 virtual void InspectElement(int x, int y) = 0; 68 69 // Returns the unique id of the agent. 70 virtual std::string GetId() = 0; 71 72 // Returns web contents instance for this host if any. 73 virtual WebContents* GetWebContents() = 0; 74 75 // Temporarily detaches render view host from this host. Must be followed by 76 // a call to ConnectWebContents (may leak the host instance otherwise). 77 virtual void DisconnectWebContents() = 0; 78 79 // Attaches render view host to this host. 80 virtual void ConnectWebContents(WebContents* web_contents) = 0; 81 82 // Returns true if DevToolsAgentHost is for worker. 83 virtual bool IsWorker() const = 0; 84 85 // Terminates all debugging sessions and detaches all clients. 86 static void DetachAllClients(); 87 88 typedef base::Callback<void(DevToolsAgentHost*, bool attached)> 89 AgentStateCallback; 90 91 static void AddAgentStateCallback(const AgentStateCallback& callback); 92 static void RemoveAgentStateCallback(const AgentStateCallback& callback); 93 94 protected: 95 friend class base::RefCounted<DevToolsAgentHost>; 96 virtual ~DevToolsAgentHost() {} 97}; 98 99} // namespace content 100 101#endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ 102