OLD | NEW |
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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "components/prefs/pref_member.h" | 13 #include "components/prefs/pref_member.h" |
14 | 14 |
15 class Profile; | 15 class Profile; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class BrowserContext; | 18 class BrowserContext; |
19 class DownloadManager; | 19 class DownloadManager; |
20 } | 20 } |
21 | 21 |
22 namespace user_prefs { | 22 namespace user_prefs { |
23 class PrefRegistrySyncable; | 23 class PrefRegistrySyncable; |
24 } | 24 } |
25 | 25 |
26 // Stores all download-related preferences. | 26 // Stores all download-related preferences. |
27 class DownloadPrefs { | 27 class DownloadPrefs { |
28 public: | 28 public: |
| 29 enum class DownloadRestriction { |
| 30 NONE = 0, |
| 31 DANGEROUS_FILES = 1, |
| 32 POTENTIALLY_DANGEROUS_FILES = 2, |
| 33 ALL_FILES = 3, |
| 34 }; |
29 explicit DownloadPrefs(Profile* profile); | 35 explicit DownloadPrefs(Profile* profile); |
30 ~DownloadPrefs(); | 36 ~DownloadPrefs(); |
31 | 37 |
32 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
33 | 39 |
34 // Returns the default download directory. | 40 // Returns the default download directory. |
35 static const base::FilePath& GetDefaultDownloadDirectory(); | 41 static const base::FilePath& GetDefaultDownloadDirectory(); |
36 | 42 |
37 // Returns the default download directory for the current profile. | 43 // Returns the default download directory for the current profile. |
38 base::FilePath GetDefaultDownloadDirectoryForProfile() const; | 44 base::FilePath GetDefaultDownloadDirectoryForProfile() const; |
39 | 45 |
40 // Returns the DownloadPrefs corresponding to the given DownloadManager | 46 // Returns the DownloadPrefs corresponding to the given DownloadManager |
41 // or BrowserContext. | 47 // or BrowserContext. |
42 static DownloadPrefs* FromDownloadManager( | 48 static DownloadPrefs* FromDownloadManager( |
43 content::DownloadManager* download_manager); | 49 content::DownloadManager* download_manager); |
44 static DownloadPrefs* FromBrowserContext( | 50 static DownloadPrefs* FromBrowserContext( |
45 content::BrowserContext* browser_context); | 51 content::BrowserContext* browser_context); |
46 | 52 |
47 base::FilePath DownloadPath() const; | 53 base::FilePath DownloadPath() const; |
48 void SetDownloadPath(const base::FilePath& path); | 54 void SetDownloadPath(const base::FilePath& path); |
49 base::FilePath SaveFilePath() const; | 55 base::FilePath SaveFilePath() const; |
50 void SetSaveFilePath(const base::FilePath& path); | 56 void SetSaveFilePath(const base::FilePath& path); |
51 int save_file_type() const { return *save_file_type_; } | 57 int save_file_type() const { return *save_file_type_; } |
52 void SetSaveFileType(int type); | 58 void SetSaveFileType(int type); |
| 59 DownloadRestriction download_restriction() const { |
| 60 return static_cast<DownloadRestriction>(*download_restriction_); |
| 61 } |
53 | 62 |
54 // Returns true if the prompt_for_download preference has been set and the | 63 // Returns true if the prompt_for_download preference has been set and the |
55 // download location is not managed (which means the user shouldn't be able | 64 // download location is not managed (which means the user shouldn't be able |
56 // to choose another download location). | 65 // to choose another download location). |
57 bool PromptForDownload() const; | 66 bool PromptForDownload() const; |
58 | 67 |
59 // Returns true if the download path preference is managed. | 68 // Returns true if the download path preference is managed. |
60 bool IsDownloadPathManaged() const; | 69 bool IsDownloadPathManaged() const; |
61 | 70 |
62 // Returns true if there is at least one file extension registered | 71 // Returns true if there is at least one file extension registered |
(...skipping 29 matching lines...) Expand all Loading... |
92 | 101 |
93 private: | 102 private: |
94 void SaveAutoOpenState(); | 103 void SaveAutoOpenState(); |
95 | 104 |
96 Profile* profile_; | 105 Profile* profile_; |
97 | 106 |
98 BooleanPrefMember prompt_for_download_; | 107 BooleanPrefMember prompt_for_download_; |
99 FilePathPrefMember download_path_; | 108 FilePathPrefMember download_path_; |
100 FilePathPrefMember save_file_path_; | 109 FilePathPrefMember save_file_path_; |
101 IntegerPrefMember save_file_type_; | 110 IntegerPrefMember save_file_type_; |
| 111 IntegerPrefMember download_restriction_; |
102 | 112 |
103 // Set of file extensions to open at download completion. | 113 // Set of file extensions to open at download completion. |
104 struct AutoOpenCompareFunctor { | 114 struct AutoOpenCompareFunctor { |
105 bool operator()(const base::FilePath::StringType& a, | 115 bool operator()(const base::FilePath::StringType& a, |
106 const base::FilePath::StringType& b) const; | 116 const base::FilePath::StringType& b) const; |
107 }; | 117 }; |
108 typedef std::set<base::FilePath::StringType, | 118 typedef std::set<base::FilePath::StringType, |
109 AutoOpenCompareFunctor> AutoOpenSet; | 119 AutoOpenCompareFunctor> AutoOpenSet; |
110 AutoOpenSet auto_open_; | 120 AutoOpenSet auto_open_; |
111 | 121 |
112 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) | 122 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
113 bool should_open_pdf_in_system_reader_; | 123 bool should_open_pdf_in_system_reader_; |
114 #endif | 124 #endif |
115 | 125 |
116 DISALLOW_COPY_AND_ASSIGN(DownloadPrefs); | 126 DISALLOW_COPY_AND_ASSIGN(DownloadPrefs); |
117 }; | 127 }; |
118 | 128 |
119 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ | 129 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PREFS_H_ |
OLD | NEW |