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

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: 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 342
343 return true; 343 return true;
344 } 344 }
345 345
346 void RemoveDownloadFileFromChildSecurityPolicy(int child_id, 346 void RemoveDownloadFileFromChildSecurityPolicy(int child_id,
347 const base::FilePath& path) { 347 const base::FilePath& path) {
348 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( 348 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile(
349 child_id, path); 349 child_id, path);
350 } 350 }
351 351
352 DownloadInterruptReason CallbackAndReturn(
353 const DownloadUrlParameters::OnStartedCallback& started_cb,
354 DownloadInterruptReason interrupt_reason) {
355 if (started_cb.is_null())
356 return interrupt_reason;
357 BrowserThread::PostTask(
358 BrowserThread::UI,
359 FROM_HERE,
360 base::Bind(
361 started_cb, static_cast<DownloadItem*>(NULL), interrupt_reason));
362
363 return interrupt_reason;
364 }
365
366 int GetCertID(net::URLRequest* request, int child_id) { 352 int GetCertID(net::URLRequest* request, int child_id) {
367 if (request->ssl_info().cert.get()) { 353 if (request->ssl_info().cert.get()) {
368 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(), 354 return CertStore::GetInstance()->StoreCert(request->ssl_info().cert.get(),
369 child_id); 355 child_id);
370 } 356 }
371 return 0; 357 return 0;
372 } 358 }
373 359
374 void NotifyRedirectOnUI(int render_process_id, 360 void NotifyRedirectOnUI(int render_process_id,
375 int render_frame_host, 361 int render_frame_host,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 635 }
650 636
651 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( 637 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload(
652 scoped_ptr<net::URLRequest> request, 638 scoped_ptr<net::URLRequest> request,
653 const Referrer& referrer, 639 const Referrer& referrer,
654 bool is_content_initiated, 640 bool is_content_initiated,
655 ResourceContext* context, 641 ResourceContext* context,
656 int child_id, 642 int child_id,
657 int render_view_route_id, 643 int render_view_route_id,
658 int render_frame_route_id, 644 int render_frame_route_id,
659 bool prefer_cache, 645 bool do_not_prompt_for_login) {
660 bool do_not_prompt_for_login,
661 scoped_ptr<DownloadSaveInfo> save_info,
662 uint32_t download_id,
663 const DownloadStartedCallback& started_callback) {
664 if (is_shutdown_) 646 if (is_shutdown_)
665 return CallbackAndReturn(started_callback, 647 return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
666 DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
667 648
668 const GURL& url = request->original_url(); 649 const GURL& url = request->original_url();
669 650
670 // http://crbug.com/90971 651 // http://crbug.com/90971
671 char url_buf[128]; 652 char url_buf[128];
672 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); 653 base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf));
673 base::debug::Alias(url_buf); 654 base::debug::Alias(url_buf);
674 CHECK(ContainsKey(active_resource_contexts_, context)); 655 CHECK(ContainsKey(active_resource_contexts_, context));
675 656
676 SetReferrerForRequest(request.get(), referrer); 657 SetReferrerForRequest(request.get(), referrer);
677 658
678 int extra_load_flags = net::LOAD_NORMAL;
679 if (prefer_cache) {
680 // If there is upload data attached, only retrieve from cache because there
681 // is no current mechanism to prompt the user for their consent for a
682 // re-post. For GETs, try to retrieve data from the cache and skip
683 // validating the entry if present.
684 if (request->get_upload() != NULL)
685 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
686 else
687 extra_load_flags |= net::LOAD_PREFERRING_CACHE;
688 } else {
689 extra_load_flags |= net::LOAD_DISABLE_CACHE;
690 }
691 request->SetLoadFlags(request->load_flags() | extra_load_flags);
692
693 // We treat a download as a main frame load, and thus update the policy URL on 659 // We treat a download as a main frame load, and thus update the policy URL on
694 // redirects. 660 // redirects.
695 // 661 //
696 // TODO(davidben): Is this correct? If this came from a 662 // TODO(davidben): Is this correct? If this came from a
697 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set 663 // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set
698 // appropriately? 664 // appropriately?
699 request->set_first_party_url_policy( 665 request->set_first_party_url_policy(
700 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 666 net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
701 667
702 // Check if the renderer is permitted to request the requested URL. 668 // Check if the renderer is permitted to request the requested URL.
703 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 669 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
704 CanRequestURL(child_id, url)) { 670 CanRequestURL(child_id, url)) {
705 VLOG(1) << "Denied unauthorized download request for " 671 DVLOG(1) << "Denied unauthorized download request for "
706 << url.possibly_invalid_spec(); 672 << url.possibly_invalid_spec();
707 return CallbackAndReturn(started_callback, 673 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
708 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
709 } 674 }
710 675
711 request_id_--; 676 request_id_--;
712 677
713 const net::URLRequestContext* request_context = context->GetRequestContext(); 678 const net::URLRequestContext* request_context = context->GetRequestContext();
714 if (!request_context->job_factory()->IsHandledURL(url)) { 679 if (!request_context->job_factory()->IsHandledURL(url)) {
715 VLOG(1) << "Download request for unsupported protocol: " 680 DVLOG(1) << "Download request for unsupported protocol: "
716 << url.possibly_invalid_spec(); 681 << url.possibly_invalid_spec();
717 return CallbackAndReturn(started_callback, 682 return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
718 DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST);
719 } 683 }
720 684
721 ResourceRequestInfoImpl* extra_info = 685 ResourceRequestInfoImpl* extra_info =
722 CreateRequestInfo(child_id, render_view_route_id, 686 CreateRequestInfo(child_id, render_view_route_id,
723 render_frame_route_id, true, context); 687 render_frame_route_id, true, context);
724 extra_info->set_do_not_prompt_for_login(do_not_prompt_for_login); 688 extra_info->set_do_not_prompt_for_login(do_not_prompt_for_login);
725 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 689 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
726 690
727 if (request->url().SchemeIs(url::kBlobScheme)) { 691 if (request->url().SchemeIs(url::kBlobScheme)) {
728 ChromeBlobStorageContext* blob_context = 692 ChromeBlobStorageContext* blob_context =
729 GetChromeBlobStorageContextForResourceContext(context); 693 GetChromeBlobStorageContextForResourceContext(context);
730 storage::BlobProtocolHandler::SetRequestedBlobDataHandle( 694 storage::BlobProtocolHandler::SetRequestedBlobDataHandle(
731 request.get(), 695 request.get(),
732 blob_context->context()->GetBlobDataFromPublicURL(request->url())); 696 blob_context->context()->GetBlobDataFromPublicURL(request->url()));
733 } 697 }
734 698
735 // From this point forward, the |DownloadResourceHandler| is responsible for 699 // From this point forward, the |DownloadResourceHandler| is responsible for
736 // |started_callback|. 700 // |started_callback|.
737 scoped_ptr<ResourceHandler> handler(CreateResourceHandlerForDownload( 701 scoped_ptr<ResourceHandler> handler(CreateResourceHandlerForDownload(
738 request.get(), is_content_initiated, true, download_id, 702 request.get(), is_content_initiated, true));
739 std::move(save_info), started_callback));
740 703
741 BeginRequestInternal(std::move(request), std::move(handler)); 704 BeginRequestInternal(std::move(request), std::move(handler));
742 705
743 return DOWNLOAD_INTERRUPT_REASON_NONE; 706 return DOWNLOAD_INTERRUPT_REASON_NONE;
744 } 707 }
745 708
746 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest( 709 void ResourceDispatcherHostImpl::ClearLoginDelegateForRequest(
747 net::URLRequest* request) { 710 net::URLRequest* request) {
748 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); 711 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request);
749 if (info) { 712 if (info) {
750 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID()); 713 ResourceLoader* loader = GetLoader(info->GetGlobalRequestID());
751 if (loader) 714 if (loader)
752 loader->ClearLoginDelegate(); 715 loader->ClearLoginDelegate();
753 } 716 }
754 } 717 }
755 718
756 void ResourceDispatcherHostImpl::Shutdown() { 719 void ResourceDispatcherHostImpl::Shutdown() {
757 DCHECK_CURRENTLY_ON(BrowserThread::UI); 720 DCHECK_CURRENTLY_ON(BrowserThread::UI);
758 BrowserThread::PostTask(BrowserThread::IO, 721 BrowserThread::PostTask(BrowserThread::IO,
759 FROM_HERE, 722 FROM_HERE,
760 base::Bind(&ResourceDispatcherHostImpl::OnShutdown, 723 base::Bind(&ResourceDispatcherHostImpl::OnShutdown,
761 base::Unretained(this))); 724 base::Unretained(this)));
762 } 725 }
763 726
764 scoped_ptr<ResourceHandler> 727 scoped_ptr<ResourceHandler>
765 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload( 728 ResourceDispatcherHostImpl::CreateResourceHandlerForDownload(
766 net::URLRequest* request, 729 net::URLRequest* request,
767 bool is_content_initiated, 730 bool is_content_initiated,
768 bool must_download, 731 bool must_download) {
769 uint32_t id, 732 scoped_ptr<ResourceHandler> handler(new DownloadResourceHandler(request));
770 scoped_ptr<DownloadSaveInfo> save_info,
771 const DownloadUrlParameters::OnStartedCallback& started_cb) {
772 scoped_ptr<ResourceHandler> handler(new DownloadResourceHandler(
773 id, request, started_cb, std::move(save_info)));
774 if (delegate_) { 733 if (delegate_) {
775 const ResourceRequestInfoImpl* request_info( 734 const ResourceRequestInfoImpl* request_info(
776 ResourceRequestInfoImpl::ForRequest(request)); 735 ResourceRequestInfoImpl::ForRequest(request));
777 736
778 ScopedVector<ResourceThrottle> throttles; 737 ScopedVector<ResourceThrottle> throttles;
779 delegate_->DownloadStarting( 738 delegate_->DownloadStarting(
780 request, request_info->GetContext(), request_info->GetChildID(), 739 request, request_info->GetContext(), request_info->GetChildID(),
781 request_info->GetRouteID(), request_info->GetRequestID(), 740 request_info->GetRouteID(), request_info->GetRequestID(),
782 is_content_initiated, must_download, &throttles); 741 is_content_initiated, must_download, &throttles);
783 if (!throttles.empty()) { 742 if (!throttles.empty()) {
(...skipping 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after
2561 load_flags |= net::LOAD_PREFETCH; 2520 load_flags |= net::LOAD_PREFETCH;
2562 } 2521 }
2563 2522
2564 if (is_sync_load) 2523 if (is_sync_load)
2565 load_flags |= net::LOAD_IGNORE_LIMITS; 2524 load_flags |= net::LOAD_IGNORE_LIMITS;
2566 2525
2567 return load_flags; 2526 return load_flags;
2568 } 2527 }
2569 2528
2570 } // namespace content 2529 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698