Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: components/devtools_discovery/basic_target_descriptor.cc

Issue 1109483003: [DevTools] Migrate chrome to devtools_discovery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devtools-discovery-android
Patch Set: rebased Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/devtools_discovery/basic_target_descriptor.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"; 16 const char BasicTargetDescriptor::kTypePage[] = "page";
17 const char BasicTargetDescriptor::kTypeServiceWorker[] = "service_worker"; 17 const char BasicTargetDescriptor::kTypeServiceWorker[] = "service_worker";
18 const char BasicTargetDescriptor::kTypeSharedWorker[] = "worker"; 18 const char BasicTargetDescriptor::kTypeSharedWorker[] = "worker";
19 const char BasicTargetDescriptor::kTypeOther[] = "other"; 19 const char BasicTargetDescriptor::kTypeOther[] = "other";
20 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
21 BasicTargetDescriptor::BasicTargetDescriptor( 39 BasicTargetDescriptor::BasicTargetDescriptor(
22 scoped_refptr<DevToolsAgentHost> agent_host) 40 scoped_refptr<DevToolsAgentHost> agent_host)
23 : 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()) {
24 if (content::WebContents* web_contents = agent_host_->GetWebContents()) { 45 if (content::WebContents* web_contents = agent_host_->GetWebContents()) {
25 content::NavigationController& controller = web_contents->GetController(); 46 content::NavigationController& controller = web_contents->GetController();
26 content::NavigationEntry* entry = controller.GetActiveEntry(); 47 content::NavigationEntry* entry = controller.GetActiveEntry();
27 if (entry != NULL && entry->GetURL().is_valid()) 48 if (entry != NULL && entry->GetURL().is_valid())
28 favicon_url_ = entry->GetFavicon().url; 49 favicon_url_ = entry->GetFavicon().url;
29 last_activity_time_ = web_contents->GetLastActiveTime(); 50 last_activity_time_ = web_contents->GetLastActiveTime();
30 } 51 }
31 } 52 }
32 53
33 BasicTargetDescriptor::~BasicTargetDescriptor() { 54 BasicTargetDescriptor::~BasicTargetDescriptor() {
34 } 55 }
35 56
36 std::string BasicTargetDescriptor::GetId() const { 57 std::string BasicTargetDescriptor::GetId() const {
37 return agent_host_->GetId(); 58 return agent_host_->GetId();
38 } 59 }
39 60
40 std::string BasicTargetDescriptor::GetParentId() const { 61 std::string BasicTargetDescriptor::GetParentId() const {
41 return std::string(); 62 return parent_id_;
42 } 63 }
43 64
44 std::string BasicTargetDescriptor::GetType() const { 65 std::string BasicTargetDescriptor::GetType() const {
45 switch (agent_host_->GetType()) { 66 return type_;
46 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
47 return kTypePage;
48 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
49 return kTypeServiceWorker;
50 case DevToolsAgentHost::TYPE_SHARED_WORKER:
51 return kTypeSharedWorker;
52 default:
53 break;
54 }
55 return kTypeOther;
56 } 67 }
57 68
58 std::string BasicTargetDescriptor::GetTitle() const { 69 std::string BasicTargetDescriptor::GetTitle() const {
59 return agent_host_->GetTitle(); 70 return title_;
60 } 71 }
61 72
62 std::string BasicTargetDescriptor::GetDescription() const { 73 std::string BasicTargetDescriptor::GetDescription() const {
63 return std::string(); 74 return description_;
64 } 75 }
65 76
66 GURL BasicTargetDescriptor::GetURL() const { 77 GURL BasicTargetDescriptor::GetURL() const {
67 return agent_host_->GetURL(); 78 return url_;
68 } 79 }
69 80
70 GURL BasicTargetDescriptor::GetFaviconURL() const { 81 GURL BasicTargetDescriptor::GetFaviconURL() const {
71 return favicon_url_; 82 return favicon_url_;
72 } 83 }
73 84
74 base::TimeTicks BasicTargetDescriptor::GetLastActivityTime() const { 85 base::TimeTicks BasicTargetDescriptor::GetLastActivityTime() const {
75 return last_activity_time_; 86 return last_activity_time_;
76 } 87 }
77 88
78 bool BasicTargetDescriptor::IsAttached() const { 89 bool BasicTargetDescriptor::IsAttached() const {
79 return agent_host_->IsAttached(); 90 return agent_host_->IsAttached();
80 } 91 }
81 92
82 scoped_refptr<DevToolsAgentHost> BasicTargetDescriptor::GetAgentHost() const { 93 scoped_refptr<DevToolsAgentHost> BasicTargetDescriptor::GetAgentHost() const {
83 return agent_host_; 94 return agent_host_;
84 } 95 }
85 96
86 bool BasicTargetDescriptor::Activate() const { 97 bool BasicTargetDescriptor::Activate() const {
87 return agent_host_->Activate(); 98 return agent_host_->Activate();
88 } 99 }
89 100
90 bool BasicTargetDescriptor::Close() const { 101 bool BasicTargetDescriptor::Close() const {
91 return agent_host_->Close(); 102 return agent_host_->Close();
92 } 103 }
93 104
94 } // namespace devtools_discovery 105 } // namespace devtools_discovery
OLDNEW
« no previous file with comments | « components/devtools_discovery/basic_target_descriptor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698