OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
11 #endif | 11 #endif |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
18 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
21 #include "base/string16.h" | 21 #include "base/string16.h" |
22 #include "base/string_number_conversions.h" | 22 #include "base/string_number_conversions.h" |
23 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
24 #include "base/sys_string_conversions.h" | 24 #include "base/sys_string_conversions.h" |
25 #include "base/thread_restrictions.h" | 25 #include "base/thread_restrictions.h" |
26 #include "base/utf_string_conversions.h" | 26 #include "base/utf_string_conversions.h" |
27 #include "base/values.h" | 27 #include "base/values.h" |
28 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
29 #include "chrome/browser/browser_thread.h" | 29 #include "chrome/browser/browser_thread.h" |
| 30 #include "chrome/browser/download/download_extensions.h" |
30 #include "chrome/browser/download/download_item.h" | 31 #include "chrome/browser/download/download_item.h" |
31 #include "chrome/browser/download/download_item_model.h" | 32 #include "chrome/browser/download/download_item_model.h" |
32 #include "chrome/browser/download/download_manager.h" | 33 #include "chrome/browser/download/download_manager.h" |
33 #include "chrome/browser/extensions/crx_installer.h" | 34 #include "chrome/browser/extensions/crx_installer.h" |
34 #include "chrome/browser/extensions/extension_install_ui.h" | 35 #include "chrome/browser/extensions/extension_install_ui.h" |
35 #include "chrome/browser/extensions/extensions_service.h" | 36 #include "chrome/browser/extensions/extensions_service.h" |
36 #include "chrome/browser/history/download_create_info.h" | 37 #include "chrome/browser/history/download_create_info.h" |
37 #include "chrome/browser/net/chrome_url_request_context.h" | 38 #include "chrome/browser/net/chrome_url_request_context.h" |
38 #include "chrome/browser/profiles/profile.h" | 39 #include "chrome/browser/profiles/profile.h" |
39 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 40 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 FilePath::StringType file_name; | 713 FilePath::StringType file_name; |
713 base::SStringPrintf( | 714 base::SStringPrintf( |
714 &file_name, | 715 &file_name, |
715 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), | 716 PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), |
716 suggested_path.value().c_str()); | 717 suggested_path.value().c_str()); |
717 return FilePath(file_name); | 718 return FilePath(file_name); |
718 } | 719 } |
719 | 720 |
720 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests. | 721 // TODO(erikkay,phajdan.jr): This is apparently not being exercised in tests. |
721 bool IsDangerous(DownloadCreateInfo* info, Profile* profile) { | 722 bool IsDangerous(DownloadCreateInfo* info, Profile* profile) { |
722 // Downloads can be marked as dangerous for two reasons: | 723 DownloadDangerLevel danger_level = GetFileDangerLevel( |
723 // a) They have a dangerous-looking filename | 724 info->suggested_path.BaseName()); |
724 // b) They are an extension that is not from the gallery | 725 |
725 if (IsExecutableFile(info->suggested_path.BaseName())) { | 726 if (danger_level == Dangerous) { |
| 727 return true; |
| 728 } else if (danger_level == AllowOnUserGesture && !info->has_user_gesture) { |
726 return true; | 729 return true; |
727 } else if (info->is_extension_install) { | 730 } else if (info->is_extension_install) { |
728 ExtensionsService* service = profile->GetExtensionsService(); | 731 ExtensionsService* service = profile->GetExtensionsService(); |
729 if (!service || | 732 if (!service || |
730 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { | 733 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { |
| 734 // Extensions that are not from the gallery are considered dangerous. |
731 return true; | 735 return true; |
732 } | 736 } |
733 } | 737 } |
| 738 |
734 return false; | 739 return false; |
735 } | 740 } |
736 | 741 |
737 } // namespace download_util | 742 } // namespace download_util |
OLD | NEW |