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

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

Issue 1982723002: Use FileTypePolicies for download danger classifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_policies
Patch Set: Fix bad rebase Created 4 years, 7 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/download_prefs.h" 5 #include "chrome/browser/download/download_prefs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
15 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/sys_string_conversions.h" 21 #include "base/strings/sys_string_conversions.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "chrome/browser/download/chrome_download_manager_delegate.h" 24 #include "chrome/browser/download/chrome_download_manager_delegate.h"
25 #include "chrome/browser/download/download_extensions.h"
26 #include "chrome/browser/download/download_service.h" 25 #include "chrome/browser/download/download_service.h"
27 #include "chrome/browser/download/download_service_factory.h" 26 #include "chrome/browser/download/download_service_factory.h"
28 #include "chrome/browser/download/download_target_determiner.h" 27 #include "chrome/browser/download/download_target_determiner.h"
29 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/profiles/profile_manager.h" 29 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
32 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/safe_browsing/file_type_policies.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 33 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/download_manager.h" 36 #include "content/public/browser/download_manager.h"
37 #include "content/public/browser/save_page_type.h" 37 #include "content/public/browser/save_page_type.h"
38 38
39 #if defined(OS_CHROMEOS) 39 #if defined(OS_CHROMEOS)
40 #include "chrome/browser/chromeos/drive/drive_integration_service.h" 40 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
41 #include "chrome/browser/chromeos/drive/file_system_util.h" 41 #include "chrome/browser/chromeos/drive/file_system_util.h"
42 #include "chrome/browser/chromeos/file_manager/path_util.h" 42 #include "chrome/browser/chromeos/file_manager/path_util.h"
43 #endif 43 #endif
44 44
45 #if defined(OS_WIN) 45 #if defined(OS_WIN)
46 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" 46 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
47 #endif 47 #endif
48 48
49 using content::BrowserContext; 49 using content::BrowserContext;
50 using content::BrowserThread; 50 using content::BrowserThread;
51 using content::DownloadManager; 51 using content::DownloadManager;
52 using safe_browsing::FileTypePolicies;
52 53
53 namespace { 54 namespace {
54 55
55 // Consider downloads 'dangerous' if they go to the home directory on Linux and 56 // Consider downloads 'dangerous' if they go to the home directory on Linux and
56 // to the desktop on any platform. 57 // to the desktop on any platform.
57 bool DownloadPathIsDangerous(const base::FilePath& download_path) { 58 bool DownloadPathIsDangerous(const base::FilePath& download_path) {
58 #if defined(OS_LINUX) 59 #if defined(OS_LINUX)
59 base::FilePath home_dir = base::GetHomeDir(); 60 base::FilePath home_dir = base::GetHomeDir();
60 if (download_path == home_dir) { 61 if (download_path == home_dir) {
61 return true; 62 return true;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // Construct something like ".<extension>", since 181 // Construct something like ".<extension>", since
181 // IsAllowedToOpenAutomatically() needs a filename. 182 // IsAllowedToOpenAutomatically() needs a filename.
182 base::FilePath filename_with_extension = base::FilePath( 183 base::FilePath filename_with_extension = base::FilePath(
183 base::FilePath::StringType(1, base::FilePath::kExtensionSeparator) + 184 base::FilePath::StringType(1, base::FilePath::kExtensionSeparator) +
184 extension); 185 extension);
185 186
186 // Note that the list of file types that are not allowed to open 187 // Note that the list of file types that are not allowed to open
187 // automatically can change in the future. When the list is tightened, it is 188 // automatically can change in the future. When the list is tightened, it is
188 // expected that some entries in the users' auto open list will get dropped 189 // expected that some entries in the users' auto open list will get dropped
189 // permanently as a result. 190 // permanently as a result.
190 if (download_util::IsAllowedToOpenAutomatically(filename_with_extension)) 191 if (FileTypePolicies::GetInstance()->IsAllowedToOpenAutomatically(
192 filename_with_extension))
191 auto_open_.insert(extension); 193 auto_open_.insert(extension);
192 } 194 }
193 } 195 }
194 196
195 DownloadPrefs::~DownloadPrefs() {} 197 DownloadPrefs::~DownloadPrefs() {}
196 198
197 // static 199 // static
198 void DownloadPrefs::RegisterProfilePrefs( 200 void DownloadPrefs::RegisterProfilePrefs(
199 user_prefs::PrefRegistrySyncable* registry) { 201 user_prefs::PrefRegistrySyncable* registry) {
200 registry->RegisterBooleanPref( 202 registry->RegisterBooleanPref(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 if (extension == FILE_PATH_LITERAL("pdf") && ShouldOpenPdfInSystemReader()) 308 if (extension == FILE_PATH_LITERAL("pdf") && ShouldOpenPdfInSystemReader())
307 return true; 309 return true;
308 #endif 310 #endif
309 311
310 return auto_open_.find(extension) != auto_open_.end(); 312 return auto_open_.find(extension) != auto_open_.end();
311 } 313 }
312 314
313 bool DownloadPrefs::EnableAutoOpenBasedOnExtension( 315 bool DownloadPrefs::EnableAutoOpenBasedOnExtension(
314 const base::FilePath& file_name) { 316 const base::FilePath& file_name) {
315 base::FilePath::StringType extension = file_name.Extension(); 317 base::FilePath::StringType extension = file_name.Extension();
316 if (!download_util::IsAllowedToOpenAutomatically(file_name)) 318 if (!FileTypePolicies::GetInstance()->IsAllowedToOpenAutomatically(
319 file_name))
317 return false; 320 return false;
318 321
319 DCHECK(extension[0] == base::FilePath::kExtensionSeparator); 322 DCHECK(extension[0] == base::FilePath::kExtensionSeparator);
320 extension.erase(0, 1); 323 extension.erase(0, 1);
321 324
322 auto_open_.insert(extension); 325 auto_open_.insert(extension);
323 SaveAutoOpenState(); 326 SaveAutoOpenState();
324 return true; 327 return true;
325 } 328 }
326 329
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 extensions.erase(extensions.size() - 1); 382 extensions.erase(extensions.size() - 1);
380 383
381 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); 384 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions);
382 } 385 }
383 386
384 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 387 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
385 const base::FilePath::StringType& a, 388 const base::FilePath::StringType& a,
386 const base::FilePath::StringType& b) const { 389 const base::FilePath::StringType& b) const {
387 return base::FilePath::CompareLessIgnoreCase(a, b); 390 return base::FilePath::CompareLessIgnoreCase(a, b);
388 } 391 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model_unittest.cc ('k') | chrome/browser/download/download_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698