Chromium Code Reviews| Index: content/browser/download/save_file_manager.cc |
| diff --git a/content/browser/download/save_file_manager.cc b/content/browser/download/save_file_manager.cc |
| index bd554b079a14d611e190f718011d07f874586bd0..e94a14ef14a07eff50e8fd634261e13906068325 100644 |
| --- a/content/browser/download/save_file_manager.cc |
| +++ b/content/browser/download/save_file_manager.cc |
| @@ -12,14 +12,22 @@ |
| #include "base/stl_util.h" |
| #include "base/strings/string_util.h" |
| #include "base/threading/thread.h" |
| +#include "content/browser/child_process_security_policy_impl.h" |
| #include "content/browser/download/save_file.h" |
| +#include "content/browser/download/save_file_resource_handler.h" |
| #include "content/browser/download/save_package.h" |
| #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| +#include "content/browser/loader/resource_request_info_impl.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/resource_context.h" |
| #include "net/base/io_buffer.h" |
| +#include "net/base/load_flags.h" |
| +#include "net/url_request/url_request.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_job_factory.h" |
| #include "url/gurl.h" |
| namespace content { |
| @@ -289,9 +297,54 @@ void SaveFileManager::OnSaveURL(const GURL& url, |
| int render_frame_routing_id, |
| ResourceContext* context) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - ResourceDispatcherHostImpl::Get()->BeginSaveFile( |
| - url, referrer, save_item_id, save_package_id, render_process_host_id, |
| - render_view_routing_id, render_frame_routing_id, context); |
| + |
| + if (ResourceDispatcherHostImpl::Get()->is_shutdown()) |
| + return; |
|
Randy Smith (Not in Mondays)
2016/08/18 17:38:57
Save question as previous--can this be lowered int
ananta
2016/08/18 22:27:09
Done.
|
| + |
| + const net::URLRequestContext* request_context = context->GetRequestContext(); |
| + bool known_proto = request_context->job_factory()->IsHandledURL(url); |
| + if (!known_proto) { |
| + // Since any URLs which have non-standard scheme have been filtered |
| + // by save manager(see GURL::SchemeIsStandard). This situation |
| + // should not happen. |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + std::unique_ptr<net::URLRequest> request( |
| + request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); |
| + request->set_method("GET"); |
| + |
| + // So far, for saving page, we need fetch content from cache, in the |
| + // future, maybe we can use a configuration to configure this behavior. |
| + request->SetLoadFlags(net::LOAD_PREFERRING_CACHE); |
| + |
| + // Since we're just saving some resources we need, disallow downloading. |
| + ResourceRequestInfoImpl* extra_info = |
| + ResourceDispatcherHostImpl::Get()->CreateRequestInfo( |
| + render_process_host_id, render_view_routing_id, |
| + render_frame_routing_id, false, context); |
| + extra_info->AssociateWithRequest(request.get()); // Request takes ownership. |
|
Randy Smith (Not in Mondays)
2016/08/18 17:38:57
Same question as elsewhere: Can we pass this into
ananta
2016/08/18 22:27:09
Done.
|
| + |
| + // Check if the renderer is permitted to request the requested URL. |
| + using AuthorizationState = SaveFileResourceHandler::AuthorizationState; |
| + AuthorizationState authorization_state = AuthorizationState::AUTHORIZED; |
| + if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( |
| + render_process_host_id, url)) { |
| + DVLOG(1) << "Denying unauthorized save of " << url.possibly_invalid_spec(); |
| + authorization_state = AuthorizationState::NOT_AUTHORIZED; |
| + // No need to return here (i.e. okay to begin processing the request below), |
| + // because NOT_AUTHORIZED will cause the request to be cancelled. See also |
| + // doc comments for AuthorizationState enum. |
| + } |
| + |
| + std::unique_ptr<SaveFileResourceHandler> handler(new SaveFileResourceHandler( |
| + request.get(), save_item_id, save_package_id, render_process_host_id, |
| + render_frame_routing_id, url, authorization_state)); |
| + |
| + ResourceDispatcherHostImpl::Get()->BeginURLRequest(std::move(request), |
| + referrer, |
| + std::move(handler)); |
| } |
| void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, |