devtools_target_impl.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
1// Copyright 2013 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 CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
6#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
7
8#include <vector>
9
10#include "base/callback.h"
11#include "content/public/browser/devtools_target.h"
12#include "content/public/browser/worker_service.h"
13
14class Profile;
15
16namespace content {
17class DevToolsAgentHost;
18class RenderViewHost;
19}
20
21class DevToolsTargetImpl : public content::DevToolsTarget {
22 public:
23  explicit DevToolsTargetImpl(
24      scoped_refptr<content::DevToolsAgentHost> agent_host);
25  virtual ~DevToolsTargetImpl();
26
27  // content::DevToolsTarget overrides:
28  virtual std::string GetId() const OVERRIDE;
29  virtual std::string GetType() const OVERRIDE;
30  virtual std::string GetTitle() const OVERRIDE;
31  virtual std::string GetDescription() const OVERRIDE;
32  virtual GURL GetURL() const OVERRIDE;
33  virtual GURL GetFaviconURL() const OVERRIDE;
34  virtual base::TimeTicks GetLastActivityTime() const OVERRIDE;
35  virtual scoped_refptr<content::DevToolsAgentHost>
36      GetAgentHost() const OVERRIDE;
37  virtual bool IsAttached() const OVERRIDE;
38  virtual bool Activate() const OVERRIDE;
39  virtual bool Close() const OVERRIDE;
40
41  // Returns the RenderViewHost associated with the target on NULL if there is
42  // not any.
43  virtual content::RenderViewHost* GetRenderViewHost() const;
44
45  // Returns the tab id if the target is associated with a tab, -1 otherwise.
46  virtual int GetTabId() const;
47
48  // Returns the extension id if the target is associated with an extension
49  // background page.
50  virtual std::string GetExtensionId() const;
51
52  // Open a new DevTools window or activate the existing one.
53  virtual void Inspect(Profile* profile) const;
54
55  // Reload the target page.
56  virtual void Reload() const;
57
58  // Creates a new target associated with RenderViewHost.
59  static scoped_ptr<DevToolsTargetImpl> CreateForRenderViewHost(
60      content::RenderViewHost*, bool is_tab);
61
62  void set_type(const std::string& type) { type_ = type; }
63  void set_title(const std::string& title) { title_ = title; }
64  void set_description(const std::string& desc) { description_ = desc; }
65  void set_url(const GURL& url) { url_ = url; }
66  void set_favicon_url(const GURL& url) { favicon_url_ = url; }
67  void set_last_activity_time(const base::TimeTicks& time) {
68     last_activity_time_ = time;
69  }
70
71  typedef std::vector<DevToolsTargetImpl*> List;
72  typedef base::Callback<void(const List&)> Callback;
73
74  static List EnumerateRenderViewHostTargets();
75  static void EnumerateWorkerTargets(Callback callback);
76  static void EnumerateAllTargets(Callback callback);
77
78 private:
79  scoped_refptr<content::DevToolsAgentHost> agent_host_;
80  std::string id_;
81  std::string type_;
82  std::string title_;
83  std::string description_;
84  GURL url_;
85  GURL favicon_url_;
86  base::TimeTicks last_activity_time_;
87};
88
89#endif  // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
90