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/ui/webui/devtools_ui.h" | 5 #include "chrome/browser/ui/webui/devtools_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
13 #include "chrome/browser/net/chrome_url_request_context.h" | 13 #include "chrome/browser/net/chrome_url_request_context.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.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/browser/devtools_remote_frontend_util.h" |
18 #include "content/public/browser/url_data_source.h" | 19 #include "content/public/browser/url_data_source.h" |
19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
20 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
22 #include "net/url_request/url_fetcher_delegate.h" | 23 #include "net/url_request/url_fetcher_delegate.h" |
23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
25 | 26 |
26 using content::BrowserThread; | 27 using content::BrowserThread; |
27 using content::WebContents; | 28 using content::WebContents; |
28 | 29 |
29 namespace { | 30 namespace { |
30 | 31 |
31 std::string PathWithoutParams(const std::string& path) { | 32 std::string PathWithoutParams(const std::string& path) { |
32 return GURL(std::string("chrome-devtools://devtools/") + path) | 33 return GURL(std::string("chrome-devtools://devtools/") + path) |
33 .path().substr(1); | 34 .path().substr(1); |
34 } | 35 } |
35 | 36 |
36 const char kRemoteFrontendDomain[] = "chrome-devtools-frontend.appspot.com"; | |
37 const char kRemoteFrontendBase[] = | |
38 "https://chrome-devtools-frontend.appspot.com/"; | |
39 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; | 37 const char kHttpNotFound[] = "HTTP/1.1 404 Not Found\n\n"; |
40 | 38 |
41 #if defined(DEBUG_DEVTOOLS) | 39 #if defined(DEBUG_DEVTOOLS) |
42 // Local frontend url provided by InspectUI. | 40 // Local frontend url provided by InspectUI. |
43 const char kLocalFrontendURLPrefix[] = "https://localhost:9222/"; | 41 const char kLocalFrontendURLPrefix[] = "https://localhost:9222/"; |
44 // URL local frontend should be served from. | 42 // URL local frontend should be served from. |
45 const char kLocalFrontendBase[] = "http://localhost:9222/"; | 43 const char kLocalFrontendBase[] = "http://localhost:9222/"; |
46 // Local frontend path in DevToolsDataSource. | 44 // Local frontend path in DevToolsDataSource. |
47 const char kLocalFrontendDataSourcePath[] = "localhost"; | 45 const char kLocalFrontendDataSourcePath[] = "localhost"; |
48 #endif // defined(DEBUG_DEVTOOLS) | 46 #endif // defined(DEBUG_DEVTOOLS) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 resource_id)); | 170 resource_id)); |
173 callback.Run(bytes.get()); | 171 callback.Run(bytes.get()); |
174 } | 172 } |
175 | 173 |
176 // Serves remote DevTools frontend from hard-coded App Engine domain. | 174 // Serves remote DevTools frontend from hard-coded App Engine domain. |
177 void StartRemoteDataRequest( | 175 void StartRemoteDataRequest( |
178 const std::string& path, | 176 const std::string& path, |
179 int render_process_id, | 177 int render_process_id, |
180 int render_view_id, | 178 int render_view_id, |
181 const content::URLDataSource::GotDataCallback& callback) { | 179 const content::URLDataSource::GotDataCallback& callback) { |
182 GURL url = GURL(kRemoteFrontendBase + path); | 180 GURL url = GURL(content::GetDevToolsFrontendResourceURL(path)); |
183 CHECK_EQ(url.host(), kRemoteFrontendDomain); | 181 CHECK(content::IsDevToolsFrontendHost(url)); |
184 new FetchRequest(request_context_.get(), url, callback); | 182 new FetchRequest(request_context_.get(), url, callback); |
185 } | 183 } |
186 | 184 |
187 // Serves debug DevTools frontend from localhost:9222. | 185 // Serves debug DevTools frontend from localhost:9222. |
188 #if defined(DEBUG_DEVTOOLS) | 186 #if defined(DEBUG_DEVTOOLS) |
189 void StartLocalDataRequest( | 187 void StartLocalDataRequest( |
190 const std::string& path, | 188 const std::string& path, |
191 int render_process_id, | 189 int render_process_id, |
192 int render_view_id, | 190 int render_view_id, |
193 const content::URLDataSource::GotDataCallback& callback) { | 191 const content::URLDataSource::GotDataCallback& callback) { |
(...skipping 27 matching lines...) Expand all Loading... |
221 std::string path = url.path(); | 219 std::string path = url.path(); |
222 CHECK(path.find(chrome::kChromeUIDevToolsHost) == 1); | 220 CHECK(path.find(chrome::kChromeUIDevToolsHost) == 1); |
223 return GURL(base::StringPrintf("%s://%s/%s/%s", | 221 return GURL(base::StringPrintf("%s://%s/%s/%s", |
224 chrome::kChromeDevToolsScheme, | 222 chrome::kChromeDevToolsScheme, |
225 chrome::kChromeUIDevToolsHost, | 223 chrome::kChromeUIDevToolsHost, |
226 kLocalFrontendDataSourcePath, | 224 kLocalFrontendDataSourcePath, |
227 path.substr(1).c_str())); | 225 path.substr(1).c_str())); |
228 } | 226 } |
229 #endif // defined(DEBUG_DEVTOOLS) | 227 #endif // defined(DEBUG_DEVTOOLS) |
230 CHECK(url.is_valid()); | 228 CHECK(url.is_valid()); |
231 CHECK_EQ(url.host(), kRemoteFrontendDomain); | 229 CHECK(content::IsDevToolsFrontendHost(url)); |
232 return GURL(base::StringPrintf("%s://%s/%s/%s", | 230 return GURL(base::StringPrintf("%s://%s/%s/%s", |
233 chrome::kChromeDevToolsScheme, | 231 chrome::kChromeDevToolsScheme, |
234 chrome::kChromeUIDevToolsHost, | 232 chrome::kChromeUIDevToolsHost, |
235 chrome::kChromeUIDevToolsRemotePath, | 233 chrome::kChromeUIDevToolsRemotePath, |
236 url.path().substr(1).c_str())); | 234 url.path().substr(1).c_str())); |
237 } | 235 } |
238 | 236 |
239 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 237 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
240 web_ui->SetBindings(0); | 238 web_ui->SetBindings(0); |
241 Profile* profile = Profile::FromWebUI(web_ui); | 239 Profile* profile = Profile::FromWebUI(web_ui); |
242 content::URLDataSource::Add( | 240 content::URLDataSource::Add( |
243 profile, | 241 profile, |
244 new DevToolsDataSource(profile->GetRequestContext())); | 242 new DevToolsDataSource(profile->GetRequestContext())); |
245 } | 243 } |
OLD | NEW |