| 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_manager_delegate.h" | 5 #include "content/shell/browser/shell_devtools_manager_delegate.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/atomicops.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 20 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
| 48 const char kFrontEndURL[] = | 49 const char kFrontEndURL[] = |
| 49 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; | 50 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; |
| 50 #endif | 51 #endif |
| 51 | 52 |
| 52 const int kBackLog = 10; | 53 const int kBackLog = 10; |
| 53 | 54 |
| 55 base::subtle::Atomic32 g_last_used_port; |
| 56 |
| 54 #if defined(OS_ANDROID) | 57 #if defined(OS_ANDROID) |
| 55 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory { | 58 class UnixDomainServerSocketFactory : public content::DevToolsSocketFactory { |
| 56 public: | 59 public: |
| 57 explicit UnixDomainServerSocketFactory(const std::string& socket_name) | 60 explicit UnixDomainServerSocketFactory(const std::string& socket_name) |
| 58 : socket_name_(socket_name) {} | 61 : socket_name_(socket_name) {} |
| 59 | 62 |
| 60 private: | 63 private: |
| 61 // content::DevToolsSocketFactory. | 64 // content::DevToolsSocketFactory. |
| 62 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { | 65 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 63 std::unique_ptr<net::UnixDomainServerSocket> socket( | 66 std::unique_ptr<net::UnixDomainServerSocket> socket( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 85 : address_(address), port_(port) {} | 88 : address_(address), port_(port) {} |
| 86 | 89 |
| 87 private: | 90 private: |
| 88 // content::DevToolsSocketFactory. | 91 // content::DevToolsSocketFactory. |
| 89 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { | 92 std::unique_ptr<net::ServerSocket> CreateForHttpServer() override { |
| 90 std::unique_ptr<net::ServerSocket> socket( | 93 std::unique_ptr<net::ServerSocket> socket( |
| 91 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 94 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
| 92 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) | 95 if (socket->ListenWithAddressAndPort(address_, port_, kBackLog) != net::OK) |
| 93 return std::unique_ptr<net::ServerSocket>(); | 96 return std::unique_ptr<net::ServerSocket>(); |
| 94 | 97 |
| 98 net::IPEndPoint endpoint; |
| 99 if (socket->GetLocalAddress(&endpoint) == net::OK) |
| 100 base::subtle::NoBarrier_Store(&g_last_used_port, endpoint.port()); |
| 101 |
| 95 return socket; | 102 return socket; |
| 96 } | 103 } |
| 97 | 104 |
| 98 std::unique_ptr<net::ServerSocket> CreateForTethering( | 105 std::unique_ptr<net::ServerSocket> CreateForTethering( |
| 99 std::string* out_name) override { | 106 std::string* out_name) override { |
| 100 return nullptr; | 107 return nullptr; |
| 101 } | 108 } |
| 102 | 109 |
| 103 std::string address_; | 110 std::string address_; |
| 104 uint16_t port_; | 111 uint16_t port_; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return std::unique_ptr<content::DevToolsSocketFactory>( | 143 return std::unique_ptr<content::DevToolsSocketFactory>( |
| 137 new TCPServerSocketFactory("127.0.0.1", port)); | 144 new TCPServerSocketFactory("127.0.0.1", port)); |
| 138 #endif | 145 #endif |
| 139 } | 146 } |
| 140 | 147 |
| 141 } // namespace | 148 } // namespace |
| 142 | 149 |
| 143 // ShellDevToolsManagerDelegate ---------------------------------------------- | 150 // ShellDevToolsManagerDelegate ---------------------------------------------- |
| 144 | 151 |
| 145 // static | 152 // static |
| 153 int ShellDevToolsManagerDelegate::GetHttpHandlerPort() { |
| 154 return base::subtle::NoBarrier_Load(&g_last_used_port); |
| 155 } |
| 156 |
| 157 // static |
| 146 void ShellDevToolsManagerDelegate::StartHttpHandler( | 158 void ShellDevToolsManagerDelegate::StartHttpHandler( |
| 147 BrowserContext* browser_context) { | 159 BrowserContext* browser_context) { |
| 148 std::string frontend_url; | 160 std::string frontend_url; |
| 149 #if defined(OS_ANDROID) | 161 #if defined(OS_ANDROID) |
| 150 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); | 162 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); |
| 151 #endif | 163 #endif |
| 152 DevToolsAgentHost::StartRemoteDebuggingServer( | 164 DevToolsAgentHost::StartRemoteDebuggingServer( |
| 153 CreateSocketFactory(), | 165 CreateSocketFactory(), |
| 154 frontend_url, | 166 frontend_url, |
| 155 browser_context->GetPath(), | 167 browser_context->GetPath(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); | 220 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); |
| 209 #endif | 221 #endif |
| 210 } | 222 } |
| 211 | 223 |
| 212 std::string ShellDevToolsManagerDelegate::GetFrontendResource( | 224 std::string ShellDevToolsManagerDelegate::GetFrontendResource( |
| 213 const std::string& path) { | 225 const std::string& path) { |
| 214 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | 226 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); |
| 215 } | 227 } |
| 216 | 228 |
| 217 } // namespace content | 229 } // namespace content |
| OLD | NEW |