| 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/browser/devtools/remote_debugging_server.h" | 5 #include "chromecast/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/macros.h" | 11 #include "base/macros.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 "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chromecast/base/pref_names.h" | 15 #include "chromecast/base/pref_names.h" |
| 16 #include "chromecast/browser/cast_browser_process.h" | 16 #include "chromecast/browser/cast_browser_process.h" |
| 17 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h" | 17 #include "chromecast/browser/devtools/cast_dev_tools_delegate.h" |
| 18 #include "chromecast/common/cast_content_client.h" | 18 #include "chromecast/common/cast_content_client.h" |
| 19 #include "components/devtools_http_handler/devtools_http_handler.h" | 19 #include "components/devtools_http_handler/devtools_http_handler.h" |
| 20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/devtools_socket_factory.h" |
| 22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 23 #include "content/public/common/user_agent.h" | 24 #include "content/public/common/user_agent.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/socket/tcp_server_socket.h" | 26 #include "net/socket/tcp_server_socket.h" |
| 26 | 27 |
| 27 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 28 #include "content/public/browser/android/devtools_auth.h" | 29 #include "content/public/browser/android/devtools_auth.h" |
| 29 #include "net/socket/unix_domain_server_socket_posix.h" | 30 #include "net/socket/unix_domain_server_socket_posix.h" |
| 30 #endif // defined(OS_ANDROID) | 31 #endif // defined(OS_ANDROID) |
| 31 | 32 |
| 32 using devtools_http_handler::DevToolsHttpHandler; | 33 using devtools_http_handler::DevToolsHttpHandler; |
| 33 | 34 |
| 34 namespace chromecast { | 35 namespace chromecast { |
| 35 namespace shell { | 36 namespace shell { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 const char kFrontEndURL[] = | 40 const char kFrontEndURL[] = |
| 40 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; | 41 "https://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; |
| 41 const uint16_t kDefaultRemoteDebuggingPort = 9222; | 42 const uint16_t kDefaultRemoteDebuggingPort = 9222; |
| 42 | 43 |
| 43 const int kBackLog = 10; | 44 const int kBackLog = 10; |
| 44 | 45 |
| 45 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 46 class UnixDomainServerSocketFactory | 47 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory { |
| 47 : public DevToolsHttpHandler::ServerSocketFactory { | |
| 48 public: | 48 public: |
| 49 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 49 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 50 : socket_name_(socket_name) {} | 50 : socket_name_(socket_name) {} |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. | 53 // content::DevToolsSocketFactory. |
| 54 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { | 54 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 55 std::unique_ptr<net::UnixDomainServerSocket> socket( | 55 std::unique_ptr<net::UnixDomainServerSocket> socket( |
| 56 new net::UnixDomainServerSocket( | 56 new net::UnixDomainServerSocket( |
| 57 base::Bind(&content::CanUserConnectToDevTools), | 57 base::Bind(&content::CanUserConnectToDevTools), |
| 58 true /* use_abstract_namespace */)); | 58 true /* use_abstract_namespace */)); |
| 59 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) | 59 if (socket->BindAndListen(socket_name_, kBackLog) != net::OK) |
| 60 return std::unique_ptr<net::ServerSocket>(); | 60 return std::unique_ptr<net::ServerSocket>(); |
| 61 | 61 |
| 62 return std::move(socket); | 62 return std::move(socket); |
| 63 } | 63 } |
| 64 | 64 |
| 65 std::unique_ptr<net::ServerSocket> CreateForTethering( |
| 66 std::string* name) override { |
| 67 return nullptr; |
| 68 } |
| 69 |
| 65 std::string socket_name_; | 70 std::string socket_name_; |
| 66 | 71 |
| 67 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); | 72 DISALLOW_COPY_AND_ASSIGN(UnixDomainServerSocketFactory); |
| 68 }; | 73 }; |
| 69 #else | 74 #else |
| 70 class TCPServerSocketFactory | 75 class TCPServerSocketFactory : public content::DevToolsSocketFactory { |
| 71 : public DevToolsHttpHandler::ServerSocketFactory { | |
| 72 public: | 76 public: |
| 73 TCPServerSocketFactory(const std::string& address, uint16_t port) | 77 TCPServerSocketFactory(const std::string& address, uint16_t port) |
| 74 : address_(address), port_(port) {} | 78 : address_(address), port_(port) {} |
| 75 | 79 |
| 76 private: | 80 private: |
| 77 // devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory. | 81 // content::DevToolsSocketFactory. |
| 78 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { | 82 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 79 std::unique_ptr<net::ServerSocket> socket( | 83 std::unique_ptr<net::ServerSocket> socket( |
| 80 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 84 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 81 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) | 85 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) |
| 82 return std::unique_ptr<net::ServerSocket>(); | 86 return std::unique_ptr<net::ServerSocket>(); |
| 83 | 87 |
| 84 return socket; | 88 return socket; |
| 85 } | 89 } |
| 86 | 90 |
| 91 std::unique_ptr<net::ServerSocket> CreateForTethering( |
| 92 std::string* name) override { |
| 93 return nullptr; |
| 94 } |
| 95 |
| 87 std::string address_; | 96 std::string address_; |
| 88 uint16_t port_; | 97 uint16_t port_; |
| 89 | 98 |
| 90 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 99 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
| 91 }; | 100 }; |
| 92 #endif | 101 #endif |
| 93 | 102 |
| 94 std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory> CreateSocketFactory( | 103 std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory( |
| 95 uint16_t port) { | 104 uint16_t port) { |
| 96 #if defined(OS_ANDROID) | 105 #if defined(OS_ANDROID) |
| 97 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 98 std::string socket_name = "cast_shell_devtools_remote"; | 107 std::string socket_name = "cast_shell_devtools_remote"; |
| 99 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { | 108 if (command_line->HasSwitch(switches::kRemoteDebuggingSocketName)) { |
| 100 socket_name = command_line->GetSwitchValueASCII( | 109 socket_name = command_line->GetSwitchValueASCII( |
| 101 switches::kRemoteDebuggingSocketName); | 110 switches::kRemoteDebuggingSocketName); |
| 102 } | 111 } |
| 103 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( | 112 return std::unique_ptr<content::DevToolsSocketFactory>( |
| 104 new UnixDomainServerSocketFactory(socket_name)); | 113 new UnixDomainServerSocketFactory(socket_name)); |
| 105 #else | 114 #else |
| 106 return std::unique_ptr<DevToolsHttpHandler::ServerSocketFactory>( | 115 return std::unique_ptr<content::DevToolsSocketFactory>( |
| 107 new TCPServerSocketFactory("0.0.0.0", port)); | 116 new TCPServerSocketFactory("0.0.0.0", port)); |
| 108 #endif | 117 #endif |
| 109 } | 118 } |
| 110 | 119 |
| 111 std::string GetFrontendUrl() { | 120 std::string GetFrontendUrl() { |
| 112 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); | 121 return base::StringPrintf(kFrontEndURL, content::GetWebKitRevision().c_str()); |
| 113 } | 122 } |
| 114 | 123 |
| 115 } // namespace | 124 } // namespace |
| 116 | 125 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 GetUserAgent())); | 167 GetUserAgent())); |
| 159 LOG(INFO) << "Devtools started: port=" << port_; | 168 LOG(INFO) << "Devtools started: port=" << port_; |
| 160 } else if (!enabled && devtools_http_handler_) { | 169 } else if (!enabled && devtools_http_handler_) { |
| 161 LOG(INFO) << "Stop devtools: port=" << port_; | 170 LOG(INFO) << "Stop devtools: port=" << port_; |
| 162 devtools_http_handler_.reset(); | 171 devtools_http_handler_.reset(); |
| 163 } | 172 } |
| 164 } | 173 } |
| 165 | 174 |
| 166 } // namespace shell | 175 } // namespace shell |
| 167 } // namespace chromecast | 176 } // namespace chromecast |
| OLD | NEW |