| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_target_determiner.h" | 5 #include "chrome/browser/download/download_target_determiner.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 11 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| 12 #include "chrome/browser/download/download_crx_util.h" | 12 #include "chrome/browser/download/download_crx_util.h" |
| 13 #include "chrome/browser/download/download_extensions.h" | 13 #include "chrome/browser/download/download_extensions.h" |
| 14 #include "chrome/browser/download/download_prefs.h" | 14 #include "chrome/browser/download/download_prefs.h" |
| 15 #include "chrome/browser/extensions/webstore_installer.h" | |
| 16 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/download_interrupt_reasons.h" | 21 #include "content/public/browser/download_interrupt_reasons.h" |
| 23 #include "extensions/common/constants.h" | 22 #include "extensions/common/constants.h" |
| 24 #include "extensions/common/feature_switch.h" | |
| 25 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 26 #include "net/base/filename_util.h" | 24 #include "net/base/filename_util.h" |
| 27 #include "net/base/mime_util.h" | 25 #include "net/base/mime_util.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 29 | 27 |
| 28 #if defined(ENABLE_EXTENSIONS) |
| 29 #include "chrome/browser/extensions/webstore_installer.h" |
| 30 #include "extensions/common/feature_switch.h" |
| 31 #endif |
| 32 |
| 30 #if defined(ENABLE_PLUGINS) | 33 #if defined(ENABLE_PLUGINS) |
| 31 #include "chrome/browser/plugins/plugin_prefs.h" | 34 #include "chrome/browser/plugins/plugin_prefs.h" |
| 32 #include "content/public/browser/plugin_service.h" | 35 #include "content/public/browser/plugin_service.h" |
| 33 #include "content/public/common/webplugininfo.h" | 36 #include "content/public/common/webplugininfo.h" |
| 34 #endif | 37 #endif |
| 35 | 38 |
| 36 using content::BrowserThread; | 39 using content::BrowserThread; |
| 37 using content::DownloadItem; | 40 using content::DownloadItem; |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 | 758 |
| 756 // User-initiated extension downloads from pref-whitelisted sources are not | 759 // User-initiated extension downloads from pref-whitelisted sources are not |
| 757 // considered dangerous. | 760 // considered dangerous. |
| 758 if (download_->HasUserGesture() && | 761 if (download_->HasUserGesture() && |
| 759 is_extension_download && | 762 is_extension_download && |
| 760 download_crx_util::OffStoreInstallAllowedByPrefs( | 763 download_crx_util::OffStoreInstallAllowedByPrefs( |
| 761 GetProfile(), *download_)) { | 764 GetProfile(), *download_)) { |
| 762 return false; | 765 return false; |
| 763 } | 766 } |
| 764 | 767 |
| 768 #if defined(ENABLE_EXTENSIONS) |
| 765 // Extensions that are not from the gallery are considered dangerous. | 769 // Extensions that are not from the gallery are considered dangerous. |
| 766 // When off-store install is disabled we skip this, since in this case, we | 770 // When off-store install is disabled we skip this, since in this case, we |
| 767 // will not offer to install the extension. | 771 // will not offer to install the extension. |
| 768 if (extensions::FeatureSwitch::easy_off_store_install()->IsEnabled() && | 772 if (extensions::FeatureSwitch::easy_off_store_install()->IsEnabled() && |
| 769 is_extension_download && | 773 is_extension_download && |
| 770 !extensions::WebstoreInstaller::GetAssociatedApproval(*download_)) { | 774 !extensions::WebstoreInstaller::GetAssociatedApproval(*download_)) { |
| 771 return true; | 775 return true; |
| 772 } | 776 } |
| 777 #endif |
| 773 | 778 |
| 774 // Anything the user has marked auto-open is OK if it's user-initiated. | 779 // Anything the user has marked auto-open is OK if it's user-initiated. |
| 775 if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(virtual_path_) && | 780 if (download_prefs_->IsAutoOpenEnabledBasedOnExtension(virtual_path_) && |
| 776 download_->HasUserGesture()) | 781 download_->HasUserGesture()) |
| 777 return false; | 782 return false; |
| 778 | 783 |
| 779 switch (download_util::GetFileDangerLevel(virtual_path_.BaseName())) { | 784 switch (download_util::GetFileDangerLevel(virtual_path_.BaseName())) { |
| 780 case download_util::NOT_DANGEROUS: | 785 case download_util::NOT_DANGEROUS: |
| 781 return false; | 786 return false; |
| 782 | 787 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 // asynchronously. | 819 // asynchronously. |
| 815 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, | 820 new DownloadTargetDeterminer(download, initial_virtual_path, download_prefs, |
| 816 delegate, callback); | 821 delegate, callback); |
| 817 } | 822 } |
| 818 | 823 |
| 819 // static | 824 // static |
| 820 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( | 825 base::FilePath DownloadTargetDeterminer::GetCrDownloadPath( |
| 821 const base::FilePath& suggested_path) { | 826 const base::FilePath& suggested_path) { |
| 822 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); | 827 return base::FilePath(suggested_path.value() + kCrdownloadSuffix); |
| 823 } | 828 } |
| OLD | NEW |