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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } else { | 68 } else { |
69 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 69 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
70 } | 70 } |
71 } | 71 } |
72 return new net::TCPListenSocketFactory("127.0.0.1", port); | 72 return new net::TCPListenSocketFactory("127.0.0.1", port); |
73 #endif | 73 #endif |
74 } | 74 } |
75 | 75 |
76 class Target : public content::DevToolsTarget { | 76 class Target : public content::DevToolsTarget { |
77 public: | 77 public: |
78 explicit Target(WebContents* web_contents); | 78 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
79 | 79 |
80 virtual std::string GetId() const OVERRIDE { return id_; } | 80 virtual std::string GetId() const OVERRIDE { return id_; } |
81 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 81 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
82 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 82 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } |
83 virtual std::string GetTitle() const OVERRIDE { return title_; } | 83 virtual std::string GetTitle() const OVERRIDE { return title_; } |
84 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 84 virtual std::string GetDescription() const OVERRIDE { return std::string(); } |
85 virtual GURL GetURL() const OVERRIDE { return url_; } | 85 virtual GURL GetURL() const OVERRIDE { return url_; } |
86 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 86 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } |
87 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 87 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
88 return last_activity_time_; | 88 return last_activity_time_; |
89 } | 89 } |
90 virtual bool IsAttached() const OVERRIDE { | 90 virtual bool IsAttached() const OVERRIDE { |
91 return agent_host_->IsAttached(); | 91 return agent_host_->IsAttached(); |
92 } | 92 } |
93 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 93 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
94 return agent_host_; | 94 return agent_host_; |
95 } | 95 } |
96 virtual bool Activate() const OVERRIDE; | 96 virtual bool Activate() const OVERRIDE; |
97 virtual bool Close() const OVERRIDE; | 97 virtual bool Close() const OVERRIDE; |
98 | 98 |
99 private: | 99 private: |
100 scoped_refptr<DevToolsAgentHost> agent_host_; | 100 scoped_refptr<DevToolsAgentHost> agent_host_; |
101 std::string id_; | 101 std::string id_; |
102 std::string title_; | 102 std::string title_; |
103 GURL url_; | 103 GURL url_; |
104 GURL favicon_url_; | 104 GURL favicon_url_; |
105 base::TimeTicks last_activity_time_; | 105 base::TimeTicks last_activity_time_; |
106 }; | 106 }; |
107 | 107 |
108 Target::Target(WebContents* web_contents) { | 108 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
109 agent_host_ = | 109 : agent_host_(agent_host), |
110 DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); | 110 id_(agent_host_->GetId()), |
111 id_ = agent_host_->GetId(); | 111 url_(agent_host_->GetURL()) { |
112 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 112 if (RenderViewHost* rvh = agent_host_->GetRenderViewHost()) { |
113 url_ = web_contents->GetURL(); | 113 if (WebContents* web_contents = WebContents::FromRenderViewHost(rvh)) { |
114 content::NavigationController& controller = web_contents->GetController(); | 114 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); |
115 content::NavigationEntry* entry = controller.GetActiveEntry(); | 115 content::NavigationController& controller = web_contents->GetController(); |
116 if (entry != NULL && entry->GetURL().is_valid()) | 116 content::NavigationEntry* entry = controller.GetActiveEntry(); |
117 favicon_url_ = entry->GetFavicon().url; | 117 if (entry != NULL && entry->GetURL().is_valid()) |
118 last_activity_time_ = web_contents->GetLastActiveTime(); | 118 favicon_url_ = entry->GetFavicon().url; |
| 119 last_activity_time_ = web_contents->GetLastActiveTime(); |
| 120 } |
| 121 } |
119 } | 122 } |
120 | 123 |
121 bool Target::Activate() const { | 124 bool Target::Activate() const { |
122 RenderViewHost* rvh = agent_host_->GetRenderViewHost(); | 125 RenderViewHost* rvh = agent_host_->GetRenderViewHost(); |
123 if (!rvh) | 126 if (!rvh) |
124 return false; | 127 return false; |
125 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | 128 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
126 if (!web_contents) | 129 if (!web_contents) |
127 return false; | 130 return false; |
128 web_contents->GetDelegate()->ActivateContents(web_contents); | 131 web_contents->GetDelegate()->ActivateContents(web_contents); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return std::string(); | 188 return std::string(); |
186 } | 189 } |
187 | 190 |
188 scoped_ptr<DevToolsTarget> | 191 scoped_ptr<DevToolsTarget> |
189 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { | 192 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { |
190 Shell* shell = Shell::CreateNewWindow(browser_context_, | 193 Shell* shell = Shell::CreateNewWindow(browser_context_, |
191 url, | 194 url, |
192 NULL, | 195 NULL, |
193 MSG_ROUTING_NONE, | 196 MSG_ROUTING_NONE, |
194 gfx::Size()); | 197 gfx::Size()); |
195 return scoped_ptr<DevToolsTarget>(new Target(shell->web_contents())); | 198 return scoped_ptr<DevToolsTarget>( |
| 199 new Target(DevToolsAgentHost::GetOrCreateFor(shell->web_contents()))); |
| 200 } |
| 201 |
| 202 static void CreateTargets(const ShellDevToolsDelegate::TargetCallback& callback, |
| 203 const DevToolsAgentHost::List& agents) { |
| 204 ShellDevToolsDelegate::TargetList targets; |
| 205 for (DevToolsAgentHost::List::const_iterator it = agents.begin(); |
| 206 it != agents.end(); ++it) { |
| 207 targets.push_back(new Target(*it)); |
| 208 } |
| 209 callback.Run(targets); |
196 } | 210 } |
197 | 211 |
198 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | 212 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { |
199 TargetList targets; | 213 DevToolsAgentHost::GetOrCreateAllHosts(base::Bind(&CreateTargets, callback)); |
200 std::vector<RenderViewHost*> rvh_list = | |
201 content::DevToolsAgentHost::GetValidRenderViewHosts(); | |
202 for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); | |
203 it != rvh_list.end(); ++it) { | |
204 WebContents* web_contents = WebContents::FromRenderViewHost(*it); | |
205 if (web_contents) | |
206 targets.push_back(new Target(web_contents)); | |
207 } | |
208 callback.Run(targets); | |
209 } | 214 } |
210 | 215 |
211 scoped_ptr<net::StreamListenSocket> | 216 scoped_ptr<net::StreamListenSocket> |
212 ShellDevToolsDelegate::CreateSocketForTethering( | 217 ShellDevToolsDelegate::CreateSocketForTethering( |
213 net::StreamListenSocket::Delegate* delegate, | 218 net::StreamListenSocket::Delegate* delegate, |
214 std::string* name) { | 219 std::string* name) { |
215 return scoped_ptr<net::StreamListenSocket>(); | 220 return scoped_ptr<net::StreamListenSocket>(); |
216 } | 221 } |
217 | 222 |
218 } // namespace content | 223 } // namespace content |
OLD | NEW |