OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/string_split.h" | 8 #include "base/string_split.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 prefs->GetString(prefs::kDownloadExtensionsToOpen); | 23 prefs->GetString(prefs::kDownloadExtensionsToOpen); |
24 std::vector<std::string> extensions; | 24 std::vector<std::string> extensions; |
25 base::SplitString(extensions_to_open, ':', &extensions); | 25 base::SplitString(extensions_to_open, ':', &extensions); |
26 | 26 |
27 for (size_t i = 0; i < extensions.size(); ++i) { | 27 for (size_t i = 0; i < extensions.size(); ++i) { |
28 #if defined(OS_POSIX) | 28 #if defined(OS_POSIX) |
29 FilePath path(extensions[i]); | 29 FilePath path(extensions[i]); |
30 #elif defined(OS_WIN) | 30 #elif defined(OS_WIN) |
31 FilePath path(UTF8ToWide(extensions[i])); | 31 FilePath path(UTF8ToWide(extensions[i])); |
32 #endif | 32 #endif |
33 if (!extensions[i].empty() && !download_util::IsExecutableFile(path)) | 33 if (!extensions[i].empty() && download_util::IsFileSafe(path)) |
34 auto_open_.insert(path.value()); | 34 auto_open_.insert(path.value()); |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
38 DownloadPrefs::~DownloadPrefs() { | 38 DownloadPrefs::~DownloadPrefs() { |
39 SaveAutoOpenState(); | 39 SaveAutoOpenState(); |
40 } | 40 } |
41 | 41 |
42 // static | 42 // static |
43 void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) { | 43 void DownloadPrefs::RegisterUserPrefs(PrefService* prefs) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const FilePath::StringType& extension) const { | 80 const FilePath::StringType& extension) const { |
81 return auto_open_.find(extension) != auto_open_.end(); | 81 return auto_open_.find(extension) != auto_open_.end(); |
82 } | 82 } |
83 | 83 |
84 bool DownloadPrefs::EnableAutoOpenBasedOnExtension(const FilePath& file_name) { | 84 bool DownloadPrefs::EnableAutoOpenBasedOnExtension(const FilePath& file_name) { |
85 FilePath::StringType extension = file_name.Extension(); | 85 FilePath::StringType extension = file_name.Extension(); |
86 if (extension.empty()) | 86 if (extension.empty()) |
87 return false; | 87 return false; |
88 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 88 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
89 extension.erase(0, 1); | 89 extension.erase(0, 1); |
90 if (download_util::IsExecutableExtension(extension)) | 90 if (!download_util::IsFileExtensionSafe(extension)) |
91 return false; | 91 return false; |
92 | 92 |
93 auto_open_.insert(extension); | 93 auto_open_.insert(extension); |
94 SaveAutoOpenState(); | 94 SaveAutoOpenState(); |
95 return true; | 95 return true; |
96 } | 96 } |
97 | 97 |
98 void DownloadPrefs::DisableAutoOpenBasedOnExtension(const FilePath& file_name) { | 98 void DownloadPrefs::DisableAutoOpenBasedOnExtension(const FilePath& file_name) { |
99 FilePath::StringType extension = file_name.Extension(); | 99 FilePath::StringType extension = file_name.Extension(); |
100 if (extension.empty()) | 100 if (extension.empty()) |
(...skipping 30 matching lines...) Expand all Loading... |
131 extensions.erase(extensions.size() - 1); | 131 extensions.erase(extensions.size() - 1); |
132 | 132 |
133 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); | 133 prefs_->SetString(prefs::kDownloadExtensionsToOpen, extensions); |
134 } | 134 } |
135 | 135 |
136 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( | 136 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( |
137 const FilePath::StringType& a, | 137 const FilePath::StringType& a, |
138 const FilePath::StringType& b) const { | 138 const FilePath::StringType& b) const { |
139 return FilePath::CompareLessIgnoreCase(a, b); | 139 return FilePath::CompareLessIgnoreCase(a, b); |
140 } | 140 } |
OLD | NEW |