summaryrefslogtreecommitdiffstats
path: root/components/devtools_discovery/basic_target_descriptor.cc
blob: 29b52dd8cc97afddf7952e3bb129a58723b79b6e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/devtools_discovery/basic_target_descriptor.h"

#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"

using content::DevToolsAgentHost;

namespace devtools_discovery {

const char BasicTargetDescriptor::kTypePage[] = "page";
const char BasicTargetDescriptor::kTypeServiceWorker[] = "service_worker";
const char BasicTargetDescriptor::kTypeSharedWorker[] = "worker";
const char BasicTargetDescriptor::kTypeOther[] = "other";

namespace {

std::string GetTypeFromAgentHost(DevToolsAgentHost* agent_host) {
  switch (agent_host->GetType()) {
    case DevToolsAgentHost::TYPE_WEB_CONTENTS:
      return BasicTargetDescriptor::kTypePage;
    case DevToolsAgentHost::TYPE_SERVICE_WORKER:
      return BasicTargetDescriptor::kTypeServiceWorker;
    case DevToolsAgentHost::TYPE_SHARED_WORKER:
      return BasicTargetDescriptor::kTypeSharedWorker;
    default:
      break;
  }
  return BasicTargetDescriptor::kTypeOther;
}

}  // namespace

BasicTargetDescriptor::BasicTargetDescriptor(
    scoped_refptr<DevToolsAgentHost> agent_host)
    : agent_host_(agent_host),
      type_(GetTypeFromAgentHost(agent_host.get())),
      title_(agent_host->GetTitle()),
      url_(agent_host->GetURL()) {
  if (content::WebContents* web_contents = agent_host_->GetWebContents()) {
    content::NavigationController& controller = web_contents->GetController();
    content::NavigationEntry* entry = controller.GetLastCommittedEntry();
    if (entry != NULL && entry->GetURL().is_valid())
      favicon_url_ = entry->GetFavicon().url;
    last_activity_time_ = web_contents->GetLastActiveTime();
  }
}

BasicTargetDescriptor::~BasicTargetDescriptor() {
}

std::string BasicTargetDescriptor::GetId() const {
  return agent_host_->GetId();
}

std::string BasicTargetDescriptor::GetParentId() const {
  return parent_id_;
}

std::string BasicTargetDescriptor::GetType() const {
  return type_;
}

std::string BasicTargetDescriptor::GetTitle() const {
  return title_;
}

std::string BasicTargetDescriptor::GetDescription() const {
  return description_;
}

GURL BasicTargetDescriptor::GetURL() const {
  return url_;
}

GURL BasicTargetDescriptor::GetFaviconURL() const {
  return favicon_url_;
}

base::TimeTicks BasicTargetDescriptor::GetLastActivityTime() const {
  return last_activity_time_;
}

bool BasicTargetDescriptor::IsAttached() const {
  return agent_host_->IsAttached();
}

scoped_refptr<DevToolsAgentHost> BasicTargetDescriptor::GetAgentHost() const {
  return agent_host_;
}

bool BasicTargetDescriptor::Activate() const {
  return agent_host_->Activate();
}

bool BasicTargetDescriptor::Close() const {
  return agent_host_->Close();
}

}  // namespace devtools_discovery