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.
5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_
10 #include "base/callback.h"
11 #include "content/public/browser/devtools_target.h"
12 #include "content/public/browser/worker_service.h"
17 class DevToolsAgentHost;
22 class DevToolsTargetImpl : public content::DevToolsTarget {
24 static const char kTargetTypeApp[];
25 static const char kTargetTypeBackgroundPage[];
26 static const char kTargetTypePage[];
27 static const char kTargetTypeWorker[];
28 static const char kTargetTypeWebView[];
29 static const char kTargetTypeIFrame[];
30 static const char kTargetTypeOther[];
31 static const char kTargetTypeServiceWorker[];
33 explicit DevToolsTargetImpl(
34 scoped_refptr<content::DevToolsAgentHost> agent_host);
35 virtual ~DevToolsTargetImpl();
37 // content::DevToolsTarget overrides:
38 virtual std::string GetId() const OVERRIDE;
39 virtual std::string GetParentId() const OVERRIDE;
40 virtual std::string GetType() const OVERRIDE;
41 virtual std::string GetTitle() const OVERRIDE;
42 virtual std::string GetDescription() const OVERRIDE;
43 virtual GURL GetURL() const OVERRIDE;
44 virtual GURL GetFaviconURL() const OVERRIDE;
45 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE;
46 virtual scoped_refptr<content::DevToolsAgentHost>
47 GetAgentHost() const OVERRIDE;
48 virtual bool IsAttached() const OVERRIDE;
49 virtual bool Activate() const OVERRIDE;
50 virtual bool Close() const OVERRIDE;
52 // Returns the WebContents associated with the target on NULL if there is
54 virtual content::WebContents* GetWebContents() const;
56 // Returns the tab id if the target is associated with a tab, -1 otherwise.
57 virtual int GetTabId() const;
59 // Returns the extension id if the target is associated with an extension
61 virtual std::string GetExtensionId() const;
63 // Open a new DevTools window or activate the existing one.
64 virtual void Inspect(Profile* profile) const;
66 // Reload the target page.
67 virtual void Reload() const;
69 // Creates a new target associated with WebContents.
70 static scoped_ptr<DevToolsTargetImpl> CreateForWebContents(
71 content::WebContents* web_contents,
74 void set_parent_id(const std::string& parent_id) { parent_id_ = parent_id; }
75 void set_type(const std::string& type) { type_ = type; }
76 void set_title(const std::string& title) { title_ = title; }
77 void set_description(const std::string& desc) { description_ = desc; }
78 void set_url(const GURL& url) { url_ = url; }
79 void set_favicon_url(const GURL& url) { favicon_url_ = url; }
80 void set_last_activity_time(const base::TimeTicks& time) {
81 last_activity_time_ = time;
84 typedef std::vector<DevToolsTargetImpl*> List;
85 typedef base::Callback<void(const List&)> Callback;
87 static void EnumerateAllTargets(Callback callback);
90 scoped_refptr<content::DevToolsAgentHost> agent_host_;
91 std::string parent_id_;
94 std::string description_;
97 base::TimeTicks last_activity_time_;
100 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_