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

Side by Side 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: Address next round of review comments and keep the download test in resource_dispatcher_host_unitteā€¦ Created 4 years, 3 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
« no previous file with comments | « content/browser/download/download_resource_handler.cc ('k') | content/browser/loader/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "content/browser/download/save_file_manager.h" 7 #include "content/browser/download/save_file_manager.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "content/browser/child_process_security_policy_impl.h"
15 #include "content/browser/download/save_file.h" 16 #include "content/browser/download/save_file.h"
17 #include "content/browser/download/save_file_resource_handler.h"
16 #include "content/browser/download/save_package.h" 18 #include "content/browser/download/save_package.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 19 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/browser/renderer_host/render_view_host_impl.h" 20 #include "content/browser/renderer_host/render_view_host_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 21 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/resource_context.h"
22 #include "net/base/io_buffer.h" 25 #include "net/base/io_buffer.h"
26 #include "net/base/load_flags.h"
27 #include "net/url_request/url_request.h"
28 #include "net/url_request/url_request_context.h"
29 #include "net/url_request/url_request_job_factory.h"
23 #include "url/gurl.h" 30 #include "url/gurl.h"
24 31
25 namespace content { 32 namespace content {
26 33
27 namespace { 34 namespace {
28 35
29 // Pointer to the singleton SaveFileManager instance. 36 // Pointer to the singleton SaveFileManager instance.
30 static SaveFileManager* g_save_file_manager = nullptr; 37 static SaveFileManager* g_save_file_manager = nullptr;
31 38
32 } // namespace 39 } // namespace
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 289
283 void SaveFileManager::OnSaveURL(const GURL& url, 290 void SaveFileManager::OnSaveURL(const GURL& url,
284 const Referrer& referrer, 291 const Referrer& referrer,
285 SaveItemId save_item_id, 292 SaveItemId save_item_id,
286 SavePackageId save_package_id, 293 SavePackageId save_package_id,
287 int render_process_host_id, 294 int render_process_host_id,
288 int render_view_routing_id, 295 int render_view_routing_id,
289 int render_frame_routing_id, 296 int render_frame_routing_id,
290 ResourceContext* context) { 297 ResourceContext* context) {
291 DCHECK_CURRENTLY_ON(BrowserThread::IO); 298 DCHECK_CURRENTLY_ON(BrowserThread::IO);
292 ResourceDispatcherHostImpl::Get()->BeginSaveFile( 299
293 url, referrer, save_item_id, save_package_id, render_process_host_id, 300 const net::URLRequestContext* request_context = context->GetRequestContext();
294 render_view_routing_id, render_frame_routing_id, context); 301 if (!request_context->job_factory()->IsHandledURL(url)) {
302 // Since any URLs which have non-standard scheme have been filtered
303 // by save manager(see GURL::SchemeIsStandard). This situation
304 // should not happen.
305 NOTREACHED();
306 return;
307 }
308
309 std::unique_ptr<net::URLRequest> request(
310 request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL));
311 request->set_method("GET");
312
313 // The URLRequest needs to be initialized with the referrer and other
314 // information prior to issuing it.
315 ResourceDispatcherHostImpl::Get()->InitializeURLRequest(
316 request.get(), referrer,
317 false, // download.
318 render_process_host_id, render_view_routing_id, render_frame_routing_id,
319 context);
320
321 // So far, for saving page, we need fetch content from cache, in the
322 // future, maybe we can use a configuration to configure this behavior.
323 request->SetLoadFlags(net::LOAD_PREFERRING_CACHE);
324
325 // Check if the renderer is permitted to request the requested URL.
326 using AuthorizationState = SaveFileResourceHandler::AuthorizationState;
327 AuthorizationState authorization_state = AuthorizationState::AUTHORIZED;
328 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
329 render_process_host_id, url)) {
330 DVLOG(1) << "Denying unauthorized save of " << url.possibly_invalid_spec();
331 authorization_state = AuthorizationState::NOT_AUTHORIZED;
332 // No need to return here (i.e. okay to begin processing the request below),
333 // because NOT_AUTHORIZED will cause the request to be cancelled. See also
334 // doc comments for AuthorizationState enum.
335 }
336
337 std::unique_ptr<SaveFileResourceHandler> handler(new SaveFileResourceHandler(
338 request.get(), save_item_id, save_package_id, render_process_host_id,
339 render_frame_routing_id, url, authorization_state));
340
341 ResourceDispatcherHostImpl::Get()->BeginURLRequest(
342 std::move(request), std::move(handler),
343 false, // download
344 false, // content_initiated (download specific)
345 false, // do_not_prompt_for_login (download specific)
346 context);
295 } 347 }
296 348
297 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id, 349 void SaveFileManager::ExecuteCancelSaveRequest(int render_process_id,
298 int request_id) { 350 int request_id) {
299 DCHECK_CURRENTLY_ON(BrowserThread::IO); 351 DCHECK_CURRENTLY_ON(BrowserThread::IO);
300 ResourceDispatcherHostImpl::Get()->CancelRequest( 352 ResourceDispatcherHostImpl::Get()->CancelRequest(
301 render_process_id, request_id); 353 render_process_id, request_id);
302 } 354 }
303 355
304 // Notifications sent from the UI thread and run on the file thread. 356 // Notifications sent from the UI thread and run on the file thread.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 SaveFile* save_file = it->second; 450 SaveFile* save_file = it->second;
399 DCHECK(!save_file->InProgress()); 451 DCHECK(!save_file->InProgress());
400 base::DeleteFile(save_file->FullPath(), false); 452 base::DeleteFile(save_file->FullPath(), false);
401 delete save_file; 453 delete save_file;
402 save_file_map_.erase(it); 454 save_file_map_.erase(it);
403 } 455 }
404 } 456 }
405 } 457 }
406 458
407 } // namespace content 459 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_resource_handler.cc ('k') | content/browser/loader/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698