Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
| 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" |
| 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
| 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
| 30 #include "webkit/glue/ftp_directory_listing_response_delegate.h" | 30 #include "webkit/glue/ftp_directory_listing_response_delegate.h" |
| 31 #include "webkit/glue/multipart_response_delegate.h" | 31 #include "webkit/glue/multipart_response_delegate.h" |
| 32 #include "webkit/glue/resource_loader_bridge.h" | 32 #include "webkit/glue/resource_loader_bridge.h" |
| 33 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
| 34 #include "webkit/glue/weburlrequest_extradata_impl.h" | |
| 34 | 35 |
| 35 using base::Time; | 36 using base::Time; |
| 36 using base::TimeDelta; | 37 using base::TimeDelta; |
| 37 using WebKit::WebData; | 38 using WebKit::WebData; |
| 38 using WebKit::WebHTTPBody; | 39 using WebKit::WebHTTPBody; |
| 39 using WebKit::WebHTTPHeaderVisitor; | 40 using WebKit::WebHTTPHeaderVisitor; |
| 40 using WebKit::WebHTTPLoadInfo; | 41 using WebKit::WebHTTPLoadInfo; |
| 42 using WebKit::WebReferrerPolicy; | |
| 41 using WebKit::WebSecurityPolicy; | 43 using WebKit::WebSecurityPolicy; |
| 42 using WebKit::WebString; | 44 using WebKit::WebString; |
| 43 using WebKit::WebURL; | 45 using WebKit::WebURL; |
| 44 using WebKit::WebURLError; | 46 using WebKit::WebURLError; |
| 45 using WebKit::WebURLLoadTiming; | 47 using WebKit::WebURLLoadTiming; |
| 46 using WebKit::WebURLLoader; | 48 using WebKit::WebURLLoader; |
| 47 using WebKit::WebURLLoaderClient; | 49 using WebKit::WebURLLoaderClient; |
| 48 using WebKit::WebURLRequest; | 50 using WebKit::WebURLRequest; |
| 49 using WebKit::WebURLResponse; | 51 using WebKit::WebURLResponse; |
| 50 | 52 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 friend class base::RefCounted<Context>; | 287 friend class base::RefCounted<Context>; |
| 286 ~Context() {} | 288 ~Context() {} |
| 287 | 289 |
| 288 // We can optimize the handling of data URLs in most cases. | 290 // We can optimize the handling of data URLs in most cases. |
| 289 bool CanHandleDataURL(const GURL& url) const; | 291 bool CanHandleDataURL(const GURL& url) const; |
| 290 void HandleDataURL(); | 292 void HandleDataURL(); |
| 291 | 293 |
| 292 WebURLLoaderImpl* loader_; | 294 WebURLLoaderImpl* loader_; |
| 293 WebURLRequest request_; | 295 WebURLRequest request_; |
| 294 WebURLLoaderClient* client_; | 296 WebURLLoaderClient* client_; |
| 297 WebReferrerPolicy referrer_policy_; | |
| 295 scoped_ptr<ResourceLoaderBridge> bridge_; | 298 scoped_ptr<ResourceLoaderBridge> bridge_; |
| 296 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 299 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 297 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 300 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
| 298 scoped_ptr<ResourceLoaderBridge> completed_bridge_; | 301 scoped_ptr<ResourceLoaderBridge> completed_bridge_; |
| 299 }; | 302 }; |
| 300 | 303 |
| 301 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) | 304 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) |
| 302 : loader_(loader), | 305 : loader_(loader), |
| 303 client_(NULL) { | 306 client_(NULL), |
| 307 referrer_policy_(WebKit::WebReferrerPolicyDefault) { | |
| 304 } | 308 } |
| 305 | 309 |
| 306 void WebURLLoaderImpl::Context::Cancel() { | 310 void WebURLLoaderImpl::Context::Cancel() { |
| 307 // The bridge will still send OnCompletedRequest, which will Release() us, so | 311 // The bridge will still send OnCompletedRequest, which will Release() us, so |
| 308 // we don't do that here. | 312 // we don't do that here. |
| 309 if (bridge_.get()) | 313 if (bridge_.get()) |
| 310 bridge_->Cancel(); | 314 bridge_->Cancel(); |
| 311 | 315 |
| 312 // Ensure that we do not notify the multipart delegate anymore as it has | 316 // Ensure that we do not notify the multipart delegate anymore as it has |
| 313 // its own pointer to the client. | 317 // its own pointer to the client. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 request_info.requestor_pid = request.requestorProcessID(); | 411 request_info.requestor_pid = request.requestorProcessID(); |
| 408 request_info.request_type = | 412 request_info.request_type = |
| 409 ResourceType::FromTargetType(request.targetType()); | 413 ResourceType::FromTargetType(request.targetType()); |
| 410 request_info.appcache_host_id = request.appCacheHostID(); | 414 request_info.appcache_host_id = request.appCacheHostID(); |
| 411 request_info.routing_id = request.requestorID(); | 415 request_info.routing_id = request.requestorID(); |
| 412 request_info.download_to_file = request.downloadToFile(); | 416 request_info.download_to_file = request.downloadToFile(); |
| 413 request_info.has_user_gesture = request.hasUserGesture(); | 417 request_info.has_user_gesture = request.hasUserGesture(); |
| 414 request_info.extra_data = request.extraData(); | 418 request_info.extra_data = request.extraData(); |
| 415 bridge_.reset(ResourceLoaderBridge::Create(request_info)); | 419 bridge_.reset(ResourceLoaderBridge::Create(request_info)); |
| 416 | 420 |
| 421 referrer_policy_ = static_cast<WebURLRequestExtraDataImpl*>( | |
|
darin (slow to review)
2011/11/21 22:44:37
should you null check request.extraData() here? o
jochen (gone - plz use gerrit)
2011/11/22 10:38:28
I've added both the null check, and code to the te
| |
| 422 request.extraData())->referrer_policy(); | |
| 423 | |
| 417 if (!request.httpBody().isNull()) { | 424 if (!request.httpBody().isNull()) { |
| 418 // GET and HEAD requests shouldn't have http bodies. | 425 // GET and HEAD requests shouldn't have http bodies. |
| 419 DCHECK(method != "GET" && method != "HEAD"); | 426 DCHECK(method != "GET" && method != "HEAD"); |
| 420 const WebHTTPBody& httpBody = request.httpBody(); | 427 const WebHTTPBody& httpBody = request.httpBody(); |
| 421 size_t i = 0; | 428 size_t i = 0; |
| 422 WebHTTPBody::Element element; | 429 WebHTTPBody::Element element; |
| 423 while (httpBody.elementAt(i++, element)) { | 430 while (httpBody.elementAt(i++, element)) { |
| 424 switch (element.type) { | 431 switch (element.type) { |
| 425 case WebHTTPBody::Element::TypeData: | 432 case WebHTTPBody::Element::TypeData: |
| 426 if (!element.data.isEmpty()) { | 433 if (!element.data.isEmpty()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 response.initialize(); | 488 response.initialize(); |
| 482 PopulateURLResponse(request_.url(), info, &response); | 489 PopulateURLResponse(request_.url(), info, &response); |
| 483 | 490 |
| 484 // TODO(darin): We lack sufficient information to construct the actual | 491 // TODO(darin): We lack sufficient information to construct the actual |
| 485 // request that resulted from the redirect. | 492 // request that resulted from the redirect. |
| 486 WebURLRequest new_request(new_url); | 493 WebURLRequest new_request(new_url); |
| 487 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); | 494 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); |
| 488 new_request.setDownloadToFile(request_.downloadToFile()); | 495 new_request.setDownloadToFile(request_.downloadToFile()); |
| 489 | 496 |
| 490 WebString referrer_string = WebString::fromUTF8("Referer"); | 497 WebString referrer_string = WebString::fromUTF8("Referer"); |
| 491 WebString referrer = request_.httpHeaderField(referrer_string); | 498 WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
| 492 if (!WebSecurityPolicy::shouldHideReferrer(new_url, referrer)) | 499 referrer_policy_, |
| 500 new_url, | |
| 501 request_.httpHeaderField(referrer_string)); | |
| 502 if (!referrer.isEmpty()) | |
| 493 new_request.setHTTPHeaderField(referrer_string, referrer); | 503 new_request.setHTTPHeaderField(referrer_string, referrer); |
| 494 | 504 |
| 495 if (response.httpStatusCode() == 307) | 505 if (response.httpStatusCode() == 307) |
| 496 new_request.setHTTPMethod(request_.httpMethod()); | 506 new_request.setHTTPMethod(request_.httpMethod()); |
| 497 | 507 |
| 498 client_->willSendRequest(loader_, new_request, response); | 508 client_->willSendRequest(loader_, new_request, response); |
| 499 request_ = new_request; | 509 request_ = new_request; |
| 500 *has_new_first_party_for_cookies = true; | 510 *has_new_first_party_for_cookies = true; |
| 501 *new_first_party_for_cookies = request_.firstPartyForCookies(); | 511 *new_first_party_for_cookies = request_.firstPartyForCookies(); |
| 502 | 512 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 | 745 |
| 736 void WebURLLoaderImpl::setDefersLoading(bool value) { | 746 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 737 context_->SetDefersLoading(value); | 747 context_->SetDefersLoading(value); |
| 738 } | 748 } |
| 739 | 749 |
| 740 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { | 750 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { |
| 741 context_->UpdateRoutingId(new_routing_id); | 751 context_->UpdateRoutingId(new_routing_id); |
| 742 } | 752 } |
| 743 | 753 |
| 744 } // namespace webkit_glue | 754 } // namespace webkit_glue |
| OLD | NEW |