| 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/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // Utilities ------------------------------------------------------------------ | 66 // Utilities ------------------------------------------------------------------ |
| 67 | 67 |
| 68 namespace { | 68 namespace { |
| 69 | 69 |
| 70 const char kThrottledErrorDescription[] = | 70 const char kThrottledErrorDescription[] = |
| 71 "Request throttled. Visit http://dev.chromium.org/throttling for more " | 71 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
| 72 "information."; | 72 "information."; |
| 73 | 73 |
| 74 class HeaderFlattener : public WebHTTPHeaderVisitor { | 74 class HeaderFlattener : public WebHTTPHeaderVisitor { |
| 75 public: | 75 public: |
| 76 explicit HeaderFlattener(int load_flags) | 76 explicit HeaderFlattener() : has_accept_header_(false) {} |
| 77 : load_flags_(load_flags), | |
| 78 has_accept_header_(false) { | |
| 79 } | |
| 80 | 77 |
| 81 virtual void visitHeader(const WebString& name, const WebString& value) { | 78 virtual void visitHeader(const WebString& name, const WebString& value) { |
| 82 // Headers are latin1. | 79 // Headers are latin1. |
| 83 const std::string& name_latin1 = name.latin1(); | 80 const std::string& name_latin1 = name.latin1(); |
| 84 const std::string& value_latin1 = value.latin1(); | 81 const std::string& value_latin1 = value.latin1(); |
| 85 | 82 |
| 86 // Skip over referrer headers found in the header map because we already | 83 // Skip over referrer headers found in the header map because we already |
| 87 // pulled it out as a separate parameter. | 84 // pulled it out as a separate parameter. |
| 88 if (LowerCaseEqualsASCII(name_latin1, "referer")) | 85 if (LowerCaseEqualsASCII(name_latin1, "referer")) |
| 89 return; | 86 return; |
| 90 | 87 |
| 91 // Skip over "Cache-Control: max-age=0" header if the corresponding | |
| 92 // load flag is already specified. FrameLoader sets both the flag and | |
| 93 // the extra header -- the extra header is redundant since our network | |
| 94 // implementation will add the necessary headers based on load flags. | |
| 95 // See http://code.google.com/p/chromium/issues/detail?id=3434. | |
| 96 if ((load_flags_ & net::LOAD_VALIDATE_CACHE) && | |
| 97 LowerCaseEqualsASCII(name_latin1, "cache-control") && | |
| 98 LowerCaseEqualsASCII(value_latin1, "max-age=0")) | |
| 99 return; | |
| 100 | |
| 101 if (LowerCaseEqualsASCII(name_latin1, "accept")) | 88 if (LowerCaseEqualsASCII(name_latin1, "accept")) |
| 102 has_accept_header_ = true; | 89 has_accept_header_ = true; |
| 103 | 90 |
| 104 if (!buffer_.empty()) | 91 if (!buffer_.empty()) |
| 105 buffer_.append("\r\n"); | 92 buffer_.append("\r\n"); |
| 106 buffer_.append(name_latin1 + ": " + value_latin1); | 93 buffer_.append(name_latin1 + ": " + value_latin1); |
| 107 } | 94 } |
| 108 | 95 |
| 109 const std::string& GetBuffer() { | 96 const std::string& GetBuffer() { |
| 110 // In some cases, WebKit doesn't add an Accept header, but not having the | 97 // In some cases, WebKit doesn't add an Accept header, but not having the |
| 111 // header confuses some web servers. See bug 808613. | 98 // header confuses some web servers. See bug 808613. |
| 112 if (!has_accept_header_) { | 99 if (!has_accept_header_) { |
| 113 if (!buffer_.empty()) | 100 if (!buffer_.empty()) |
| 114 buffer_.append("\r\n"); | 101 buffer_.append("\r\n"); |
| 115 buffer_.append("Accept: */*"); | 102 buffer_.append("Accept: */*"); |
| 116 has_accept_header_ = true; | 103 has_accept_header_ = true; |
| 117 } | 104 } |
| 118 return buffer_; | 105 return buffer_; |
| 119 } | 106 } |
| 120 | 107 |
| 121 private: | 108 private: |
| 122 int load_flags_; | |
| 123 std::string buffer_; | 109 std::string buffer_; |
| 124 bool has_accept_header_; | 110 bool has_accept_header_; |
| 125 }; | 111 }; |
| 126 | 112 |
| 127 // Extracts the information from a data: url. | 113 // Extracts the information from a data: url. |
| 128 bool GetInfoFromDataURL(const GURL& url, | 114 bool GetInfoFromDataURL(const GURL& url, |
| 129 ResourceResponseInfo* info, | 115 ResourceResponseInfo* info, |
| 130 std::string* data, | 116 std::string* data, |
| 131 int* error_code) { | 117 int* error_code) { |
| 132 std::string mime_type; | 118 std::string mime_type; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 } | 356 } |
| 371 | 357 |
| 372 if (!request.allowStoredCredentials()) | 358 if (!request.allowStoredCredentials()) |
| 373 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; | 359 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 374 | 360 |
| 375 if (request.targetType() == WebURLRequest::TargetIsXHR && | 361 if (request.targetType() == WebURLRequest::TargetIsXHR && |
| 376 (url.has_username() || url.has_password())) { | 362 (url.has_username() || url.has_password())) { |
| 377 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; | 363 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; |
| 378 } | 364 } |
| 379 | 365 |
| 380 HeaderFlattener flattener(load_flags); | 366 HeaderFlattener flattener; |
| 381 request.visitHTTPHeaderFields(&flattener); | 367 request.visitHTTPHeaderFields(&flattener); |
| 382 | 368 |
| 383 // TODO(brettw) this should take parameter encoding into account when | 369 // TODO(brettw) this should take parameter encoding into account when |
| 384 // creating the GURLs. | 370 // creating the GURLs. |
| 385 | 371 |
| 386 RequestInfo request_info; | 372 RequestInfo request_info; |
| 387 request_info.method = method; | 373 request_info.method = method; |
| 388 request_info.url = url; | 374 request_info.url = url; |
| 389 request_info.first_party_for_cookies = request.firstPartyForCookies(); | 375 request_info.first_party_for_cookies = request.firstPartyForCookies(); |
| 390 request_info.referrer = referrer_url; | 376 request_info.referrer = referrer_url; |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 void WebURLLoaderImpl::setDefersLoading(bool value) { | 862 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 877 context_->SetDefersLoading(value); | 863 context_->SetDefersLoading(value); |
| 878 } | 864 } |
| 879 | 865 |
| 880 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, | 866 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, |
| 881 int intra_priority_value) { | 867 int intra_priority_value) { |
| 882 context_->DidChangePriority(new_priority, intra_priority_value); | 868 context_->DidChangePriority(new_priority, intra_priority_value); |
| 883 } | 869 } |
| 884 | 870 |
| 885 } // namespace content | 871 } // namespace content |
| OLD | NEW |