Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: content/browser/webui/url_data_manager_backend.cc

Issue 1421743002: Implement chrome://network-errors for direct access to network error interstitials (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments from jochen Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/webui/url_data_manager_backend.h" 5 #include "content/browser/webui/url_data_manager_backend.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/debug/alias.h" 13 #include "base/debug/alias.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/profiler/scoped_tracker.h" 19 #include "base/profiler/scoped_tracker.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
22 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
23 #include "base/trace_event/trace_event.h" 24 #include "base/trace_event/trace_event.h"
24 #include "content/browser/fileapi/chrome_blob_storage_context.h" 25 #include "content/browser/fileapi/chrome_blob_storage_context.h"
25 #include "content/browser/histogram_internals_request_job.h" 26 #include "content/browser/histogram_internals_request_job.h"
26 #include "content/browser/net/view_blob_internals_job_factory.h" 27 #include "content/browser/net/view_blob_internals_job_factory.h"
27 #include "content/browser/net/view_http_cache_job_factory.h" 28 #include "content/browser/net/view_http_cache_job_factory.h"
28 #include "content/browser/resource_context_impl.h" 29 #include "content/browser/resource_context_impl.h"
29 #include "content/browser/tcmalloc_internals_request_job.h" 30 #include "content/browser/tcmalloc_internals_request_job.h"
30 #include "content/browser/webui/shared_resources_data_source.h" 31 #include "content/browser/webui/shared_resources_data_source.h"
31 #include "content/browser/webui/url_data_source_impl.h" 32 #include "content/browser/webui/url_data_source_impl.h"
32 #include "content/public/browser/browser_context.h" 33 #include "content/public/browser/browser_context.h"
33 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/content_browser_client.h" 35 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/browser/render_process_host.h" 36 #include "content/public/browser/render_process_host.h"
36 #include "content/public/browser/resource_request_info.h" 37 #include "content/public/browser/resource_request_info.h"
37 #include "content/public/common/url_constants.h" 38 #include "content/public/common/url_constants.h"
38 #include "net/base/io_buffer.h" 39 #include "net/base/io_buffer.h"
39 #include "net/base/net_errors.h" 40 #include "net/base/net_errors.h"
40 #include "net/http/http_response_headers.h" 41 #include "net/http/http_response_headers.h"
41 #include "net/http/http_status_code.h" 42 #include "net/http/http_status_code.h"
43 #include "net/log/net_log_util.h"
42 #include "net/url_request/url_request.h" 44 #include "net/url_request/url_request.h"
43 #include "net/url_request/url_request_context.h" 45 #include "net/url_request/url_request_context.h"
46 #include "net/url_request/url_request_error_job.h"
44 #include "net/url_request/url_request_job.h" 47 #include "net/url_request/url_request_job.h"
45 #include "net/url_request/url_request_job_factory.h" 48 #include "net/url_request/url_request_job_factory.h"
49
46 #include "url/url_util.h" 50 #include "url/url_util.h"
47 51
48 namespace content { 52 namespace content {
49 53
50 namespace { 54 namespace {
51 55
52 const char kChromeURLContentSecurityPolicyHeaderBase[] = 56 const char kChromeURLContentSecurityPolicyHeaderBase[] =
53 "Content-Security-Policy: script-src chrome://resources 'self'"; 57 "Content-Security-Policy: script-src chrome://resources 'self'";
54 58
55 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY"; 59 const char kChromeURLXFrameOptionsHeader[] = "X-Frame-Options: DENY";
56 60 static const char kNetworkErrorKey[] = "netError";
57 const int kNoRenderProcessId = -1; 61 const int kNoRenderProcessId = -1;
58 62
59 bool SchemeIsInSchemes(const std::string& scheme, 63 bool SchemeIsInSchemes(const std::string& scheme,
60 const std::vector<std::string>& schemes) { 64 const std::vector<std::string>& schemes) {
61 return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end(); 65 return std::find(schemes.begin(), schemes.end(), scheme) != schemes.end();
62 } 66 }
63 67
64 // Returns whether |url| passes some sanity checks and is a valid GURL. 68 // Returns whether |url| passes some sanity checks and is a valid GURL.
65 bool CheckURLIsValid(const GURL& url) { 69 bool CheckURLIsValid(const GURL& url) {
66 std::vector<std::string> additional_schemes; 70 std::vector<std::string> additional_schemes;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 std::string mime_type = source->source()->GetMimeType(path); 460 std::string mime_type = source->source()->GetMimeType(path);
457 BrowserThread::PostTask( 461 BrowserThread::PostTask(
458 BrowserThread::IO, FROM_HERE, 462 BrowserThread::IO, FROM_HERE,
459 base::Bind(&URLRequestChromeJob::MimeTypeAvailable, job, mime_type)); 463 base::Bind(&URLRequestChromeJob::MimeTypeAvailable, job, mime_type));
460 } 464 }
461 465
462 } // namespace 466 } // namespace
463 467
464 namespace { 468 namespace {
465 469
470 bool IsValidNetworkErrorCode(int error_code) {
471 scoped_ptr<base::DictionaryValue> error_codes = net::GetNetConstants();
472 const base::DictionaryValue* net_error_codes_dict = nullptr;
473
474 for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd();
475 itr.Advance()) {
476 if (itr.key() == kNetworkErrorKey) {
477 itr.value().GetAsDictionary(&net_error_codes_dict);
478 break;
479 }
480 }
481
482 if (net_error_codes_dict != nullptr) {
483 for (base::DictionaryValue::Iterator itr(*net_error_codes_dict);
484 !itr.IsAtEnd(); itr.Advance()) {
485 int net_error_code;
486 itr.value().GetAsInteger(&net_error_code);
487 if (error_code == net_error_code)
488 return true;
489 }
490 }
491 return false;
492 }
493
466 class ChromeProtocolHandler 494 class ChromeProtocolHandler
467 : public net::URLRequestJobFactory::ProtocolHandler { 495 : public net::URLRequestJobFactory::ProtocolHandler {
468 public: 496 public:
469 // |is_incognito| should be set for incognito profiles. 497 // |is_incognito| should be set for incognito profiles.
470 ChromeProtocolHandler(ResourceContext* resource_context, 498 ChromeProtocolHandler(ResourceContext* resource_context,
471 bool is_incognito, 499 bool is_incognito,
472 AppCacheServiceImpl* appcache_service, 500 AppCacheServiceImpl* appcache_service,
473 ChromeBlobStorageContext* blob_storage_context) 501 ChromeBlobStorageContext* blob_storage_context)
474 : resource_context_(resource_context), 502 : resource_context_(resource_context),
475 is_incognito_(is_incognito), 503 is_incognito_(is_incognito),
(...skipping 24 matching lines...) Expand all
500 return new TcmallocInternalsRequestJob(request, network_delegate); 528 return new TcmallocInternalsRequestJob(request, network_delegate);
501 } 529 }
502 #endif 530 #endif
503 531
504 // Next check for chrome://histograms/, which uses its own job type. 532 // Next check for chrome://histograms/, which uses its own job type.
505 if (request->url().SchemeIs(kChromeUIScheme) && 533 if (request->url().SchemeIs(kChromeUIScheme) &&
506 request->url().host() == kChromeUIHistogramHost) { 534 request->url().host() == kChromeUIHistogramHost) {
507 return new HistogramInternalsRequestJob(request, network_delegate); 535 return new HistogramInternalsRequestJob(request, network_delegate);
508 } 536 }
509 537
538 // Check for chrome://network-error/, which uses its own job type.
539 if (request->url().SchemeIs(kChromeUIScheme) &&
540 request->url().host() == kChromeUINetworkErrorHost) {
541 // Get the error code passed in via the request URL path.
542 std::basic_string<char> error_code_string =
543 request->url().path().substr(1);
544
545 int error_code;
546 if (base::StringToInt(error_code_string, &error_code)) {
547 // Check for a valid error code.
548 if (IsValidNetworkErrorCode(error_code) &&
549 error_code != net::Error::ERR_IO_PENDING) {
550 return new net::URLRequestErrorJob(request, network_delegate,
551 error_code);
552 }
553 }
554 }
555
510 // Fall back to using a custom handler 556 // Fall back to using a custom handler
511 return new URLRequestChromeJob( 557 return new URLRequestChromeJob(
512 request, network_delegate, 558 request, network_delegate,
513 GetURLDataManagerForResourceContext(resource_context_), is_incognito_); 559 GetURLDataManagerForResourceContext(resource_context_), is_incognito_);
514 } 560 }
515 561
516 bool IsSafeRedirectTarget(const GURL& location) const override { 562 bool IsSafeRedirectTarget(const GURL& location) const override {
517 return false; 563 return false;
518 } 564 }
519 565
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 819
774 } // namespace 820 } // namespace
775 821
776 net::URLRequestJobFactory::ProtocolHandler* 822 net::URLRequestJobFactory::ProtocolHandler*
777 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 823 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
778 bool is_incognito) { 824 bool is_incognito) {
779 return new DevToolsJobFactory(resource_context, is_incognito); 825 return new DevToolsJobFactory(resource_context, is_incognito);
780 } 826 }
781 827
782 } // namespace content 828 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/content_web_ui_controller_factory.cc ('k') | content/browser/webui/url_data_manager_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698