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.
5 #ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
6 #define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
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"
21 class DevToolsExternalAgentProxyDelegate
;
24 // Describes interface for managing devtools agents from browser process.
25 class CONTENT_EXPORT DevToolsAgentHost
26 : public base::RefCounted
<DevToolsAgentHost
> {
29 // Agent host associated with WebContents.
32 // Agent host associated with RenderFrameHost.
35 // Agent host associated with shared worker.
38 // Agent host associated with service worker.
41 // Agent host associated with DevToolsExternalAgentProxyDelegate.
45 // Returns DevToolsAgentHost with a given |id| or nullptr of it doesn't exist.
46 static scoped_refptr
<DevToolsAgentHost
> GetForId(const std::string
& id
);
48 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|.
49 // New DevToolsAgentHost will be created if it does not exist.
50 static scoped_refptr
<DevToolsAgentHost
> GetOrCreateFor(
51 WebContents
* web_contents
);
53 // Returns true iff an instance of DevToolsAgentHost for the |web_contents|
55 static bool HasFor(WebContents
* web_contents
);
57 // Returns DevToolsAgentHost that can be used for inspecting shared worker
58 // with given worker process host id and routing id.
59 static scoped_refptr
<DevToolsAgentHost
> GetForWorker(int worker_process_id
,
62 // Creates DevToolsAgentHost that communicates to the target by means of
63 // provided |delegate|. |delegate| ownership is passed to the created agent
65 static scoped_refptr
<DevToolsAgentHost
> Create(
66 DevToolsExternalAgentProxyDelegate
* delegate
);
68 static bool IsDebuggerAttached(WebContents
* web_contents
);
70 typedef std::vector
<scoped_refptr
<DevToolsAgentHost
> > List
;
72 // Returns all possible DevToolsAgentHosts.
73 static List
GetOrCreateAll();
75 // Client attaches to this agent host to start debugging it.
76 virtual void AttachClient(DevToolsAgentHostClient
* client
) = 0;
78 // Already attached client detaches from this agent host to stop debugging it.
79 virtual void DetachClient() = 0;
81 // Returns true if there is a client attached.
82 virtual bool IsAttached() = 0;
84 // Sends a message to the agent. Returns true if the message is handled.
85 virtual bool DispatchProtocolMessage(const std::string
& message
) = 0;
87 // Starts inspecting element at position (|x|, |y|) in the specified page.
88 virtual void InspectElement(int x
, int y
) = 0;
90 // Returns the unique id of the agent.
91 virtual std::string
GetId() = 0;
93 // Returns web contents instance for this host if any.
94 virtual WebContents
* GetWebContents() = 0;
96 // Returns related browser context instance if available.
97 virtual BrowserContext
* GetBrowserContext() = 0;
99 // Temporarily detaches render view host from this host. Must be followed by
100 // a call to ConnectWebContents (may leak the host instance otherwise).
101 virtual void DisconnectWebContents() = 0;
103 // Attaches render view host to this host.
104 virtual void ConnectWebContents(WebContents
* web_contents
) = 0;
106 // Returns true if DevToolsAgentHost is for worker.
107 virtual bool IsWorker() const = 0;
109 // Returns agent host type.
110 virtual Type
GetType() = 0;
112 // Returns agent host title.
113 virtual std::string
GetTitle() = 0;
115 // Returns url associated with agent host.
116 virtual GURL
GetURL() = 0;
118 // Activates agent host. Returns false if the operation failed.
119 virtual bool Activate() = 0;
121 // Closes agent host. Returns false if the operation failed.
122 virtual bool Close() = 0;
124 // Terminates all debugging sessions and detaches all clients.
125 static void DetachAllClients();
127 typedef base::Callback
<void(DevToolsAgentHost
*, bool attached
)>
130 static void AddAgentStateCallback(const AgentStateCallback
& callback
);
131 static void RemoveAgentStateCallback(const AgentStateCallback
& callback
);
134 friend class base::RefCounted
<DevToolsAgentHost
>;
135 virtual ~DevToolsAgentHost() {}
138 } // namespace content
140 #endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_