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" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "content/public/browser/devtools_agent_host.h" | 15 #include "content/public/browser/devtools_agent_host.h" |
16 #include "content/public/browser/devtools_http_handler.h" | 16 #include "content/public/browser/devtools_http_handler.h" |
17 #include "content/public/browser/devtools_target.h" | 17 #include "content/public/browser/devtools_target.h" |
18 #include "content/public/browser/favicon_status.h" | 18 #include "content/public/browser/favicon_status.h" |
19 #include "content/public/browser/navigation_entry.h" | 19 #include "content/public/browser/navigation_entry.h" |
20 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
23 #include "content/public/common/url_constants.h" | 23 #include "content/public/common/url_constants.h" |
24 #include "content/public/common/user_agent.h" | 24 #include "content/public/common/user_agent.h" |
25 #include "content/shell/browser/shell.h" | 25 #include "content/shell/browser/shell.h" |
26 #include "grit/shell_resources.h" | 26 #include "grit/shell_resources.h" |
27 #include "net/socket/tcp_listen_socket.h" | 27 #include "net/socket/tcp_server_socket.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 | 29 |
30 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
31 #include "content/public/browser/android/devtools_auth.h" | 31 #include "content/public/browser/android/devtools_auth.h" |
32 #include "net/socket/unix_domain_listen_socket_posix.h" | 32 #include "net/socket/unix_domain_server_socket_posix.h" |
33 #endif | 33 #endif |
34 | 34 |
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"; | 45 const char kTargetTypePage[] = "page"; |
46 | 46 |
47 net::StreamListenSocketFactory* CreateSocketFactory() { | 47 #if defined(OS_ANDROID) |
| 48 class UnixDomainServerSocketFactory |
| 49 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 50 public: |
| 51 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 52 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 53 |
| 54 private: |
| 55 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 56 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 57 return scoped_ptr<net::ServerSocket>( |
| 58 new net::UnixDomainServerSocket( |
| 59 base::Bind(&content::CanUserConnectToDevTools), |
| 60 true)); |
| 61 } |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 64 }; |
| 65 #else |
| 66 class TCPServerSocketFactory |
| 67 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 68 public: |
| 69 TCPServerSocketFactory(const std::string& address, int port, int backlog) |
| 70 : content::DevToolsHttpHandler::ServerSocketFactory( |
| 71 address, port, backlog) {} |
| 72 |
| 73 private: |
| 74 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 75 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 76 return scoped_ptr<net::ServerSocket>( |
| 77 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
| 78 } |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 81 }; |
| 82 #endif |
| 83 |
| 84 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> |
| 85 CreateSocketFactory() { |
48 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 86 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
49 #if defined(OS_ANDROID) | 87 #if defined(OS_ANDROID) |
50 std::string socket_name = "content_shell_devtools_remote"; | 88 std::string socket_name = "content_shell_devtools_remote"; |
51 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 89 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
52 socket_name = command_line.GetSwitchValueASCII( | 90 socket_name = command_line.GetSwitchValueASCII( |
53 switches::kRemoteDebuggingSocketName); | 91 switches::kRemoteDebuggingSocketName); |
54 } | 92 } |
55 return new net::deprecated:: | 93 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
56 UnixDomainListenSocketWithAbstractNamespaceFactory( | 94 new UnixDomainServerSocketFactory(socket_name)); |
57 socket_name, "", base::Bind(&content::CanUserConnectToDevTools)); | |
58 #else | 95 #else |
59 // See if the user specified a port on the command line (useful for | 96 // See if the user specified a port on the command line (useful for |
60 // automation). If not, use an ephemeral port by specifying 0. | 97 // automation). If not, use an ephemeral port by specifying 0. |
61 int port = 0; | 98 int port = 0; |
62 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { | 99 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { |
63 int temp_port; | 100 int temp_port; |
64 std::string port_str = | 101 std::string port_str = |
65 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); | 102 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); |
66 if (base::StringToInt(port_str, &temp_port) && | 103 if (base::StringToInt(port_str, &temp_port) && |
67 temp_port > 0 && temp_port < 65535) { | 104 temp_port > 0 && temp_port < 65535) { |
68 port = temp_port; | 105 port = temp_port; |
69 } else { | 106 } else { |
70 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 107 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
71 } | 108 } |
72 } | 109 } |
73 return new net::TCPListenSocketFactory("127.0.0.1", port); | 110 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
| 111 new TCPServerSocketFactory("127.0.0.1", port, 1)); |
74 #endif | 112 #endif |
75 } | 113 } |
76 | 114 |
77 class Target : public content::DevToolsTarget { | 115 class Target : public content::DevToolsTarget { |
78 public: | 116 public: |
79 explicit Target(WebContents* web_contents); | 117 explicit Target(WebContents* web_contents); |
80 | 118 |
81 virtual std::string GetId() const OVERRIDE { return id_; } | 119 virtual std::string GetId() const OVERRIDE { return id_; } |
82 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 120 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
83 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } | 121 virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 248 } |
211 | 249 |
212 scoped_ptr<net::StreamListenSocket> | 250 scoped_ptr<net::StreamListenSocket> |
213 ShellDevToolsDelegate::CreateSocketForTethering( | 251 ShellDevToolsDelegate::CreateSocketForTethering( |
214 net::StreamListenSocket::Delegate* delegate, | 252 net::StreamListenSocket::Delegate* delegate, |
215 std::string* name) { | 253 std::string* name) { |
216 return scoped_ptr<net::StreamListenSocket>(); | 254 return scoped_ptr<net::StreamListenSocket>(); |
217 } | 255 } |
218 | 256 |
219 } // namespace content | 257 } // namespace content |
OLD | NEW |