| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #include "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 void DownloadManager::RemoveObserver(Observer* observer) { | 1228 void DownloadManager::RemoveObserver(Observer* observer) { |
| 1229 observers_.RemoveObserver(observer); | 1229 observers_.RemoveObserver(observer); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 // Post Windows Shell operations to the Download thread, to avoid blocking the | 1232 // Post Windows Shell operations to the Download thread, to avoid blocking the |
| 1233 // user interface. | 1233 // user interface. |
| 1234 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { | 1234 void DownloadManager::ShowDownloadInShell(const DownloadItem* download) { |
| 1235 DCHECK(file_manager_); | 1235 DCHECK(file_manager_); |
| 1236 DCHECK(MessageLoop::current() == ui_loop_); |
| 1237 #if defined(OS_MACOSX) |
| 1238 // Mac needs to run this operation on the UI thread. |
| 1239 platform_util::ShowItemInFolder(download->full_path()); |
| 1240 #else |
| 1236 file_loop_->PostTask(FROM_HERE, | 1241 file_loop_->PostTask(FROM_HERE, |
| 1237 NewRunnableMethod(file_manager_, | 1242 NewRunnableMethod(file_manager_, |
| 1238 &DownloadFileManager::OnShowDownloadInShell, | 1243 &DownloadFileManager::OnShowDownloadInShell, |
| 1239 FilePath(download->full_path()))); | 1244 FilePath(download->full_path()))); |
| 1245 #endif |
| 1240 } | 1246 } |
| 1241 | 1247 |
| 1242 void DownloadManager::OpenDownload(const DownloadItem* download, | 1248 void DownloadManager::OpenDownload(const DownloadItem* download, |
| 1243 gfx::NativeView parent_window) { | 1249 gfx::NativeView parent_window) { |
| 1244 // Open Chrome extensions with ExtensionsService. For everything else do shell | 1250 // Open Chrome extensions with ExtensionsService. For everything else do shell |
| 1245 // execute. | 1251 // execute. |
| 1246 if (IsChromeExtension(download->full_path(), download->mime_type())) { | 1252 if (IsChromeExtension(download->full_path(), download->mime_type())) { |
| 1247 OpenChromeExtension(download->full_path(), download->url(), | 1253 OpenChromeExtension(download->full_path(), download->url(), |
| 1248 download->referrer_url()); | 1254 download->referrer_url()); |
| 1249 } else { | 1255 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1264 true, // please delete crx on completion | 1270 true, // please delete crx on completion |
| 1265 g_browser_process->file_thread()->message_loop(), | 1271 g_browser_process->file_thread()->message_loop(), |
| 1266 service, | 1272 service, |
| 1267 new ExtensionInstallUI(profile_)); | 1273 new ExtensionInstallUI(profile_)); |
| 1268 } | 1274 } |
| 1269 } | 1275 } |
| 1270 | 1276 |
| 1271 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, | 1277 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, |
| 1272 gfx::NativeView parent_window) { | 1278 gfx::NativeView parent_window) { |
| 1273 DCHECK(file_manager_); | 1279 DCHECK(file_manager_); |
| 1280 DCHECK(MessageLoop::current() == ui_loop_); |
| 1281 #if defined(OS_MACOSX) |
| 1282 // Mac OS X requires opening downloads on the UI thread. |
| 1283 platform_util::OpenItem(download->full_path()); |
| 1284 #else |
| 1274 file_loop_->PostTask(FROM_HERE, | 1285 file_loop_->PostTask(FROM_HERE, |
| 1275 NewRunnableMethod(file_manager_, | 1286 NewRunnableMethod(file_manager_, |
| 1276 &DownloadFileManager::OnOpenDownloadInShell, | 1287 &DownloadFileManager::OnOpenDownloadInShell, |
| 1277 download->full_path(), download->url(), parent_window)); | 1288 download->full_path(), download->url(), parent_window)); |
| 1289 #endif |
| 1278 } | 1290 } |
| 1279 | 1291 |
| 1280 void DownloadManager::OpenFilesOfExtension( | 1292 void DownloadManager::OpenFilesOfExtension( |
| 1281 const FilePath::StringType& extension, bool open) { | 1293 const FilePath::StringType& extension, bool open) { |
| 1282 if (open && !IsExecutable(extension)) | 1294 if (open && !IsExecutable(extension)) |
| 1283 auto_open_.insert(extension); | 1295 auto_open_.insert(extension); |
| 1284 else | 1296 else |
| 1285 auto_open_.erase(extension); | 1297 auto_open_.erase(extension); |
| 1286 SaveAutoOpens(); | 1298 SaveAutoOpens(); |
| 1287 } | 1299 } |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1524 | 1536 |
| 1525 if (contents) | 1537 if (contents) |
| 1526 contents->OnStartDownload(download); | 1538 contents->OnStartDownload(download); |
| 1527 } | 1539 } |
| 1528 | 1540 |
| 1529 // Clears the last download path, used to initialize "save as" dialogs. | 1541 // Clears the last download path, used to initialize "save as" dialogs. |
| 1530 void DownloadManager::ClearLastDownloadPath() { | 1542 void DownloadManager::ClearLastDownloadPath() { |
| 1531 last_download_path_ = FilePath(); | 1543 last_download_path_ = FilePath(); |
| 1532 } | 1544 } |
| 1533 | 1545 |
| OLD | NEW |