devtools_agent_host.h revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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  // Returns true iff an instance of DevToolsAgentHost exists for the shared
41  // worker with given process host id and routing id.
42  static bool HasForWorker(int worker_process_id,
43                           int worker_route_id);
44
45  static bool IsDebuggerAttached(WebContents* web_contents);
46
47  // Returns a list of all existing RenderViewHost's that can be debugged.
48  static std::vector<RenderViewHost*> GetValidRenderViewHosts();
49
50  // Returns true if there is a client attached.
51  virtual bool IsAttached() = 0;
52
53  // Starts inspecting element at position (|x|, |y|) in the specified page.
54  virtual void InspectElement(int x, int y) = 0;
55
56  // Returns the unique id of the agent.
57  virtual std::string GetId() = 0;
58
59  // Returns render view host instance for this host if any.
60  virtual RenderViewHost* GetRenderViewHost() = 0;
61
62  // Temporarily detaches render view host from this host. Must be followed by
63  // a call to ConnectRenderViewHost (may leak the host instance otherwise).
64  virtual void DisconnectRenderViewHost() = 0;
65
66  // Attaches render view host to this host.
67  virtual void ConnectRenderViewHost(RenderViewHost* rvh) = 0;
68
69 protected:
70  friend class base::RefCounted<DevToolsAgentHost>;
71  virtual ~DevToolsAgentHost() {}
72};
73
74}  // namespace content
75
76#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
77