OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/devtools/remote_debugging_server.h" | 5 #include "chrome/browser/devtools/remote_debugging_server.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/devtools/devtools_window.h" | 15 #include "chrome/browser/devtools/devtools_window.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/common/chrome_content_client.h" | 19 #include "chrome/common/chrome_content_client.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/grit/browser_resources.h" | |
22 #include "components/devtools_http_handler/devtools_http_handler.h" | |
23 #include "components/devtools_http_handler/devtools_http_handler_delegate.h" | |
24 #include "components/version_info/version_info.h" | 21 #include "components/version_info/version_info.h" |
| 22 #include "content/public/browser/devtools_agent_host.h" |
25 #include "content/public/browser/devtools_frontend_host.h" | 23 #include "content/public/browser/devtools_frontend_host.h" |
26 #include "content/public/browser/devtools_socket_factory.h" | 24 #include "content/public/browser/devtools_socket_factory.h" |
27 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
28 #include "net/socket/tcp_server_socket.h" | 26 #include "net/socket/tcp_server_socket.h" |
29 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
30 | 28 |
31 namespace { | 29 namespace { |
32 | 30 |
33 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; | 31 base::LazyInstance<bool>::Leaky g_tethering_enabled = LAZY_INSTANCE_INITIALIZER; |
34 | 32 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 return CreateLocalHostServerSocket(port); | 77 return CreateLocalHostServerSocket(port); |
80 } | 78 } |
81 | 79 |
82 std::string address_; | 80 std::string address_; |
83 uint16_t port_; | 81 uint16_t port_; |
84 uint16_t last_tethering_port_; | 82 uint16_t last_tethering_port_; |
85 | 83 |
86 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); | 84 DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); |
87 }; | 85 }; |
88 | 86 |
89 class ChromeDevToolsHttpHandlerDelegate | |
90 : public devtools_http_handler::DevToolsHttpHandlerDelegate { | |
91 public: | |
92 ChromeDevToolsHttpHandlerDelegate(); | |
93 ~ChromeDevToolsHttpHandlerDelegate() override; | |
94 | |
95 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. | |
96 std::string GetDiscoveryPageHTML() override; | |
97 std::string GetFrontendResource(const std::string& path) override; | |
98 | |
99 private: | |
100 DISALLOW_COPY_AND_ASSIGN(ChromeDevToolsHttpHandlerDelegate); | |
101 }; | |
102 | |
103 ChromeDevToolsHttpHandlerDelegate::ChromeDevToolsHttpHandlerDelegate() { | |
104 } | |
105 | |
106 ChromeDevToolsHttpHandlerDelegate::~ChromeDevToolsHttpHandlerDelegate() { | |
107 } | |
108 | |
109 std::string ChromeDevToolsHttpHandlerDelegate::GetDiscoveryPageHTML() { | |
110 return ResourceBundle::GetSharedInstance().GetRawDataResource( | |
111 IDR_DEVTOOLS_DISCOVERY_PAGE_HTML).as_string(); | |
112 } | |
113 | |
114 std::string ChromeDevToolsHttpHandlerDelegate::GetFrontendResource( | |
115 const std::string& path) { | |
116 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | |
117 } | |
118 | |
119 } // namespace | 87 } // namespace |
120 | 88 |
121 // static | 89 // static |
122 void RemoteDebuggingServer::EnableTetheringForDebug() { | 90 void RemoteDebuggingServer::EnableTetheringForDebug() { |
123 g_tethering_enabled.Get() = true; | 91 g_tethering_enabled.Get() = true; |
124 } | 92 } |
125 | 93 |
126 RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, | 94 RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, |
127 uint16_t port) { | 95 uint16_t port) { |
128 base::FilePath output_dir; | 96 base::FilePath output_dir; |
129 if (!port) { | 97 if (!port) { |
130 // The client requested an ephemeral port. Must write the selected | 98 // The client requested an ephemeral port. Must write the selected |
131 // port to a well-known location in the profile directory to | 99 // port to a well-known location in the profile directory to |
132 // bootstrap the connection process. | 100 // bootstrap the connection process. |
133 bool result = PathService::Get(chrome::DIR_USER_DATA, &output_dir); | 101 bool result = PathService::Get(chrome::DIR_USER_DATA, &output_dir); |
134 DCHECK(result); | 102 DCHECK(result); |
135 } | 103 } |
136 | 104 |
137 base::FilePath debug_frontend_dir; | 105 base::FilePath debug_frontend_dir; |
138 #if defined(DEBUG_DEVTOOLS) | 106 #if defined(DEBUG_DEVTOOLS) |
139 PathService::Get(chrome::DIR_INSPECTOR, &debug_frontend_dir); | 107 PathService::Get(chrome::DIR_INSPECTOR, &debug_frontend_dir); |
140 #endif | 108 #endif |
141 | 109 |
142 devtools_http_handler_.reset(new devtools_http_handler::DevToolsHttpHandler( | 110 content::DevToolsAgentHost::StartRemoteDebuggingServer( |
143 base::WrapUnique(new TCPServerSocketFactory(ip, port)), std::string(), | 111 base::WrapUnique(new TCPServerSocketFactory(ip, port)), |
144 new ChromeDevToolsHttpHandlerDelegate(), output_dir, debug_frontend_dir, | 112 std::string(), |
145 version_info::GetProductNameAndVersionForUserAgent(), ::GetUserAgent())); | 113 output_dir, |
| 114 debug_frontend_dir, |
| 115 version_info::GetProductNameAndVersionForUserAgent(), |
| 116 ::GetUserAgent()); |
146 } | 117 } |
147 | 118 |
148 RemoteDebuggingServer::~RemoteDebuggingServer() { | 119 RemoteDebuggingServer::~RemoteDebuggingServer() { |
149 // Ensure Profile is alive, because the whole DevTools subsystem | 120 // Ensure Profile is alive, because the whole DevTools subsystem |
150 // accesses it during shutdown. | 121 // accesses it during shutdown. |
151 DCHECK(g_browser_process->profile_manager()); | 122 DCHECK(g_browser_process->profile_manager()); |
| 123 content::DevToolsAgentHost::StopRemoteDebuggingServer(); |
152 } | 124 } |
OLD | NEW |