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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
6 | 6 |
7 #include "content/child/web_url_loader_impl.h" | 7 #include "content/child/web_url_loader_impl.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/child/resource_loader_bridge.h" | 21 #include "content/child/resource_loader_bridge.h" |
22 #include "content/child/sync_load_response.h" | 22 #include "content/child/sync_load_response.h" |
23 #include "content/child/web_url_request_util.h" | 23 #include "content/child/web_url_request_util.h" |
24 #include "content/child/weburlresponse_extradata_impl.h" | 24 #include "content/child/weburlresponse_extradata_impl.h" |
25 #include "content/common/resource_request_body.h" | 25 #include "content/common/resource_request_body.h" |
26 #include "content/common/service_worker/service_worker_types.h" | 26 #include "content/common/service_worker/service_worker_types.h" |
27 #include "content/public/child/request_peer.h" | 27 #include "content/public/child/request_peer.h" |
28 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
29 #include "net/base/data_url.h" | 29 #include "net/base/data_url.h" |
30 #include "net/base/filename_util.h" | 30 #include "net/base/filename_util.h" |
31 #include "net/base/load_flags.h" | |
32 #include "net/base/mime_util.h" | 31 #include "net/base/mime_util.h" |
33 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
34 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
35 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
36 #include "net/url_request/redirect_info.h" | 35 #include "net/url_request/redirect_info.h" |
37 #include "net/url_request/url_request_data_job.h" | 36 #include "net/url_request/url_request_data_job.h" |
38 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | |
39 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" | 37 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" |
40 #include "third_party/WebKit/public/platform/WebURL.h" | 38 #include "third_party/WebKit/public/platform/WebURL.h" |
41 #include "third_party/WebKit/public/platform/WebURLError.h" | 39 #include "third_party/WebKit/public/platform/WebURLError.h" |
42 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" | 40 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" |
43 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 41 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
44 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 42 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
45 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 43 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
46 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 44 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
47 | 45 |
48 using base::Time; | 46 using base::Time; |
(...skipping 16 matching lines...) Expand all Loading... |
65 namespace content { | 63 namespace content { |
66 | 64 |
67 // Utilities ------------------------------------------------------------------ | 65 // Utilities ------------------------------------------------------------------ |
68 | 66 |
69 namespace { | 67 namespace { |
70 | 68 |
71 const char kThrottledErrorDescription[] = | 69 const char kThrottledErrorDescription[] = |
72 "Request throttled. Visit http://dev.chromium.org/throttling for more " | 70 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
73 "information."; | 71 "information."; |
74 | 72 |
75 class HeaderFlattener : public WebHTTPHeaderVisitor { | |
76 public: | |
77 HeaderFlattener() : has_accept_header_(false) {} | |
78 | |
79 virtual void visitHeader(const WebString& name, const WebString& value) { | |
80 // Headers are latin1. | |
81 const std::string& name_latin1 = name.latin1(); | |
82 const std::string& value_latin1 = value.latin1(); | |
83 | |
84 // Skip over referrer headers found in the header map because we already | |
85 // pulled it out as a separate parameter. | |
86 if (LowerCaseEqualsASCII(name_latin1, "referer")) | |
87 return; | |
88 | |
89 if (LowerCaseEqualsASCII(name_latin1, "accept")) | |
90 has_accept_header_ = true; | |
91 | |
92 if (!buffer_.empty()) | |
93 buffer_.append("\r\n"); | |
94 buffer_.append(name_latin1 + ": " + value_latin1); | |
95 } | |
96 | |
97 const std::string& GetBuffer() { | |
98 // In some cases, WebKit doesn't add an Accept header, but not having the | |
99 // header confuses some web servers. See bug 808613. | |
100 if (!has_accept_header_) { | |
101 if (!buffer_.empty()) | |
102 buffer_.append("\r\n"); | |
103 buffer_.append("Accept: */*"); | |
104 has_accept_header_ = true; | |
105 } | |
106 return buffer_; | |
107 } | |
108 | |
109 private: | |
110 std::string buffer_; | |
111 bool has_accept_header_; | |
112 }; | |
113 | |
114 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; | 73 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; |
115 | 74 |
116 // Converts timing data from |load_timing| to the format used by WebKit. | 75 // Converts timing data from |load_timing| to the format used by WebKit. |
117 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, | 76 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, |
118 WebURLLoadTiming* url_timing) { | 77 WebURLLoadTiming* url_timing) { |
119 DCHECK(!load_timing.request_start.is_null()); | 78 DCHECK(!load_timing.request_start.is_null()); |
120 | 79 |
121 const TimeTicks kNullTicks; | 80 const TimeTicks kNullTicks; |
122 url_timing->initialize(); | 81 url_timing->initialize(); |
123 url_timing->setRequestTime( | 82 url_timing->setRequestTime( |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 base::MessageLoop::current()->PostTask( | 420 base::MessageLoop::current()->PostTask( |
462 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); | 421 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); |
463 } | 422 } |
464 return; | 423 return; |
465 } | 424 } |
466 | 425 |
467 GURL referrer_url( | 426 GURL referrer_url( |
468 request.httpHeaderField(WebString::fromUTF8("Referer")).latin1()); | 427 request.httpHeaderField(WebString::fromUTF8("Referer")).latin1()); |
469 const std::string& method = request.httpMethod().latin1(); | 428 const std::string& method = request.httpMethod().latin1(); |
470 | 429 |
471 int load_flags = net::LOAD_NORMAL; | |
472 switch (request.cachePolicy()) { | |
473 case WebURLRequest::ReloadIgnoringCacheData: | |
474 // Required by LayoutTests/http/tests/misc/refresh-headers.php | |
475 load_flags |= net::LOAD_VALIDATE_CACHE; | |
476 break; | |
477 case WebURLRequest::ReloadBypassingCache: | |
478 load_flags |= net::LOAD_BYPASS_CACHE; | |
479 break; | |
480 case WebURLRequest::ReturnCacheDataElseLoad: | |
481 load_flags |= net::LOAD_PREFERRING_CACHE; | |
482 break; | |
483 case WebURLRequest::ReturnCacheDataDontLoad: | |
484 load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
485 break; | |
486 case WebURLRequest::UseProtocolCachePolicy: | |
487 break; | |
488 default: | |
489 NOTREACHED(); | |
490 } | |
491 | |
492 if (request.reportUploadProgress()) | |
493 load_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS; | |
494 if (request.reportRawHeaders()) | |
495 load_flags |= net::LOAD_REPORT_RAW_HEADERS; | |
496 | |
497 if (!request.allowStoredCredentials()) { | |
498 load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES; | |
499 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES; | |
500 } | |
501 | |
502 if (!request.allowStoredCredentials()) | |
503 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; | |
504 | |
505 if (request.requestContext() == WebURLRequest::RequestContextXMLHttpRequest && | |
506 (url.has_username() || url.has_password())) { | |
507 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; | |
508 } | |
509 | |
510 HeaderFlattener flattener; | |
511 request.visitHTTPHeaderFields(&flattener); | |
512 | |
513 // TODO(brettw) this should take parameter encoding into account when | 430 // TODO(brettw) this should take parameter encoding into account when |
514 // creating the GURLs. | 431 // creating the GURLs. |
515 | 432 |
516 // TODO(horo): Check credentials flag is unset when credentials mode is omit. | 433 // TODO(horo): Check credentials flag is unset when credentials mode is omit. |
517 // Check credentials flag is set when credentials mode is include. | 434 // Check credentials flag is set when credentials mode is include. |
518 | 435 |
519 RequestInfo request_info; | 436 RequestInfo request_info; |
520 request_info.method = method; | 437 request_info.method = method; |
521 request_info.url = url; | 438 request_info.url = url; |
522 request_info.first_party_for_cookies = request.firstPartyForCookies(); | 439 request_info.first_party_for_cookies = request.firstPartyForCookies(); |
523 request_info.referrer = referrer_url; | 440 request_info.referrer = referrer_url; |
524 request_info.headers = flattener.GetBuffer(); | 441 request_info.headers = GetWebURLRequestHeaders(request); |
525 request_info.load_flags = load_flags; | 442 ; |
| 443 request_info.load_flags = GetLoadFlagsForWebURLRequest(request); |
526 request_info.enable_load_timing = true; | 444 request_info.enable_load_timing = true; |
527 // requestor_pid only needs to be non-zero if the request originates outside | 445 // requestor_pid only needs to be non-zero if the request originates outside |
528 // the render process, so we can use requestorProcessID even for requests | 446 // the render process, so we can use requestorProcessID even for requests |
529 // from in-process plugins. | 447 // from in-process plugins. |
530 request_info.requestor_pid = request.requestorProcessID(); | 448 request_info.requestor_pid = request.requestorProcessID(); |
531 request_info.request_type = WebURLRequestToResourceType(request); | 449 request_info.request_type = WebURLRequestToResourceType(request); |
532 request_info.priority = | 450 request_info.priority = |
533 ConvertWebKitPriorityToNetPriority(request.priority()); | 451 ConvertWebKitPriorityToNetPriority(request.priority()); |
534 request_info.appcache_host_id = request.appCacheHostID(); | 452 request_info.appcache_host_id = request.appCacheHostID(); |
535 request_info.routing_id = request.requestorID(); | 453 request_info.routing_id = request.requestorID(); |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 int intra_priority_value) { | 978 int intra_priority_value) { |
1061 context_->DidChangePriority(new_priority, intra_priority_value); | 979 context_->DidChangePriority(new_priority, intra_priority_value); |
1062 } | 980 } |
1063 | 981 |
1064 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 982 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
1065 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 983 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
1066 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 984 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
1067 } | 985 } |
1068 | 986 |
1069 } // namespace content | 987 } // namespace content |
OLD | NEW |