OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 if (extension.empty()) { | 1135 if (extension.empty()) { |
1136 net::GetPreferredExtensionForMimeType(mime_type, &extension); | 1136 net::GetPreferredExtensionForMimeType(mime_type, &extension); |
1137 } else { | 1137 } else { |
1138 // Append extension generated from the mime type if: | 1138 // Append extension generated from the mime type if: |
1139 // 1. New extension is not ".txt" | 1139 // 1. New extension is not ".txt" |
1140 // 2. New extension is not the same as the already existing extension. | 1140 // 2. New extension is not the same as the already existing extension. |
1141 // 3. New extension is not executable. This action mitigates the case when | 1141 // 3. New extension is not executable. This action mitigates the case when |
1142 // an executable is hidden in a benign file extension; | 1142 // an executable is hidden in a benign file extension; |
1143 // E.g. my-cat.jpg becomes my-cat.jpg.js if content type is | 1143 // E.g. my-cat.jpg becomes my-cat.jpg.js if content type is |
1144 // application/x-javascript. | 1144 // application/x-javascript. |
| 1145 // 4. New extension is not ".tar" for .gz files. For misconfigured web |
| 1146 // servers, i.e. bug 5772. |
1145 FilePath::StringType append_extension; | 1147 FilePath::StringType append_extension; |
1146 if (net::GetPreferredExtensionForMimeType(mime_type, &append_extension)) { | 1148 if (net::GetPreferredExtensionForMimeType(mime_type, &append_extension)) { |
1147 if (append_extension != FILE_PATH_LITERAL("txt") && | 1149 if (append_extension != FILE_PATH_LITERAL("txt") && |
1148 append_extension != extension && | 1150 append_extension != extension && |
1149 !IsExecutable(append_extension)) { | 1151 !IsExecutable(append_extension) && |
| 1152 (append_extension != FILE_PATH_LITERAL("tar") || |
| 1153 extension != FILE_PATH_LITERAL("gz"))) { |
1150 extension += FILE_PATH_LITERAL("."); | 1154 extension += FILE_PATH_LITERAL("."); |
1151 extension += append_extension; | 1155 extension += append_extension; |
1152 } | 1156 } |
1153 } | 1157 } |
1154 } | 1158 } |
1155 | 1159 |
1156 generated_extension->swap(extension); | 1160 generated_extension->swap(extension); |
1157 } | 1161 } |
1158 | 1162 |
1159 void DownloadManager::GenerateFilename(DownloadCreateInfo* info, | 1163 void DownloadManager::GenerateFilename(DownloadCreateInfo* info, |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 searched_downloads.push_back(dit->second); | 1444 searched_downloads.push_back(dit->second); |
1441 } | 1445 } |
1442 | 1446 |
1443 requestor->SetDownloads(searched_downloads); | 1447 requestor->SetDownloads(searched_downloads); |
1444 } | 1448 } |
1445 | 1449 |
1446 // Clears the last download path, used to initialize "save as" dialogs. | 1450 // Clears the last download path, used to initialize "save as" dialogs. |
1447 void DownloadManager::ClearLastDownloadPath() { | 1451 void DownloadManager::ClearLastDownloadPath() { |
1448 last_download_path_ = FilePath(); | 1452 last_download_path_ = FilePath(); |
1449 } | 1453 } |
OLD | NEW |