OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/net/network_error_request_job.h" | |
6 | |
7 #include "base/strings/string_number_conversions.h" | |
8 #include "base/values.h" | |
9 #include "net/base/escape.h" | |
10 #include "net/base/net_errors.h" | |
11 #include "net/log/net_log_util.h" | |
12 #include "net/url_request/url_request.h" | |
13 #include "url/gurl.h" | |
14 | |
15 namespace content { | |
16 | |
17 static const char kNetworkErrorKey[] = "netError"; | |
18 | |
19 NetworkErrorRequestJob::NetworkErrorRequestJob( | |
20 net::URLRequest* request, | |
21 net::NetworkDelegate* network_delegate) | |
22 : net::URLRequestSimpleJob(request, network_delegate), | |
23 error_code_(net::Error::OK) { | |
24 std::basic_string<char> error_code_string = | |
25 request->url().path().substr(1, std::string::npos); | |
26 | |
27 if (!base::StringToInt(error_code_string, &error_code_)) | |
28 error_code_ = 0; | |
29 } | |
30 | |
31 // Creates a HTML page listing all error codes. | |
32 void ListAllErrorCodes(std::string* data) { | |
33 std::string unescaped_query; | |
34 std::string unescaped_title("Network error codes"); | |
35 | |
36 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
| |
37 data->append( | |
38 "<meta http-equiv=\"Content-Security-Policy\" " | |
39 "content=\"object-src 'none'; script-src 'none'\">"); | |
40 data->append( | |
41 "<meta name=\"viewport\" content=\"width=device-width\">"); | |
42 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
| |
43 data->append(unescaped_title); | |
44 data->append("</title>\n"); | |
45 data->append("<link rel=\"stylesheet\""); | |
46 data->append("href=\"chrome://resources/css/chrome_shared.css\">\n"); | |
47 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
| |
48 data->append("<h1>"); | |
49 data->append(unescaped_title); | |
50 data->append("</h1>"); | |
51 | |
52 scoped_ptr<base::DictionaryValue> error_codes = net::GetNetConstants(); | |
53 const base::DictionaryValue* net_error_codes_dict = nullptr; | |
54 | |
55 for (base::DictionaryValue::Iterator itr(*error_codes); !itr.IsAtEnd(); | |
56 itr.Advance()) { | |
57 if (itr.key() == kNetworkErrorKey) { | |
58 itr.value().GetAsDictionary(&net_error_codes_dict); | |
59 break; | |
60 } | |
61 } | |
62 | |
63 data->append("<ul>"); | |
64 for (base::DictionaryValue::Iterator itr(*net_error_codes_dict); | |
65 !itr.IsAtEnd(); itr.Advance()) { | |
66 int error_code; | |
67 itr.value().GetAsInteger(&error_code); | |
68 data->append("<li><a href=\""); | |
69 data->append(base::IntToString(error_code)); | |
70 data->append("\">"); | |
71 data->append(itr.key()); | |
72 data->append(" ("); | |
73 data->append(base::IntToString(error_code)); | |
74 data->append(")</a></li>\n"); | |
75 } | |
76 data->append("</ul>"); | |
77 } | |
78 | |
79 int NetworkErrorRequestJob::GetData( | |
80 std::string* mime_type, | |
81 std::string* charset, | |
82 std::string* data, | |
83 const net::CompletionCallback& callback) const { | |
84 mime_type->assign("text/html"); | |
85 charset->assign("UTF8"); | |
86 | |
87 if (error_code_ == 0 || error_code_ == net::Error::ERR_IO_PENDING) { | |
88 ListAllErrorCodes(data); | |
89 return net::OK; | |
90 } | |
91 return error_code_; | |
92 } | |
93 | |
94 } // namespace content | |
OLD | NEW |