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