OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/child/weburlloader_impl.h" | 7 #include "webkit/child/weburlloader_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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 "information."; | 64 "information."; |
65 | 65 |
66 class HeaderFlattener : public WebHTTPHeaderVisitor { | 66 class HeaderFlattener : public WebHTTPHeaderVisitor { |
67 public: | 67 public: |
68 explicit HeaderFlattener(int load_flags) | 68 explicit HeaderFlattener(int load_flags) |
69 : load_flags_(load_flags), | 69 : load_flags_(load_flags), |
70 has_accept_header_(false) { | 70 has_accept_header_(false) { |
71 } | 71 } |
72 | 72 |
73 virtual void visitHeader(const WebString& name, const WebString& value) { | 73 virtual void visitHeader(const WebString& name, const WebString& value) { |
74 // TODO(darin): is UTF-8 really correct here? It is if the strings are | 74 // Headers are latin1. |
75 // already ASCII (i.e., if they are already escaped properly). | 75 const std::string& name_latin1 = name.latin1(); |
76 const std::string& name_utf8 = name.utf8(); | 76 const std::string& value_latin1 = value.latin1(); |
77 const std::string& value_utf8 = value.utf8(); | |
78 | 77 |
79 // Skip over referrer headers found in the header map because we already | 78 // Skip over referrer headers found in the header map because we already |
80 // pulled it out as a separate parameter. | 79 // pulled it out as a separate parameter. |
81 if (LowerCaseEqualsASCII(name_utf8, "referer")) | 80 if (LowerCaseEqualsASCII(name_latin1, "referer")) |
82 return; | 81 return; |
83 | 82 |
84 // Skip over "Cache-Control: max-age=0" header if the corresponding | 83 // Skip over "Cache-Control: max-age=0" header if the corresponding |
85 // load flag is already specified. FrameLoader sets both the flag and | 84 // load flag is already specified. FrameLoader sets both the flag and |
86 // the extra header -- the extra header is redundant since our network | 85 // the extra header -- the extra header is redundant since our network |
87 // implementation will add the necessary headers based on load flags. | 86 // implementation will add the necessary headers based on load flags. |
88 // See http://code.google.com/p/chromium/issues/detail?id=3434. | 87 // See http://code.google.com/p/chromium/issues/detail?id=3434. |
89 if ((load_flags_ & net::LOAD_VALIDATE_CACHE) && | 88 if ((load_flags_ & net::LOAD_VALIDATE_CACHE) && |
90 LowerCaseEqualsASCII(name_utf8, "cache-control") && | 89 LowerCaseEqualsASCII(name_latin1, "cache-control") && |
91 LowerCaseEqualsASCII(value_utf8, "max-age=0")) | 90 LowerCaseEqualsASCII(value_latin1, "max-age=0")) |
92 return; | 91 return; |
93 | 92 |
94 if (LowerCaseEqualsASCII(name_utf8, "accept")) | 93 if (LowerCaseEqualsASCII(name_latin1, "accept")) |
95 has_accept_header_ = true; | 94 has_accept_header_ = true; |
96 | 95 |
97 if (!buffer_.empty()) | 96 if (!buffer_.empty()) |
98 buffer_.append("\r\n"); | 97 buffer_.append("\r\n"); |
99 buffer_.append(name_utf8 + ": " + value_utf8); | 98 buffer_.append(name_latin1 + ": " + value_latin1); |
100 } | 99 } |
101 | 100 |
102 const std::string& GetBuffer() { | 101 const std::string& GetBuffer() { |
103 // In some cases, WebKit doesn't add an Accept header, but not having the | 102 // In some cases, WebKit doesn't add an Accept header, but not having the |
104 // header confuses some web servers. See bug 808613. | 103 // header confuses some web servers. See bug 808613. |
105 if (!has_accept_header_) { | 104 if (!has_accept_header_) { |
106 if (!buffer_.empty()) | 105 if (!buffer_.empty()) |
107 buffer_.append("\r\n"); | 106 buffer_.append("\r\n"); |
108 buffer_.append("Accept: */*"); | 107 buffer_.append("Accept: */*"); |
109 has_accept_header_ = true; | 108 has_accept_header_ = true; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 if (!info.load_timing.receive_headers_end.is_null()) { | 216 if (!info.load_timing.receive_headers_end.is_null()) { |
218 WebURLLoadTiming timing; | 217 WebURLLoadTiming timing; |
219 PopulateURLLoadTiming(info.load_timing, &timing); | 218 PopulateURLLoadTiming(info.load_timing, &timing); |
220 response->setLoadTiming(timing); | 219 response->setLoadTiming(timing); |
221 } | 220 } |
222 | 221 |
223 if (info.devtools_info.get()) { | 222 if (info.devtools_info.get()) { |
224 WebHTTPLoadInfo load_info; | 223 WebHTTPLoadInfo load_info; |
225 | 224 |
226 load_info.setHTTPStatusCode(info.devtools_info->http_status_code); | 225 load_info.setHTTPStatusCode(info.devtools_info->http_status_code); |
227 load_info.setHTTPStatusText(WebString::fromUTF8( | 226 load_info.setHTTPStatusText(WebString::fromLatin1( |
228 info.devtools_info->http_status_text)); | 227 info.devtools_info->http_status_text)); |
229 load_info.setEncodedDataLength(info.encoded_data_length); | 228 load_info.setEncodedDataLength(info.encoded_data_length); |
230 | 229 |
231 load_info.setRequestHeadersText(WebString::fromUTF8( | 230 load_info.setRequestHeadersText(WebString::fromLatin1( |
232 info.devtools_info->request_headers_text)); | 231 info.devtools_info->request_headers_text)); |
233 load_info.setResponseHeadersText(WebString::fromUTF8( | 232 load_info.setResponseHeadersText(WebString::fromLatin1( |
234 info.devtools_info->response_headers_text)); | 233 info.devtools_info->response_headers_text)); |
235 const HeadersVector& request_headers = info.devtools_info->request_headers; | 234 const HeadersVector& request_headers = info.devtools_info->request_headers; |
236 for (HeadersVector::const_iterator it = request_headers.begin(); | 235 for (HeadersVector::const_iterator it = request_headers.begin(); |
237 it != request_headers.end(); ++it) { | 236 it != request_headers.end(); ++it) { |
238 load_info.addRequestHeader(WebString::fromUTF8(it->first), | 237 load_info.addRequestHeader(WebString::fromLatin1(it->first), |
239 WebString::fromUTF8(it->second)); | 238 WebString::fromLatin1(it->second)); |
240 } | 239 } |
241 const HeadersVector& response_headers = | 240 const HeadersVector& response_headers = |
242 info.devtools_info->response_headers; | 241 info.devtools_info->response_headers; |
243 for (HeadersVector::const_iterator it = response_headers.begin(); | 242 for (HeadersVector::const_iterator it = response_headers.begin(); |
244 it != response_headers.end(); ++it) { | 243 it != response_headers.end(); ++it) { |
245 load_info.addResponseHeader(WebString::fromUTF8(it->first), | 244 load_info.addResponseHeader(WebString::fromLatin1(it->first), |
246 WebString::fromUTF8(it->second)); | 245 WebString::fromLatin1(it->second)); |
247 } | 246 } |
248 response->setHTTPLoadInfo(load_info); | 247 response->setHTTPLoadInfo(load_info); |
249 } | 248 } |
250 | 249 |
251 const net::HttpResponseHeaders* headers = info.headers.get(); | 250 const net::HttpResponseHeaders* headers = info.headers.get(); |
252 if (!headers) | 251 if (!headers) |
253 return; | 252 return; |
254 | 253 |
255 WebURLResponse::HTTPVersion version = WebURLResponse::Unknown; | 254 WebURLResponse::HTTPVersion version = WebURLResponse::Unknown; |
256 if (headers->GetHttpVersion() == net::HttpVersion(0, 9)) | 255 if (headers->GetHttpVersion() == net::HttpVersion(0, 9)) |
257 version = WebURLResponse::HTTP_0_9; | 256 version = WebURLResponse::HTTP_0_9; |
258 else if (headers->GetHttpVersion() == net::HttpVersion(1, 0)) | 257 else if (headers->GetHttpVersion() == net::HttpVersion(1, 0)) |
259 version = WebURLResponse::HTTP_1_0; | 258 version = WebURLResponse::HTTP_1_0; |
260 else if (headers->GetHttpVersion() == net::HttpVersion(1, 1)) | 259 else if (headers->GetHttpVersion() == net::HttpVersion(1, 1)) |
261 version = WebURLResponse::HTTP_1_1; | 260 version = WebURLResponse::HTTP_1_1; |
262 response->setHTTPVersion(version); | 261 response->setHTTPVersion(version); |
263 response->setHTTPStatusCode(headers->response_code()); | 262 response->setHTTPStatusCode(headers->response_code()); |
264 response->setHTTPStatusText(WebString::fromUTF8(headers->GetStatusText())); | 263 response->setHTTPStatusText(WebString::fromLatin1(headers->GetStatusText())); |
265 | 264 |
266 // TODO(darin): We should leverage HttpResponseHeaders for this, and this | 265 // TODO(darin): We should leverage HttpResponseHeaders for this, and this |
267 // should be using the same code as ResourceDispatcherHost. | 266 // should be using the same code as ResourceDispatcherHost. |
268 // TODO(jungshik): Figure out the actual value of the referrer charset and | 267 // TODO(jungshik): Figure out the actual value of the referrer charset and |
269 // pass it to GetSuggestedFilename. | 268 // pass it to GetSuggestedFilename. |
270 std::string value; | 269 std::string value; |
271 headers->EnumerateHeader(NULL, "content-disposition", &value); | 270 headers->EnumerateHeader(NULL, "content-disposition", &value); |
272 response->setSuggestedFileName( | 271 response->setSuggestedFileName( |
273 net::GetSuggestedFilename(url, | 272 net::GetSuggestedFilename(url, |
274 value, | 273 value, |
275 std::string(), // referrer_charset | 274 std::string(), // referrer_charset |
276 std::string(), // suggested_name | 275 std::string(), // suggested_name |
277 std::string(), // mime_type | 276 std::string(), // mime_type |
278 std::string())); // default_name | 277 std::string())); // default_name |
279 | 278 |
280 Time time_val; | 279 Time time_val; |
281 if (headers->GetLastModifiedValue(&time_val)) | 280 if (headers->GetLastModifiedValue(&time_val)) |
282 response->setLastModifiedDate(time_val.ToDoubleT()); | 281 response->setLastModifiedDate(time_val.ToDoubleT()); |
283 | 282 |
284 // Build up the header map. | 283 // Build up the header map. |
285 void* iter = NULL; | 284 void* iter = NULL; |
286 std::string name; | 285 std::string name; |
287 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 286 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
288 response->addHTTPHeaderField(WebString::fromUTF8(name), | 287 response->addHTTPHeaderField(WebString::fromLatin1(name), |
289 WebString::fromUTF8(value)); | 288 WebString::fromLatin1(value)); |
290 } | 289 } |
291 } | 290 } |
292 | 291 |
293 net::RequestPriority ConvertWebKitPriorityToNetPriority( | 292 net::RequestPriority ConvertWebKitPriorityToNetPriority( |
294 const WebURLRequest::Priority& priority) { | 293 const WebURLRequest::Priority& priority) { |
295 switch (priority) { | 294 switch (priority) { |
296 case WebURLRequest::PriorityVeryHigh: | 295 case WebURLRequest::PriorityVeryHigh: |
297 return net::HIGHEST; | 296 return net::HIGHEST; |
298 | 297 |
299 case WebURLRequest::PriorityHigh: | 298 case WebURLRequest::PriorityHigh: |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 &sync_load_response->error_code); | 427 &sync_load_response->error_code); |
429 } else { | 428 } else { |
430 AddRef(); // Balanced in OnCompletedRequest | 429 AddRef(); // Balanced in OnCompletedRequest |
431 base::MessageLoop::current()->PostTask( | 430 base::MessageLoop::current()->PostTask( |
432 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); | 431 FROM_HERE, base::Bind(&Context::HandleDataURL, this)); |
433 } | 432 } |
434 return; | 433 return; |
435 } | 434 } |
436 | 435 |
437 GURL referrer_url( | 436 GURL referrer_url( |
438 request.httpHeaderField(WebString::fromUTF8("Referer")).utf8()); | 437 request.httpHeaderField(WebString::fromUTF8("Referer")).latin1()); |
439 const std::string& method = request.httpMethod().utf8(); | 438 const std::string& method = request.httpMethod().latin1(); |
440 | 439 |
441 int load_flags = net::LOAD_NORMAL; | 440 int load_flags = net::LOAD_NORMAL; |
442 switch (request.cachePolicy()) { | 441 switch (request.cachePolicy()) { |
443 case WebURLRequest::ReloadIgnoringCacheData: | 442 case WebURLRequest::ReloadIgnoringCacheData: |
444 // Required by LayoutTests/http/tests/misc/refresh-headers.php | 443 // Required by LayoutTests/http/tests/misc/refresh-headers.php |
445 load_flags |= net::LOAD_VALIDATE_CACHE; | 444 load_flags |= net::LOAD_VALIDATE_CACHE; |
446 break; | 445 break; |
447 case WebURLRequest::ReturnCacheDataElseLoad: | 446 case WebURLRequest::ReturnCacheDataElseLoad: |
448 load_flags |= net::LOAD_PREFERRING_CACHE; | 447 load_flags |= net::LOAD_PREFERRING_CACHE; |
449 break; | 448 break; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 | 844 |
846 void WebURLLoaderImpl::setDefersLoading(bool value) { | 845 void WebURLLoaderImpl::setDefersLoading(bool value) { |
847 context_->SetDefersLoading(value); | 846 context_->SetDefersLoading(value); |
848 } | 847 } |
849 | 848 |
850 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 849 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
851 context_->DidChangePriority(new_priority); | 850 context_->DidChangePriority(new_priority); |
852 } | 851 } |
853 | 852 |
854 } // namespace webkit_glue | 853 } // namespace webkit_glue |
OLD | NEW |