diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 00:16:37 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 00:16:37 +0000 |
commit | 9535043eaf3371cdca71209dfb6fcde6cd26785a (patch) | |
tree | 48d03fe1d0daa7c8ce6bb1fad74c572803066a78 /chrome/browser/download | |
parent | e2d720aac2f853cf8b9602245bdb449912347bee (diff) | |
download | chromium_src-9535043eaf3371cdca71209dfb6fcde6cd26785a.zip chromium_src-9535043eaf3371cdca71209dfb6fcde6cd26785a.tar.gz chromium_src-9535043eaf3371cdca71209dfb6fcde6cd26785a.tar.bz2 |
Revert 137540 - Disable off-store extension installs by default. Also get rid of ExtensionService::IsDownloadFromGallery.
BUG=55584
Review URL: https://chromiumcodereview.appspot.com/10356052
TBR=aa@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10387167
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137575 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r-- | chrome/browser/download/chrome_download_manager_delegate.cc | 58 | ||||
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 13 | ||||
-rw-r--r-- | chrome/browser/download/download_crx_util.cc | 13 | ||||
-rw-r--r-- | chrome/browser/download/download_crx_util.h | 5 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.cc | 3 |
5 files changed, 42 insertions, 50 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index cbe0e98..5edc20d 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -32,7 +32,6 @@ #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/extension_switch_utils.h" #include "chrome/common/extensions/user_script.h" #include "chrome/common/pref_names.h" #include "content/public/browser/download_item.h" @@ -93,12 +92,12 @@ bool ChromeDownloadManagerDelegate::IsExtensionDownload( if (item->PromptUserForSaveLocation()) return false; - if (item->GetMimeType() == Extension::kMimeType || - UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType())) { - return true; - } else { + if ((item->GetMimeType() != Extension::kMimeType) && + !UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType())) { return false; } + + return download_crx_util::ShouldOpenExtensionDownload(*item); } void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { @@ -254,28 +253,22 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) { if (IsExtensionDownload(item)) { - // We can open extensions if either they came from the store, or - // off-store-install is enabled. - if (extensions::switch_utils::IsOffStoreInstallEnabled() || - WebstoreInstaller::GetAssociatedApproval(*item)) { - scoped_refptr<CrxInstaller> crx_installer = - download_crx_util::OpenChromeExtension(profile_, *item); - - // CRX_INSTALLER_DONE will fire when the install completes. Observe() - // will call DelayedDownloadOpened() on this item. If this DownloadItem - // is not around when CRX_INSTALLER_DONE fires, Complete() will not be - // called. - registrar_.Add(this, - chrome::NOTIFICATION_CRX_INSTALLER_DONE, - content::Source<CrxInstaller>(crx_installer.get())); - - crx_installers_[crx_installer.get()] = item->GetId(); - // The status text and percent complete indicator will change now - // that we are installing a CRX. Update observers so that they pick - // up the change. - item->UpdateObservers(); - return false; - } + scoped_refptr<CrxInstaller> crx_installer = + download_crx_util::OpenChromeExtension(profile_, *item); + + // CRX_INSTALLER_DONE will fire when the install completes. Observe() + // will call DelayedDownloadOpened() on this item. If this DownloadItem is + // not around when CRX_INSTALLER_DONE fires, Complete() will not be called. + registrar_.Add(this, + chrome::NOTIFICATION_CRX_INSTALLER_DONE, + content::Source<CrxInstaller>(crx_installer.get())); + + crx_installers_[crx_installer.get()] = item->GetId(); + // The status text and percent complete indicator will change now + // that we are installing a CRX. Update observers so that they pick + // up the change. + item->UpdateObservers(); + return false; } if (ShouldOpenWithWebIntents(item)) { @@ -700,12 +693,11 @@ bool ChromeDownloadManagerDelegate::IsDangerousFile( return false; // Extensions that are not from the gallery are considered dangerous. - // When off-store install is disabled we skip this, since in this case, we - // will not offer to install the extension. - if (extensions::switch_utils::IsOffStoreInstallEnabled() && - IsExtensionDownload(&download) && - !WebstoreInstaller::GetAssociatedApproval(download)) { - return true; + if (IsExtensionDownload(&download)) { + ExtensionService* service = profile_->GetExtensionService(); + if (!service || !service->IsDownloadFromGallery(download.GetURL(), + download.GetReferrerUrl())) + return true; } // Anything the user has marked auto-open is OK if it's user-initiated. diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index d6e2d5b..93c9873 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -40,7 +40,6 @@ #include "chrome/browser/ui/browser_window.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/extension_switch_utils.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "chrome/test/base/in_process_browser_test.h" @@ -1654,9 +1653,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_AutoOpen) { // Download an extension. Expect a dangerous download warning. // Deny the download. IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { - if (!extensions::switch_utils::IsOffStoreInstallEnabled()) - return; - GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); scoped_ptr<DownloadTestObserver> observer( @@ -1681,9 +1677,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { // Download an extension. Expect a dangerous download warning. // Allow the download, deny the install. IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { - if (!extensions::switch_utils::IsOffStoreInstallEnabled()) - return; - GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); // Install a mock install UI that simulates a user denying permission to @@ -1714,9 +1707,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { // Download an extension. Expect a dangerous download warning. // Allow the download, and the install. IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { - if (!extensions::switch_utils::IsOffStoreInstallEnabled()) - return; - GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); // Install a mock install UI that simulates a user allowing permission to @@ -1773,9 +1763,6 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { // Install a large (100kb) theme. IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { - if (!extensions::switch_utils::IsOffStoreInstallEnabled()) - return; - GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); // Install a mock install UI that simulates a user allowing permission to diff --git a/chrome/browser/download/download_crx_util.cc b/chrome/browser/download/download_crx_util.cc index 8711140..a34ebec 100644 --- a/chrome/browser/download/download_crx_util.cc +++ b/chrome/browser/download/download_crx_util.cc @@ -51,6 +51,15 @@ void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { mock_install_ui_for_testing = mock_ui; } +bool ShouldOpenExtensionDownload(const DownloadItem& download_item) { + if (extensions::switch_utils::IsOffStoreInstallEnabled() || + WebstoreInstaller::GetAssociatedApproval(download_item)) { + return true; + } else { + return false; + } +} + scoped_refptr<CrxInstaller> OpenChromeExtension( Profile* profile, const DownloadItem& download_item) { @@ -71,8 +80,8 @@ scoped_refptr<CrxInstaller> OpenChromeExtension( installer->InstallUserScript(download_item.GetFullPath(), download_item.GetURL()); } else { - bool is_gallery_download = - WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; + bool is_gallery_download = service->IsDownloadFromGallery( + download_item.GetURL(), download_item.GetReferrerUrl()); installer->set_original_mime_type(download_item.GetOriginalMimeType()); installer->set_apps_require_extension_mime_type(true); installer->set_download_url(download_item.GetURL()); diff --git a/chrome/browser/download/download_crx_util.h b/chrome/browser/download/download_crx_util.h index 0a105fa..43de912 100644 --- a/chrome/browser/download/download_crx_util.h +++ b/chrome/browser/download/download_crx_util.h @@ -29,6 +29,11 @@ namespace download_crx_util { // install, and again after the first install and before the second. void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui); +// Returns true if the specified download_item containing an extension should be +// automatically installed. This is typically true in the case of webstore +// installations. +bool ShouldOpenExtensionDownload(const content::DownloadItem& download_item); + // Start installing a downloaded item item as a CRX (extension, theme, app, // ...). The installer does work on the file thread, so the installation // is not complete when this function returns. Returns the object managing diff --git a/chrome/browser/download/download_shelf_context_menu.cc b/chrome/browser/download/download_shelf_context_menu.cc index 952bc7d..ddc9c9d 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -11,7 +11,6 @@ #include "chrome/browser/safe_browsing/download_protection_service.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_switch_utils.h" #include "content/public/browser/download_item.h" #include "content/public/browser/download_manager.h" #include "grit/generated_resources.h" @@ -51,7 +50,7 @@ bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { return download_item_->CanShowInFolder() && !download_item_->IsTemporary() && (!Extension::IsExtension(download_item_->GetTargetName()) || - extensions::switch_utils::IsOffStoreInstallEnabled()); + download_crx_util::ShouldOpenExtensionDownload(*download_item_)); case ALWAYS_OPEN_TYPE: // For temporary downloads, the target filename might be a temporary // filename. Don't base an "Always open" decision based on it. Also |