devtools_agent_host.h revision 23730a6e56a168d1879203e4b3819bb36e3d8f1f
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/memory/ref_counted.h"
13#include "content/common/content_export.h"
14
15namespace content {
16
17class RenderViewHost;
18class WebContents;
19
20// Describes interface for managing devtools agents from browser process.
21class CONTENT_EXPORT DevToolsAgentHost
22    : public base::RefCounted<DevToolsAgentHost> {
23 public:
24  // Returns DevToolsAgentHost with a given |id| or NULL of it does not exist.
25  static scoped_refptr<DevToolsAgentHost> GetForId(const std::string& id);
26
27  // Returns DevToolsAgentHost that can be used for inspecting |rvh|.
28  // New DevToolsAgentHost will be created if it does not exist.
29  static scoped_refptr<DevToolsAgentHost> GetOrCreateFor(RenderViewHost* rvh);
30
31  // Returns true iff an instance of DevToolsAgentHost for the |rvh|
32  // does exist.
33  static bool HasFor(RenderViewHost* rvh);
34
35  // Returns DevToolsAgentHost that can be used for inspecting shared worker
36  // with given worker process host id and routing id.
37  static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id,
38                                                       int worker_route_id);
39
40  static bool IsDebuggerAttached(WebContents* web_contents);
41
42  // Returns a list of all existing RenderViewHost's that can be debugged.
43  static std::vector<RenderViewHost*> GetValidRenderViewHosts();
44
45  // Returns true if there is a client attached.
46  virtual bool IsAttached() = 0;
47
48  // Starts inspecting element at position (|x|, |y|) in the specified page.
49  virtual void InspectElement(int x, int y) = 0;
50
51  // Returns the unique id of the agent.
52  virtual std::string GetId() = 0;
53
54  // Returns render view host instance for this host if any.
55  virtual RenderViewHost* GetRenderViewHost() = 0;
56
57  // Temporarily detaches render view host from this host. Must be followed by
58  // a call to ConnectRenderViewHost (may leak the host instance otherwise).
59  virtual void DisconnectRenderViewHost() = 0;
60
61  // Attaches render view host to this host.
62  virtual void ConnectRenderViewHost(RenderViewHost* rvh) = 0;
63
64 protected:
65  friend class base::RefCounted<DevToolsAgentHost>;
66  virtual ~DevToolsAgentHost() {}
67};
68
69}  // namespace content
70
71#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
72