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> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" |
| 11 #include "base/strings/string_number_conversions.h" |
8 #include "content/public/browser/devtools_http_handler.h" | 12 #include "content/public/browser/devtools_http_handler.h" |
9 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/content_switches.h" |
10 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
11 #include "content/shell/shell.h" | 16 #include "content/shell/shell.h" |
12 #include "grit/shell_resources.h" | 17 #include "grit/shell_resources.h" |
13 #include "net/socket/tcp_listen_socket.h" | 18 #include "net/socket/tcp_listen_socket.h" |
14 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
15 | 20 |
16 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
17 #include "content/public/browser/android/devtools_auth.h" | 22 #include "content/public/browser/android/devtools_auth.h" |
18 #include "net/socket/unix_domain_socket_posix.h" | 23 #include "net/socket/unix_domain_socket_posix.h" |
| 24 #endif |
19 | 25 |
20 namespace { | 26 namespace { |
21 const char kSocketName[] = "content_shell_devtools_remote"; | 27 |
| 28 net::StreamListenSocketFactory* CreateSocketFactory() { |
| 29 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 30 #if defined(OS_ANDROID) |
| 31 std::string socket_name = "content_shell_devtools_remote"; |
| 32 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 33 socket_name = command_line.GetSwitchValueASCII( |
| 34 switches::kRemoteDebuggingSocketName); |
| 35 } |
| 36 return new net::UnixDomainSocketWithAbstractNamespaceFactory( |
| 37 socket_name, base::Bind(&content::CanUserConnectToDevTools)); |
| 38 #else |
| 39 // See if the user specified a port on the command line (useful for |
| 40 // automation). If not, use an ephemeral port by specifying 0. |
| 41 int port = 0; |
| 42 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { |
| 43 int temp_port; |
| 44 std::string port_str = |
| 45 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); |
| 46 if (base::StringToInt(port_str, &temp_port) && |
| 47 temp_port > 0 && temp_port < 65535) { |
| 48 port = temp_port; |
| 49 } else { |
| 50 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
| 51 } |
| 52 } |
| 53 return new net::TCPListenSocketFactory("127.0.0.1", port); |
| 54 #endif |
22 } | 55 } |
23 #endif | 56 } // namespace |
24 | 57 |
25 namespace content { | 58 namespace content { |
26 | 59 |
27 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context, | 60 ShellDevToolsDelegate::ShellDevToolsDelegate(BrowserContext* browser_context) |
28 int port) | |
29 : browser_context_(browser_context) { | 61 : browser_context_(browser_context) { |
30 devtools_http_handler_ = DevToolsHttpHandler::Start( | 62 devtools_http_handler_ = |
31 #if defined(OS_ANDROID) | 63 DevToolsHttpHandler::Start(CreateSocketFactory(), std::string(), this); |
32 new net::UnixDomainSocketWithAbstractNamespaceFactory( | |
33 kSocketName, base::Bind(&CanUserConnectToDevTools)), | |
34 #else | |
35 new net::TCPListenSocketFactory("127.0.0.1", port), | |
36 #endif | |
37 std::string(), | |
38 this); | |
39 } | 64 } |
40 | 65 |
41 ShellDevToolsDelegate::~ShellDevToolsDelegate() { | 66 ShellDevToolsDelegate::~ShellDevToolsDelegate() { |
42 } | 67 } |
43 | 68 |
44 void ShellDevToolsDelegate::Stop() { | 69 void ShellDevToolsDelegate::Stop() { |
45 // The call below destroys this. | 70 // The call below destroys this. |
46 devtools_http_handler_->Stop(); | 71 devtools_http_handler_->Stop(); |
47 } | 72 } |
48 | 73 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 108 } |
84 | 109 |
85 scoped_refptr<net::StreamListenSocket> | 110 scoped_refptr<net::StreamListenSocket> |
86 ShellDevToolsDelegate::CreateSocketForTethering( | 111 ShellDevToolsDelegate::CreateSocketForTethering( |
87 net::StreamListenSocket::Delegate* delegate, | 112 net::StreamListenSocket::Delegate* delegate, |
88 std::string* name) { | 113 std::string* name) { |
89 return NULL; | 114 return NULL; |
90 } | 115 } |
91 | 116 |
92 } // namespace content | 117 } // namespace content |
OLD | NEW |