| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/glue/weburlloader_impl.h" | 7 #include "webkit/glue/weburlloader_impl.h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "net/base/data_url.h" | 15 #include "net/base/data_url.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 18 #include "net/base/net_util.h" |
| 19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" | 20 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebResourceRawHeaders.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoadTiming.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoadTiming.h" |
| 25 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" |
| 26 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | 27 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" |
| 27 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" | 28 #include "third_party/WebKit/WebKit/chromium/public/WebURLResponse.h" |
| 28 #include "webkit/glue/ftp_directory_listing_response_delegate.h" | 29 #include "webkit/glue/ftp_directory_listing_response_delegate.h" |
| 29 #include "webkit/glue/multipart_response_delegate.h" | 30 #include "webkit/glue/multipart_response_delegate.h" |
| 30 #include "webkit/glue/resource_loader_bridge.h" | 31 #include "webkit/glue/resource_loader_bridge.h" |
| 31 #include "webkit/glue/site_isolation_metrics.h" | 32 #include "webkit/glue/site_isolation_metrics.h" |
| 32 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
| 33 | 34 |
| 34 using base::Time; | 35 using base::Time; |
| 35 using base::TimeDelta; | 36 using base::TimeDelta; |
| 36 using WebKit::WebData; | 37 using WebKit::WebData; |
| 37 using WebKit::WebHTTPBody; | 38 using WebKit::WebHTTPBody; |
| 38 using WebKit::WebHTTPHeaderVisitor; | 39 using WebKit::WebHTTPHeaderVisitor; |
| 40 using WebKit::WebResourceRawHeaders; |
| 39 using WebKit::WebSecurityPolicy; | 41 using WebKit::WebSecurityPolicy; |
| 40 using WebKit::WebString; | 42 using WebKit::WebString; |
| 41 using WebKit::WebURL; | 43 using WebKit::WebURL; |
| 42 using WebKit::WebURLError; | 44 using WebKit::WebURLError; |
| 43 using WebKit::WebURLLoadTiming; | 45 using WebKit::WebURLLoadTiming; |
| 44 using WebKit::WebURLLoader; | 46 using WebKit::WebURLLoader; |
| 45 using WebKit::WebURLLoaderClient; | 47 using WebKit::WebURLLoaderClient; |
| 46 using WebKit::WebURLRequest; | 48 using WebKit::WebURLRequest; |
| 47 using WebKit::WebURLResponse; | 49 using WebKit::WebURLResponse; |
| 48 | 50 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 info->security_info.clear(); | 158 info->security_info.clear(); |
| 157 info->content_length = -1; | 159 info->content_length = -1; |
| 158 | 160 |
| 159 return true; | 161 return true; |
| 160 } | 162 } |
| 161 | 163 |
| 162 *status = URLRequestStatus(URLRequestStatus::FAILED, net::ERR_INVALID_URL); | 164 *status = URLRequestStatus(URLRequestStatus::FAILED, net::ERR_INVALID_URL); |
| 163 return false; | 165 return false; |
| 164 } | 166 } |
| 165 | 167 |
| 168 typedef ResourceLoaderBridge::DevToolsInfo::HeadersVector HeadersVector; |
| 169 |
| 166 void PopulateURLResponse( | 170 void PopulateURLResponse( |
| 167 const GURL& url, | 171 const GURL& url, |
| 168 const ResourceLoaderBridge::ResponseInfo& info, | 172 const ResourceLoaderBridge::ResponseInfo& info, |
| 169 WebURLResponse* response) { | 173 WebURLResponse* response) { |
| 170 response->setURL(url); | 174 response->setURL(url); |
| 171 response->setResponseTime(info.response_time.ToDoubleT()); | 175 response->setResponseTime(info.response_time.ToDoubleT()); |
| 172 response->setMIMEType(WebString::fromUTF8(info.mime_type)); | 176 response->setMIMEType(WebString::fromUTF8(info.mime_type)); |
| 173 response->setTextEncodingName(WebString::fromUTF8(info.charset)); | 177 response->setTextEncodingName(WebString::fromUTF8(info.charset)); |
| 174 response->setExpectedContentLength(info.content_length); | 178 response->setExpectedContentLength(info.content_length); |
| 175 response->setSecurityInfo(info.security_info); | 179 response->setSecurityInfo(info.security_info); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 timing.setDNSEnd(timing_info.dns_end); | 200 timing.setDNSEnd(timing_info.dns_end); |
| 197 timing.setConnectStart(timing_info.connect_start); | 201 timing.setConnectStart(timing_info.connect_start); |
| 198 timing.setConnectEnd(timing_info.connect_end); | 202 timing.setConnectEnd(timing_info.connect_end); |
| 199 timing.setSSLStart(timing_info.ssl_start); | 203 timing.setSSLStart(timing_info.ssl_start); |
| 200 timing.setSSLEnd(timing_info.ssl_end); | 204 timing.setSSLEnd(timing_info.ssl_end); |
| 201 timing.setSendStart(timing_info.send_start); | 205 timing.setSendStart(timing_info.send_start); |
| 202 timing.setSendEnd(timing_info.send_end); | 206 timing.setSendEnd(timing_info.send_end); |
| 203 timing.setReceiveHeadersEnd(timing_info.receive_headers_end); | 207 timing.setReceiveHeadersEnd(timing_info.receive_headers_end); |
| 204 response->setLoadTiming(timing); | 208 response->setLoadTiming(timing); |
| 205 | 209 |
| 210 if (info.devtools_info.get()) { |
| 211 WebResourceRawHeaders rawHeaders; |
| 212 |
| 213 const HeadersVector& request_headers = info.devtools_info->request_headers; |
| 214 for (HeadersVector::const_iterator it = request_headers .begin(); |
| 215 it != request_headers.end(); ++it) { |
| 216 rawHeaders.addRequestHeader(WebString::fromUTF8(it->first), |
| 217 WebString::fromUTF8(it->second)); |
| 218 } |
| 219 const HeadersVector& response_headers = |
| 220 info.devtools_info->request_headers; |
| 221 for (HeadersVector::const_iterator it = response_headers.begin(); |
| 222 it != response_headers.end(); ++it) { |
| 223 rawHeaders.addResponseHeader(WebString::fromUTF8(it->first), |
| 224 WebString::fromUTF8(it->second)); |
| 225 } |
| 226 response->setResourceRawHeaders(rawHeaders); |
| 227 } |
| 228 |
| 206 const net::HttpResponseHeaders* headers = info.headers; | 229 const net::HttpResponseHeaders* headers = info.headers; |
| 207 if (!headers) | 230 if (!headers) |
| 208 return; | 231 return; |
| 209 | 232 |
| 210 response->setHTTPStatusCode(headers->response_code()); | 233 response->setHTTPStatusCode(headers->response_code()); |
| 211 response->setHTTPStatusText(WebString::fromUTF8(headers->GetStatusText())); | 234 response->setHTTPStatusText(WebString::fromUTF8(headers->GetStatusText())); |
| 212 | 235 |
| 213 // TODO(darin): We should leverage HttpResponseHeaders for this, and this | 236 // TODO(darin): We should leverage HttpResponseHeaders for this, and this |
| 214 // should be using the same code as ResourceDispatcherHost. | 237 // should be using the same code as ResourceDispatcherHost. |
| 215 // TODO(jungshik): Figure out the actual value of the referrer charset and | 238 // TODO(jungshik): Figure out the actual value of the referrer charset and |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 load_flags |= net::LOAD_ONLY_FROM_CACHE; | 380 load_flags |= net::LOAD_ONLY_FROM_CACHE; |
| 358 break; | 381 break; |
| 359 case WebURLRequest::UseProtocolCachePolicy: | 382 case WebURLRequest::UseProtocolCachePolicy: |
| 360 break; | 383 break; |
| 361 } | 384 } |
| 362 | 385 |
| 363 if (request.reportUploadProgress()) | 386 if (request.reportUploadProgress()) |
| 364 load_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS; | 387 load_flags |= net::LOAD_ENABLE_UPLOAD_PROGRESS; |
| 365 if (request.reportLoadTiming()) | 388 if (request.reportLoadTiming()) |
| 366 load_flags |= net::LOAD_ENABLE_LOAD_TIMING; | 389 load_flags |= net::LOAD_ENABLE_LOAD_TIMING; |
| 390 if (request.reportRawHeaders()) |
| 391 load_flags |= net::LOAD_REPORT_RAW_HEADERS; |
| 367 | 392 |
| 368 if (!request.allowCookies() || !request.allowStoredCredentials()) { | 393 if (!request.allowCookies() || !request.allowStoredCredentials()) { |
| 369 load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES; | 394 load_flags |= net::LOAD_DO_NOT_SAVE_COOKIES; |
| 370 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES; | 395 load_flags |= net::LOAD_DO_NOT_SEND_COOKIES; |
| 371 } | 396 } |
| 372 | 397 |
| 373 if (!request.allowStoredCredentials()) | 398 if (!request.allowStoredCredentials()) |
| 374 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; | 399 load_flags |= net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 375 | 400 |
| 376 | |
| 377 // TODO(jcampan): in the non out-of-process plugin case the request does not | 401 // TODO(jcampan): in the non out-of-process plugin case the request does not |
| 378 // have a requestor_pid. Find a better place to set this. | 402 // have a requestor_pid. Find a better place to set this. |
| 379 int requestor_pid = request.requestorProcessID(); | 403 int requestor_pid = request.requestorProcessID(); |
| 380 if (requestor_pid == 0) | 404 if (requestor_pid == 0) |
| 381 requestor_pid = base::GetCurrentProcId(); | 405 requestor_pid = base::GetCurrentProcId(); |
| 382 | 406 |
| 383 HeaderFlattener flattener(load_flags); | 407 HeaderFlattener flattener(load_flags); |
| 384 request.visitHTTPHeaderFields(&flattener); | 408 request.visitHTTPHeaderFields(&flattener); |
| 385 | 409 |
| 386 // TODO(abarth): These are wrong! I need to figure out how to get the right | 410 // TODO(abarth): These are wrong! I need to figure out how to get the right |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 722 |
| 699 void WebURLLoaderImpl::cancel() { | 723 void WebURLLoaderImpl::cancel() { |
| 700 context_->Cancel(); | 724 context_->Cancel(); |
| 701 } | 725 } |
| 702 | 726 |
| 703 void WebURLLoaderImpl::setDefersLoading(bool value) { | 727 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 704 context_->SetDefersLoading(value); | 728 context_->SetDefersLoading(value); |
| 705 } | 729 } |
| 706 | 730 |
| 707 } // namespace webkit_glue | 731 } // namespace webkit_glue |
| OLD | NEW |