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

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

Issue 2873913002: Implement chrome://network-error with network service. (Closed)
Patch Set: merge Created 3 years, 7 months 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 return; 341 return;
342 342
343 if (!backend_->StartRequest(request_, this)) { 343 if (!backend_->StartRequest(request_, this)) {
344 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, 344 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
345 net::ERR_INVALID_URL)); 345 net::ERR_INVALID_URL));
346 } 346 }
347 } 347 }
348 348
349 namespace { 349 namespace {
350 350
351 bool IsValidNetworkErrorCode(int error_code) {
352 std::unique_ptr<base::DictionaryValue> error_codes = net::GetNetConstants();
353 const base::DictionaryValue* net_error_codes_dict = nullptr;
354
355 for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd();
356 itr.Advance()) {
357 if (itr.key() == kNetworkErrorKey) {
358 itr.value().GetAsDictionary(&net_error_codes_dict);
359 break;
360 }
361 }
362
363 if (net_error_codes_dict != nullptr) {
364 for (base::DictionaryValue::Iterator itr(*net_error_codes_dict);
365 !itr.IsAtEnd(); itr.Advance()) {
366 int net_error_code;
367 itr.value().GetAsInteger(&net_error_code);
368 if (error_code == net_error_code)
369 return true;
370 }
371 }
372 return false;
373 }
374
375 class ChromeProtocolHandler 351 class ChromeProtocolHandler
376 : public net::URLRequestJobFactory::ProtocolHandler { 352 : public net::URLRequestJobFactory::ProtocolHandler {
377 public: 353 public:
378 ChromeProtocolHandler(ResourceContext* resource_context, 354 ChromeProtocolHandler(ResourceContext* resource_context,
379 ChromeBlobStorageContext* blob_storage_context) 355 ChromeBlobStorageContext* blob_storage_context)
380 : resource_context_(resource_context), 356 : resource_context_(resource_context),
381 blob_storage_context_(blob_storage_context) {} 357 blob_storage_context_(blob_storage_context) {}
382 ~ChromeProtocolHandler() override {} 358 ~ChromeProtocolHandler() override {}
383 359
384 net::URLRequestJob* MaybeCreateJob( 360 net::URLRequestJob* MaybeCreateJob(
(...skipping 21 matching lines...) Expand all
406 // Check for chrome://network-error/, which uses its own job type. 382 // Check for chrome://network-error/, which uses its own job type.
407 if (request->url().SchemeIs(kChromeUIScheme) && 383 if (request->url().SchemeIs(kChromeUIScheme) &&
408 request->url().host_piece() == kChromeUINetworkErrorHost) { 384 request->url().host_piece() == kChromeUINetworkErrorHost) {
409 // Get the error code passed in via the request URL path. 385 // Get the error code passed in via the request URL path.
410 std::basic_string<char> error_code_string = 386 std::basic_string<char> error_code_string =
411 request->url().path().substr(1); 387 request->url().path().substr(1);
412 388
413 int error_code; 389 int error_code;
414 if (base::StringToInt(error_code_string, &error_code)) { 390 if (base::StringToInt(error_code_string, &error_code)) {
415 // Check for a valid error code. 391 // Check for a valid error code.
416 if (IsValidNetworkErrorCode(error_code) && 392 if (URLDataManagerBackend::IsValidNetworkErrorCode(error_code) &&
417 error_code != net::Error::ERR_IO_PENDING) { 393 error_code != net::Error::ERR_IO_PENDING) {
418 return new net::URLRequestErrorJob(request, network_delegate, 394 return new net::URLRequestErrorJob(request, network_delegate,
419 error_code); 395 error_code);
420 } 396 }
421 } 397 }
422 } 398 }
423 399
424 // Check for chrome://dino which is an alias for chrome://network-error/-106 400 // Check for chrome://dino which is an alias for chrome://network-error/-106
425 if (request->url().SchemeIs(kChromeUIScheme) && 401 if (request->url().SchemeIs(kChromeUIScheme) &&
426 request->url().host() == kChromeUIDinoHost) { 402 request->url().host() == kChromeUIDinoHost) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 std::string* path) { 670 std::string* path) {
695 const std::string& spec = url.possibly_invalid_spec(); 671 const std::string& spec = url.possibly_invalid_spec();
696 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); 672 const url::Parsed& parsed = url.parsed_for_possibly_invalid_spec();
697 // + 1 to skip the slash at the beginning of the path. 673 // + 1 to skip the slash at the beginning of the path.
698 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1; 674 int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1;
699 675
700 if (offset < static_cast<int>(spec.size())) 676 if (offset < static_cast<int>(spec.size()))
701 path->assign(spec.substr(offset)); 677 path->assign(spec.substr(offset));
702 } 678 }
703 679
680 bool URLDataManagerBackend::IsValidNetworkErrorCode(int error_code) {
681 std::unique_ptr<base::DictionaryValue> error_codes = net::GetNetConstants();
682 const base::DictionaryValue* net_error_codes_dict = nullptr;
683
684 for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd();
685 itr.Advance()) {
686 if (itr.key() == kNetworkErrorKey) {
687 itr.value().GetAsDictionary(&net_error_codes_dict);
688 break;
689 }
690 }
691
692 if (net_error_codes_dict != nullptr) {
693 for (base::DictionaryValue::Iterator itr(*net_error_codes_dict);
694 !itr.IsAtEnd(); itr.Advance()) {
695 int net_error_code;
696 itr.value().GetAsInteger(&net_error_code);
697 if (error_code == net_error_code)
698 return true;
699 }
700 }
701 return false;
702 }
703
704 std::vector<std::string> URLDataManagerBackend::GetWebUISchemes() { 704 std::vector<std::string> URLDataManagerBackend::GetWebUISchemes() {
705 std::vector<std::string> schemes; 705 std::vector<std::string> schemes;
706 schemes.push_back(kChromeUIScheme); 706 schemes.push_back(kChromeUIScheme);
707 GetContentClient()->browser()->GetAdditionalWebUISchemes(&schemes); 707 GetContentClient()->browser()->GetAdditionalWebUISchemes(&schemes);
708 return schemes; 708 return schemes;
709 } 709 }
710 710
711 namespace { 711 namespace {
712 712
713 class DevToolsJobFactory 713 class DevToolsJobFactory
(...skipping 30 matching lines...) Expand all
744 } 744 }
745 745
746 } // namespace 746 } // namespace
747 747
748 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler( 748 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler(
749 ResourceContext* resource_context) { 749 ResourceContext* resource_context) {
750 return new DevToolsJobFactory(resource_context); 750 return new DevToolsJobFactory(resource_context);
751 } 751 }
752 752
753 } // namespace content 753 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/url_data_manager_backend.h ('k') | content/browser/webui/web_ui_url_loader_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698