Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ | 6 #define CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/browser/devtools_agent_host_client.h" | 15 #include "content/public/browser/devtools_agent_host_client.h" |
| 16 #include "url/gurl.h" | |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 class DevToolsExternalAgentProxyDelegate; | 20 class DevToolsExternalAgentProxyDelegate; |
| 20 class WebContents; | 21 class WebContents; |
| 21 | 22 |
| 22 // Describes interface for managing devtools agents from browser process. | 23 // Describes interface for managing devtools agents from browser process. |
| 23 class CONTENT_EXPORT DevToolsAgentHost | 24 class CONTENT_EXPORT DevToolsAgentHost |
| 24 : public base::RefCounted<DevToolsAgentHost> { | 25 : public base::RefCounted<DevToolsAgentHost> { |
| 25 public: | 26 public: |
| 27 enum Type { | |
| 28 // Agent host associated with WebContents. | |
| 29 AGENT_HOST_WEB_CONTENTS, | |
|
dgozman
2014/08/22 08:38:28
I'd say this should be TYPE_WEB_CONTENTS.
vkuzkokov
2014/08/22 11:01:48
Done.
| |
| 30 | |
| 31 // Agent host associated with shared worker. | |
| 32 AGENT_HOST_SHARED_WORKER, | |
| 33 | |
| 34 // Agent host associated with service worker. | |
| 35 AGENT_HOST_SERVICE_WORKER, | |
| 36 | |
| 37 // Agent host associated with DevToolsExternalAgentProxyDelegate. | |
| 38 AGENT_HOST_EXTERNAL, | |
| 39 }; | |
| 40 | |
| 26 // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. | 41 // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. |
| 27 static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); | 42 static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); |
| 28 | 43 |
| 29 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. | 44 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. |
| 30 // New DevToolsAgentHost will be created if it does not exist. | 45 // New DevToolsAgentHost will be created if it does not exist. |
| 31 static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( | 46 static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( |
| 32 WebContents* web_contents); | 47 WebContents* web_contents); |
| 33 | 48 |
| 34 // Returns true iff an instance of DevToolsAgentHost for the |web_contents| | 49 // Returns true iff an instance of DevToolsAgentHost for the |web_contents| |
| 35 // does exist. | 50 // does exist. |
| 36 static bool HasFor(WebContents* web_contents); | 51 static bool HasFor(WebContents* web_contents); |
| 37 | 52 |
| 38 // Returns DevToolsAgentHost that can be used for inspecting shared worker | 53 // Returns DevToolsAgentHost that can be used for inspecting shared worker |
| 39 // with given worker process host id and routing id. | 54 // with given worker process host id and routing id. |
| 40 static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id, | 55 static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id, |
| 41 int worker_route_id); | 56 int worker_route_id); |
| 42 | 57 |
| 43 // Creates DevToolsAgentHost that communicates to the target by means of | 58 // Creates DevToolsAgentHost that communicates to the target by means of |
| 44 // provided |delegate|. |delegate| ownership is passed to the created agent | 59 // provided |delegate|. |delegate| ownership is passed to the created agent |
| 45 // host. | 60 // host. |
| 46 static scoped_refptr<DevToolsAgentHost> Create( | 61 static scoped_refptr<DevToolsAgentHost> Create( |
| 47 DevToolsExternalAgentProxyDelegate* delegate); | 62 DevToolsExternalAgentProxyDelegate* delegate); |
| 48 | 63 |
| 49 static bool IsDebuggerAttached(WebContents* web_contents); | 64 static bool IsDebuggerAttached(WebContents* web_contents); |
| 50 | 65 |
| 51 // Returns a list of all existing WebContents that can be debugged. | 66 typedef std::vector<scoped_refptr<DevToolsAgentHost> > List; |
| 52 static std::vector<WebContents*> GetInspectableWebContents(); | 67 |
| 68 // Returns all possible DevToolsAgentHosts. | |
| 69 static List GetOrCreateAll(); | |
| 53 | 70 |
| 54 // Client attaches to this agent host to start debugging it. | 71 // Client attaches to this agent host to start debugging it. |
| 55 virtual void AttachClient(DevToolsAgentHostClient* client) = 0; | 72 virtual void AttachClient(DevToolsAgentHostClient* client) = 0; |
| 56 | 73 |
| 57 // Already attached client detaches from this agent host to stop debugging it. | 74 // Already attached client detaches from this agent host to stop debugging it. |
| 58 virtual void DetachClient() = 0; | 75 virtual void DetachClient() = 0; |
| 59 | 76 |
| 60 // Returns true if there is a client attached. | 77 // Returns true if there is a client attached. |
| 61 virtual bool IsAttached() = 0; | 78 virtual bool IsAttached() = 0; |
| 62 | 79 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 75 // Temporarily detaches render view host from this host. Must be followed by | 92 // Temporarily detaches render view host from this host. Must be followed by |
| 76 // a call to ConnectWebContents (may leak the host instance otherwise). | 93 // a call to ConnectWebContents (may leak the host instance otherwise). |
| 77 virtual void DisconnectWebContents() = 0; | 94 virtual void DisconnectWebContents() = 0; |
| 78 | 95 |
| 79 // Attaches render view host to this host. | 96 // Attaches render view host to this host. |
| 80 virtual void ConnectWebContents(WebContents* web_contents) = 0; | 97 virtual void ConnectWebContents(WebContents* web_contents) = 0; |
| 81 | 98 |
| 82 // Returns true if DevToolsAgentHost is for worker. | 99 // Returns true if DevToolsAgentHost is for worker. |
| 83 virtual bool IsWorker() const = 0; | 100 virtual bool IsWorker() const = 0; |
| 84 | 101 |
| 102 // Returns agent host type. | |
| 103 virtual Type GetType() = 0; | |
| 104 | |
| 105 // Returns agent host title. | |
| 106 virtual std::string GetTitle() = 0; | |
| 107 | |
| 108 // Returns url associated with agent host. | |
| 109 virtual GURL GetURL() = 0; | |
| 110 | |
| 111 // Activates agent host. Returns false if the operation failed. | |
| 112 virtual bool Activate() = 0; | |
| 113 | |
| 114 // Closes agent host. Returns false if the operation failed. | |
| 115 virtual bool Close() = 0; | |
| 116 | |
| 85 // Terminates all debugging sessions and detaches all clients. | 117 // Terminates all debugging sessions and detaches all clients. |
| 86 static void DetachAllClients(); | 118 static void DetachAllClients(); |
| 87 | 119 |
| 88 typedef base::Callback<void(DevToolsAgentHost*, bool attached)> | 120 typedef base::Callback<void(DevToolsAgentHost*, bool attached)> |
| 89 AgentStateCallback; | 121 AgentStateCallback; |
| 90 | 122 |
| 91 static void AddAgentStateCallback(const AgentStateCallback& callback); | 123 static void AddAgentStateCallback(const AgentStateCallback& callback); |
| 92 static void RemoveAgentStateCallback(const AgentStateCallback& callback); | 124 static void RemoveAgentStateCallback(const AgentStateCallback& callback); |
| 93 | 125 |
| 94 protected: | 126 protected: |
| 95 friend class base::RefCounted<DevToolsAgentHost>; | 127 friend class base::RefCounted<DevToolsAgentHost>; |
| 96 virtual ~DevToolsAgentHost() {} | 128 virtual ~DevToolsAgentHost() {} |
| 97 }; | 129 }; |
| 98 | 130 |
| 99 } // namespace content | 131 } // namespace content |
| 100 | 132 |
| 101 #endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ | 133 #endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ |
| OLD | NEW |