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 const char kTargetTypeServiceWorker[] = "service_worker"; | 46 const char kTargetTypeServiceWorker[] = "service_worker"; |
47 const char kTargetTypeOther[] = "other"; | 47 const char kTargetTypeOther[] = "other"; |
48 | 48 |
49 net::StreamListenSocketFactory* CreateSocketFactory() { | 49 #if defined(OS_ANDROID) |
| 50 class UnixDomainServerSocketFactory |
| 51 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 52 public: |
| 53 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 54 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 55 |
| 56 private: |
| 57 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 58 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 59 return scoped_ptr<net::ServerSocket>( |
| 60 new net::UnixDomainServerSocket( |
| 61 base::Bind(&content::CanUserConnectToDevTools), |
| 62 true /* use_abstract_namespace */)); |
| 63 } |
| 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 66 }; |
| 67 #else |
| 68 class TCPServerSocketFactory |
| 69 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 70 public: |
| 71 TCPServerSocketFactory(const std::string& address, int port, int backlog) |
| 72 : content::DevToolsHttpHandler::ServerSocketFactory( |
| 73 address, port, backlog) {} |
| 74 |
| 75 private: |
| 76 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 77 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 78 return scoped_ptr<net::ServerSocket>( |
| 79 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
| 80 } |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 83 }; |
| 84 #endif |
| 85 |
| 86 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> |
| 87 CreateSocketFactory() { |
50 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 88 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
51 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
52 std::string socket_name = "content_shell_devtools_remote"; | 90 std::string socket_name = "content_shell_devtools_remote"; |
53 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { | 91 if (command_line.HasSwitch(switches::kRemoteDebuggingSocketName)) { |
54 socket_name = command_line.GetSwitchValueASCII( | 92 socket_name = command_line.GetSwitchValueASCII( |
55 switches::kRemoteDebuggingSocketName); | 93 switches::kRemoteDebuggingSocketName); |
56 } | 94 } |
57 return new net::deprecated:: | 95 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
58 UnixDomainListenSocketWithAbstractNamespaceFactory( | 96 new UnixDomainServerSocketFactory(socket_name)); |
59 socket_name, "", base::Bind(&content::CanUserConnectToDevTools)); | |
60 #else | 97 #else |
61 // See if the user specified a port on the command line (useful for | 98 // See if the user specified a port on the command line (useful for |
62 // automation). If not, use an ephemeral port by specifying 0. | 99 // automation). If not, use an ephemeral port by specifying 0. |
63 int port = 0; | 100 int port = 0; |
64 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { | 101 if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { |
65 int temp_port; | 102 int temp_port; |
66 std::string port_str = | 103 std::string port_str = |
67 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); | 104 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); |
68 if (base::StringToInt(port_str, &temp_port) && | 105 if (base::StringToInt(port_str, &temp_port) && |
69 temp_port > 0 && temp_port < 65535) { | 106 temp_port > 0 && temp_port < 65535) { |
70 port = temp_port; | 107 port = temp_port; |
71 } else { | 108 } else { |
72 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 109 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
73 } | 110 } |
74 } | 111 } |
75 return new net::TCPListenSocketFactory("127.0.0.1", port); | 112 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
| 113 new TCPServerSocketFactory("127.0.0.1", port, 1)); |
76 #endif | 114 #endif |
77 } | 115 } |
78 | 116 |
79 class Target : public content::DevToolsTarget { | 117 class Target : public content::DevToolsTarget { |
80 public: | 118 public: |
81 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); | 119 explicit Target(scoped_refptr<DevToolsAgentHost> agent_host); |
82 | 120 |
83 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } | 121 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } |
84 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 122 virtual std::string GetParentId() const OVERRIDE { return std::string(); } |
85 virtual std::string GetType() const OVERRIDE { | 123 virtual std::string GetType() const OVERRIDE { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 } | 245 } |
208 | 246 |
209 scoped_ptr<net::StreamListenSocket> | 247 scoped_ptr<net::StreamListenSocket> |
210 ShellDevToolsDelegate::CreateSocketForTethering( | 248 ShellDevToolsDelegate::CreateSocketForTethering( |
211 net::StreamListenSocket::Delegate* delegate, | 249 net::StreamListenSocket::Delegate* delegate, |
212 std::string* name) { | 250 std::string* name) { |
213 return scoped_ptr<net::StreamListenSocket>(); | 251 return scoped_ptr<net::StreamListenSocket>(); |
214 } | 252 } |
215 | 253 |
216 } // namespace content | 254 } // namespace content |
OLD | NEW |