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/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 | 15 |
| 15 namespace content { | 16 namespace content { |
| 16 | 17 |
| 17 class DevToolsExternalAgentProxyDelegate; | 18 class DevToolsExternalAgentProxyDelegate; |
| 18 class RenderViewHost; | 19 class RenderViewHost; |
| 19 class WebContents; | 20 class WebContents; |
| 20 | 21 |
| 21 // Describes interface for managing devtools agents from browser process. | 22 // Describes interface for managing devtools agents from browser process. |
| 22 class CONTENT_EXPORT DevToolsAgentHost | 23 class CONTENT_EXPORT DevToolsAgentHost |
| 23 : public base::RefCounted<DevToolsAgentHost> { | 24 : public base::RefCounted<DevToolsAgentHost> { |
| 24 public: | 25 public: |
| 26 enum DetachReason { | |
| 27 DETACHED_BY_CLIENT, | |
| 28 REPLACED_WITH_ANOTHER_CLIENT, | |
| 29 HOST_CLOSED | |
| 30 }; | |
| 31 | |
| 32 // Client can attach to the agent host and start inspecting it. | |
| 33 class Client { | |
|
pfeldman
2014/08/07 14:41:58
It would be great if Detach and DTAH::DispatchProt
| |
| 34 public: | |
| 35 virtual ~Client() {} | |
| 36 | |
| 37 // Dispatches given protocol message on the client. | |
| 38 virtual void SendMessageFromAgentHost(DevToolsAgentHost* agent_host, | |
| 39 const std::string& message) = 0; | |
| 40 | |
| 41 // This method is called when attached agent host is detached. | |
| 42 virtual void AgentHostDetached(DevToolsAgentHost* agent_host, | |
| 43 DetachReason reason) = 0; | |
| 44 }; | |
| 45 | |
| 25 // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. | 46 // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist. |
| 26 static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); | 47 static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id); |
| 27 | 48 |
| 28 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. | 49 // Returns DevToolsAgentHost that can be used for inspecting |web_contents|. |
| 29 // New DevToolsAgentHost will be created if it does not exist. | 50 // New DevToolsAgentHost will be created if it does not exist. |
| 30 static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( | 51 static scoped_refptr<DevToolsAgentHost> GetOrCreateFor( |
| 31 WebContents* web_contents); | 52 WebContents* web_contents); |
| 32 | 53 |
| 33 // Returns DevToolsAgentHost that can be used for inspecting |rvh|. | 54 // Returns DevToolsAgentHost that can be used for inspecting |rvh|. |
| 34 // New DevToolsAgentHost will be created if it does not exist. | 55 // New DevToolsAgentHost will be created if it does not exist. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 47 // provided |delegate|. |delegate| ownership is passed to the created agent | 68 // provided |delegate|. |delegate| ownership is passed to the created agent |
| 48 // host. | 69 // host. |
| 49 static scoped_refptr<DevToolsAgentHost> Create( | 70 static scoped_refptr<DevToolsAgentHost> Create( |
| 50 DevToolsExternalAgentProxyDelegate* delegate); | 71 DevToolsExternalAgentProxyDelegate* delegate); |
| 51 | 72 |
| 52 static bool IsDebuggerAttached(WebContents* web_contents); | 73 static bool IsDebuggerAttached(WebContents* web_contents); |
| 53 | 74 |
| 54 // Returns a list of all existing RenderViewHost's that can be debugged. | 75 // Returns a list of all existing RenderViewHost's that can be debugged. |
| 55 static std::vector<RenderViewHost*> GetValidRenderViewHosts(); | 76 static std::vector<RenderViewHost*> GetValidRenderViewHosts(); |
| 56 | 77 |
| 78 // Client attaches to this agent host to start debugging it. | |
| 79 virtual void AttachClient(Client* client) = 0; | |
| 80 | |
| 81 // Already attached client detaches from this agent host to stop debugging it. | |
| 82 virtual void DetachClient() = 0; | |
| 83 | |
| 57 // Returns true if there is a client attached. | 84 // Returns true if there is a client attached. |
| 58 virtual bool IsAttached() = 0; | 85 virtual bool IsAttached() = 0; |
| 59 | 86 |
| 87 // Sends a message to the agent. | |
| 88 virtual void DispatchOnInspectorBackend(const std::string& message) = 0; | |
| 89 | |
| 60 // Starts inspecting element at position (|x|, |y|) in the specified page. | 90 // Starts inspecting element at position (|x|, |y|) in the specified page. |
| 61 virtual void InspectElement(int x, int y) = 0; | 91 virtual void InspectElement(int x, int y) = 0; |
| 62 | 92 |
| 63 // Returns the unique id of the agent. | 93 // Returns the unique id of the agent. |
| 64 virtual std::string GetId() = 0; | 94 virtual std::string GetId() = 0; |
| 65 | 95 |
| 66 // Returns render view host instance for this host if any. | 96 // Returns render view host instance for this host if any. |
| 67 virtual RenderViewHost* GetRenderViewHost() = 0; | 97 virtual RenderViewHost* GetRenderViewHost() = 0; |
| 68 | 98 |
| 69 // Temporarily detaches render view host from this host. Must be followed by | 99 // Temporarily detaches render view host from this host. Must be followed by |
| 70 // a call to ConnectRenderViewHost (may leak the host instance otherwise). | 100 // a call to ConnectRenderViewHost (may leak the host instance otherwise). |
| 71 virtual void DisconnectRenderViewHost() = 0; | 101 virtual void DisconnectRenderViewHost() = 0; |
| 72 | 102 |
| 73 // Attaches render view host to this host. | 103 // Attaches render view host to this host. |
| 74 virtual void ConnectRenderViewHost(RenderViewHost* rvh) = 0; | 104 virtual void ConnectRenderViewHost(RenderViewHost* rvh) = 0; |
| 75 | 105 |
| 76 // Returns true if DevToolsAgentHost is for worker. | 106 // Returns true if DevToolsAgentHost is for worker. |
| 77 virtual bool IsWorker() const = 0; | 107 virtual bool IsWorker() const = 0; |
| 78 | 108 |
| 109 // Terminates all debugging sessions and detaches all clients. | |
| 110 static void DetachAllClients(); | |
| 111 | |
| 112 typedef base::Callback<void(DevToolsAgentHost*, bool attached)> | |
| 113 AgentStateCallback; | |
| 114 | |
| 115 static void AddAgentStateCallback(const AgentStateCallback& callback); | |
| 116 static void RemoveAgentStateCallback(const AgentStateCallback& callback); | |
| 117 | |
| 79 protected: | 118 protected: |
| 80 friend class base::RefCounted<DevToolsAgentHost>; | 119 friend class base::RefCounted<DevToolsAgentHost>; |
| 81 virtual ~DevToolsAgentHost() {} | 120 virtual ~DevToolsAgentHost() {} |
| 82 }; | 121 }; |
| 83 | 122 |
| 84 } // namespace content | 123 } // namespace content |
| 85 | 124 |
| 86 #endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ | 125 #endif // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_ |
| OLD | NEW |