OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/web_url_request_util.h" | 5 #include "content/child/web_url_request_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
| 10 #include "net/base/net_errors.h" |
10 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 11 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
11 #include "third_party/WebKit/public/platform/WebString.h" | 12 #include "third_party/WebKit/public/platform/WebString.h" |
| 13 #include "third_party/WebKit/public/platform/WebURL.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLError.h" |
12 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 15 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
13 | 16 |
14 using blink::WebHTTPBody; | 17 using blink::WebHTTPBody; |
15 using blink::WebString; | 18 using blink::WebString; |
16 using blink::WebURLRequest; | 19 using blink::WebURLRequest; |
17 | 20 |
18 namespace content { | 21 namespace content { |
19 | 22 |
20 namespace { | 23 namespace { |
21 | 24 |
| 25 const char kThrottledErrorDescription[] = |
| 26 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
| 27 "information."; |
| 28 |
22 class HeaderFlattener : public blink::WebHTTPHeaderVisitor { | 29 class HeaderFlattener : public blink::WebHTTPHeaderVisitor { |
23 public: | 30 public: |
24 HeaderFlattener() : has_accept_header_(false) {} | 31 HeaderFlattener() : has_accept_header_(false) {} |
25 | 32 |
26 virtual void visitHeader(const WebString& name, const WebString& value) { | 33 virtual void visitHeader(const WebString& name, const WebString& value) { |
27 // Headers are latin1. | 34 // Headers are latin1. |
28 const std::string& name_latin1 = name.latin1(); | 35 const std::string& name_latin1 = name.latin1(); |
29 const std::string& value_latin1 = value.latin1(); | 36 const std::string& value_latin1 = value.latin1(); |
30 | 37 |
31 // Skip over referrer headers found in the header map because we already | 38 // Skip over referrer headers found in the header map because we already |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 request_body->AppendBlob(element.blobUUID.utf8()); | 272 request_body->AppendBlob(element.blobUUID.utf8()); |
266 break; | 273 break; |
267 default: | 274 default: |
268 NOTREACHED(); | 275 NOTREACHED(); |
269 } | 276 } |
270 } | 277 } |
271 request_body->set_identifier(request.httpBody().identifier()); | 278 request_body->set_identifier(request.httpBody().identifier()); |
272 return request_body; | 279 return request_body; |
273 } | 280 } |
274 | 281 |
| 282 blink::WebURLError CreateWebURLError(const blink::WebURL& unreachable_url, |
| 283 bool stale_copy_in_cache, |
| 284 int reason) { |
| 285 blink::WebURLError error; |
| 286 error.domain = WebString::fromUTF8(net::kErrorDomain); |
| 287 error.reason = reason; |
| 288 error.unreachableURL = unreachable_url; |
| 289 error.staleCopyInCache = stale_copy_in_cache; |
| 290 if (reason == net::ERR_ABORTED) { |
| 291 error.isCancellation = true; |
| 292 } else if (reason == net::ERR_TEMPORARILY_THROTTLED) { |
| 293 error.localizedDescription = |
| 294 WebString::fromUTF8(kThrottledErrorDescription); |
| 295 } else { |
| 296 error.localizedDescription = |
| 297 WebString::fromUTF8(net::ErrorToString(reason)); |
| 298 } |
| 299 return error; |
| 300 } |
| 301 |
275 } // namespace content | 302 } // namespace content |
OLD | NEW |