OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #if defined(TOOLKIT_USES_GTK) | 62 #if defined(TOOLKIT_USES_GTK) |
63 #if defined(TOOLKIT_VIEWS) | 63 #if defined(TOOLKIT_VIEWS) |
64 #include "ui/base/dragdrop/drag_drop_types.h" | 64 #include "ui/base/dragdrop/drag_drop_types.h" |
65 #include "views/widget/widget_gtk.h" | 65 #include "views/widget/widget_gtk.h" |
66 #elif defined(TOOLKIT_GTK) | 66 #elif defined(TOOLKIT_GTK) |
67 #include "chrome/browser/ui/gtk/custom_drag.h" | 67 #include "chrome/browser/ui/gtk/custom_drag.h" |
68 #endif // defined(TOOLKIT_GTK) | 68 #endif // defined(TOOLKIT_GTK) |
69 #endif // defined(TOOLKIT_USES_GTK) | 69 #endif // defined(TOOLKIT_USES_GTK) |
70 | 70 |
71 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
72 #include "app/win/win_util.h" | |
73 #include "base/win/scoped_comptr.h" | 72 #include "base/win/scoped_comptr.h" |
74 #include "chrome/browser/browser_list.h" | 73 #include "chrome/browser/browser_list.h" |
75 #include "chrome/browser/ui/views/frame/browser_view.h" | 74 #include "chrome/browser/ui/views/frame/browser_view.h" |
76 #include "ui/base/dragdrop/drag_source.h" | 75 #include "ui/base/dragdrop/drag_source.h" |
77 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 76 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
78 #endif | 77 #endif |
79 | 78 |
80 namespace download_util { | 79 namespace download_util { |
81 | 80 |
82 // How many times to cycle the complete animation. This should be an odd number | 81 // How many times to cycle the complete animation. This should be an odd number |
(...skipping 29 matching lines...) Expand all Loading... |
112 | 111 |
113 // See <http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html>. | 112 // See <http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html>. |
114 // That vulnerability report is not exactly on point, but files become magical | 113 // That vulnerability report is not exactly on point, but files become magical |
115 // if their end in a CLSID. Here we block extensions that look like CLSIDs. | 114 // if their end in a CLSID. Here we block extensions that look like CLSIDs. |
116 if (extension_lower.size() > 0 && extension_lower.at(0) == L'{' && | 115 if (extension_lower.size() > 0 && extension_lower.at(0) == L'{' && |
117 extension_lower.at(extension_lower.length() - 1) == L'}') | 116 extension_lower.at(extension_lower.length() - 1) == L'}') |
118 return true; | 117 return true; |
119 | 118 |
120 return false; | 119 return false; |
121 } | 120 } |
| 121 |
| 122 // Returns whether the specified file name is a reserved name on windows. |
| 123 // This includes names like "com2.zip" (which correspond to devices) and |
| 124 // desktop.ini and thumbs.db which have special meaning to the windows shell. |
| 125 bool IsReservedName(const string16& filename) { |
| 126 // This list is taken from the MSDN article "Naming a file" |
| 127 // http://msdn2.microsoft.com/en-us/library/aa365247(VS.85).aspx |
| 128 // I also added clock$ because GetSaveFileName seems to consider it as a |
| 129 // reserved name too. |
| 130 static const wchar_t* const known_devices[] = { |
| 131 L"con", L"prn", L"aux", L"nul", L"com1", L"com2", L"com3", L"com4", L"com5", |
| 132 L"com6", L"com7", L"com8", L"com9", L"lpt1", L"lpt2", L"lpt3", L"lpt4", |
| 133 L"lpt5", L"lpt6", L"lpt7", L"lpt8", L"lpt9", L"clock$" |
| 134 }; |
| 135 string16 filename_lower = StringToLowerASCII(filename); |
| 136 |
| 137 for (int i = 0; i < arraysize(known_devices); ++i) { |
| 138 // Exact match. |
| 139 if (filename_lower == known_devices[i]) |
| 140 return true; |
| 141 // Starts with "DEVICE.". |
| 142 if (filename_lower.find(string16(known_devices[i]) + L".") == 0) |
| 143 return true; |
| 144 } |
| 145 |
| 146 static const wchar_t* const magic_names[] = { |
| 147 // These file names are used by the "Customize folder" feature of the shell. |
| 148 L"desktop.ini", |
| 149 L"thumbs.db", |
| 150 }; |
| 151 |
| 152 for (int i = 0; i < arraysize(magic_names); ++i) { |
| 153 if (filename_lower == magic_names[i]) |
| 154 return true; |
| 155 } |
| 156 |
| 157 return false; |
| 158 } |
122 #endif // OS_WIN | 159 #endif // OS_WIN |
123 | 160 |
124 } // namespace | 161 } // namespace |
125 | 162 |
126 // Download temporary file creation -------------------------------------------- | 163 // Download temporary file creation -------------------------------------------- |
127 | 164 |
128 class DefaultDownloadDirectory { | 165 class DefaultDownloadDirectory { |
129 public: | 166 public: |
130 const FilePath& path() const { return path_; } | 167 const FilePath& path() const { return path_; } |
131 private: | 168 private: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { | 281 void GenerateSafeFileName(const std::string& mime_type, FilePath* file_name) { |
245 // Make sure we get the right file extension | 282 // Make sure we get the right file extension |
246 FilePath::StringType extension; | 283 FilePath::StringType extension; |
247 GenerateExtension(*file_name, mime_type, &extension); | 284 GenerateExtension(*file_name, mime_type, &extension); |
248 *file_name = file_name->ReplaceExtension(extension); | 285 *file_name = file_name->ReplaceExtension(extension); |
249 | 286 |
250 #if defined(OS_WIN) | 287 #if defined(OS_WIN) |
251 // Prepend "_" to the file name if it's a reserved name | 288 // Prepend "_" to the file name if it's a reserved name |
252 FilePath::StringType leaf_name = file_name->BaseName().value(); | 289 FilePath::StringType leaf_name = file_name->BaseName().value(); |
253 DCHECK(!leaf_name.empty()); | 290 DCHECK(!leaf_name.empty()); |
254 if (app::win::IsReservedName(leaf_name)) { | 291 if (IsReservedName(leaf_name)) { |
255 leaf_name = FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; | 292 leaf_name = FilePath::StringType(FILE_PATH_LITERAL("_")) + leaf_name; |
256 *file_name = file_name->DirName(); | 293 *file_name = file_name->DirName(); |
257 if (file_name->value() == FilePath::kCurrentDirectory) { | 294 if (file_name->value() == FilePath::kCurrentDirectory) { |
258 *file_name = FilePath(leaf_name); | 295 *file_name = FilePath(leaf_name); |
259 } else { | 296 } else { |
260 *file_name = file_name->Append(leaf_name); | 297 *file_name = file_name->Append(leaf_name); |
261 } | 298 } |
262 } | 299 } |
263 #endif | 300 #endif |
264 } | 301 } |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 814 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
778 // Extensions that are not from the gallery are considered dangerous. | 815 // Extensions that are not from the gallery are considered dangerous. |
779 ret = true; | 816 ret = true; |
780 } | 817 } |
781 } | 818 } |
782 | 819 |
783 return ret; | 820 return ret; |
784 } | 821 } |
785 | 822 |
786 } // namespace download_util | 823 } // namespace download_util |
OLD | NEW |