Chromium Code Reviews| Index: content/browser/network_error_request_job.cc |
| diff --git a/content/browser/network_error_request_job.cc b/content/browser/network_error_request_job.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8cfedcd833f42a4e38da151d4be4da00fa3d8d3b |
| --- /dev/null |
| +++ b/content/browser/network_error_request_job.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2015 The Chromium Authors. All rights reserved. |
|
mmenke
2015/10/22 15:41:31
(c) not needed in new files.
edwardjung
2015/11/06 12:05:50
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/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/url_request/url_request.h" |
| +#include "net/url_request/url_request_error_job.h" |
|
mmenke
2015/10/22 15:41:31
Not needed, since you're using another approach (W
edwardjung
2015/11/06 12:05:50
Done.
|
| +#include "url/gurl.h" |
| + |
| +namespace content { |
| + |
| +NetworkErrorRequestJob::NetworkErrorRequestJob( |
|
mmenke
2015/10/22 15:41:31
I think we want browser tests for this, both that
|
| + net::URLRequest* request, |
| + net::NetworkDelegate* network_delegate) |
| + : net::URLRequestSimpleJob(request, network_delegate) { |
|
mmenke
2015/10/22 15:41:31
BUG: Need to initialize error_code_.
edwardjung
2015/11/06 12:05:50
Done.
|
| + const std::string& spec = request->url().possibly_invalid_spec(); |
| + const url::Parsed& parsed = request->url().parsed_for_possibly_invalid_spec(); |
| + // + 1 to skip the slash at the beginning of the path. |
| + int offset = parsed.CountCharactersBefore(url::Parsed::PATH, false) + 1; |
|
mmenke
2015/10/22 15:41:31
Just use this: request->url().path().substr(1, st
edwardjung
2015/11/06 12:05:51
Thanks.
|
| + |
| + if (offset < static_cast<int>(spec.size())) { |
|
mmenke
2015/10/22 15:41:31
Using above suggestion, this just becomes:
if (!b
edwardjung
2015/11/06 12:05:50
Done.
|
| + std::string path; |
| + path.assign(spec.substr(offset)); |
| + base::StringToInt(path, &error_code_); |
| + } |
| +} |
| + |
| +void NetworkErrorRequestJob::ListAllErrorCodes(std::string* data) { |
|
mmenke
2015/10/22 15:41:30
This can just go in an anonymous namespace.
edwardjung
2015/11/06 12:05:50
Done.
|
| + 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(net::EscapeForHTML(unescaped_title)); |
|
mmenke
2015/10/22 15:41:31
Why is this needed?
edwardjung
2015/11/06 12:05:50
Removed.
|
| + data->append("</title>\n"); |
| + data->append("</head><body>"); |
| + data->append("<h1>Network errors</h1>"); |
| + data->append("<ul>"); |
| +#define NET_ERROR(label, value) \ |
| + data->append("<li><a href=" #value ">" #label "</a></li>"); |
|
mmenke
2015/10/22 15:41:30
I really don't like to add all these strings.
The
|
| +#include "net/base/net_error_list.h" |
| +#undef NET_ERROR |
| + data->append("</ul>"); |
|
mmenke
2015/10/22 15:41:30
</body></html>?
edwardjung
2015/11/06 12:05:50
Technically not needed in HTML5.
|
| +} |
| + |
| +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"); |
| + data->clear(); |
|
mmenke
2015/10/22 15:41:30
Not needed.
edwardjung
2015/11/06 12:05:50
Done.
|
| + |
| + if (error_code_ != 0) { |
| + return error_code_; |
|
mmenke
2015/10/22 15:41:31
BUG: This will cause invalid memory accesses if e
|
| + } else { |
| + ListAllErrorCodes(data); |
| + return net::OK; |
|
mmenke
2015/10/22 15:41:30
I'd actually include this case first (As the "erro
edwardjung
2015/11/06 12:05:50
Done.
|
| + } |
| +} |
| + |
| +} // namespace content |