OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/devtools_discovery/basic_target_descriptor.h" | 5 #include "components/devtools_discovery/basic_target_descriptor.h" |
6 | 6 |
7 #include "content/public/browser/devtools_agent_host.h" | 7 #include "content/public/browser/devtools_agent_host.h" |
8 #include "content/public/browser/favicon_status.h" | 8 #include "content/public/browser/favicon_status.h" |
9 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
11 | 11 |
12 using content::DevToolsAgentHost; | 12 using content::DevToolsAgentHost; |
13 | 13 |
14 namespace devtools_discovery { | 14 namespace devtools_discovery { |
15 | 15 |
| 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"; |
| 20 |
| 21 namespace { |
| 22 |
| 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; |
| 33 } |
| 34 return BasicTargetDescriptor::kTypeOther; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
16 BasicTargetDescriptor::BasicTargetDescriptor( | 39 BasicTargetDescriptor::BasicTargetDescriptor( |
17 scoped_refptr<DevToolsAgentHost> agent_host) | 40 scoped_refptr<DevToolsAgentHost> agent_host) |
18 : agent_host_(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(); |
| 51 } |
19 } | 52 } |
20 | 53 |
21 BasicTargetDescriptor::~BasicTargetDescriptor() { | 54 BasicTargetDescriptor::~BasicTargetDescriptor() { |
22 } | 55 } |
23 | 56 |
| 57 std::string BasicTargetDescriptor::GetId() const { |
| 58 return agent_host_->GetId(); |
| 59 } |
| 60 |
| 61 std::string BasicTargetDescriptor::GetParentId() const { |
| 62 return parent_id_; |
| 63 } |
| 64 |
| 65 std::string BasicTargetDescriptor::GetType() const { |
| 66 return type_; |
| 67 } |
| 68 |
| 69 std::string BasicTargetDescriptor::GetTitle() const { |
| 70 return title_; |
| 71 } |
| 72 |
| 73 std::string BasicTargetDescriptor::GetDescription() const { |
| 74 return description_; |
| 75 } |
| 76 |
| 77 GURL BasicTargetDescriptor::GetURL() const { |
| 78 return url_; |
| 79 } |
| 80 |
| 81 GURL BasicTargetDescriptor::GetFaviconURL() const { |
| 82 return favicon_url_; |
| 83 } |
| 84 |
| 85 base::TimeTicks BasicTargetDescriptor::GetLastActivityTime() const { |
| 86 return last_activity_time_; |
| 87 } |
| 88 |
| 89 bool BasicTargetDescriptor::IsAttached() const { |
| 90 return agent_host_->IsAttached(); |
| 91 } |
| 92 |
24 scoped_refptr<DevToolsAgentHost> BasicTargetDescriptor::GetAgentHost() const { | 93 scoped_refptr<DevToolsAgentHost> BasicTargetDescriptor::GetAgentHost() const { |
25 return agent_host_; | 94 return agent_host_; |
26 } | 95 } |
27 | 96 |
| 97 bool BasicTargetDescriptor::Activate() const { |
| 98 return agent_host_->Activate(); |
| 99 } |
| 100 |
| 101 bool BasicTargetDescriptor::Close() const { |
| 102 return agent_host_->Close(); |
| 103 } |
| 104 |
28 } // namespace devtools_discovery | 105 } // namespace devtools_discovery |
OLD | NEW |