OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/net_internals_ui.h" | 5 #include "chrome/browser/dom_ui/net_internals_ui.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/net/chrome_net_log.h" | 29 #include "chrome/browser/net/chrome_net_log.h" |
30 #include "chrome/browser/net/connection_tester.h" | 30 #include "chrome/browser/net/connection_tester.h" |
31 #include "chrome/browser/net/passive_log_collector.h" | 31 #include "chrome/browser/net/passive_log_collector.h" |
32 #include "chrome/browser/net/url_fixer_upper.h" | 32 #include "chrome/browser/net/url_fixer_upper.h" |
33 #include "chrome/browser/platform_util.h" | 33 #include "chrome/browser/platform_util.h" |
34 #include "chrome/browser/profile.h" | 34 #include "chrome/browser/profile.h" |
35 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/net/url_request_context_getter.h" | 36 #include "chrome/common/net/url_request_context_getter.h" |
37 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
38 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
39 #include "grit/net_internals_resources.h" | |
40 #include "grit/net_internals_resources_map.h" | |
41 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
42 #include "net/base/host_resolver_impl.h" | 40 #include "net/base/host_resolver_impl.h" |
43 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
44 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
45 #include "net/base/sys_addrinfo.h" | 43 #include "net/base/sys_addrinfo.h" |
46 #include "net/disk_cache/disk_cache.h" | 44 #include "net/disk_cache/disk_cache.h" |
47 #include "net/http/http_cache.h" | 45 #include "net/http/http_cache.h" |
48 #include "net/proxy/proxy_service.h" | 46 #include "net/proxy/proxy_service.h" |
49 #include "net/url_request/url_request_context.h" | 47 #include "net/url_request/url_request_context.h" |
50 | 48 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 // | 309 // |
312 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
313 | 311 |
314 NetInternalsHTMLSource::NetInternalsHTMLSource() | 312 NetInternalsHTMLSource::NetInternalsHTMLSource() |
315 : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) { | 313 : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) { |
316 } | 314 } |
317 | 315 |
318 void NetInternalsHTMLSource::StartDataRequest(const std::string& path, | 316 void NetInternalsHTMLSource::StartDataRequest(const std::string& path, |
319 bool is_off_the_record, | 317 bool is_off_the_record, |
320 int request_id) { | 318 int request_id) { |
| 319 // The provided |path| identifies a file in resources/net_internals/. |
| 320 std::string data_string; |
| 321 FilePath file_path; |
| 322 PathService::Get(chrome::DIR_NET_INTERNALS, &file_path); |
| 323 std::string filename; |
| 324 |
321 // The provided "path" may contain a fragment, or query section. We only | 325 // The provided "path" may contain a fragment, or query section. We only |
322 // care about the path itself, and will disregard anything else. | 326 // care about the path itself, and will disregard anything else. |
323 std::string filename = | 327 filename = GURL(std::string("chrome://net/") + path).path().substr(1); |
324 GURL(std::string("chrome://net/") + path).path().substr(1); | 328 |
325 if (filename.empty()) | 329 if (filename.empty()) |
326 filename = "index.html"; | 330 filename = "index.html"; |
327 | 331 |
328 // The name of the files in the grd list are prefixed with the following | 332 file_path = file_path.AppendASCII(filename); |
329 // directory: | |
330 std::string key("net_internals/"); | |
331 key += filename; | |
332 | 333 |
333 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 334 if (!file_util::ReadFileToString(file_path, &data_string)) { |
334 for (size_t i = 0; i < kNetInternalsResourcesSize; ++i) { | 335 LOG(WARNING) << "Could not read resource: " << file_path.value(); |
335 if (kNetInternalsResources[i].name == key) { | 336 data_string = StringPrintf("<p style='color:red'>Failed to read file " |
336 scoped_refptr<RefCountedStaticMemory> bytes( | 337 "RESOURCES/net_internals/%s</p>", |
337 rb.LoadDataResourceBytes(kNetInternalsResources[i].value)); | 338 EscapeForHTML(filename).c_str()); |
338 if (bytes && bytes->front()) { | 339 |
339 SendResponse(request_id, bytes); | 340 // During the transition from old implementation to new implementation, |
340 return; | 341 // users may be entering the URLs for the old frontend. |
341 } | 342 data_string.append( |
342 } | 343 "<p>Note that the URL scheme for net-internals has changed because of " |
| 344 "its new implementation (bug 37421):</p>" |
| 345 "<ul>" |
| 346 "<li>chrome://net-internals/proxyservice.* → " |
| 347 "<a href='chrome://net-internals#proxy'>chrome://net-internals#proxy" |
| 348 "</a></li>" |
| 349 "<li>chrome://net-internals/hostresolver.* → <a href='chrome://net" |
| 350 "-internals#dns'>chrome://net-internals#dns</a></li>" |
| 351 "<li>chrome://net-internals/urlrequest.* → <a href='chrome://net-" |
| 352 "internals#requests'>chrome://net-internals#requests</a></li>" |
| 353 "<li>chrome://net-internals/ (overview for copy-pasting) → <a href" |
| 354 "='chrome://net-internals#data'>chrome://net-internals#data</a></li>" |
| 355 "<li>chrome://net-internals/view-cache/* → <a href=" |
| 356 "'chrome://view-http-cache'>chrome://view-http-cache</a></li>" |
| 357 "</ul>"); |
343 } | 358 } |
344 | 359 |
345 LOG(WARNING) << "Could not read resource: " << path; | |
346 std::string data_string = "<p style='color:red'>Failed to read resource"; | |
347 data_string.append(EscapeForHTML(filename)); | |
348 data_string.append("</p>"); | |
349 | |
350 // During the transition from old implementation to new implementation, | |
351 // users may be entering the URLs for the old frontend. | |
352 data_string.append( | |
353 "<p>Note that the URL scheme for net-internals has changed because of " | |
354 "its new implementation (bug 37421):</p>" | |
355 "<ul>" | |
356 "<li>chrome://net-internals/proxyservice.* → " | |
357 "<a href='chrome://net-internals#proxy'>chrome://net-internals#proxy" | |
358 "</a></li>" | |
359 "<li>chrome://net-internals/hostresolver.* → <a href='chrome://net" | |
360 "-internals#dns'>chrome://net-internals#dns</a></li>" | |
361 "<li>chrome://net-internals/urlrequest.* → <a href='chrome://net-" | |
362 "internals#requests'>chrome://net-internals#requests</a></li>" | |
363 "<li>chrome://net-internals/ (overview for copy-pasting) → <a href" | |
364 "='chrome://net-internals#data'>chrome://net-internals#data</a></li>" | |
365 "<li>chrome://net-internals/view-cache/* → <a href=" | |
366 "'chrome://view-http-cache'>chrome://view-http-cache</a></li>" | |
367 "</ul>"); | |
368 | |
369 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); | 360 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes); |
370 bytes->data.resize(data_string.size()); | 361 bytes->data.resize(data_string.size()); |
371 std::copy(data_string.begin(), data_string.end(), bytes->data.begin()); | 362 std::copy(data_string.begin(), data_string.end(), bytes->data.begin()); |
| 363 |
372 SendResponse(request_id, bytes); | 364 SendResponse(request_id, bytes); |
373 } | 365 } |
374 | 366 |
375 std::string NetInternalsHTMLSource::GetMimeType(const std::string&) const { | 367 std::string NetInternalsHTMLSource::GetMimeType(const std::string&) const { |
376 // TODO(eroman): This is incorrect -- some of the subresources may be | 368 // TODO(eroman): This is incorrect -- some of the subresources may be |
377 // css/javascript. | 369 // css/javascript. |
378 return "text/html"; | 370 return "text/html"; |
379 } | 371 } |
380 | 372 |
381 //////////////////////////////////////////////////////////////////////////////// | 373 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); | 908 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource(); |
917 | 909 |
918 // Set up the chrome://net-internals/ source. | 910 // Set up the chrome://net-internals/ source. |
919 ChromeThread::PostTask( | 911 ChromeThread::PostTask( |
920 ChromeThread::IO, FROM_HERE, | 912 ChromeThread::IO, FROM_HERE, |
921 NewRunnableMethod( | 913 NewRunnableMethod( |
922 Singleton<ChromeURLDataManager>::get(), | 914 Singleton<ChromeURLDataManager>::get(), |
923 &ChromeURLDataManager::AddDataSource, | 915 &ChromeURLDataManager::AddDataSource, |
924 make_scoped_refptr(html_source))); | 916 make_scoped_refptr(html_source))); |
925 } | 917 } |
OLD | NEW |