Chromium Code Reviews| Index: content/browser/net/network_error_request_job.cc |
| diff --git a/content/browser/net/network_error_request_job.cc b/content/browser/net/network_error_request_job.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba01f4bfa3fd9b48a42fcef5e8c7c93957f1ebe7 |
| --- /dev/null |
| +++ b/content/browser/net/network_error_request_job.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_error_request_job.h" |
| + |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/values.h" |
| +#include "net/base/escape.h" |
| +#include "net/base/net_errors.h" |
| +#include "net/log/net_log_util.h" |
| +#include "net/url_request/url_request.h" |
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +static const char kNetworkErrorKey[] = "netError"; |
| + |
| +NetworkErrorRequestJob::NetworkErrorRequestJob( |
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate) |
| + : net::URLRequestSimpleJob(request, network_delegate), |
| + error_code_(net::Error::OK) { |
| + std::basic_string<char> error_code_string = |
| + request->url().path().substr(1, std::string::npos); |
| + |
| + if (!base::StringToInt(error_code_string, &error_code_)) |
| + error_code_ = 0; |
| +} |
| + |
| +// Creates a HTML page listing all error codes. |
| +void ListAllErrorCodes(std::string* data) { |
| + std::string unescaped_query; |
| + std::string unescaped_title("Network error codes"); |
| + |
| + data->append("<!DOCTYPE html>\n<html>\n<head>\n"); |
|
Dan Beam
2015/11/19 20:12:52
an additional nit: <!doctype html>
edwardjung
2015/11/20 16:34:51
Will fix in the HTML template
|
| + data->append( |
| + "<meta http-equiv=\"Content-Security-Policy\" " |
| + "content=\"object-src 'none'; script-src 'none'\">"); |
| + data->append( |
| + "<meta name=\"viewport\" content=\"width=device-width\">"); |
| + data->append("<title>"); |
|
Evan Stade
2015/11/19 16:35:21
this seems like a pretty awkward way to do this, i
edwardjung
2015/11/19 17:10:14
What do you recommend. Is there a template I shoul
Evan Stade
2015/11/19 19:07:14
I have no idea why a few of the chrome:// internal
Dan Beam
2015/11/19 20:12:52
no, they should not exist.
agree with estade@ tha
edwardjung
2015/11/20 16:34:51
Okay I'll switch to using the content_web_ui_contr
|
| + data->append(unescaped_title); |
| + data->append("</title>\n"); |
| + data->append("<link rel=\"stylesheet\""); |
| + data->append("href=\"chrome://resources/css/chrome_shared.css\">\n"); |
| + data->append("</head><body style=\"margin:1em; line-height:1.5em\">"); |
|
Evan Stade
2015/11/19 16:35:21
and it doesn't allow for separation of content and
edwardjung
2015/11/19 17:10:14
Agreed, but didn't know whether creating a new sty
|
| + data->append("<h1>"); |
| + data->append(unescaped_title); |
| + data->append("</h1>"); |
| + |
| + 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; |
| + } |
| + } |
| + |
| + data->append("<ul>"); |
| + for (base::DictionaryValue::Iterator itr(*net_error_codes_dict); |
| + !itr.IsAtEnd(); itr.Advance()) { |
| + int error_code; |
| + itr.value().GetAsInteger(&error_code); |
| + data->append("<li><a href=\""); |
| + data->append(base::IntToString(error_code)); |
| + data->append("\">"); |
| + data->append(itr.key()); |
| + data->append(" ("); |
| + data->append(base::IntToString(error_code)); |
| + data->append(")</a></li>\n"); |
| + } |
| + data->append("</ul>"); |
| +} |
| + |
| +int NetworkErrorRequestJob::GetData( |
| + std::string* mime_type, |
| + std::string* charset, |
| + std::string* data, |
| + const net::CompletionCallback& callback) const { |
| + mime_type->assign("text/html"); |
| + charset->assign("UTF8"); |
| + |
| + if (error_code_ == 0 || error_code_ == net::Error::ERR_IO_PENDING) { |
| + ListAllErrorCodes(data); |
| + return net::OK; |
| + } |
| + return error_code_; |
| +} |
| + |
| +} // namespace content |