| 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_server_socket.h" | 20 #include "net/socket/tcp_listen_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_server_socket_posix.h" | 24 #include "net/socket/unix_domain_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 #if defined(OS_ANDROID) | 38 net::StreamListenSocketFactory* CreateSocketFactory(int port) { |
| 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) { | |
| 77 #if defined(OS_ANDROID) | 39 #if defined(OS_ANDROID) |
| 78 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 40 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 79 std::string socket_name = "content_shell_devtools_remote"; | 41 std::string socket_name = "content_shell_devtools_remote"; |
| 80 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { | 42 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 81 socket_name = command_line->GetSwitchValueASCII( | 43 socket_name = command_line->GetSwitchValueASCII( |
| 82 switches::kRemoteDebuggingSocketName); | 44 switches::kRemoteDebuggingSocketName); |
| 83 } | 45 } |
| 84 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( | 46 return new net::UnixDomainSocketWithAbstractNamespaceFactory( |
| 85 new UnixDomainServerSocketFactory(socket_name)); | 47 socket_name, "", base::Bind(&content::CanUserConnectToDevTools)); |
| 86 #else | 48 #else |
| 87 return scoped_ptr<content::DevToolsHttpHandler::ServerSocketFactory>( | 49 return new net::TCPListenSocketFactory("0.0.0.0", port); |
| 88 new TCPServerSocketFactory("0.0.0.0", port, 1)); | 50 #endif // defined(OS_ANDROID) |
| 89 #endif | |
| 90 } | 51 } |
| 91 | 52 |
| 92 std::string GetFrontendUrl() { | 53 std::string GetFrontendUrl() { |
| 93 #if defined(OS_ANDROID) | 54 #if defined(OS_ANDROID) |
| 94 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); | 55 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); |
| 95 #else | 56 #else |
| 96 return std::string(); | 57 return std::string(); |
| 97 #endif // defined(OS_ANDROID) | 58 #endif // defined(OS_ANDROID) |
| 98 } | 59 } |
| 99 | 60 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 CreateSocketFactory(port_), | 107 CreateSocketFactory(port_), |
| 147 GetFrontendUrl(), | 108 GetFrontendUrl(), |
| 148 new CastDevToolsDelegate(), | 109 new CastDevToolsDelegate(), |
| 149 base::FilePath()); | 110 base::FilePath()); |
| 150 LOG(INFO) << "Devtools started: port=" << port_; | 111 LOG(INFO) << "Devtools started: port=" << port_; |
| 151 } | 112 } |
| 152 } | 113 } |
| 153 | 114 |
| 154 } // namespace shell | 115 } // namespace shell |
| 155 } // namespace chromecast | 116 } // namespace chromecast |
| OLD | NEW |