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/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "components/devtools_http_handler/devtools_http_handler.h" | |
21 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/devtools_agent_host.h" | 21 #include "content/public/browser/devtools_agent_host.h" |
23 #include "content/public/browser/devtools_frontend_host.h" | 22 #include "content/public/browser/devtools_frontend_host.h" |
24 #include "content/public/browser/devtools_socket_factory.h" | 23 #include "content/public/browser/devtools_socket_factory.h" |
25 #include "content/public/browser/favicon_status.h" | 24 #include "content/public/browser/favicon_status.h" |
26 #include "content/public/browser/navigation_entry.h" | 25 #include "content/public/browser/navigation_entry.h" |
27 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
29 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
30 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
31 #include "content/public/common/user_agent.h" | 30 #include "content/public/common/user_agent.h" |
32 #include "content/shell/browser/shell.h" | 31 #include "content/shell/browser/shell.h" |
33 #include "content/shell/common/shell_content_client.h" | 32 #include "content/shell/common/shell_content_client.h" |
34 #include "grit/shell_resources.h" | 33 #include "grit/shell_resources.h" |
35 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
36 #include "net/socket/tcp_server_socket.h" | 35 #include "net/socket/tcp_server_socket.h" |
37 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
38 | 37 |
39 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
40 #include "content/public/browser/android/devtools_auth.h" | 39 #include "content/public/browser/android/devtools_auth.h" |
41 #include "net/socket/unix_domain_server_socket_posix.h" | 40 #include "net/socket/unix_domain_server_socket_posix.h" |
42 #endif | 41 #endif |
43 | 42 |
44 using devtools_http_handler::DevToolsHttpHandler; | |
45 | |
46 namespace content { | 43 namespace content { |
47 | 44 |
48 namespace { | 45 namespace { |
49 | 46 |
50 #if defined(OS_ANDROID) | 47 #if defined(OS_ANDROID) |
51 const char kFrontEndURL[] = | 48 const char kFrontEndURL[] = |
52 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; | 49 "http://chrome-devtools-frontend.appspot.com/serve_rev/%s/inspector.html"; |
53 #endif | 50 #endif |
54 | 51 |
55 const int kBackLog = 10; | 52 const int kBackLog = 10; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 port = static_cast<uint16_t>(temp_port); | 131 port = static_cast<uint16_t>(temp_port); |
135 } else { | 132 } else { |
136 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; | 133 DLOG(WARNING) << "Invalid http debugger port number " << temp_port; |
137 } | 134 } |
138 } | 135 } |
139 return std::unique_ptr<content::DevToolsSocketFactory>( | 136 return std::unique_ptr<content::DevToolsSocketFactory>( |
140 new TCPServerSocketFactory("127.0.0.1", port)); | 137 new TCPServerSocketFactory("127.0.0.1", port)); |
141 #endif | 138 #endif |
142 } | 139 } |
143 | 140 |
144 // ShellDevToolsDelegate ---------------------------------------------------- | 141 } // namespace |
145 | |
146 class ShellDevToolsDelegate : | |
147 public devtools_http_handler::DevToolsHttpHandlerDelegate { | |
148 public: | |
149 explicit ShellDevToolsDelegate(); | |
150 ~ShellDevToolsDelegate() override; | |
151 | |
152 // devtools_http_handler::DevToolsHttpHandlerDelegate implementation. | |
153 std::string GetDiscoveryPageHTML() override; | |
154 std::string GetFrontendResource(const std::string& path) override; | |
155 | |
156 private: | |
157 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsDelegate); | |
158 }; | |
159 | |
160 ShellDevToolsDelegate::ShellDevToolsDelegate() { | |
161 } | |
162 | |
163 ShellDevToolsDelegate::~ShellDevToolsDelegate() { | |
164 } | |
165 | |
166 std::string ShellDevToolsDelegate::GetDiscoveryPageHTML() { | |
167 #if defined(OS_ANDROID) | |
168 return std::string(); | |
169 #else | |
170 return ResourceBundle::GetSharedInstance().GetRawDataResource( | |
171 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); | |
172 #endif | |
173 } | |
174 | |
175 std::string ShellDevToolsDelegate::GetFrontendResource( | |
176 const std::string& path) { | |
177 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); | |
178 } | |
179 | |
180 } // namespace | |
181 | 142 |
182 // ShellDevToolsManagerDelegate ---------------------------------------------- | 143 // ShellDevToolsManagerDelegate ---------------------------------------------- |
183 | 144 |
184 // static | 145 // static |
185 DevToolsHttpHandler* | 146 void ShellDevToolsManagerDelegate::StartHttpHandler( |
186 ShellDevToolsManagerDelegate::CreateHttpHandler( | |
187 BrowserContext* browser_context) { | 147 BrowserContext* browser_context) { |
188 std::string frontend_url; | 148 std::string frontend_url; |
189 #if defined(OS_ANDROID) | 149 #if defined(OS_ANDROID) |
190 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); | 150 frontend_url = base::StringPrintf(kFrontEndURL, GetWebKitRevision().c_str()); |
191 #endif | 151 #endif |
192 return new DevToolsHttpHandler( | 152 DevToolsAgentHost::StartRemoteDebuggingServer( |
193 CreateSocketFactory(), | 153 CreateSocketFactory(), |
194 frontend_url, | 154 frontend_url, |
195 new ShellDevToolsDelegate(), | |
196 browser_context->GetPath(), | 155 browser_context->GetPath(), |
197 base::FilePath(), | 156 base::FilePath(), |
198 std::string(), | 157 std::string(), |
199 GetShellUserAgent()); | 158 GetShellUserAgent()); |
200 } | 159 } |
201 | 160 |
| 161 // static |
| 162 void ShellDevToolsManagerDelegate::StopHttpHandler() { |
| 163 DevToolsAgentHost::StopRemoteDebuggingServer(); |
| 164 } |
| 165 |
202 ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate( | 166 ShellDevToolsManagerDelegate::ShellDevToolsManagerDelegate( |
203 BrowserContext* browser_context) | 167 BrowserContext* browser_context) |
204 : browser_context_(browser_context) { | 168 : browser_context_(browser_context) { |
205 } | 169 } |
206 | 170 |
207 ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() { | 171 ShellDevToolsManagerDelegate::~ShellDevToolsManagerDelegate() { |
208 } | 172 } |
209 | 173 |
210 base::DictionaryValue* ShellDevToolsManagerDelegate::HandleCommand( | |
211 DevToolsAgentHost* agent_host, | |
212 base::DictionaryValue* command_dict) { | |
213 return nullptr; | |
214 } | |
215 | |
216 std::string ShellDevToolsManagerDelegate::GetTargetType(RenderFrameHost* host) { | |
217 return DevToolsAgentHost::kTypePage; | |
218 } | |
219 | |
220 std::string ShellDevToolsManagerDelegate::GetTargetTitle( | |
221 RenderFrameHost* host) { | |
222 return ""; | |
223 } | |
224 | |
225 | |
226 scoped_refptr<DevToolsAgentHost> | 174 scoped_refptr<DevToolsAgentHost> |
227 ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { | 175 ShellDevToolsManagerDelegate::CreateNewTarget(const GURL& url) { |
228 Shell* shell = Shell::CreateNewWindow(browser_context_, | 176 Shell* shell = Shell::CreateNewWindow(browser_context_, |
229 url, | 177 url, |
230 nullptr, | 178 nullptr, |
231 gfx::Size()); | 179 gfx::Size()); |
232 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents()); | 180 return DevToolsAgentHost::GetOrCreateFor(shell->web_contents()); |
233 } | 181 } |
234 | 182 |
| 183 std::string ShellDevToolsManagerDelegate::GetDiscoveryPageHTML() { |
| 184 #if defined(OS_ANDROID) |
| 185 return std::string(); |
| 186 #else |
| 187 return ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 188 IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); |
| 189 #endif |
| 190 } |
| 191 |
| 192 std::string ShellDevToolsManagerDelegate::GetFrontendResource( |
| 193 const std::string& path) { |
| 194 return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); |
| 195 } |
| 196 |
235 } // namespace content | 197 } // namespace content |
OLD | NEW |