1 // Copyright 2015 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 #include "components/devtools_discovery/basic_target_descriptor.h"
7 #include "content/public/browser/devtools_agent_host.h"
8 #include "content/public/browser/favicon_status.h"
9 #include "content/public/browser/navigation_entry.h"
10 #include "content/public/browser/web_contents.h"
12 using content::DevToolsAgentHost
;
14 namespace devtools_discovery
{
16 const char BasicTargetDescriptor::kTypePage
[] = "page";
17 const char BasicTargetDescriptor::kTypeServiceWorker
[] = "service_worker";
18 const char BasicTargetDescriptor::kTypeSharedWorker
[] = "worker";
19 const char BasicTargetDescriptor::kTypeOther
[] = "other";
23 std::string
GetTypeFromAgentHost(DevToolsAgentHost
* agent_host
) {
24 switch (agent_host
->GetType()) {
25 case DevToolsAgentHost::TYPE_WEB_CONTENTS
:
26 return BasicTargetDescriptor::kTypePage
;
27 case DevToolsAgentHost::TYPE_SERVICE_WORKER
:
28 return BasicTargetDescriptor::kTypeServiceWorker
;
29 case DevToolsAgentHost::TYPE_SHARED_WORKER
:
30 return BasicTargetDescriptor::kTypeSharedWorker
;
34 return BasicTargetDescriptor::kTypeOther
;
39 BasicTargetDescriptor::BasicTargetDescriptor(
40 scoped_refptr
<DevToolsAgentHost
> agent_host
)
41 : agent_host_(agent_host
),
42 type_(GetTypeFromAgentHost(agent_host
.get())),
43 title_(agent_host
->GetTitle()),
44 url_(agent_host
->GetURL()) {
45 if (content::WebContents
* web_contents
= agent_host_
->GetWebContents()) {
46 content::NavigationController
& controller
= web_contents
->GetController();
47 content::NavigationEntry
* entry
= controller
.GetActiveEntry();
48 if (entry
!= NULL
&& entry
->GetURL().is_valid())
49 favicon_url_
= entry
->GetFavicon().url
;
50 last_activity_time_
= web_contents
->GetLastActiveTime();
54 BasicTargetDescriptor::~BasicTargetDescriptor() {
57 std::string
BasicTargetDescriptor::GetId() const {
58 return agent_host_
->GetId();
61 std::string
BasicTargetDescriptor::GetParentId() const {
65 std::string
BasicTargetDescriptor::GetType() const {
69 std::string
BasicTargetDescriptor::GetTitle() const {
73 std::string
BasicTargetDescriptor::GetDescription() const {
77 GURL
BasicTargetDescriptor::GetURL() const {
81 GURL
BasicTargetDescriptor::GetFaviconURL() const {
85 base::TimeTicks
BasicTargetDescriptor::GetLastActivityTime() const {
86 return last_activity_time_
;
89 bool BasicTargetDescriptor::IsAttached() const {
90 return agent_host_
->IsAttached();
93 scoped_refptr
<DevToolsAgentHost
> BasicTargetDescriptor::GetAgentHost() const {
97 bool BasicTargetDescriptor::Activate() const {
98 return agent_host_
->Activate();
101 bool BasicTargetDescriptor::Close() const {
102 return agent_host_
->Close();
105 } // namespace devtools_discovery