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 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/net/chrome_url_request_context.h" | 27 #include "chrome/browser/net/chrome_url_request_context.h" |
28 #include "chrome/browser/profile.h" | 28 #include "chrome/browser/profile.h" |
29 #include "chrome/browser/renderer_host/render_process_host.h" | 29 #include "chrome/browser/renderer_host/render_process_host.h" |
30 #include "chrome/browser/renderer_host/render_view_host.h" | 30 #include "chrome/browser/renderer_host/render_view_host.h" |
31 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 31 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
32 #include "chrome/browser/tab_contents/tab_util.h" | 32 #include "chrome/browser/tab_contents/tab_util.h" |
33 #include "chrome/browser/tab_contents/tab_contents.h" | 33 #include "chrome/browser/tab_contents/tab_contents.h" |
34 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
35 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/extensions/extension.h" | 36 #include "chrome/common/extensions/extension.h" |
| 37 #include "chrome/common/extensions/user_script.h" |
37 #include "chrome/common/notification_service.h" | 38 #include "chrome/common/notification_service.h" |
38 #include "chrome/common/notification_type.h" | 39 #include "chrome/common/notification_type.h" |
39 #include "chrome/common/platform_util.h" | 40 #include "chrome/common/platform_util.h" |
40 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
41 #include "chrome/common/pref_service.h" | 42 #include "chrome/common/pref_service.h" |
42 #include "googleurl/src/gurl.h" | 43 #include "googleurl/src/gurl.h" |
43 #include "grit/chromium_strings.h" | 44 #include "grit/chromium_strings.h" |
44 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
45 #include "net/base/mime_util.h" | 46 #include "net/base/mime_util.h" |
46 #include "net/base/net_util.h" | 47 #include "net/base/net_util.h" |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 void DownloadManager::OpenChromeExtension(const FilePath& full_path, | 1237 void DownloadManager::OpenChromeExtension(const FilePath& full_path, |
1237 const GURL& download_url, | 1238 const GURL& download_url, |
1238 const GURL& referrer_url) { | 1239 const GURL& referrer_url) { |
1239 // We don't support extensions in OTR mode. | 1240 // We don't support extensions in OTR mode. |
1240 ExtensionsService* service = profile_->GetExtensionsService(); | 1241 ExtensionsService* service = profile_->GetExtensionsService(); |
1241 if (service) { | 1242 if (service) { |
1242 NotificationService* nservice = NotificationService::current(); | 1243 NotificationService* nservice = NotificationService::current(); |
1243 nservice->Notify(NotificationType::EXTENSION_READY_FOR_INSTALL, | 1244 nservice->Notify(NotificationType::EXTENSION_READY_FOR_INSTALL, |
1244 Source<DownloadManager>(this), | 1245 Source<DownloadManager>(this), |
1245 NotificationService::NoDetails()); | 1246 NotificationService::NoDetails()); |
1246 CrxInstaller::Start(full_path, | 1247 if (UserScript::HasUserScriptFileExtension(full_path)) { |
1247 service->install_directory(), | 1248 CrxInstaller::InstallUserScript( |
1248 Extension::INTERNAL, | 1249 full_path, |
1249 "", // no expected id | 1250 download_url, |
1250 true, // please delete crx on completion | 1251 service->install_directory(), |
1251 true, // privilege increase allowed | 1252 true, // please delete crx on completion |
1252 service, | 1253 service, |
1253 new ExtensionInstallUI(profile_)); | 1254 new ExtensionInstallUI(profile_)); |
| 1255 } else { |
| 1256 CrxInstaller::Start( |
| 1257 full_path, |
| 1258 service->install_directory(), |
| 1259 Extension::INTERNAL, |
| 1260 "", // no expected id |
| 1261 true, // please delete crx on completion |
| 1262 true, // privilege increase allowed |
| 1263 service, |
| 1264 new ExtensionInstallUI(profile_)); |
| 1265 } |
1254 } | 1266 } |
1255 } | 1267 } |
1256 | 1268 |
1257 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, | 1269 void DownloadManager::OpenDownloadInShell(const DownloadItem* download, |
1258 gfx::NativeView parent_window) { | 1270 gfx::NativeView parent_window) { |
1259 DCHECK(file_manager_); | 1271 DCHECK(file_manager_); |
1260 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); | 1272 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
1261 #if defined(OS_MACOSX) | 1273 #if defined(OS_MACOSX) |
1262 // Mac OS X requires opening downloads on the UI thread. | 1274 // Mac OS X requires opening downloads on the UI thread. |
1263 platform_util::OpenItem(download->full_path()); | 1275 platform_util::OpenItem(download->full_path()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1446 if (file_name->value() == FilePath::kCurrentDirectory) { | 1458 if (file_name->value() == FilePath::kCurrentDirectory) { |
1447 *file_name = FilePath(leaf_name); | 1459 *file_name = FilePath(leaf_name); |
1448 } else { | 1460 } else { |
1449 *file_name = file_name->Append(leaf_name); | 1461 *file_name = file_name->Append(leaf_name); |
1450 } | 1462 } |
1451 } | 1463 } |
1452 #endif | 1464 #endif |
1453 } | 1465 } |
1454 | 1466 |
1455 bool DownloadManager::IsExtensionInstall(const DownloadItem* item) { | 1467 bool DownloadManager::IsExtensionInstall(const DownloadItem* item) { |
1456 return item->mime_type() == Extension::kMimeType && !item->save_as(); | 1468 if (item->save_as()) |
| 1469 return false; |
| 1470 |
| 1471 if (UserScript::HasUserScriptFileExtension(item->original_name())) |
| 1472 return true; |
| 1473 |
| 1474 return item->mime_type() == Extension::kMimeType; |
1457 } | 1475 } |
1458 | 1476 |
1459 bool DownloadManager::IsExtensionInstall(const DownloadCreateInfo* info) { | 1477 bool DownloadManager::IsExtensionInstall(const DownloadCreateInfo* info) { |
1460 return info->mime_type == Extension::kMimeType && !info->save_as; | 1478 if (info->save_as) |
| 1479 return false; |
| 1480 |
| 1481 if (UserScript::HasUserScriptFileExtension(info->path)) |
| 1482 return true; |
| 1483 |
| 1484 return info->mime_type == Extension::kMimeType; |
1461 } | 1485 } |
1462 | 1486 |
1463 // Operations posted to us from the history service ---------------------------- | 1487 // Operations posted to us from the history service ---------------------------- |
1464 | 1488 |
1465 // The history service has retrieved all download entries. 'entries' contains | 1489 // The history service has retrieved all download entries. 'entries' contains |
1466 // 'DownloadCreateInfo's in sorted order (by ascending start_time). | 1490 // 'DownloadCreateInfo's in sorted order (by ascending start_time). |
1467 void DownloadManager::OnQueryDownloadEntriesComplete( | 1491 void DownloadManager::OnQueryDownloadEntriesComplete( |
1468 std::vector<DownloadCreateInfo>* entries) { | 1492 std::vector<DownloadCreateInfo>* entries) { |
1469 for (size_t i = 0; i < entries->size(); ++i) { | 1493 for (size_t i = 0; i < entries->size(); ++i) { |
1470 DownloadItem* download = new DownloadItem(entries->at(i)); | 1494 DownloadItem* download = new DownloadItem(entries->at(i)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 | 1571 |
1548 if (contents) | 1572 if (contents) |
1549 contents->OnStartDownload(download); | 1573 contents->OnStartDownload(download); |
1550 } | 1574 } |
1551 | 1575 |
1552 // Clears the last download path, used to initialize "save as" dialogs. | 1576 // Clears the last download path, used to initialize "save as" dialogs. |
1553 void DownloadManager::ClearLastDownloadPath() { | 1577 void DownloadManager::ClearLastDownloadPath() { |
1554 last_download_path_ = FilePath(); | 1578 last_download_path_ = FilePath(); |
1555 } | 1579 } |
1556 | 1580 |
OLD | NEW |