| 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 25 matching lines...) Expand all Loading... |
| 36 using content::RenderViewHost; | 36 using content::RenderViewHost; |
| 37 using content::WebContents; | 37 using content::WebContents; |
| 38 | 38 |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 42 const char kFrontEndURL[] = | 42 const char kFrontEndURL[] = |
| 43 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; | 43 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
| 44 #endif | 44 #endif |
| 45 const char kTargetTypePage[] = "page"; | 45 const char kTargetTypePage[] = "page"; |
| 46 const char kTargetTypeOther[] = "other"; |
| 46 | 47 |
| 47 net::StreamListenSocketFactory* CreateSocketFactory() { | 48 net::StreamListenSocketFactory* CreateSocketFactory() { |
| 48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 49 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 49 #if defined(OS_ANDROID) | 50 #if defined(OS_ANDROID) |
| 50 std::string socket_name = "content_shell_devtools_remote"; | 51 std::string socket_name = "content_shell_devtools_remote"; |
| 51 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 52 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 52 socket_name = command_line.GetSwitchValueASCII( | 53 socket_name = command_line.GetSwitchValueASCII( |
| 53 switches::kRemoteDebuggingSocketName); | 54 switches::kRemoteDebuggingSocketName); |
| 54 } | 55 } |
| 55 return new net::deprecated:: | 56 return new net::deprecated:: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 69 } else { | 70 } else { |
| 70 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 71 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 return new net::TCPListenSocketFactory("127.0.0.1", port); | 74 return new net::TCPListenSocketFactory("127.0.0.1", port); |
| 74 #endif | 75 #endif |
| 75 } | 76 } |
| 76 | 77 |
| 77 class Target : public content::DevToolsTarget { | 78 class Target : public content::DevToolsTarget { |
| 78 public: | 79 public: |
| 79 explicit Target(WebContents* web_contents); | 80 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
| 80 | 81 |
| 81 virtual std::string GetId() const OVERRIDE { return id_; } | 82 virtual std::string GetId() const OVERRIDE { return id_; } |
| 82 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 83 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
| 83 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 84 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } |
| 84 virtual std::string GetTitle() const OVERRIDE { return title_; } | 85 virtual std::string GetTitle() const OVERRIDE { return title_; } |
| 85 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 86 virtual std::string GetDescription() const OVERRIDE { return std::string(); } |
| 86 virtual GURL GetURL() const OVERRIDE { return url_; } | 87 virtual GURL GetURL() const OVERRIDE { return url_; } |
| 87 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } | 88 virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } |
| 88 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 89 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { |
| 89 return last_activity_time_; | 90 return last_activity_time_; |
| 90 } | 91 } |
| 91 virtual bool IsAttached() const OVERRIDE { | 92 virtual bool IsAttached() const OVERRIDE { |
| 92 return agent_host_->IsAttached(); | 93 return agent_host_->IsAttached(); |
| 93 } | 94 } |
| 94 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 95 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { |
| 95 return agent_host_; | 96 return agent_host_; |
| 96 } | 97 } |
| 97 virtual bool Activate() const OVERRIDE; | 98 virtual bool Activate() const OVERRIDE; |
| 98 virtual bool Close() const OVERRIDE; | 99 virtual bool Close() const OVERRIDE; |
| 99 | 100 |
| 100 private: | 101 private: |
| 101 scoped_refptr<DevToolsAgentHost> agent_host_; | 102 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 102 std::string id_; | 103 std::string id_; |
| 104 std::string type_; |
| 103 std::string title_; | 105 std::string title_; |
| 104 GURL url_; | 106 GURL url_; |
| 105 GURL favicon_url_; | 107 GURL favicon_url_; |
| 106 base::TimeTicks last_activity_time_; | 108 base::TimeTicks last_activity_time_; |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 Target::Target(WebContents* web_contents) { | 111 Target::Target(scoped_refptr<DevToolsAgentHost> agent_host) |
| 110 agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); | 112 : agent_host_(agent_host), |
| 111 id_ = agent_host_->GetId(); | 113 id_(agent_host_->GetId()), |
| 112 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); | 114 type_(kTargetTypeOther), |
| 113 url_ = web_contents->GetURL(); | 115 url_(agent_host_->GetURL()) { |
| 114 content::NavigationController& controller = web_contents->GetController(); | 116 if (WebContents* web_contents = agent_host_->GetWebContents()) { |
| 115 content::NavigationEntry* entry = controller.GetActiveEntry(); | 117 title_ = base::UTF16ToUTF8(web_contents->GetTitle()); |
| 116 if (entry != NULL && entry->GetURL().is_valid()) | 118 content::NavigationController& controller = web_contents->GetController(); |
| 117 favicon_url_ = entry->GetFavicon().url; | 119 content::NavigationEntry* entry = controller.GetActiveEntry(); |
| 118 last_activity_time_ = web_contents->GetLastActiveTime(); | 120 if (entry != NULL && entry->GetURL().is_valid()) |
| 121 favicon_url_ = entry->GetFavicon().url; |
| 122 last_activity_time_ = web_contents->GetLastActiveTime(); |
| 123 type_ = kTargetTypePage; |
| 124 } |
| 119 } | 125 } |
| 120 | 126 |
| 121 bool Target::Activate() const { | 127 bool Target::Activate() const { |
| 122 WebContents* web_contents = agent_host_->GetWebContents(); | 128 WebContents* web_contents = agent_host_->GetWebContents(); |
| 123 if (!web_contents) | 129 if (!web_contents) |
| 124 return false; | 130 return false; |
| 125 web_contents->GetDelegate()->ActivateContents(web_contents); | 131 web_contents->GetDelegate()->ActivateContents(web_contents); |
| 126 return true; | 132 return true; |
| 127 } | 133 } |
| 128 | 134 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return std::string(); | 188 return std::string(); |
| 183 } | 189 } |
| 184 | 190 |
| 185 scoped_ptr<DevToolsTarget> | 191 scoped_ptr<DevToolsTarget> |
| 186 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { | 192 ShellDevToolsDelegate::CreateNewTarget(const GURL& url) { |
| 187 Shell* shell = Shell::CreateNewWindow(browser_context_, | 193 Shell* shell = Shell::CreateNewWindow(browser_context_, |
| 188 url, | 194 url, |
| 189 NULL, | 195 NULL, |
| 190 MSG_ROUTING_NONE, | 196 MSG_ROUTING_NONE, |
| 191 gfx::Size()); | 197 gfx::Size()); |
| 192 return scoped_ptr<DevToolsTarget>(new Target(shell->web_contents())); | 198 return scoped_ptr<DevToolsTarget>( |
| 199 new Target(DevToolsAgentHost::GetOrCreateFor(shell->web_contents()))); |
| 193 } | 200 } |
| 194 | 201 |
| 195 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { | 202 void ShellDevToolsDelegate::EnumerateTargets(TargetCallback callback) { |
| 196 TargetList targets; | 203 TargetList targets; |
| 197 std::vector<WebContents*> wc_list = | 204 content::DevToolsAgentHost::List agents = |
| 198 content::DevToolsAgentHost::GetInspectableWebContents(); | 205 content::DevToolsAgentHost::GetOrCreateAll(); |
| 199 for (std::vector<WebContents*>::iterator it = wc_list.begin(); | 206 for (content::DevToolsAgentHost::List::iterator it = agents.begin(); |
| 200 it != wc_list.end(); | 207 it != agents.end(); ++it) { |
| 201 ++it) { | |
| 202 targets.push_back(new Target(*it)); | 208 targets.push_back(new Target(*it)); |
| 203 } | 209 } |
| 204 callback.Run(targets); | 210 callback.Run(targets); |
| 205 } | 211 } |
| 206 | 212 |
| 207 scoped_ptr<net::StreamListenSocket> | 213 scoped_ptr<net::StreamListenSocket> |
| 208 ShellDevToolsDelegate::CreateSocketForTethering( | 214 ShellDevToolsDelegate::CreateSocketForTethering( |
| 209 net::StreamListenSocket::Delegate* delegate, | 215 net::StreamListenSocket::Delegate* delegate, |
| 210 std::string* name) { | 216 std::string* name) { |
| 211 return scoped_ptr<net::StreamListenSocket>(); | 217 return scoped_ptr<net::StreamListenSocket>(); |
| 212 } | 218 } |
| 213 | 219 |
| 214 } // namespace content | 220 } // namespace content |
| OLD | NEW |