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

Side by Side Diff: content/browser/download/save_file_manager.cc

Issue 2075273002: Resource requests from Save-Page-As should go through CanRequestURL checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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/download/save_file.h" 15 #include "content/browser/download/save_file.h"
16 #include "content/browser/download/save_package.h" 16 #include "content/browser/download/save_package.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 17 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/browser/renderer_host/render_view_host_impl.h" 18 #include "content/browser/renderer_host/render_view_host_impl.h"
19 #include "content/browser/web_contents/web_contents_impl.h" 19 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_frame_host.h" 21 #include "content/public/browser/render_frame_host.h"
22 #include "net/base/filename_util.h"
23 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
24 #include "url/gurl.h" 23 #include "url/gurl.h"
25 24
26 namespace content { 25 namespace content {
27 26
28 SaveFileManager::SaveFileManager() {} 27 SaveFileManager::SaveFileManager() {}
29 28
30 SaveFileManager::~SaveFileManager() { 29 SaveFileManager::~SaveFileManager() {
31 // Check for clean shutdown. 30 // Check for clean shutdown.
32 DCHECK(save_file_map_.empty()); 31 DCHECK(save_file_map_.empty());
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 save_file->render_process_id(), save_file->request_id())); 316 save_file->render_process_id(), save_file->request_id()));
318 } 317 }
319 318
320 // Whatever the save file is complete or not, just delete it. This 319 // Whatever the save file is complete or not, just delete it. This
321 // will delete the underlying file if InProgress() is true. 320 // will delete the underlying file if InProgress() is true.
322 save_file_map_.erase(it); 321 save_file_map_.erase(it);
323 delete save_file; 322 delete save_file;
324 } 323 }
325 } 324 }
326 325
327 // It is possible that SaveItem which has specified save_item_id has been
328 // canceled
329 // before this function runs. So if we can not find corresponding SaveFile by
330 // using specified save_item_id, just return.
331 void SaveFileManager::SaveLocalFile(const GURL& original_file_url,
332 SaveItemId save_item_id,
333 SavePackageId save_package_id) {
334 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
335 SaveFile* save_file = LookupSaveFile(save_item_id);
336 if (!save_file)
337 return;
338 // If it has finished, just return.
339 if (!save_file->InProgress())
340 return;
341
342 // Close the save file before the copy operation.
343 save_file->Finish();
344 save_file->Detach();
345
346 DCHECK(original_file_url.SchemeIsFile());
347 base::FilePath file_path;
348 net::FileURLToFilePath(original_file_url, &file_path);
349 // If we can not get valid file path from original URL, treat it as
350 // disk error.
351 if (file_path.empty())
352 SaveFinished(save_item_id, save_package_id, false);
353
354 // Copy the local file to the temporary file. It will be renamed to its
355 // final name later.
356 bool success = base::CopyFile(file_path, save_file->FullPath());
357 if (!success)
358 base::DeleteFile(save_file->FullPath(), false);
359 SaveFinished(save_item_id, save_package_id, success);
360 }
Łukasz Anforowicz 2016/06/18 00:37:20 The deleted code was added in the "initial commit"
361
362 void SaveFileManager::OnDeleteDirectoryOrFile(const base::FilePath& full_path, 326 void SaveFileManager::OnDeleteDirectoryOrFile(const base::FilePath& full_path,
363 bool is_dir) { 327 bool is_dir) {
364 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 328 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
365 DCHECK(!full_path.empty()); 329 DCHECK(!full_path.empty());
366 330
367 base::DeleteFile(full_path, is_dir); 331 base::DeleteFile(full_path, is_dir);
368 } 332 }
369 333
370 void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names, 334 void SaveFileManager::RenameAllFiles(const FinalNamesMap& final_names,
371 const base::FilePath& resource_dir, 335 const base::FilePath& resource_dir,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 SaveFile* save_file = it->second; 383 SaveFile* save_file = it->second;
420 DCHECK(!save_file->InProgress()); 384 DCHECK(!save_file->InProgress());
421 base::DeleteFile(save_file->FullPath(), false); 385 base::DeleteFile(save_file->FullPath(), false);
422 delete save_file; 386 delete save_file;
423 save_file_map_.erase(it); 387 save_file_map_.erase(it);
424 } 388 }
425 } 389 }
426 } 390 }
427 391
428 } // namespace content 392 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698