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

Unified Diff: content/browser/download/save_file_manager.cc

Issue 2251643003: Remove the BeginSaveFile and BeginDownload methods from ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content_unittests compile failures. The BeginDownloadHelper function is now a static public fun… Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
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..a16a9c7db8def16f91df6af4b2631a8880062ffd 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,55 @@ 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;
+
+ 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");
+ if (referrer.url.is_valid())
+ request->SetReferrer(referrer.url.spec());
+
+ // 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.
+
+ // 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),
+ std::move(handler));
}
void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id,

Powered by Google App Engine
This is Rietveld 408576698