| 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 #include "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 void run() override { | 329 void run() override { |
| 330 context_->HandleDataURL(); | 330 context_->HandleDataURL(); |
| 331 } | 331 } |
| 332 | 332 |
| 333 private: | 333 private: |
| 334 scoped_refptr<Context> context_; | 334 scoped_refptr<Context> context_; |
| 335 }; | 335 }; |
| 336 | 336 |
| 337 // Called when the body data stream is detached from the reader side. | 337 // Called when the body data stream is detached from the reader side. |
| 338 void CancelBodyStreaming(); | 338 void CancelBodyStreaming(); |
| 339 // We can optimize the handling of data URLs in most cases. | |
| 340 bool CanHandleDataURLRequestLocally() const; | |
| 341 void HandleDataURL(); | 339 void HandleDataURL(); |
| 342 | 340 |
| 343 WebURLLoaderImpl* loader_; | 341 WebURLLoaderImpl* loader_; |
| 344 WebURLRequest request_; | 342 WebURLRequest request_; |
| 345 WebURLLoaderClient* client_; | 343 WebURLLoaderClient* client_; |
| 346 ResourceDispatcher* resource_dispatcher_; | 344 ResourceDispatcher* resource_dispatcher_; |
| 347 scoped_ptr<blink::WebTaskRunner> web_task_runner_; | 345 scoped_ptr<blink::WebTaskRunner> web_task_runner_; |
| 348 WebReferrerPolicy referrer_policy_; | 346 WebReferrerPolicy referrer_policy_; |
| 349 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 347 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 350 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 348 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 DCHECK(request_id_ == -1); | 459 DCHECK(request_id_ == -1); |
| 462 request_ = request; // Save the request. | 460 request_ = request; // Save the request. |
| 463 if (request.extraData()) { | 461 if (request.extraData()) { |
| 464 RequestExtraData* extra_data = | 462 RequestExtraData* extra_data = |
| 465 static_cast<RequestExtraData*>(request.extraData()); | 463 static_cast<RequestExtraData*>(request.extraData()); |
| 466 stream_override_ = extra_data->TakeStreamOverrideOwnership(); | 464 stream_override_ = extra_data->TakeStreamOverrideOwnership(); |
| 467 } | 465 } |
| 468 | 466 |
| 469 GURL url = request.url(); | 467 GURL url = request.url(); |
| 470 | 468 |
| 471 if (CanHandleDataURLRequestLocally()) { | 469 if (CanHandleDataURLRequestLocally(request_, |
| 470 resource_dispatcher_ != nullptr)) { |
| 472 if (sync_load_response) { | 471 if (sync_load_response) { |
| 473 // This is a sync load. Do the work now. | 472 // This is a sync load. Do the work now. |
| 474 sync_load_response->url = url; | 473 sync_load_response->url = url; |
| 475 sync_load_response->error_code = | 474 sync_load_response->error_code = |
| 476 GetInfoFromDataURL(sync_load_response->url, sync_load_response, | 475 GetInfoFromDataURL(sync_load_response->url, sync_load_response, |
| 477 &sync_load_response->data); | 476 &sync_load_response->data); |
| 478 } else { | 477 } else { |
| 479 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE | 478 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE |
| 480 // coexist. | 479 // coexist. |
| 481 web_task_runner_->postTask( | 480 web_task_runner_->postTask( |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 if (client_) { | 803 if (client_) { |
| 805 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. | 804 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. |
| 806 client_->didFail( | 805 client_->didFail( |
| 807 loader_, CreateWebURLError(request_.url(), false, net::ERR_ABORTED)); | 806 loader_, CreateWebURLError(request_.url(), false, net::ERR_ABORTED)); |
| 808 } | 807 } |
| 809 | 808 |
| 810 // Notify the browser process that the request is canceled. | 809 // Notify the browser process that the request is canceled. |
| 811 Cancel(); | 810 Cancel(); |
| 812 } | 811 } |
| 813 | 812 |
| 814 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { | 813 bool WebURLLoaderImpl::CanHandleDataURLRequestLocally( |
| 815 GURL url = request_.url(); | 814 const WebURLRequest& request, |
| 815 bool resource_dispatcher_exists) { |
| 816 GURL url = request.url(); |
| 816 if (!url.SchemeIs(url::kDataScheme)) | 817 if (!url.SchemeIs(url::kDataScheme)) |
| 817 return false; | 818 return false; |
| 818 | 819 |
| 819 // The fast paths for data URL, Start() and HandleDataURL(), don't support | 820 // The fast paths for data URL, Start() and HandleDataURL(), don't support |
| 820 // the downloadToFile option. | 821 // the downloadToFile option. |
| 821 if (request_.downloadToFile()) | 822 if (request.downloadToFile()) |
| 822 return false; | 823 return false; |
| 823 | 824 |
| 824 // Data url requests from object tags may need to be intercepted as streams | 825 // Data url requests from object tags may need to be intercepted as streams |
| 825 // and so need to be sent to the browser. | 826 // and so need to be sent to the browser. |
| 826 if (request_.getRequestContext() == WebURLRequest::RequestContextObject) | 827 if (request.getRequestContext() == WebURLRequest::RequestContextObject) |
| 827 return false; | 828 return false; |
| 828 | 829 |
| 829 // Optimize for the case where we can handle a data URL locally. We must | 830 // Optimize for the case where we can handle a data URL locally. We must |
| 830 // skip this for data URLs targetted at frames since those could trigger a | 831 // skip this for data URLs targetted at frames since those could trigger a |
| 831 // download. | 832 // download. |
| 832 // | 833 // |
| 833 // NOTE: We special case MIME types we can render both for performance | 834 // NOTE: We special case MIME types we can render both for performance |
| 834 // reasons as well as to support unit tests. | 835 // reasons as well as to support unit tests. |
| 835 | 836 |
| 836 #if defined(OS_ANDROID) | 837 #if defined(OS_ANDROID) |
| 837 // For compatibility reasons on Android we need to expose top-level data:// | 838 // For compatibility reasons on Android we need to expose top-level data:// |
| 838 // to the browser. In tests resource_dispatcher_ can be null, and test pages | 839 // to the browser. In tests resource_dispatcher_ can be null, and test pages |
| 839 // need to be loaded locally. | 840 // need to be loaded locally. |
| 840 if (resource_dispatcher_ && | 841 if (resource_dispatcher_exists && |
| 841 request_.getFrameType() == WebURLRequest::FrameTypeTopLevel) | 842 request.getFrameType() == WebURLRequest::FrameTypeTopLevel) |
| 842 return false; | 843 return false; |
| 843 #endif | 844 #endif |
| 844 | 845 |
| 845 if (request_.getFrameType() != WebURLRequest::FrameTypeTopLevel && | 846 if (request.getFrameType() != WebURLRequest::FrameTypeTopLevel && |
| 846 request_.getFrameType() != WebURLRequest::FrameTypeNested) | 847 request.getFrameType() != WebURLRequest::FrameTypeNested) |
| 847 return true; | 848 return true; |
| 848 | 849 |
| 849 std::string mime_type, unused_charset; | 850 std::string mime_type, unused_charset; |
| 850 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && | 851 if (net::DataURL::Parse(request.url(), &mime_type, &unused_charset, NULL) && |
| 851 mime_util::IsSupportedMimeType(mime_type)) | 852 mime_util::IsSupportedMimeType(mime_type)) |
| 852 return true; | 853 return true; |
| 853 | 854 |
| 854 return false; | 855 return false; |
| 855 } | 856 } |
| 856 | 857 |
| 857 void WebURLLoaderImpl::Context::HandleDataURL() { | 858 void WebURLLoaderImpl::Context::HandleDataURL() { |
| 858 DCHECK_NE(defers_loading_, DEFERRED_DATA); | 859 DCHECK_NE(defers_loading_, DEFERRED_DATA); |
| 859 if (defers_loading_ == SHOULD_DEFER) { | 860 if (defers_loading_ == SHOULD_DEFER) { |
| 860 defers_loading_ = DEFERRED_DATA; | 861 defers_loading_ = DEFERRED_DATA; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 } | 1155 } |
| 1155 | 1156 |
| 1156 void WebURLLoaderImpl::setLoadingTaskRunner( | 1157 void WebURLLoaderImpl::setLoadingTaskRunner( |
| 1157 blink::WebTaskRunner* loading_task_runner) { | 1158 blink::WebTaskRunner* loading_task_runner) { |
| 1158 // There's no guarantee on the lifetime of |loading_task_runner| so we take a | 1159 // There's no guarantee on the lifetime of |loading_task_runner| so we take a |
| 1159 // copy. | 1160 // copy. |
| 1160 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); | 1161 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); |
| 1161 } | 1162 } |
| 1162 | 1163 |
| 1163 } // namespace content | 1164 } // namespace content |
| OLD | NEW |