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

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 2060923002: Neutralize dangerous subresource files during Save Page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@save-package-cleanup-1
Patch Set: Catch up with ToT Created 4 years, 5 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 "chrome/browser/download/chrome_download_manager_delegate.h" 5 #include "chrome/browser/download/chrome_download_manager_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 24 matching lines...) Expand all
35 #include "chrome/browser/platform_util.h" 35 #include "chrome/browser/platform_util.h"
36 #include "chrome/browser/profiles/profile.h" 36 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 37 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
38 #include "chrome/browser/ui/browser.h" 38 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_finder.h" 39 #include "chrome/browser/ui/browser_finder.h"
40 #include "chrome/browser/ui/chrome_pages.h" 40 #include "chrome/browser/ui/chrome_pages.h"
41 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 41 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
42 #include "chrome/common/chrome_constants.h" 42 #include "chrome/common/chrome_constants.h"
43 #include "chrome/common/features.h" 43 #include "chrome/common/features.h"
44 #include "chrome/common/pref_names.h" 44 #include "chrome/common/pref_names.h"
45 #include "chrome/common/safe_browsing/file_type_policies.h"
46 #include "chrome/grit/generated_resources.h"
45 #include "components/pref_registry/pref_registry_syncable.h" 47 #include "components/pref_registry/pref_registry_syncable.h"
46 #include "components/prefs/pref_member.h" 48 #include "components/prefs/pref_member.h"
47 #include "components/prefs/pref_service.h" 49 #include "components/prefs/pref_service.h"
48 #include "content/public/browser/download_item.h" 50 #include "content/public/browser/download_item.h"
49 #include "content/public/browser/download_manager.h" 51 #include "content/public/browser/download_manager.h"
50 #include "content/public/browser/notification_source.h" 52 #include "content/public/browser/notification_source.h"
51 #include "content/public/browser/page_navigator.h" 53 #include "content/public/browser/page_navigator.h"
52 #include "net/base/filename_util.h" 54 #include "net/base/filename_util.h"
53 #include "net/base/mime_util.h" 55 #include "net/base/mime_util.h"
56 #include "ui/base/l10n/l10n_util.h"
54 57
55 #if BUILDFLAG(ANDROID_JAVA_UI) 58 #if BUILDFLAG(ANDROID_JAVA_UI)
56 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info bar_delegate.h" 59 #include "chrome/browser/android/download/chrome_download_manager_overwrite_info bar_delegate.h"
57 #include "chrome/browser/infobars/infobar_service.h" 60 #include "chrome/browser/infobars/infobar_service.h"
58 #endif 61 #endif
59 62
60 #if defined(OS_CHROMEOS) 63 #if defined(OS_CHROMEOS)
61 #include "chrome/browser/chromeos/drive/download_handler.h" 64 #include "chrome/browser/chromeos/drive/download_handler.h"
62 #include "chrome/browser/chromeos/drive/file_system_util.h" 65 #include "chrome/browser/chromeos/drive/file_system_util.h"
63 #endif 66 #endif
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 // Deletes itself. 428 // Deletes itself.
426 new SavePackageFilePicker( 429 new SavePackageFilePicker(
427 web_contents, 430 web_contents,
428 suggested_path, 431 suggested_path,
429 default_extension, 432 default_extension,
430 can_save_as_complete, 433 can_save_as_complete,
431 download_prefs_.get(), 434 download_prefs_.get(),
432 callback); 435 callback);
433 } 436 }
434 437
438 void ChromeDownloadManagerDelegate::SanitizeSavePackageResourceName(
439 base::FilePath* filename) {
440 safe_browsing::FileTypePolicies* file_type_policies =
441 safe_browsing::FileTypePolicies::GetInstance();
442
443 if (file_type_policies->GetFileDangerLevel(*filename) ==
444 safe_browsing::DownloadFileType::NOT_DANGEROUS)
445 return;
446
447 base::FilePath default_filename = base::FilePath::FromUTF8Unsafe(
448 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
449 *filename = filename->AddExtension(default_filename.BaseName().value());
450 }
451
435 void ChromeDownloadManagerDelegate::OpenDownloadUsingPlatformHandler( 452 void ChromeDownloadManagerDelegate::OpenDownloadUsingPlatformHandler(
436 DownloadItem* download) { 453 DownloadItem* download) {
437 base::FilePath platform_path( 454 base::FilePath platform_path(
438 GetPlatformDownloadPath(profile_, download, PLATFORM_TARGET_PATH)); 455 GetPlatformDownloadPath(profile_, download, PLATFORM_TARGET_PATH));
439 DCHECK(!platform_path.empty()); 456 DCHECK(!platform_path.empty());
440 platform_util::OpenItem(profile_, platform_path, platform_util::OPEN_FILE, 457 platform_util::OpenItem(profile_, platform_path, platform_util::OPEN_FILE,
441 platform_util::OpenOperationCallback()); 458 platform_util::OpenOperationCallback());
442 } 459 }
443 460
444 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) { 461 void ChromeDownloadManagerDelegate::OpenDownload(DownloadItem* download) {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) || 789 path.MatchesExtension(FILE_PATH_LITERAL(".xht")) ||
773 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) || 790 path.MatchesExtension(FILE_PATH_LITERAL(".xhtm")) ||
774 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) || 791 path.MatchesExtension(FILE_PATH_LITERAL(".xhtml")) ||
775 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) || 792 path.MatchesExtension(FILE_PATH_LITERAL(".xsl")) ||
776 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) { 793 path.MatchesExtension(FILE_PATH_LITERAL(".xslt"))) {
777 return true; 794 return true;
778 } 795 }
779 #endif 796 #endif
780 return false; 797 return false;
781 } 798 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.h ('k') | chrome/browser/download/save_page_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698