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