| 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..06d07ff4a40951bbb884ff241004dafe2f100887
|
| --- /dev/null
|
| +++ b/content/browser/net/network_error_request_job.cc
|
| @@ -0,0 +1,90 @@
|
| +// 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");
|
| + data->append(
|
| + "<meta http-equiv=\"Content-Security-Policy\" "
|
| + "content=\"object-src 'none'; script-src 'none'\">");
|
| + data->append("<title>");
|
| + 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\">");
|
| + 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("</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
|
|
|