OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/shell/browser/devtools/remote_debugging_server.h" | 5 #include "chromecast/shell/browser/devtools/remote_debugging_server.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chromecast/common/chromecast_config.h" | 12 #include "chromecast/common/chromecast_config.h" |
13 #include "chromecast/common/pref_names.h" | 13 #include "chromecast/common/pref_names.h" |
14 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" | 14 #include "chromecast/shell/browser/devtools/cast_dev_tools_delegate.h" |
15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/devtools_http_handler.h" | 17 #include "content/public/browser/devtools_http_handler.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/user_agent.h" | 19 #include "content/public/common/user_agent.h" |
20 #include "net/socket/tcp_listen_socket.h" | 20 #include "net/socket/tcp_server_socket.h" |
21 | 21 |
22 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
23 #include "content/public/browser/android/devtools_auth.h" | 23 #include "content/public/browser/android/devtools_auth.h" |
24 #include "net/socket/unix_domain_socket_posix.h" | 24 #include "net/socket/unix_domain_server_socket_posix.h" |
25 #endif // defined(OS_ANDROID) | 25 #endif // defined(OS_ANDROID) |
26 | 26 |
27 namespace chromecast { | 27 namespace chromecast { |
28 namespace shell { | 28 namespace shell { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 #if defined(OS_ANDROID) | 32 #if defined(OS_ANDROID) |
33 const char kFrontEndURL[] = | 33 const char kFrontEndURL[] = |
34 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; | 34 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/devtools.html"; |
35 #endif // defined(OS_ANDROID) | 35 #endif // defined(OS_ANDROID) |
36 const int kDefaultRemoteDebuggingPort = 9222; | 36 const int kDefaultRemoteDebuggingPort = 9222; |
37 | 37 |
38 net::StreamListenSocketFactory* CreateSocketFactory(int port) { | 38 #if defined(OS_ANDROID) |
| 39 class UnixDomainServerSocketFactory |
| 40 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 41 public: |
| 42 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 43 : content::DevToolsHttpHandler::ServerSocketFactory(socket_name, 0, 1) {} |
| 44 |
| 45 private: |
| 46 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 47 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 48 return scoped_ptr<net::ServerSocket>( |
| 49 new net::UnixDomainServerSocket( |
| 50 base::Bind(&content::CanUserConnectToDevTools), |
| 51 true /* use_abstract_namespace */)); |
| 52 } |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 55 }; |
| 56 #else |
| 57 class TCPServerSocketFactory |
| 58 : public content::DevToolsHttpHandler::ServerSocketFactory { |
| 59 public: |
| 60 TCPServerSocketFactory(const std::string& address, int port, int backlog) |
| 61 : content::DevToolsHttpHandler::ServerSocketFactory( |
| 62 address, port, backlog) {} |
| 63 |
| 64 private: |
| 65 // content::DevToolsHttpHandler::ServerSocketFactory. |
| 66 virtual scoped_ptr<net::ServerSocket> Create() const OVERRIDE { |
| 67 return scoped_ptr<net::ServerSocket>( |
| 68 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
| 69 } |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 72 }; |
| 73 #endif |
| 74 |
| 75 scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory> |
| 76 CreateSocketFactory(int port) { |
39 #if defined(OS_ANDROID) | 77 #if defined(OS_ANDROID) |
40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 78 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
41 std::string socket_name = "content_shell_devtools_remote"; | 79 std::string socket_name = "content_shell_devtools_remote"; |
42 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { | 80 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { |
43 socket_name = command_line->GetSwitchValueASCII( | 81 socket_name = command_line->GetSwitchValueASCII( |
44 switches::kRemoteDebuggingSocketName); | 82 switches::kRemoteDebuggingSocketName); |
45 } | 83 } |
46 return new net::UnixDomainSocketWithAbstractNamespaceFactory( | 84 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
47 socket_name, "", base::Bind(&content::CanUserConnectToDevTools)); | 85 new UnixDomainServerSocketFactory(socket_name)); |
48 #else | 86 #else |
49 return new net::TCPListenSocketFactory("0.0.0.0", port); | 87 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( |
50 #endif // defined(OS_ANDROID) | 88 new TCPServerSocketFactory("0.0.0.0", port, 1)); |
| 89 #endif |
51 } | 90 } |
52 | 91 |
53 std::string GetFrontendUrl() { | 92 std::string GetFrontendUrl() { |
54 #if defined(OS_ANDROID) | 93 #if defined(OS_ANDROID) |
55 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); | 94 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); |
56 #else | 95 #else |
57 return std::string(); | 96 return std::string(); |
58 #endif // defined(OS_ANDROID) | 97 #endif // defined(OS_ANDROID) |
59 } | 98 } |
60 | 99 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 CreateSocketFactory(port_), | 146 CreateSocketFactory(port_), |
108 GetFrontendUrl(), | 147 GetFrontendUrl(), |
109 new CastDevToolsDelegate(), | 148 new CastDevToolsDelegate(), |
110 base::FilePath()); | 149 base::FilePath()); |
111 LOG(INFO) << "Devtools started: port=" << port_; | 150 LOG(INFO) << "Devtools started: port=" << port_; |
112 } | 151 } |
113 } | 152 } |
114 | 153 |
115 } // namespace shell | 154 } // namespace shell |
116 } // namespace chromecast | 155 } // namespace chromecast |
OLD | NEW |