Index: content/browser/net/network_errors_listing_ui.cc |
diff --git a/content/browser/net/network_errors_listing_ui.cc b/content/browser/net/network_errors_listing_ui.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..96638cefdbe5d572910e911441a8f735d990d989 |
--- /dev/null |
+++ b/content/browser/net/network_errors_listing_ui.cc |
@@ -0,0 +1,94 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/net/network_errors_listing_ui.h" |
+ |
+#include "base/bind.h" |
+#include "base/json/json_writer.h" |
+#include "base/values.h" |
+#include "content/grit/content_resources.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/common/url_constants.h" |
+#include "net/base/net_errors.h" |
+#include "net/log/net_log_util.h" |
+ |
+static const char kDataFile[] = "network-error-data.json"; |
+static const char kErrorCodeField[] = "errorCode"; |
+static const char kErrorCodesDataName[] = "errorCodes"; |
+static const char kErrorIdField[] = "errorId"; |
+static const char kNetworkErrorKey[] = "netError"; |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+scoped_ptr<base::ListValue> GetNetworkErrorData() { |
+ scoped_ptr<base::DictionaryValue> error_codes = net::GetNetConstants(); |
+ const base::DictionaryValue* net_error_codes_dict = nullptr; |
+ |
+ for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd(); |
+ itr.Advance()) { |
+ if (itr.key() == kNetworkErrorKey) { |
+ itr.value().GetAsDictionary(&net_error_codes_dict); |
+ break; |
+ } |
+ } |
+ |
+ scoped_ptr<base::ListValue> error_list(new base::ListValue()); |
+ |
+ for (base::DictionaryValue::Iterator itr(*net_error_codes_dict); |
+ !itr.IsAtEnd(); itr.Advance()) { |
+ int error_code; |
+ itr.value().GetAsInteger(&error_code); |
+ // Exclude the aborted and pending codes as these don't return a page. |
+ if (error_code != net::Error::ERR_IO_PENDING && |
+ error_code != net::Error::ERR_ABORTED) { |
+ base::DictionaryValue* error = new base::DictionaryValue(); |
+ error->SetInteger(kErrorIdField, error_code); |
+ error->SetString(kErrorCodeField, itr.key()); |
+ error_list->Append(error); |
+ } |
+ } |
+ return error_list; |
+} |
+ |
+bool HandleRequestCallback(BrowserContext* current_context, |
+ const std::string& path, |
+ const WebUIDataSource::GotDataCallback& callback) { |
+ if (path != kDataFile) |
+ return false; |
+ |
+ base::DictionaryValue data; |
+ data.Set(kErrorCodesDataName, GetNetworkErrorData().release()); |
+ std::string json_string; |
+ base::JSONWriter::Write(data, &json_string); |
+ callback.Run(base::RefCountedString::TakeString(&json_string)); |
+ return true; |
+} |
+ |
+} // namespace |
+ |
+NetworkErrorsListingUI::NetworkErrorsListingUI(WebUI* web_ui) : |
jochen (gone - plz use gerrit)
2015/12/02 12:35:08
is that actually clang-formatted?
edwardjung
2015/12/03 11:02:53
Fixed.
|
+ WebUIController(web_ui) { |
+ // Set up the chrome://network-errors source. |
+ WebUIDataSource* html_source = |
+ WebUIDataSource::Create(kChromeUINetworkErrorsListingHost); |
+ |
+ // Add required resources. |
+ html_source->SetJsonPath("strings.js"); |
+ html_source->AddResourcePath("network_errors_listing.css", |
+ IDR_NETWORK_ERROR_LISTING_CSS); |
+ html_source->AddResourcePath("network_errors_listing.js", |
+ IDR_NETWORK_ERROR_LISTING_JS); |
+ html_source->SetDefaultResource(IDR_NETWORK_ERROR_LISTING_HTML); |
+ html_source->SetRequestFilter( |
+ base::Bind(&HandleRequestCallback, |
+ web_ui->GetWebContents()->GetBrowserContext())); |
+ |
+ BrowserContext* browser_context = |
+ web_ui->GetWebContents()->GetBrowserContext(); |
+ WebUIDataSource::Add(browser_context, html_source); |
+} |
+ |
+} // namespace content |