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

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: Clean up NetworkErrorRequestJob remnants 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 DCHECK_CURRENTLY_ON(BrowserThread::UI); 459 DCHECK_CURRENTLY_ON(BrowserThread::UI);
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 {
469 bool IsValidNetworkErrorCode(int error_code) {
470 scoped_ptr<base::DictionaryValue> error_codes = net::GetNetConstants();
471 const base::DictionaryValue* net_error_codes_dict = nullptr;
472
473 for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd();
474 itr.Advance()) {
475 if (itr.key() == kNetworkErrorKey) {
476 itr.value().GetAsDictionary(&net_error_codes_dict);
477 break;
478 }
479 }
480
481 for (base::DictionaryValue::Iterator itr(*net_error_codes_dict);
482 !itr.IsAtEnd(); itr.Advance()) {
483 int net_error_code;
484 itr.value().GetAsInteger(&net_error_code);
485 if (error_code == net_error_code)
486 return true;
487 }
488 return false;
489 }
465 490
466 class ChromeProtocolHandler 491 class ChromeProtocolHandler
467 : public net::URLRequestJobFactory::ProtocolHandler { 492 : public net::URLRequestJobFactory::ProtocolHandler {
468 public: 493 public:
469 // |is_incognito| should be set for incognito profiles. 494 // |is_incognito| should be set for incognito profiles.
470 ChromeProtocolHandler(ResourceContext* resource_context, 495 ChromeProtocolHandler(ResourceContext* resource_context,
471 bool is_incognito, 496 bool is_incognito,
472 AppCacheServiceImpl* appcache_service, 497 AppCacheServiceImpl* appcache_service,
473 ChromeBlobStorageContext* blob_storage_context) 498 ChromeBlobStorageContext* blob_storage_context)
474 : resource_context_(resource_context), 499 : resource_context_(resource_context),
(...skipping 25 matching lines...) Expand all
500 return new TcmallocInternalsRequestJob(request, network_delegate); 525 return new TcmallocInternalsRequestJob(request, network_delegate);
501 } 526 }
502 #endif 527 #endif
503 528
504 // Next check for chrome://histograms/, which uses its own job type. 529 // Next check for chrome://histograms/, which uses its own job type.
505 if (request->url().SchemeIs(kChromeUIScheme) && 530 if (request->url().SchemeIs(kChromeUIScheme) &&
506 request->url().host() == kChromeUIHistogramHost) { 531 request->url().host() == kChromeUIHistogramHost) {
507 return new HistogramInternalsRequestJob(request, network_delegate); 532 return new HistogramInternalsRequestJob(request, network_delegate);
508 } 533 }
509 534
535 // Check for chrome://network-error/, which uses its own job type.
536 if (request->url().SchemeIs(kChromeUIScheme) &&
537 request->url().host() == kChromeUINetworkErrorHost) {
538 // Get the error code passed in via the request URL path.
539 std::basic_string<char> error_code_string =
540 request->url().path().substr(1, std::string::npos);
Dan Beam 2015/12/01 04:24:17 this is equivalent to substr(1), I believe
edwardjung 2015/12/01 12:30:08 Yep, confirmed.
541
542 int error_code;
543 if (base::StringToInt(error_code_string, &error_code)) {
544 // Check for a valid error code.
545 if (IsValidNetworkErrorCode(error_code) &&
546 error_code != net::Error::ERR_IO_PENDING) {
547 return new net::URLRequestErrorJob(request, network_delegate,
548 error_code);
549 }
550 }
551 }
552
510 // Fall back to using a custom handler 553 // Fall back to using a custom handler
511 return new URLRequestChromeJob( 554 return new URLRequestChromeJob(
512 request, network_delegate, 555 request, network_delegate,
513 GetURLDataManagerForResourceContext(resource_context_), is_incognito_); 556 GetURLDataManagerForResourceContext(resource_context_), is_incognito_);
514 } 557 }
515 558
516 bool IsSafeRedirectTarget(const GURL& location) const override { 559 bool IsSafeRedirectTarget(const GURL& location) const override {
517 return false; 560 return false;
518 } 561 }
519 562
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 816
774 } // namespace 817 } // namespace
775 818
776 net::URLRequestJobFactory::ProtocolHandler* 819 net::URLRequestJobFactory::ProtocolHandler*
777 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, 820 CreateDevToolsProtocolHandler(content::ResourceContext* resource_context,
778 bool is_incognito) { 821 bool is_incognito) {
779 return new DevToolsJobFactory(resource_context, is_incognito); 822 return new DevToolsJobFactory(resource_context, is_incognito);
780 } 823 }
781 824
782 } // namespace content 825 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698