Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1030)

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 148133007: [Downloads] Always call DM::StartDownload() for explicit downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment updates Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <algorithm> 10 #include <algorithm>
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 343
344 return true; 344 return true;
345 } 345 }
346 346
347 void RemoveDownloadFileFromChildSecurityPolicy(int child_id, 347 void RemoveDownloadFileFromChildSecurityPolicy(int child_id,
348 const base::FilePath& path) { 348 const base::FilePath& path) {
349 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( 349 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile(
350 child_id, path); 350 child_id, path);
351 } 351 }
352 352
353 DownloadInterruptReason CallbackAndReturn(
354 const DownloadUrlParameters::OnStartedCallback& started_cb,
355 DownloadInterruptReason interrupt_reason) {
356 if (started_cb.is_null())
357 return interrupt_reason;
358 BrowserThread::PostTask(
359 BrowserThread::UI,
360 FROM_HERE,
361 base::Bind(
362 started_cb, static_cast<DownloadItem*>(NULL), interrupt_reason));
363
364 return interrupt_reason;
365 }
366
367 int GetCertID(net::URLRequest* request, int child_id) { 353 int GetCertID(net::URLRequest* request, int child_id) {
368 if (request->ssl_info().cert.get()) { 354 if (request->ssl_info().cert.get()) {
369 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(), 355 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(),
370 child_id); 356 child_id);
371 } 357 }
372 return 0; 358 return 0;
373 } 359 }
374 360
375 void NotifyRedirectOnUI(int render_process_id, 361 void NotifyRedirectOnUI(int render_process_id,
376 int render_frame_host, 362 int render_frame_host,
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 } 744 }
759 745
760 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( 746 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload(
761 scoped_ptr<net::URLRequest> request, 747 scoped_ptr<net::URLRequest> request,
762 const Referrer& referrer, 748 const Referrer& referrer,
763 bool is_content_initiated, 749 bool is_content_initiated,
764 ResourceContext* context, 750 ResourceContext* context,
765 int child_id, 751 int child_id,
766 int render_view_route_id, 752 int render_view_route_id,
767 int render_frame_route_id, 753 int render_frame_route_id,
768 bool prefer_cache, 754 bool do_not_prompt_for_login) {
769 bool do_not_prompt_for_login,
770 scoped_ptr<DownloadSaveInfo> save_info,
771 uint32_t download_id,
772 const DownloadStartedCallback& started_callback) {
773 if (is_shutdown_) 755 if (is_shutdown_)
774 return CallbackAndReturn(started_callback, 756 return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
775 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
776 757
777 const GURL& url = request->original_url(); 758 const GURL& url = request->original_url();
778 759
779 // http://crbug.com/90971 760 // http://crbug.com/90971
780 char url_buf[128]; 761 char url_buf[128];
781 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); 762 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf));
782 base::debug::Alias(url_buf); 763 base::debug::Alias(url_buf);
783 CHECK(ContainsKey(active_resource_contexts_, context)); 764 CHECK(ContainsKey(active_resource_contexts_, context));
784 765
785 SetReferrerForRequest(request.get(), referrer); 766 SetReferrerForRequest(request.get(), referrer);
786 767
787 int extra_load_flags = net::LOAD_NORMAL;
788 if (prefer_cache) {
789 // If there is upload data attached, only retrieve from cache because there
790 // is no current mechanism to prompt the user for their consent for a
791 // re-post. For GETs, try to retrieve data from the cache and skip
792 // validating the entry if present.
793 if (request->get_upload() != NULL)
794 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
795 else
796 extra_load_flags |= net::LOAD_PREFERRING_CACHE;
797 } else {
798 extra_load_flags |= net::LOAD_DISABLE_CACHE;
799 }
800 request->SetLoadFlags(request->load_flags() | extra_load_flags);
801
802 // We treat a download as a main frame load, and thus update the policy URL on 768 // We treat a download as a main frame load, and thus update the policy URL on
803 // redirects. 769 // redirects.
804 // 770 //
805 // TODO(davidben): Is this correct? If this came from a 771 // TODO(davidben): Is this correct? If this came from a
806 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set 772 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set
807 // appropriately? 773 // appropriately?
808 request->set_first_party_url_policy( 774 request->set_first_party_url_policy(
809 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 775 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
810 776
811 // Check if the renderer is permitted to request the requested URL. 777 // Check if the renderer is permitted to request the requested URL.
812 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 778 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
813 CanRequestURL(child_id, url)) { 779 CanRequestURL(child_id, url)) {
814 VLOG(1) << "Denied unauthorized download request for " 780 DVLOG(1) << "Denied unauthorized download request for "
815 << url.possibly_invalid_spec(); 781 << url.possibly_invalid_spec();
816 return CallbackAndReturn(started_callback, 782 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
817 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
818 } 783 }
819 784
820 request_id_--; 785 request_id_--;
821 786
822 const net::URLRequestContext* request_context = context->GetRequestContext(); 787 const net::URLRequestContext* request_context = context->GetRequestContext();
823 if (!request_context->job_factory()->IsHandledURL(url)) { 788 if (!request_context->job_factory()->IsHandledURL(url)) {
824 VLOG(1) << "Download request for unsupported protocol: " 789 DVLOG(1) << "Download request for unsupported protocol: "
825 << url.possibly_invalid_spec(); 790 << url.possibly_invalid_spec();
826 return CallbackAndReturn(started_callback, 791 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
827 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
828 } 792 }
829 793
830 ResourceRequestInfoImpl* extra_info = 794 ResourceRequestInfoImpl* extra_info =
831 CreateRequestInfo(child_id, render_view_route_id, 795 CreateRequestInfo(child_id, render_view_route_id,
832 render_frame_route_id, true, context); 796 render_frame_route_id, true, context);
833 extra_info->set_do_not_prompt_for_login(do_not_prompt_for_login); 797 extra_info->set_do_not_prompt_for_login(do_not_prompt_for_login);
834 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 798 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
835 799
836 if (request->url().SchemeIs(url::kBlobScheme)) { 800 if (request->url().SchemeIs(url::kBlobScheme)) {
837 ChromeBlobStorageContext* blob_context = 801 ChromeBlobStorageContext* blob_context =
838 GetChromeBlobStorageContextForResourceContext(context); 802 GetChromeBlobStorageContextForResourceContext(context);
839 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( 803 storage::BlobProtocolHandler::SetRequestedBlobDataHandle(
840 request.get(), 804 request.get(),
841 blob_context->context()->GetBlobDataFromPublicURL(request->url())); 805 blob_context->context()->GetBlobDataFromPublicURL(request->url()));
842 } 806 }
843 807
844 // From this point forward, the |DownloadResourceHandler| is responsible for 808 // From this point forward, the |DownloadResourceHandler| is responsible for
845 // |started_callback|. 809 // |started_callback|.
846 scoped_ptr<ResourceHandler> handler(CreateResourceHandlerForDownload( 810 scoped_ptr<ResourceHandler> handler(CreateResourceHandlerForDownload(
847 request.get(), is_content_initiated, true, download_id, 811 request.get(), is_content_initiated, true));
848 std::move(save_info), started_callback));
849 812
850 BeginRequestInternal(std::move(request), std::move(handler)); 813 BeginRequestInternal(std::move(request), std::move(handler));
851 814
852 return DOWNLOAD_INTERRUPT_REASON_NONE; 815 return DOWNLOAD_INTERRUPT_REASON_NONE;
853 } 816 }
854 817
855 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( 818 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest(
856 net::URLRequest* request) { 819 net::URLRequest* request) {
857 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 820 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
858 if (info) { 821 if (info) {
859 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); 822 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID());
860 if (loader) 823 if (loader)
861 loader->ClearLoginDelegate(); 824 loader->ClearLoginDelegate();
862 } 825 }
863 } 826 }
864 827
865 void ResourceDispatcherHostImpl::Shutdown() { 828 void ResourceDispatcherHostImpl::Shutdown() {
866 DCHECK_CURRENTLY_ON(BrowserThread::UI); 829 DCHECK_CURRENTLY_ON(BrowserThread::UI);
867 BrowserThread::PostTask(BrowserThread::IO, 830 BrowserThread::PostTask(BrowserThread::IO,
868 FROM_HERE, 831 FROM_HERE,
869 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, 832 base::Bind(&ResourceDispatcherHostImpl::OnShutdown,
870 base::Unretained(this))); 833 base::Unretained(this)));
871 } 834 }
872 835
873 scoped_ptr<ResourceHandler> 836 scoped_ptr<ResourceHandler>
874 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( 837 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
875 net::URLRequest* request, 838 net::URLRequest* request,
876 bool is_content_initiated, 839 bool is_content_initiated,
877 bool must_download, 840 bool must_download) {
878 uint32_t id, 841 scoped_ptr<ResourceHandler> handler(new DownloadResourceHandler(request));
879 scoped_ptr<DownloadSaveInfo> save_info,
880 const DownloadUrlParameters::OnStartedCallback& started_cb) {
881 scoped_ptr<ResourceHandler> handler(new DownloadResourceHandler(
882 id, request, started_cb, std::move(save_info)));
883 if (delegate_) { 842 if (delegate_) {
884 const ResourceRequestInfoImpl* request_info( 843 const ResourceRequestInfoImpl* request_info(
885 ResourceRequestInfoImpl::ForRequest(request)); 844 ResourceRequestInfoImpl::ForRequest(request));
886 845
887 ScopedVector<ResourceThrottle> throttles; 846 ScopedVector<ResourceThrottle> throttles;
888 delegate_->DownloadStarting( 847 delegate_->DownloadStarting(
889 request, request_info->GetContext(), request_info->GetChildID(), 848 request, request_info->GetContext(), request_info->GetChildID(),
890 request_info->GetRouteID(), request_info->GetRequestID(), 849 request_info->GetRouteID(), request_info->GetRequestID(),
891 is_content_initiated, must_download, &throttles); 850 is_content_initiated, must_download, &throttles);
892 if (!throttles.empty()) { 851 if (!throttles.empty()) {
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 load_flags |= net::LOAD_PREFETCH; 2637 load_flags |= net::LOAD_PREFETCH;
2679 } 2638 }
2680 2639
2681 if (is_sync_load) 2640 if (is_sync_load)
2682 load_flags |= net::LOAD_IGNORE_LIMITS; 2641 load_flags |= net::LOAD_IGNORE_LIMITS;
2683 2642
2684 return load_flags; 2643 return load_flags;
2685 } 2644 }
2686 2645
2687 } // namespace content 2646 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698