| 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 "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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/child/blink_platform_impl.h" | |
| 16 #include "net/base/data_url.h" | 15 #include "net/base/data_url.h" |
| 17 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 18 #include "net/base/mime_util.h" | 17 #include "net/base/mime_util.h" |
| 19 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 20 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 21 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_util.h" | 21 #include "net/http/http_util.h" |
| 23 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 24 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 23 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
| 25 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" | 24 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" |
| 26 #include "third_party/WebKit/public/platform/WebURL.h" | 25 #include "third_party/WebKit/public/platform/WebURL.h" |
| 27 #include "third_party/WebKit/public/platform/WebURLError.h" | 26 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 28 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" | 27 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" |
| 29 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 28 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 30 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 29 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 31 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 30 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 32 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 31 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 33 #include "webkit/child/ftp_directory_listing_response_delegate.h" | 32 #include "webkit/child/ftp_directory_listing_response_delegate.h" |
| 34 #include "webkit/child/multipart_response_delegate.h" | 33 #include "webkit/child/multipart_response_delegate.h" |
| 35 #include "webkit/child/resource_loader_bridge.h" | 34 #include "webkit/child/resource_loader_bridge.h" |
| 35 #include "webkit/child/webkitplatformsupport_impl.h" |
| 36 #include "webkit/child/weburlrequest_extradata_impl.h" | 36 #include "webkit/child/weburlrequest_extradata_impl.h" |
| 37 #include "webkit/child/weburlresponse_extradata_impl.h" | 37 #include "webkit/child/weburlresponse_extradata_impl.h" |
| 38 #include "webkit/common/resource_request_body.h" | 38 #include "webkit/common/resource_request_body.h" |
| 39 | 39 |
| 40 using base::Time; | 40 using base::Time; |
| 41 using base::TimeTicks; | 41 using base::TimeTicks; |
| 42 using blink::WebData; | 42 using blink::WebData; |
| 43 using blink::WebHTTPBody; | 43 using blink::WebHTTPBody; |
| 44 using blink::WebHTTPHeaderVisitor; | 44 using blink::WebHTTPHeaderVisitor; |
| 45 using blink::WebHTTPLoadInfo; | 45 using blink::WebHTTPLoadInfo; |
| 46 using blink::WebReferrerPolicy; | 46 using blink::WebReferrerPolicy; |
| 47 using blink::WebSecurityPolicy; | 47 using blink::WebSecurityPolicy; |
| 48 using blink::WebString; | 48 using blink::WebString; |
| 49 using blink::WebURL; | 49 using blink::WebURL; |
| 50 using blink::WebURLError; | 50 using blink::WebURLError; |
| 51 using blink::WebURLLoadTiming; | 51 using blink::WebURLLoadTiming; |
| 52 using blink::WebURLLoader; | 52 using blink::WebURLLoader; |
| 53 using blink::WebURLLoaderClient; | 53 using blink::WebURLLoaderClient; |
| 54 using blink::WebURLRequest; | 54 using blink::WebURLRequest; |
| 55 using blink::WebURLResponse; | 55 using blink::WebURLResponse; |
| 56 using webkit_glue::FtpDirectoryListingResponseDelegate; | |
| 57 using webkit_glue::MultipartResponseDelegate; | |
| 58 using webkit_glue::ResourceDevToolsInfo; | |
| 59 using webkit_glue::ResourceLoaderBridge; | |
| 60 using webkit_glue::ResourceRequestBody; | |
| 61 using webkit_glue::ResourceResponseInfo; | |
| 62 using webkit_glue::WebURLResponseExtraDataImpl; | |
| 63 | 56 |
| 64 namespace content { | 57 namespace webkit_glue { |
| 65 | 58 |
| 66 // Utilities ------------------------------------------------------------------ | 59 // Utilities ------------------------------------------------------------------ |
| 67 | 60 |
| 68 namespace { | 61 namespace { |
| 69 | 62 |
| 70 const char kThrottledErrorDescription[] = | 63 const char kThrottledErrorDescription[] = |
| 71 "Request throttled. Visit http://dev.chromium.org/throttling for more " | 64 "Request throttled. Visit http://dev.chromium.org/throttling for more " |
| 72 "information."; | 65 "information."; |
| 73 | 66 |
| 74 class HeaderFlattener : public WebHTTPHeaderVisitor { | 67 class HeaderFlattener : public WebHTTPHeaderVisitor { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 public ResourceLoaderBridge::Peer { | 217 public ResourceLoaderBridge::Peer { |
| 225 public: | 218 public: |
| 226 explicit Context(WebURLLoaderImpl* loader); | 219 explicit Context(WebURLLoaderImpl* loader); |
| 227 | 220 |
| 228 WebURLLoaderClient* client() const { return client_; } | 221 WebURLLoaderClient* client() const { return client_; } |
| 229 void set_client(WebURLLoaderClient* client) { client_ = client; } | 222 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 230 | 223 |
| 231 void Cancel(); | 224 void Cancel(); |
| 232 void SetDefersLoading(bool value); | 225 void SetDefersLoading(bool value); |
| 233 void DidChangePriority(WebURLRequest::Priority new_priority); | 226 void DidChangePriority(WebURLRequest::Priority new_priority); |
| 234 void Start(const WebURLRequest& request, | 227 void Start( |
| 235 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 228 const WebURLRequest& request, |
| 236 BlinkPlatformImpl* platform); | 229 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 230 WebKitPlatformSupportImpl* platform); |
| 237 | 231 |
| 238 // ResourceLoaderBridge::Peer methods: | 232 // ResourceLoaderBridge::Peer methods: |
| 239 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 233 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
| 240 virtual bool OnReceivedRedirect( | 234 virtual bool OnReceivedRedirect( |
| 241 const GURL& new_url, | 235 const GURL& new_url, |
| 242 const ResourceResponseInfo& info, | 236 const ResourceResponseInfo& info, |
| 243 bool* has_new_first_party_for_cookies, | 237 bool* has_new_first_party_for_cookies, |
| 244 GURL* new_first_party_for_cookies) OVERRIDE; | 238 GURL* new_first_party_for_cookies) OVERRIDE; |
| 245 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 239 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
| 246 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 240 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 void WebURLLoaderImpl::Context::DidChangePriority( | 298 void WebURLLoaderImpl::Context::DidChangePriority( |
| 305 WebURLRequest::Priority new_priority) { | 299 WebURLRequest::Priority new_priority) { |
| 306 if (bridge_) | 300 if (bridge_) |
| 307 bridge_->DidChangePriority( | 301 bridge_->DidChangePriority( |
| 308 ConvertWebKitPriorityToNetPriority(new_priority)); | 302 ConvertWebKitPriorityToNetPriority(new_priority)); |
| 309 } | 303 } |
| 310 | 304 |
| 311 void WebURLLoaderImpl::Context::Start( | 305 void WebURLLoaderImpl::Context::Start( |
| 312 const WebURLRequest& request, | 306 const WebURLRequest& request, |
| 313 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 307 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 314 BlinkPlatformImpl* platform) { | 308 WebKitPlatformSupportImpl* platform) { |
| 315 DCHECK(!bridge_.get()); | 309 DCHECK(!bridge_.get()); |
| 316 | 310 |
| 317 request_ = request; // Save the request. | 311 request_ = request; // Save the request. |
| 318 | 312 |
| 319 GURL url = request.url(); | 313 GURL url = request.url(); |
| 320 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 314 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
| 321 if (sync_load_response) { | 315 if (sync_load_response) { |
| 322 // This is a sync load. Do the work now. | 316 // This is a sync load. Do the work now. |
| 323 sync_load_response->url = url; | 317 sync_load_response->url = url; |
| 324 std::string data; | 318 std::string data; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 if (!data.empty()) | 678 if (!data.empty()) |
| 685 OnReceivedData(data.data(), data.size(), 0); | 679 OnReceivedData(data.data(), data.size(), 0); |
| 686 } | 680 } |
| 687 | 681 |
| 688 OnCompletedRequest(error_code, false, false, info.security_info, | 682 OnCompletedRequest(error_code, false, false, info.security_info, |
| 689 base::TimeTicks::Now(), 0); | 683 base::TimeTicks::Now(), 0); |
| 690 } | 684 } |
| 691 | 685 |
| 692 // WebURLLoaderImpl ----------------------------------------------------------- | 686 // WebURLLoaderImpl ----------------------------------------------------------- |
| 693 | 687 |
| 694 WebURLLoaderImpl::WebURLLoaderImpl(BlinkPlatformImpl* platform) | 688 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) |
| 695 : context_(new Context(this)), | 689 : context_(new Context(this)), |
| 696 platform_(platform) { | 690 platform_(platform) { |
| 697 } | 691 } |
| 698 | 692 |
| 699 WebURLLoaderImpl::~WebURLLoaderImpl() { | 693 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 700 cancel(); | 694 cancel(); |
| 701 } | 695 } |
| 702 | 696 |
| 703 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url, | 697 WebURLError WebURLLoaderImpl::CreateError(const WebURL& unreachable_url, |
| 704 bool stale_copy_in_cache, | 698 bool stale_copy_in_cache, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 } | 861 } |
| 868 | 862 |
| 869 void WebURLLoaderImpl::setDefersLoading(bool value) { | 863 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 870 context_->SetDefersLoading(value); | 864 context_->SetDefersLoading(value); |
| 871 } | 865 } |
| 872 | 866 |
| 873 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 867 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
| 874 context_->DidChangePriority(new_priority); | 868 context_->DidChangePriority(new_priority); |
| 875 } | 869 } |
| 876 | 870 |
| 877 } // namespace content | 871 } // namespace webkit_glue |
| OLD | NEW |