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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/common/pref_service.h" | 36 #include "chrome/common/pref_service.h" |
37 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
38 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
40 #include "net/base/mime_util.h" | 40 #include "net/base/mime_util.h" |
41 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
42 #include "net/url_request/url_request_context.h" | 42 #include "net/url_request/url_request_context.h" |
43 | 43 |
44 #if defined(OS_WIN) | 44 #if defined(OS_WIN) |
45 #include "app/win_util.h" | 45 #include "app/win_util.h" |
46 // TODO(port): some of these need porting. | |
47 #include "base/registry.h" | 46 #include "base/registry.h" |
48 #include "base/win_util.h" | 47 #include "base/win_util.h" |
| 48 #endif |
| 49 |
| 50 #if !defined(OS_MACOSX) |
| 51 // Used for initializing the list of dangerous extensions. We don't support it |
| 52 // yet on mac. |
49 #include "chrome/browser/download/download_util.h" | 53 #include "chrome/browser/download/download_util.h" |
50 #endif | 54 #endif |
51 | 55 |
52 #if defined(OS_LINUX) | 56 #if defined(OS_LINUX) |
53 #include <gtk/gtk.h> | 57 #include <gtk/gtk.h> |
54 #endif | 58 #endif |
55 | 59 |
56 // Periodically update our observers. | 60 // Periodically update our observers. |
57 class DownloadItemUpdateTask : public Task { | 61 class DownloadItemUpdateTask : public Task { |
58 public: | 62 public: |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 | 500 |
497 // This variable is needed to resolve which CreateDirectory we want to point | 501 // This variable is needed to resolve which CreateDirectory we want to point |
498 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity. | 502 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity. |
499 // TODO(estade): when file_util::CreateDirectory(wstring) is removed, | 503 // TODO(estade): when file_util::CreateDirectory(wstring) is removed, |
500 // get rid of |CreateDirectoryPtr|. | 504 // get rid of |CreateDirectoryPtr|. |
501 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; | 505 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; |
502 // Ensure that the download directory specified in the preferences exists. | 506 // Ensure that the download directory specified in the preferences exists. |
503 file_loop_->PostTask(FROM_HERE, NewRunnableFunction( | 507 file_loop_->PostTask(FROM_HERE, NewRunnableFunction( |
504 CreateDirectoryPtr, download_path())); | 508 CreateDirectoryPtr, download_path())); |
505 | 509 |
506 #if defined(OS_WIN) | 510 #if defined(OS_WIN) || defined(OS_LINUX) |
507 // We use this on windows to determine possibly dangerous downloads. | 511 // We use this to determine possibly dangerous downloads. |
508 download_util::InitializeExeTypes(&exe_types_); | 512 download_util::InitializeExeTypes(&exe_types_); |
509 #endif | 513 #endif |
510 | 514 |
511 // We store any file extension that should be opened automatically at | 515 // We store any file extension that should be opened automatically at |
512 // download completion in this pref. | 516 // download completion in this pref. |
513 std::wstring extensions_to_open = | 517 std::wstring extensions_to_open = |
514 prefs->GetString(prefs::kDownloadExtensionsToOpen); | 518 prefs->GetString(prefs::kDownloadExtensionsToOpen); |
515 std::vector<std::wstring> extensions; | 519 std::vector<std::wstring> extensions; |
516 SplitString(extensions_to_open, L':', &extensions); | 520 SplitString(extensions_to_open, L':', &extensions); |
517 for (size_t i = 0; i < extensions.size(); ++i) { | 521 for (size_t i = 0; i < extensions.size(); ++i) { |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 } | 1317 } |
1314 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { | 1318 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { |
1315 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) | 1319 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) |
1316 return false; | 1320 return false; |
1317 } | 1321 } |
1318 // We consider only other application types to be executable. | 1322 // We consider only other application types to be executable. |
1319 return net::MatchesMimeType("application/*", mime_type); | 1323 return net::MatchesMimeType("application/*", mime_type); |
1320 } | 1324 } |
1321 | 1325 |
1322 bool DownloadManager::IsExecutable(const FilePath::StringType& extension) { | 1326 bool DownloadManager::IsExecutable(const FilePath::StringType& extension) { |
1323 #if defined(OS_WIN) | 1327 #if defined(OS_MACOSX) |
| 1328 // We don't have dangerous download support on mac yet. |
| 1329 return false; |
| 1330 #else |
1324 if (!IsStringASCII(extension)) | 1331 if (!IsStringASCII(extension)) |
1325 return false; | 1332 return false; |
| 1333 #if defined(OS_WIN) |
1326 std::string ascii_extension = WideToASCII(extension); | 1334 std::string ascii_extension = WideToASCII(extension); |
| 1335 #elif defined(OS_LINUX) |
| 1336 std::string ascii_extension = extension; |
| 1337 #endif |
1327 StringToLowerASCII(&ascii_extension); | 1338 StringToLowerASCII(&ascii_extension); |
1328 | 1339 |
1329 return exe_types_.find(ascii_extension) != exe_types_.end(); | 1340 return exe_types_.find(ascii_extension) != exe_types_.end(); |
1330 #elif defined(OS_POSIX) | 1341 #endif // !defined(OS_MACOSX) |
1331 // TODO(port): we misght not want to call this function on other platforms. | |
1332 // Figure it out. | |
1333 NOTIMPLEMENTED(); | |
1334 return false; | |
1335 #endif | |
1336 } | 1342 } |
1337 | 1343 |
1338 void DownloadManager::ResetAutoOpenFiles() { | 1344 void DownloadManager::ResetAutoOpenFiles() { |
1339 auto_open_.clear(); | 1345 auto_open_.clear(); |
1340 SaveAutoOpens(); | 1346 SaveAutoOpens(); |
1341 } | 1347 } |
1342 | 1348 |
1343 bool DownloadManager::HasAutoOpenFileTypesRegistered() const { | 1349 bool DownloadManager::HasAutoOpenFileTypesRegistered() const { |
1344 return !auto_open_.empty(); | 1350 return !auto_open_.empty(); |
1345 } | 1351 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 } | 1531 } |
1526 | 1532 |
1527 if (contents) | 1533 if (contents) |
1528 contents->OnStartDownload(download); | 1534 contents->OnStartDownload(download); |
1529 } | 1535 } |
1530 | 1536 |
1531 // Clears the last download path, used to initialize "save as" dialogs. | 1537 // Clears the last download path, used to initialize "save as" dialogs. |
1532 void DownloadManager::ClearLastDownloadPath() { | 1538 void DownloadManager::ClearLastDownloadPath() { |
1533 last_download_path_ = FilePath(); | 1539 last_download_path_ = FilePath(); |
1534 } | 1540 } |
OLD | NEW |