| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell_devtools_delegate.h" | 5 #include "content/shell/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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "components/devtools_remote_frontend/devtools_remote_frontend_util.h" |
| 12 #include "content/public/browser/devtools_http_handler.h" | 13 #include "content/public/browser/devtools_http_handler.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 16 #include "content/shell/shell.h" | 17 #include "content/shell/shell.h" |
| 17 #include "grit/shell_resources.h" | 18 #include "grit/shell_resources.h" |
| 18 #include "net/socket/tcp_listen_socket.h" | 19 #include "net/socket/tcp_listen_socket.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 | 21 |
| 21 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 22 #include "content/public/browser/android/devtools_auth.h" | 23 #include "components/devtools_remote_frontend/devtools_auth_android.h" |
| 23 #include "net/socket/unix_domain_socket_posix.h" | 24 #include "net/socket/unix_domain_socket_posix.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 net::StreamListenSocketFactory* CreateSocketFactory() { | 29 net::StreamListenSocketFactory* CreateSocketFactory() { |
| 29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 30 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 30 #if defined(OS_ANDROID) | 31 #if defined(OS_ANDROID) |
| 31 std::string socket_name = "content_shell_devtools_remote"; | 32 std::string socket_name = |
| 33 devtools_remote_frontend::GetDevToolsServerSocketName("content_shell"); |
| 32 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 34 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 33 socket_name = command_line.GetSwitchValueASCII( | 35 socket_name = command_line.GetSwitchValueASCII( |
| 34 switches::kRemoteDebuggingSocketName); | 36 switches::kRemoteDebuggingSocketName); |
| 35 } | 37 } |
| 36 return new net::UnixDomainSocketWithAbstractNamespaceFactory( | 38 return new net::UnixDomainSocketWithAbstractNamespaceFactory( |
| 37 socket_name, "", base::Bind(&content::CanUserConnectToDevTools)); | 39 socket_name, |
| 40 "", |
| 41 base::Bind(&devtools_remote_frontend::CanUserConnectToDevTools)); |
| 38 #else | 42 #else |
| 39 // See if the user specified a port on the command line (useful for | 43 // See if the user specified a port on the command line (useful for |
| 40 // automation). If not, use an ephemeral port by specifying 0. | 44 // automation). If not, use an ephemeral port by specifying 0. |
| 41 int port = 0; | 45 int port = 0; |
| 42 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { | 46 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { |
| 43 int temp_port; | 47 int temp_port; |
| 44 std::string port_str = | 48 std::string port_str = |
| 45 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); | 49 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); |
| 46 if (base::StringToInt(port_str, &temp_port) && | 50 if (base::StringToInt(port_str, &temp_port) && |
| 47 temp_port > 0 && temp_port < 65535) { | 51 temp_port > 0 && temp_port < 65535) { |
| 48 port = temp_port; | 52 port = temp_port; |
| 49 } else { | 53 } else { |
| 50 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 54 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
| 51 } | 55 } |
| 52 } | 56 } |
| 53 return new net::TCPListenSocketFactory("127.0.0.1", port); | 57 return new net::TCPListenSocketFactory("127.0.0.1", port); |
| 54 #endif | 58 #endif |
| 55 } | 59 } |
| 56 } // namespace | 60 } // namespace |
| 57 | 61 |
| 58 namespace content { | 62 namespace content { |
| 59 | 63 |
| 60 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) | 64 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) |
| 61 : browser_context_(browser_context) { | 65 : browser_context_(browser_context) { |
| 66 // Note that Content Shell always used bundled DevTools frontend, |
| 67 // even on Android, because the shell is used for running layout tests. |
| 62 devtools_http_handler_ = | 68 devtools_http_handler_ = |
| 63 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this); | 69 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this); |
| 64 } | 70 } |
| 65 | 71 |
| 66 ShellDevToolsDelegate::~ShellDevToolsDelegate() { | 72 ShellDevToolsDelegate::~ShellDevToolsDelegate() { |
| 67 } | 73 } |
| 68 | 74 |
| 69 void ShellDevToolsDelegate::Stop() { | 75 void ShellDevToolsDelegate::Stop() { |
| 70 // The call below destroys this. | 76 // The call below destroys this. |
| 71 devtools_http_handler_->Stop(); | 77 devtools_http_handler_->Stop(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 114 } |
| 109 | 115 |
| 110 scoped_refptr<net::StreamListenSocket> | 116 scoped_refptr<net::StreamListenSocket> |
| 111 ShellDevToolsDelegate::CreateSocketForTethering( | 117 ShellDevToolsDelegate::CreateSocketForTethering( |
| 112 net::StreamListenSocket::Delegate* delegate, | 118 net::StreamListenSocket::Delegate* delegate, |
| 113 std::string* name) { | 119 std::string* name) { |
| 114 return NULL; | 120 return NULL; |
| 115 } | 121 } |
| 116 | 122 |
| 117 } // namespace content | 123 } // namespace content |
| OLD | NEW |