| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/net/network_errors_listing_ui.h" | 5 #include "content/browser/net/network_errors_listing_ui.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 error_code != net::Error::ERR_ABORTED) { | 50 error_code != net::Error::ERR_ABORTED) { |
| 51 std::unique_ptr<base::DictionaryValue> error(new base::DictionaryValue()); | 51 std::unique_ptr<base::DictionaryValue> error(new base::DictionaryValue()); |
| 52 error->SetInteger(kErrorIdField, error_code); | 52 error->SetInteger(kErrorIdField, error_code); |
| 53 error->SetString(kErrorCodeField, itr.key()); | 53 error->SetString(kErrorCodeField, itr.key()); |
| 54 error_list->Append(std::move(error)); | 54 error_list->Append(std::move(error)); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return error_list; | 57 return error_list; |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool HandleRequestCallback(BrowserContext* current_context, | 60 bool HandleWebUIRequestCallback(BrowserContext* current_context, |
| 61 const std::string& path, | 61 const std::string& path, |
| 62 const WebUIDataSource::GotDataCallback& callback) { | 62 const WebUIDataSource::GotDataCallback& callback) { |
| 63 if (path != kDataFile) | 63 if (path != kDataFile) |
| 64 return false; | 64 return false; |
| 65 | 65 |
| 66 base::DictionaryValue data; | 66 base::DictionaryValue data; |
| 67 data.Set(kErrorCodesDataName, GetNetworkErrorData()); | 67 data.Set(kErrorCodesDataName, GetNetworkErrorData()); |
| 68 std::string json_string; | 68 std::string json_string; |
| 69 base::JSONWriter::Write(data, &json_string); | 69 base::JSONWriter::Write(data, &json_string); |
| 70 callback.Run(base::RefCountedString::TakeString(&json_string)); | 70 callback.Run(base::RefCountedString::TakeString(&json_string)); |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 NetworkErrorsListingUI::NetworkErrorsListingUI(WebUI* web_ui) | 76 NetworkErrorsListingUI::NetworkErrorsListingUI(WebUI* web_ui) |
| 77 : WebUIController(web_ui) { | 77 : WebUIController(web_ui) { |
| 78 // Set up the chrome://network-errors source. | 78 // Set up the chrome://network-errors source. |
| 79 WebUIDataSource* html_source = | 79 WebUIDataSource* html_source = |
| 80 WebUIDataSource::Create(kChromeUINetworkErrorsListingHost); | 80 WebUIDataSource::Create(kChromeUINetworkErrorsListingHost); |
| 81 | 81 |
| 82 // Add required resources. | 82 // Add required resources. |
| 83 html_source->SetJsonPath("strings.js"); | 83 html_source->SetJsonPath("strings.js"); |
| 84 html_source->AddResourcePath("network_errors_listing.css", | 84 html_source->AddResourcePath("network_errors_listing.css", |
| 85 IDR_NETWORK_ERROR_LISTING_CSS); | 85 IDR_NETWORK_ERROR_LISTING_CSS); |
| 86 html_source->AddResourcePath("network_errors_listing.js", | 86 html_source->AddResourcePath("network_errors_listing.js", |
| 87 IDR_NETWORK_ERROR_LISTING_JS); | 87 IDR_NETWORK_ERROR_LISTING_JS); |
| 88 html_source->SetDefaultResource(IDR_NETWORK_ERROR_LISTING_HTML); | 88 html_source->SetDefaultResource(IDR_NETWORK_ERROR_LISTING_HTML); |
| 89 html_source->SetRequestFilter( | 89 html_source->SetRequestFilter( |
| 90 base::Bind(&HandleRequestCallback, | 90 base::Bind(&HandleWebUIRequestCallback, |
| 91 web_ui->GetWebContents()->GetBrowserContext())); | 91 web_ui->GetWebContents()->GetBrowserContext())); |
| 92 | 92 |
| 93 BrowserContext* browser_context = | 93 BrowserContext* browser_context = |
| 94 web_ui->GetWebContents()->GetBrowserContext(); | 94 web_ui->GetWebContents()->GetBrowserContext(); |
| 95 WebUIDataSource::Add(browser_context, html_source); | 95 WebUIDataSource::Add(browser_context, html_source); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace content | 98 } // namespace content |
| OLD | NEW |