| Index: content/browser/download/download_manager_impl.cc
|
| diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc
|
| index adf9698cb5d7d908e21130451b162156a70df191..2f3ab0936dfe7983aececa289f7984e2eb1492f0 100644
|
| --- a/content/browser/download/download_manager_impl.cc
|
| +++ b/content/browser/download/download_manager_impl.cc
|
| @@ -21,14 +21,19 @@
|
| #include "base/supports_user_data.h"
|
| #include "base/synchronization/lock.h"
|
| #include "build/build_config.h"
|
| +#include "content/browser/blob_storage/chrome_blob_storage_context.h"
|
| #include "content/browser/byte_stream.h"
|
| +#include "content/browser/child_process_security_policy_impl.h"
|
| #include "content/browser/download/download_create_info.h"
|
| #include "content/browser/download/download_file_factory.h"
|
| #include "content/browser/download/download_item_factory.h"
|
| #include "content/browser/download/download_item_impl.h"
|
| #include "content/browser/download/download_stats.h"
|
| #include "content/browser/loader/resource_dispatcher_host_impl.h"
|
| +#include "content/browser/loader/resource_request_info_impl.h"
|
| +#include "content/browser/loader/throttling_resource_handler.h"
|
| #include "content/browser/renderer_host/render_view_host_impl.h"
|
| +#include "content/browser/resource_context_impl.h"
|
| #include "content/browser/web_contents/web_contents_impl.h"
|
| #include "content/public/browser/browser_context.h"
|
| #include "content/public/browser/content_browser_client.h"
|
| @@ -39,6 +44,8 @@
|
| #include "content/public/browser/notification_types.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/resource_context.h"
|
| +#include "content/public/browser/resource_dispatcher_host_delegate.h"
|
| +#include "content/public/browser/resource_throttle.h"
|
| #include "content/public/browser/web_contents_delegate.h"
|
| #include "content/public/common/referrer.h"
|
| #include "net/base/elements_upload_data_stream.h"
|
| @@ -46,12 +53,23 @@
|
| #include "net/base/request_priority.h"
|
| #include "net/base/upload_bytes_element_reader.h"
|
| #include "net/url_request/url_request_context.h"
|
| +#include "storage/browser/blob/blob_storage_context.h"
|
| #include "storage/browser/blob/blob_url_request_job_factory.h"
|
| #include "url/origin.h"
|
|
|
| namespace content {
|
| namespace {
|
|
|
| +// Helper function to create an instance of the DownloadResourceHandler for
|
| +// handling download requests.
|
| +std::unique_ptr<ResourceHandler> CreateResourceHandlerForDownload(
|
| + net::URLRequest* request) {
|
| + DCHECK_CURRENTLY_ON(BrowserThread::IO);
|
| + std::unique_ptr<ResourceHandler> handler(
|
| + new DownloadResourceHandler(request));
|
| + return handler;
|
| +}
|
| +
|
| std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload(
|
| std::unique_ptr<DownloadUrlParameters> params,
|
| content::ResourceContext* resource_context,
|
| @@ -73,14 +91,12 @@ std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> BeginDownload(
|
| // ResourceDispatcherHostImpl which will in turn pass it along to the
|
| // ResourceLoader.
|
| if (params->render_process_host_id() >= 0) {
|
| - DownloadInterruptReason reason =
|
| - ResourceDispatcherHostImpl::Get()->BeginDownload(
|
| - std::move(url_request), params->referrer(),
|
| - params->content_initiated(), resource_context,
|
| - params->render_process_host_id(),
|
| - params->render_view_host_routing_id(),
|
| - params->render_frame_host_routing_id(),
|
| - params->do_not_prompt_for_login());
|
| + DownloadInterruptReason reason = DownloadManagerImpl::BeginDownloadRequest(
|
| + std::move(url_request), params->referrer(), resource_context,
|
| + params->content_initiated(), params->render_process_host_id(),
|
| + params->render_view_host_routing_id(),
|
| + params->render_frame_host_routing_id(),
|
| + params->do_not_prompt_for_login());
|
|
|
| // If the download was accepted, the DownloadResourceHandler is now
|
| // responsible for driving the request to completion.
|
| @@ -521,6 +537,76 @@ void DownloadManagerImpl::RemoveUrlDownloader(UrlDownloader* downloader) {
|
| }
|
| }
|
|
|
| +// static
|
| +void DownloadManagerImpl::ResourceDispatcherHostCreated() {
|
| + ResourceDispatcherHostImpl::Get()->RegisterCreateDownloadHandlerInterceptor(
|
| + base::Bind(&CreateResourceHandlerForDownload));
|
| +}
|
| +
|
| +// static
|
| +DownloadInterruptReason DownloadManagerImpl::BeginDownloadRequest(
|
| + std::unique_ptr<net::URLRequest> url_request,
|
| + const Referrer& referrer,
|
| + ResourceContext* resource_context,
|
| + bool is_content_initiated,
|
| + int render_process_id,
|
| + int render_view_route_id,
|
| + int render_frame_route_id,
|
| + bool do_not_prompt_for_login) {
|
| + // We treat a download as a main frame load, and thus update the policy URL on
|
| + // redirects.
|
| + //
|
| + // TODO(davidben): Is this correct? If this came from a
|
| + // ViewHostMsg_DownloadUrl in a frame, should it have first-party URL set
|
| + // appropriately?
|
| + url_request->set_first_party_url_policy(
|
| + net::URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
|
| +
|
| + const GURL& url = url_request->original_url();
|
| +
|
| + // Check if the renderer is permitted to request the requested URL.
|
| + if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
|
| + render_process_id, url)) {
|
| + DVLOG(1) << "Denied unauthorized download request for "
|
| + << url.possibly_invalid_spec();
|
| + return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
|
| + }
|
| +
|
| + const net::URLRequestContext* request_context = url_request->context();
|
| + if (!request_context->job_factory()->IsHandledURL(url)) {
|
| + DVLOG(1) << "Download request for unsupported protocol: "
|
| + << url.possibly_invalid_spec();
|
| + return DOWNLOAD_INTERRUPT_REASON_NETWORK_INVALID_REQUEST;
|
| + }
|
| +
|
| + if (url.SchemeIs(url::kBlobScheme) &&
|
| + !storage::BlobProtocolHandler::GetRequestBlobDataHandle(
|
| + url_request.get())) {
|
| + ChromeBlobStorageContext* blob_context =
|
| + GetChromeBlobStorageContextForResourceContext(resource_context);
|
| + storage::BlobProtocolHandler::SetRequestedBlobDataHandle(
|
| + url_request.get(),
|
| + blob_context->context()->GetBlobDataFromPublicURL(url));
|
| + }
|
| +
|
| + // From this point forward, the |DownloadResourceHandler| is responsible for
|
| + // |started_callback|.
|
| + // TODO(ananta)
|
| + // Find a better way to create the DownloadResourceHandler instance.
|
| + std::unique_ptr<ResourceHandler> handler(
|
| + CreateResourceHandlerForDownload(url_request.get()));
|
| +
|
| + ResourceDispatcherHostImpl::URLRequestStatus ret =
|
| + ResourceDispatcherHostImpl::Get()->BeginURLRequest(
|
| + std::move(url_request), std::move(handler), referrer,
|
| + true, // download
|
| + is_content_initiated, do_not_prompt_for_login, render_process_id,
|
| + render_view_route_id, render_frame_route_id, resource_context);
|
| + if (ret == ResourceDispatcherHostImpl::URL_REQUEST_FAILED_SHUTDOWN)
|
| + return DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN;
|
| + return DOWNLOAD_INTERRUPT_REASON_NONE;
|
| +}
|
| +
|
| namespace {
|
|
|
| bool EmptyFilter(const GURL& url) {
|
|
|