OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Download utilities. | 5 // Download utilities. |
6 | 6 |
7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 7 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 8 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/file_path.h" |
15 #include "gfx/native_widget_types.h" | 16 #include "gfx/native_widget_types.h" |
16 | 17 |
17 #if defined(TOOLKIT_VIEWS) | 18 #if defined(TOOLKIT_VIEWS) |
18 #include "views/view.h" | 19 #include "views/view.h" |
19 #endif | 20 #endif |
20 | 21 |
21 namespace gfx { | 22 namespace gfx { |
22 class Canvas; | 23 class Canvas; |
23 } | 24 } |
24 | 25 |
25 class BaseDownloadItemModel; | 26 class BaseDownloadItemModel; |
26 class DictionaryValue; | 27 class DictionaryValue; |
27 class DownloadItem; | 28 class DownloadItem; |
28 class FilePath; | 29 class DownloadManager; |
29 class GURL; | 30 class GURL; |
| 31 class Profile; |
30 class ResourceDispatcherHost; | 32 class ResourceDispatcherHost; |
31 class SkBitmap; | 33 class SkBitmap; |
32 class URLRequestContextGetter; | 34 class URLRequestContextGetter; |
33 | 35 |
| 36 struct DownloadCreateInfo; |
34 struct DownloadSaveInfo; | 37 struct DownloadSaveInfo; |
35 | 38 |
36 namespace download_util { | 39 namespace download_util { |
37 | 40 |
38 // Download temporary file creation -------------------------------------------- | 41 // Download temporary file creation -------------------------------------------- |
39 | 42 |
40 // Return the default download directory. | 43 // Return the default download directory. |
41 const FilePath& GetDefaultDownloadDirectory(); | 44 const FilePath& GetDefaultDownloadDirectory(); |
42 | 45 |
43 // Create a temporary file for a download in the user's default download | 46 // Create a temporary file for a download in the user's default download |
44 // directory and return true if was successful in creating the file. | 47 // directory and return true if was successful in creating the file. |
45 bool CreateTemporaryFileForDownload(FilePath* path); | 48 bool CreateTemporaryFileForDownload(FilePath* path); |
46 | 49 |
47 // Return true if the |download_path| is dangerous path. | 50 // Return true if the |download_path| is dangerous path. |
48 bool DownloadPathIsDangerous(const FilePath& download_path); | 51 bool DownloadPathIsDangerous(const FilePath& download_path); |
49 | 52 |
| 53 // Create an extension based on the file name and mime type. |
| 54 void GenerateExtension(const FilePath& file_name, |
| 55 const std::string& mime_type, |
| 56 FilePath::StringType* generated_extension); |
| 57 |
| 58 // Create a file name based on the response from the server. |
| 59 void GenerateFileNameFromInfo(DownloadCreateInfo* info, |
| 60 FilePath* generated_name); |
| 61 |
| 62 // Create a file name based on the response from the server. |
| 63 void GenerateFileName(const GURL& url, |
| 64 const std::string& content_disposition, |
| 65 const std::string& referrer_charset, |
| 66 const std::string& mime_type, |
| 67 FilePath* generated_name); |
| 68 |
| 69 // Used to make sure we have a safe file extension and filename for a |
| 70 // download. |file_name| can either be just the file name or it can be a |
| 71 // full path to a file. |
| 72 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name); |
| 73 |
| 74 // Opens downloaded Chrome extension file (*.crx). |
| 75 void OpenChromeExtension(Profile* profile, |
| 76 DownloadManager* download_manager, |
| 77 const DownloadItem& download_item); |
| 78 |
50 // Download progress animations ------------------------------------------------ | 79 // Download progress animations ------------------------------------------------ |
51 | 80 |
52 // Arc sweep angle for use with downloads of unknown size | 81 // Arc sweep angle for use with downloads of unknown size |
53 const int kUnknownAngleDegrees = 50; | 82 const int kUnknownAngleDegrees = 50; |
54 | 83 |
55 // Rate of progress for use with downloads of unknown size | 84 // Rate of progress for use with downloads of unknown size |
56 const int kUnknownIncrementDegrees = 12; | 85 const int kUnknownIncrementDegrees = 12; |
57 | 86 |
58 // Start angle for downloads with known size (midnight position) | 87 // Start angle for downloads with known size (midnight position) |
59 const int kStartAngleDegrees = -90; | 88 const int kStartAngleDegrees = -90; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 // Helper function for download views to use when acting as a drag source for a | 147 // Helper function for download views to use when acting as a drag source for a |
119 // DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view| | 148 // DownloadItem. If |icon| is NULL, no image will be accompany the drag. |view| |
120 // is only required for Mac OS X, elsewhere it can be NULL. | 149 // is only required for Mac OS X, elsewhere it can be NULL. |
121 void DragDownload(const DownloadItem* download, | 150 void DragDownload(const DownloadItem* download, |
122 SkBitmap* icon, | 151 SkBitmap* icon, |
123 gfx::NativeView view); | 152 gfx::NativeView view); |
124 | 153 |
125 // Executable file support ----------------------------------------------------- | 154 // Executable file support ----------------------------------------------------- |
126 | 155 |
127 // Determine if the specified extension is an executable extension. | 156 // Determine if the specified extension is an executable extension. |
128 bool IsExecutableExtension(const std::string& extension); | 157 bool IsExecutableExtension(const FilePath::StringType& extension); |
| 158 |
| 159 // Tests if we think the server means for this mime_type to be executable. |
| 160 bool IsExecutableMimeType(const std::string& mime_type); |
129 | 161 |
130 // Helpers --------------------------------------------------------------------- | 162 // Helpers --------------------------------------------------------------------- |
131 | 163 |
132 // Creates a representation of a download in a format that the downloads | 164 // Creates a representation of a download in a format that the downloads |
133 // HTML page can understand. | 165 // HTML page can understand. |
134 DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id); | 166 DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id); |
135 | 167 |
136 // Get the localized status text for an in-progress download. | 168 // Get the localized status text for an in-progress download. |
137 std::wstring GetProgressStatusText(DownloadItem* download); | 169 std::wstring GetProgressStatusText(DownloadItem* download); |
138 | 170 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // If |path| does not exist, 0 is returned. If it fails to find such | 207 // If |path| does not exist, 0 is returned. If it fails to find such |
176 // a number, -1 is returned. | 208 // a number, -1 is returned. |
177 int GetUniquePathNumberWithCrDownload(const FilePath& path); | 209 int GetUniquePathNumberWithCrDownload(const FilePath& path); |
178 | 210 |
179 // Returns a .crdownload intermediate path for the |suggested_path|. | 211 // Returns a .crdownload intermediate path for the |suggested_path|. |
180 FilePath GetCrDownloadPath(const FilePath& suggested_path); | 212 FilePath GetCrDownloadPath(const FilePath& suggested_path); |
181 | 213 |
182 } // namespace download_util | 214 } // namespace download_util |
183 | 215 |
184 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ | 216 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_UTIL_H_ |
OLD | NEW |