devtools_agent_host.h revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
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 DevToolsExternalAgentProxyDelegate;
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 |web_contents|.
28  // New DevToolsAgentHost will be created if it does not exist.
29  static scoped_refptr<DevToolsAgentHost> GetOrCreateFor(
30      WebContents* web_contents);
31
32  // Returns true iff an instance of DevToolsAgentHost for the |web_contents|
33  // does exist.
34  static bool HasFor(WebContents* web_contents);
35
36  // Returns DevToolsAgentHost that can be used for inspecting shared worker
37  // with given worker process host id and routing id.
38  static scoped_refptr<DevToolsAgentHost> GetForWorker(int worker_process_id,
39                                                       int worker_route_id);
40
41  // Creates DevToolsAgentHost that communicates to the target by means of
42  // provided |delegate|. |delegate| ownership is passed to the created agent
43  // host.
44  static scoped_refptr<DevToolsAgentHost> Create(
45      DevToolsExternalAgentProxyDelegate* delegate);
46
47  static bool IsDebuggerAttached(WebContents* web_contents);
48
49  // Returns a list of all existing WebContents that can be debugged.
50  static std::vector<WebContents*> GetInspectableWebContents();
51
52  // Returns true if there is a client attached.
53  virtual bool IsAttached() = 0;
54
55  // Starts inspecting element at position (|x|, |y|) in the specified page.
56  virtual void InspectElement(int x, int y) = 0;
57
58  // Returns the unique id of the agent.
59  virtual std::string GetId() = 0;
60
61  // Returns web contents instance for this host if any.
62  virtual WebContents* GetWebContents() = 0;
63
64  // Temporarily detaches render view host from this host. Must be followed by
65  // a call to ConnectWebContents (may leak the host instance otherwise).
66  virtual void DisconnectWebContents() = 0;
67
68  // Attaches render view host to this host.
69  virtual void ConnectWebContents(WebContents* web_contents) = 0;
70
71  // Returns true if DevToolsAgentHost is for worker.
72  virtual bool IsWorker() const = 0;
73
74 protected:
75  friend class base::RefCounted<DevToolsAgentHost>;
76  virtual ~DevToolsAgentHost() {}
77};
78
79}  // namespace content
80
81#endif  // CONTENT_PUBLIC_BROWSER_DEVTOOLS_AGENT_HOST_H_
82