OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/shell/browser/shell_devtools_delegate.h" | 5 #include "content/shell/browser/shell_devtools_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } else { | 69 } else { |
70 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 70 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
71 } | 71 } |
72 } | 72 } |
73 return new net::TCPListenSocketFactory("127.0.0.1", port); | 73 return new net::TCPListenSocketFactory("127.0.0.1", port); |
74 #endif | 74 #endif |
75 } | 75 } |
76 | 76 |
77 class Target : public content::DevToolsTarget { | 77 class Target : public content::DevToolsTarget { |
78 public: | 78 public: |
79 explicit Target(WebContents* web_contents); | 79 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
80 | 80 |
81 virtual std::string GetId() const OVERRIDE { return id_; } | 81 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } |
82 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 82 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
83 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 83 virtual std::string GetType() const OVERRIDE { |
84 virtual std::string GetTitle() const OVERRIDE { return title_; } | 84 std::string result = agent_host_->GetType(); |
| 85 if (result == DevToolsAgentHost::kTypeWebContents) |
| 86 result = kTargetTypePage; |
| 87 return result; |
| 88 } |
| 89 virtual std::string GetTitle() const OVERRIDE { |
| 90 return agent_host_->GetTitle(); |
| 91 } |
85 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 92 virtual std::string GetDescription() const OVERRIDE { return std::string(); } |
86 virtual GURL GetURL() const OVERRIDE { return url_; } | 93 virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } |
87 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 94 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } |
88 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 95 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
89 return last_activity_time_; | 96 return last_activity_time_; |
90 } | 97 } |
91 virtual bool IsAttached() const OVERRIDE { | 98 virtual bool IsAttached() const OVERRIDE { |
92 return agent_host_->IsAttached(); | 99 return agent_host_->IsAttached(); |
93 } | 100 } |
94 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 101 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
95 return agent_host_; | 102 return agent_host_; |
96 } | 103 } |
97 virtual bool Activate() const OVERRIDE; | 104 virtual bool Activate() const OVERRIDE; |
98 virtual bool Close() const OVERRIDE; | 105 virtual bool Close() const OVERRIDE; |
99 | 106 |
100 private: | 107 private: |
101 scoped_refptr<DevToolsAgentHost> agent_host_; | 108 scoped_refptr<DevToolsAgentHost> agent_host_; |
102 std::string id_; | |
103 std::string title_; | |
104 GURL url_; | |
105 GURL favicon_url_; | 109 GURL favicon_url_; |
106 base::TimeTicks last_activity_time_; | 110 base::TimeTicks last_activity_time_; |
107 }; | 111 }; |
108 | 112 |
109 Target::Target(WebContents* web_contents) { | 113 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
110 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 114 : agent_host_(agent_host) { |
111 id_ = agent_host_->GetId(); | 115 if (WebContents* web_contents = agent_host_->GetWebContents()) { |
112 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 116 content::NavigationController& controller = web_contents->GetController(); |
113 url_ = web_contents->GetURL(); | 117 content::NavigationEntry* entry = controller.GetActiveEntry(); |
114 content::NavigationController& controller = web_contents->GetController(); | 118 if (entry != NULL && entry->GetURL().is_valid()) |
115 content::NavigationEntry* entry = controller.GetActiveEntry(); | 119 favicon_url_ = entry->GetFavicon().url; |
116 if (entry != NULL && entry->GetURL().is_valid()) | 120 last_activity_time_ = web_contents->GetLastActiveTime(); |
117 favicon_url_ = entry->GetFavicon().url; | 121 } |
118 last_activity_time_ = web_contents->GetLastActiveTime(); | |
119 } | 122 } |
120 | 123 |
121 bool Target::Activate() const { | 124 bool Target::Activate() const { |
122 WebContents* web_contents = agent_host_->GetWebContents(); | 125 return agent_host_->Activate(); |
123 if (!web_contents) | |
124 return false; | |
125 web_contents->GetDelegate()->ActivateContents(web_contents); | |
126 return true; | |
127 } | 126 } |
128 | 127 |
129 bool Target::Close() const { | 128 bool Target::Close() const { |
130 WebContents* web_contents = agent_host_->GetWebContents(); | 129 return agent_host_->Close(); |
131 if (!web_contents) | |
132 return false; | |
133 web_contents->GetRenderViewHost()->ClosePage(); | |
134 return true; | |
135 } | 130 } |
136 | 131 |
137 } // namespace | 132 } // namespace |
138 | 133 |
139 namespace content { | 134 namespace content { |
140 | 135 |
141 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) | 136 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) |
142 : browser_context_(browser_context) { | 137 : browser_context_(browser_context) { |
143 std::string frontend_url; | 138 std::string frontend_url; |
144 #if defined(OS_ANDROID) | 139 #if defined(OS_ANDROID) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 return std::string(); | 177 return std::string(); |
183 } | 178 } |
184 | 179 |
185 scoped_ptr<DevToolsTarget> | 180 scoped_ptr<DevToolsTarget> |
186 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { | 181 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { |
187 Shell* shell = Shell::CreateNewWindow(browser_context_, | 182 Shell* shell = Shell::CreateNewWindow(browser_context_, |
188 url, | 183 url, |
189 NULL, | 184 NULL, |
190 MSG_ROUTING_NONE, | 185 MSG_ROUTING_NONE, |
191 gfx::Size()); | 186 gfx::Size()); |
192 return scoped_ptr<DevToolsTarget>(new Target(shell->web_contents())); | 187 return scoped_ptr<DevToolsTarget>( |
| 188 new Target(DevToolsAgentHost::GetOrCreateFor(shell->web_contents()))); |
193 } | 189 } |
194 | 190 |
195 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | 191 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { |
196 TargetList targets; | 192 TargetList targets; |
197 std::vector<WebContents*> wc_list = | 193 content::DevToolsAgentHost::List agents = |
198 content::DevToolsAgentHost::GetInspectableWebContents(); | 194 content::DevToolsAgentHost::GetOrCreateAll(); |
199 for (std::vector<WebContents*>::iterator it = wc_list.begin(); | 195 for (content::DevToolsAgentHost::List::iterator it = agents.begin(); |
200 it != wc_list.end(); | 196 it != agents.end(); ++it) { |
201 ++it) { | |
202 targets.push_back(new Target(*it)); | 197 targets.push_back(new Target(*it)); |
203 } | 198 } |
204 callback.Run(targets); | 199 callback.Run(targets); |
205 } | 200 } |
206 | 201 |
207 scoped_ptr<net::StreamListenSocket> | 202 scoped_ptr<net::StreamListenSocket> |
208 ShellDevToolsDelegate::CreateSocketForTethering( | 203 ShellDevToolsDelegate::CreateSocketForTethering( |
209 net::StreamListenSocket::Delegate* delegate, | 204 net::StreamListenSocket::Delegate* delegate, |
210 std::string* name) { | 205 std::string* name) { |
211 return scoped_ptr<net::StreamListenSocket>(); | 206 return scoped_ptr<net::StreamListenSocket>(); |
212 } | 207 } |
213 | 208 |
214 } // namespace content | 209 } // namespace content |
OLD | NEW |