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 ~DevToolsTargetImpl() override
;
37 // content::DevToolsTarget overrides:
38 std::string
GetId() const override
;
39 std::string
GetParentId() const override
;
40 std::string
GetType() const override
;
41 std::string
GetTitle() const override
;
42 std::string
GetDescription() const override
;
43 GURL
GetURL() const override
;
44 GURL
GetFaviconURL() const override
;
45 base::TimeTicks
GetLastActivityTime() const override
;
46 scoped_refptr
<content::DevToolsAgentHost
> GetAgentHost() const override
;
47 bool IsAttached() const override
;
48 bool Activate() const override
;
49 bool Close() const override
;
51 // Returns the WebContents associated with the target on NULL if there is
53 virtual content::WebContents
* GetWebContents() const;
55 // Returns the tab id if the target is associated with a tab, -1 otherwise.
56 virtual int GetTabId() const;
58 // Returns the extension id if the target is associated with an extension
60 virtual std::string
GetExtensionId() const;
62 // Open a new DevTools window or activate the existing one.
63 virtual void Inspect(Profile
* profile
) const;
65 // Reload the target page.
66 virtual void Reload() const;
68 // Creates a new target associated with WebContents.
69 static scoped_ptr
<DevToolsTargetImpl
> CreateForWebContents(
70 content::WebContents
* web_contents
,
73 void set_parent_id(const std::string
& parent_id
) { parent_id_
= parent_id
; }
74 void set_type(const std::string
& type
) { type_
= type
; }
75 void set_title(const std::string
& title
) { title_
= title
; }
76 void set_description(const std::string
& desc
) { description_
= desc
; }
77 void set_url(const GURL
& url
) { url_
= url
; }
78 void set_favicon_url(const GURL
& url
) { favicon_url_
= url
; }
79 void set_last_activity_time(const base::TimeTicks
& time
) {
80 last_activity_time_
= time
;
83 typedef std::vector
<DevToolsTargetImpl
*> List
;
84 typedef base::Callback
<void(const List
&)> Callback
;
86 static void EnumerateAllTargets(Callback callback
);
89 scoped_refptr
<content::DevToolsAgentHost
> agent_host_
;
90 std::string parent_id_
;
93 std::string description_
;
96 base::TimeTicks last_activity_time_
;
99 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_TARGET_IMPL_H_