Index: android_webview/native/aw_dev_tools_server.cc |
diff --git a/android_webview/native/aw_dev_tools_server.cc b/android_webview/native/aw_dev_tools_server.cc |
index 6783bae189ad5154a4c286036812efbe6c9e0491..608ca1be1fec5fbfa42285c99b6cd1b7ba3b13a9 100644 |
--- a/android_webview/native/aw_dev_tools_server.cc |
+++ b/android_webview/native/aw_dev_tools_server.cc |
@@ -37,7 +37,7 @@ std::string GetViewDescription(WebContents* web_contents); |
class Target : public content::DevToolsTarget { |
public: |
- explicit Target(WebContents* web_contents); |
+ explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
virtual std::string GetId() const OVERRIDE { return id_; } |
virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
@@ -67,14 +67,17 @@ class Target : public content::DevToolsTarget { |
base::TimeTicks last_activity_time_; |
}; |
-Target::Target(WebContents* web_contents) { |
- agent_host_ = |
- DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); |
- id_ = agent_host_->GetId(); |
- description_ = GetViewDescription(web_contents); |
- title_ = base::UTF16ToUTF8(web_contents->GetTitle()); |
- url_ = web_contents->GetURL(); |
- last_activity_time_ = web_contents->GetLastActiveTime(); |
+Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
+ : agent_host_(agent_host), |
+ id_(agent_host_->GetId()), |
+ url_(agent_host_->GetURL()) { |
+ if (RenderViewHost* rvh = agent_host_->GetRenderViewHost()) { |
dgozman
2014/07/14 11:17:24
Targets without RVH should get informative title (
vkuzkokov
2014/07/14 15:31:33
This should be done on client.
|
+ if (WebContents* web_contents = WebContents::FromRenderViewHost(rvh)) { |
+ description_ = GetViewDescription(web_contents); |
+ title_ = base::UTF16ToUTF8(web_contents->GetTitle()); |
+ last_activity_time_ = web_contents->GetLastActiveTime(); |
+ } |
+ } |
} |
// Delegate implementation for the devtools http handler for WebView. A new |
@@ -104,18 +107,7 @@ class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
return scoped_ptr<content::DevToolsTarget>(); |
} |
- virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { |
- TargetList targets; |
- std::vector<RenderViewHost*> rvh_list = |
- DevToolsAgentHost::GetValidRenderViewHosts(); |
- for (std::vector<RenderViewHost*>::iterator it = rvh_list.begin(); |
- it != rvh_list.end(); ++it) { |
- WebContents* web_contents = WebContents::FromRenderViewHost(*it); |
- if (web_contents) |
- targets.push_back(new Target(web_contents)); |
- } |
- callback.Run(targets); |
- } |
+ virtual void EnumerateTargets(TargetCallback callback) OVERRIDE; |
virtual scoped_ptr<net::StreamListenSocket> CreateSocketForTethering( |
net::StreamListenSocket::Delegate* delegate, |
@@ -127,6 +119,20 @@ class AwDevToolsServerDelegate : public content::DevToolsHttpHandlerDelegate { |
DISALLOW_COPY_AND_ASSIGN(AwDevToolsServerDelegate); |
}; |
+static void CreateTargets( |
+ const AwDevToolsServerDelegate::TargetCallback& callback, |
+ const DevToolsAgentHost::List& agents) { |
+ AwDevToolsServerDelegate::TargetList targets; |
+ for (DevToolsAgentHost::List::const_iterator it = agents.begin(); |
+ it != agents.end(); ++it) { |
+ targets.push_back(new Target(*it)); |
+ } |
+ callback.Run(targets); |
+} |
+ |
+void AwDevToolsServerDelegate::EnumerateTargets(TargetCallback callback) { |
+ DevToolsAgentHost::GetOrCreateAllHosts(base::Bind(&CreateTargets, callback)); |
+} |
std::string AwDevToolsServerDelegate::GetDiscoveryPageHTML() { |
const char html[] = |