[Eraser strings] Remove unused Supervised User infobar and corresponding strings
[chromium-blink-merge.git] / components / devtools_discovery / basic_target_descriptor.cc
blob29b52dd8cc97afddf7952e3bb129a58723b79b6e
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";
21 namespace {
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;
31 default:
32 break;
34 return BasicTargetDescriptor::kTypeOther;
37 } // namespace
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.GetLastCommittedEntry();
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 {
62 return parent_id_;
65 std::string BasicTargetDescriptor::GetType() const {
66 return type_;
69 std::string BasicTargetDescriptor::GetTitle() const {
70 return title_;
73 std::string BasicTargetDescriptor::GetDescription() const {
74 return description_;
77 GURL BasicTargetDescriptor::GetURL() const {
78 return url_;
81 GURL BasicTargetDescriptor::GetFaviconURL() const {
82 return favicon_url_;
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 {
94 return agent_host_;
97 bool BasicTargetDescriptor::Activate() const {
98 return agent_host_->Activate();
101 bool BasicTargetDescriptor::Close() const {
102 return agent_host_->Close();
105 } // namespace devtools_discovery