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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" | 31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" |
32 #include "webkit/glue/multipart_response_delegate.h" | 32 #include "webkit/glue/multipart_response_delegate.h" |
33 #include "webkit/glue/resource_loader_bridge.h" | 33 #include "webkit/glue/resource_loader_bridge.h" |
34 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
35 #include "webkit/glue/webkitplatformsupport_impl.h" | 35 #include "webkit/glue/webkitplatformsupport_impl.h" |
| 36 #include "webkit/glue/weburlrequest_extradata_impl.h" |
36 | 37 |
37 using base::Time; | 38 using base::Time; |
38 using base::TimeDelta; | 39 using base::TimeDelta; |
39 using WebKit::WebData; | 40 using WebKit::WebData; |
40 using WebKit::WebHTTPBody; | 41 using WebKit::WebHTTPBody; |
41 using WebKit::WebHTTPHeaderVisitor; | 42 using WebKit::WebHTTPHeaderVisitor; |
42 using WebKit::WebHTTPLoadInfo; | 43 using WebKit::WebHTTPLoadInfo; |
| 44 using WebKit::WebReferrerPolicy; |
43 using WebKit::WebSecurityPolicy; | 45 using WebKit::WebSecurityPolicy; |
44 using WebKit::WebString; | 46 using WebKit::WebString; |
45 using WebKit::WebURL; | 47 using WebKit::WebURL; |
46 using WebKit::WebURLError; | 48 using WebKit::WebURLError; |
47 using WebKit::WebURLLoadTiming; | 49 using WebKit::WebURLLoadTiming; |
48 using WebKit::WebURLLoader; | 50 using WebKit::WebURLLoader; |
49 using WebKit::WebURLLoaderClient; | 51 using WebKit::WebURLLoaderClient; |
50 using WebKit::WebURLRequest; | 52 using WebKit::WebURLRequest; |
51 using WebKit::WebURLResponse; | 53 using WebKit::WebURLResponse; |
52 | 54 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 friend class base::RefCounted<Context>; | 290 friend class base::RefCounted<Context>; |
289 ~Context() {} | 291 ~Context() {} |
290 | 292 |
291 // We can optimize the handling of data URLs in most cases. | 293 // We can optimize the handling of data URLs in most cases. |
292 bool CanHandleDataURL(const GURL& url) const; | 294 bool CanHandleDataURL(const GURL& url) const; |
293 void HandleDataURL(); | 295 void HandleDataURL(); |
294 | 296 |
295 WebURLLoaderImpl* loader_; | 297 WebURLLoaderImpl* loader_; |
296 WebURLRequest request_; | 298 WebURLRequest request_; |
297 WebURLLoaderClient* client_; | 299 WebURLLoaderClient* client_; |
| 300 WebReferrerPolicy referrer_policy_; |
298 scoped_ptr<ResourceLoaderBridge> bridge_; | 301 scoped_ptr<ResourceLoaderBridge> bridge_; |
299 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 302 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
300 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 303 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
301 scoped_ptr<ResourceLoaderBridge> completed_bridge_; | 304 scoped_ptr<ResourceLoaderBridge> completed_bridge_; |
302 }; | 305 }; |
303 | 306 |
304 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) | 307 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader) |
305 : loader_(loader), | 308 : loader_(loader), |
306 client_(NULL) { | 309 client_(NULL), |
| 310 referrer_policy_(WebKit::WebReferrerPolicyDefault) { |
307 } | 311 } |
308 | 312 |
309 void WebURLLoaderImpl::Context::Cancel() { | 313 void WebURLLoaderImpl::Context::Cancel() { |
310 // The bridge will still send OnCompletedRequest, which will Release() us, so | 314 // The bridge will still send OnCompletedRequest, which will Release() us, so |
311 // we don't do that here. | 315 // we don't do that here. |
312 if (bridge_.get()) | 316 if (bridge_.get()) |
313 bridge_->Cancel(); | 317 bridge_->Cancel(); |
314 | 318 |
315 // Ensure that we do not notify the multipart delegate anymore as it has | 319 // Ensure that we do not notify the multipart delegate anymore as it has |
316 // its own pointer to the client. | 320 // its own pointer to the client. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 request_info.requestor_pid = request.requestorProcessID(); | 415 request_info.requestor_pid = request.requestorProcessID(); |
412 request_info.request_type = | 416 request_info.request_type = |
413 ResourceType::FromTargetType(request.targetType()); | 417 ResourceType::FromTargetType(request.targetType()); |
414 request_info.appcache_host_id = request.appCacheHostID(); | 418 request_info.appcache_host_id = request.appCacheHostID(); |
415 request_info.routing_id = request.requestorID(); | 419 request_info.routing_id = request.requestorID(); |
416 request_info.download_to_file = request.downloadToFile(); | 420 request_info.download_to_file = request.downloadToFile(); |
417 request_info.has_user_gesture = request.hasUserGesture(); | 421 request_info.has_user_gesture = request.hasUserGesture(); |
418 request_info.extra_data = request.extraData(); | 422 request_info.extra_data = request.extraData(); |
419 bridge_.reset(platform->CreateResourceLoader(request_info)); | 423 bridge_.reset(platform->CreateResourceLoader(request_info)); |
420 | 424 |
| 425 if (request.extraData()) { |
| 426 referrer_policy_ = static_cast<WebURLRequestExtraDataImpl*>( |
| 427 request.extraData())->referrer_policy(); |
| 428 } |
| 429 |
421 if (!request.httpBody().isNull()) { | 430 if (!request.httpBody().isNull()) { |
422 // GET and HEAD requests shouldn't have http bodies. | 431 // GET and HEAD requests shouldn't have http bodies. |
423 DCHECK(method != "GET" && method != "HEAD"); | 432 DCHECK(method != "GET" && method != "HEAD"); |
424 const WebHTTPBody& httpBody = request.httpBody(); | 433 const WebHTTPBody& httpBody = request.httpBody(); |
425 size_t i = 0; | 434 size_t i = 0; |
426 WebHTTPBody::Element element; | 435 WebHTTPBody::Element element; |
427 while (httpBody.elementAt(i++, element)) { | 436 while (httpBody.elementAt(i++, element)) { |
428 switch (element.type) { | 437 switch (element.type) { |
429 case WebHTTPBody::Element::TypeData: | 438 case WebHTTPBody::Element::TypeData: |
430 if (!element.data.isEmpty()) { | 439 if (!element.data.isEmpty()) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 response.initialize(); | 494 response.initialize(); |
486 PopulateURLResponse(request_.url(), info, &response); | 495 PopulateURLResponse(request_.url(), info, &response); |
487 | 496 |
488 // TODO(darin): We lack sufficient information to construct the actual | 497 // TODO(darin): We lack sufficient information to construct the actual |
489 // request that resulted from the redirect. | 498 // request that resulted from the redirect. |
490 WebURLRequest new_request(new_url); | 499 WebURLRequest new_request(new_url); |
491 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); | 500 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); |
492 new_request.setDownloadToFile(request_.downloadToFile()); | 501 new_request.setDownloadToFile(request_.downloadToFile()); |
493 | 502 |
494 WebString referrer_string = WebString::fromUTF8("Referer"); | 503 WebString referrer_string = WebString::fromUTF8("Referer"); |
495 WebString referrer = request_.httpHeaderField(referrer_string); | 504 WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
496 if (!WebSecurityPolicy::shouldHideReferrer(new_url, referrer)) | 505 referrer_policy_, |
| 506 new_url, |
| 507 request_.httpHeaderField(referrer_string)); |
| 508 if (!referrer.isEmpty()) |
497 new_request.setHTTPHeaderField(referrer_string, referrer); | 509 new_request.setHTTPHeaderField(referrer_string, referrer); |
498 | 510 |
499 if (response.httpStatusCode() == 307) | 511 if (response.httpStatusCode() == 307) |
500 new_request.setHTTPMethod(request_.httpMethod()); | 512 new_request.setHTTPMethod(request_.httpMethod()); |
501 | 513 |
502 client_->willSendRequest(loader_, new_request, response); | 514 client_->willSendRequest(loader_, new_request, response); |
503 request_ = new_request; | 515 request_ = new_request; |
504 *has_new_first_party_for_cookies = true; | 516 *has_new_first_party_for_cookies = true; |
505 *new_first_party_for_cookies = request_.firstPartyForCookies(); | 517 *new_first_party_for_cookies = request_.firstPartyForCookies(); |
506 | 518 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 752 |
741 void WebURLLoaderImpl::setDefersLoading(bool value) { | 753 void WebURLLoaderImpl::setDefersLoading(bool value) { |
742 context_->SetDefersLoading(value); | 754 context_->SetDefersLoading(value); |
743 } | 755 } |
744 | 756 |
745 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { | 757 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { |
746 context_->UpdateRoutingId(new_routing_id); | 758 context_->UpdateRoutingId(new_routing_id); |
747 } | 759 } |
748 | 760 |
749 } // namespace webkit_glue | 761 } // namespace webkit_glue |
OLD | NEW |