Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/browser/download/download_manager.cc

Issue 165295: Add "dangerous download" view on OS X, for now for dmg files. Also fix download item layout. (Closed)
Patch Set: Address comments Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/download/download_exe.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/sys_string_conversions.h" 15 #include "base/sys_string_conversions.h"
16 #include "base/task.h" 16 #include "base/task.h"
17 #include "base/thread.h" 17 #include "base/thread.h"
18 #include "base/timer.h" 18 #include "base/timer.h"
19 #include "chrome/browser/browser_list.h" 19 #include "chrome/browser/browser_list.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/download/download_file.h" 21 #include "chrome/browser/download/download_file.h"
22 #include "chrome/browser/download/download_util.h"
22 #include "chrome/browser/extensions/extension_install_ui.h" 23 #include "chrome/browser/extensions/extension_install_ui.h"
23 #include "chrome/browser/extensions/extensions_service.h" 24 #include "chrome/browser/extensions/extensions_service.h"
24 #include "chrome/browser/profile.h" 25 #include "chrome/browser/profile.h"
25 #include "chrome/browser/renderer_host/render_process_host.h" 26 #include "chrome/browser/renderer_host/render_process_host.h"
26 #include "chrome/browser/renderer_host/render_view_host.h" 27 #include "chrome/browser/renderer_host/render_view_host.h"
27 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 28 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
28 #include "chrome/browser/tab_contents/tab_util.h" 29 #include "chrome/browser/tab_contents/tab_util.h"
29 #include "chrome/browser/tab_contents/tab_contents.h" 30 #include "chrome/browser/tab_contents/tab_contents.h"
30 #include "chrome/common/chrome_constants.h" 31 #include "chrome/common/chrome_constants.h"
31 #include "chrome/common/chrome_paths.h" 32 #include "chrome/common/chrome_paths.h"
32 #include "chrome/common/extensions/extension.h" 33 #include "chrome/common/extensions/extension.h"
33 #include "chrome/common/platform_util.h" 34 #include "chrome/common/platform_util.h"
34 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
35 #include "chrome/common/pref_service.h" 36 #include "chrome/common/pref_service.h"
36 #include "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
37 #include "grit/chromium_strings.h" 38 #include "grit/chromium_strings.h"
38 #include "grit/generated_resources.h" 39 #include "grit/generated_resources.h"
39 #include "net/base/mime_util.h" 40 #include "net/base/mime_util.h"
40 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
41 #include "net/url_request/url_request_context.h" 42 #include "net/url_request/url_request_context.h"
42 43
43 #if defined(OS_WIN) 44 #if defined(OS_WIN)
44 #include "app/win_util.h" 45 #include "app/win_util.h"
45 #include "base/registry.h" 46 #include "base/registry.h"
46 #include "base/win_util.h" 47 #include "base/win_util.h"
47 #endif 48 #endif
48 49
49 #if !defined(OS_MACOSX)
50 // Used for initializing the list of dangerous extensions. We don't support it
51 // yet on mac.
52 #include "chrome/browser/download/download_util.h"
53 #endif
54 50
55 #if defined(OS_LINUX) 51 #if defined(OS_LINUX)
56 #include <gtk/gtk.h> 52 #include <gtk/gtk.h>
57 #endif 53 #endif
58 54
59 // Periodically update our observers. 55 // Periodically update our observers.
60 class DownloadItemUpdateTask : public Task { 56 class DownloadItemUpdateTask : public Task {
61 public: 57 public:
62 explicit DownloadItemUpdateTask(DownloadItem* item) : item_(item) {} 58 explicit DownloadItemUpdateTask(DownloadItem* item) : item_(item) {}
63 void Run() { if (item_) item_->UpdateObservers(); } 59 void Run() { if (item_) item_->UpdateObservers(); }
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 517
522 // This variable is needed to resolve which CreateDirectory we want to point 518 // This variable is needed to resolve which CreateDirectory we want to point
523 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity. 519 // to. Without it, the NewRunnableFunction cannot resolve the ambiguity.
524 // TODO(estade): when file_util::CreateDirectory(wstring) is removed, 520 // TODO(estade): when file_util::CreateDirectory(wstring) is removed,
525 // get rid of |CreateDirectoryPtr|. 521 // get rid of |CreateDirectoryPtr|.
526 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory; 522 bool (*CreateDirectoryPtr)(const FilePath&) = &file_util::CreateDirectory;
527 // Ensure that the download directory specified in the preferences exists. 523 // Ensure that the download directory specified in the preferences exists.
528 file_loop_->PostTask(FROM_HERE, NewRunnableFunction( 524 file_loop_->PostTask(FROM_HERE, NewRunnableFunction(
529 CreateDirectoryPtr, download_path())); 525 CreateDirectoryPtr, download_path()));
530 526
531 #if defined(OS_WIN) || defined(OS_LINUX)
532 // We use this to determine possibly dangerous downloads. 527 // We use this to determine possibly dangerous downloads.
533 download_util::InitializeExeTypes(&exe_types_); 528 download_util::InitializeExeTypes(&exe_types_);
534 #endif
535 529
536 // We store any file extension that should be opened automatically at 530 // We store any file extension that should be opened automatically at
537 // download completion in this pref. 531 // download completion in this pref.
538 std::wstring extensions_to_open = 532 std::wstring extensions_to_open =
539 prefs->GetString(prefs::kDownloadExtensionsToOpen); 533 prefs->GetString(prefs::kDownloadExtensionsToOpen);
540 std::vector<std::wstring> extensions; 534 std::vector<std::wstring> extensions;
541 SplitString(extensions_to_open, L':', &extensions); 535 SplitString(extensions_to_open, L':', &extensions);
542 for (size_t i = 0; i < extensions.size(); ++i) { 536 for (size_t i = 0; i < extensions.size(); ++i) {
543 if (!extensions[i].empty() && !IsExecutable( 537 if (!extensions[i].empty() && !IsExecutable(
544 FilePath::FromWStringHack(extensions[i]).value())) 538 FilePath::FromWStringHack(extensions[i]).value()))
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 } 1322 }
1329 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) { 1323 for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) {
1330 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type)) 1324 if (net::MatchesMimeType(kExecutableBlackList[i], mime_type))
1331 return false; 1325 return false;
1332 } 1326 }
1333 // We consider only other application types to be executable. 1327 // We consider only other application types to be executable.
1334 return net::MatchesMimeType("application/*", mime_type); 1328 return net::MatchesMimeType("application/*", mime_type);
1335 } 1329 }
1336 1330
1337 bool DownloadManager::IsExecutable(const FilePath::StringType& extension) { 1331 bool DownloadManager::IsExecutable(const FilePath::StringType& extension) {
1338 #if defined(OS_MACOSX)
1339 // We don't have dangerous download support on mac yet.
1340 return false;
1341 #else
1342 if (!IsStringASCII(extension)) 1332 if (!IsStringASCII(extension))
1343 return false; 1333 return false;
1344 #if defined(OS_WIN) 1334 #if defined(OS_WIN)
1345 std::string ascii_extension = WideToASCII(extension); 1335 std::string ascii_extension = WideToASCII(extension);
1346 #elif defined(OS_LINUX) 1336 #elif defined(OS_POSIX)
1347 std::string ascii_extension = extension; 1337 std::string ascii_extension = extension;
1348 #endif 1338 #endif
1349 StringToLowerASCII(&ascii_extension); 1339 StringToLowerASCII(&ascii_extension);
1350 1340
1351 return exe_types_.find(ascii_extension) != exe_types_.end(); 1341 return exe_types_.find(ascii_extension) != exe_types_.end();
1352 #endif // !defined(OS_MACOSX)
1353 } 1342 }
1354 1343
1355 void DownloadManager::ResetAutoOpenFiles() { 1344 void DownloadManager::ResetAutoOpenFiles() {
1356 auto_open_.clear(); 1345 auto_open_.clear();
1357 SaveAutoOpens(); 1346 SaveAutoOpens();
1358 } 1347 }
1359 1348
1360 bool DownloadManager::HasAutoOpenFileTypesRegistered() const { 1349 bool DownloadManager::HasAutoOpenFileTypesRegistered() const {
1361 return !auto_open_.empty(); 1350 return !auto_open_.empty();
1362 } 1351 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 1524
1536 if (contents) 1525 if (contents)
1537 contents->OnStartDownload(download); 1526 contents->OnStartDownload(download);
1538 } 1527 }
1539 1528
1540 // Clears the last download path, used to initialize "save as" dialogs. 1529 // Clears the last download path, used to initialize "save as" dialogs.
1541 void DownloadManager::ClearLastDownloadPath() { 1530 void DownloadManager::ClearLastDownloadPath() {
1542 last_download_path_ = FilePath(); 1531 last_download_path_ = FilePath();
1543 } 1532 }
1544 1533
OLDNEW
« no previous file with comments | « chrome/browser/download/download_exe.cc ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698