diff options
-rw-r--r-- | chrome/browser/download/chrome_download_manager_delegate.cc | 8 | ||||
-rw-r--r-- | chrome/browser/download/download_crx_util.cc | 10 | ||||
-rw-r--r-- | chrome/browser/download/download_crx_util.h | 5 | ||||
-rw-r--r-- | chrome/browser/download/download_shelf_context_menu.cc | 10 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/common/chrome_switches.cc | 5 | ||||
-rw-r--r-- | chrome/common/chrome_switches.h | 1 | ||||
-rw-r--r-- | chrome/common/extensions/extension_switch_utils.cc | 21 | ||||
-rw-r--r-- | chrome/common/extensions/extension_switch_utils.h | 19 |
9 files changed, 75 insertions, 6 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc index e069edd..5b2a0e9 100644 --- a/chrome/browser/download/chrome_download_manager_delegate.cc +++ b/chrome/browser/download/chrome_download_manager_delegate.cc @@ -92,8 +92,12 @@ bool ChromeDownloadManagerDelegate::IsExtensionDownload( if (item->PromptUserForSaveLocation()) return false; - return (item->GetMimeType() == Extension::kMimeType) || - UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType()); + if ((item->GetMimeType() != Extension::kMimeType) && + !UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType())) { + return false; + } + + return download_crx_util::ShouldOpenExtensionDownload(*item); } void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { diff --git a/chrome/browser/download/download_crx_util.cc b/chrome/browser/download/download_crx_util.cc index ab242df..a34ebec 100644 --- a/chrome/browser/download/download_crx_util.cc +++ b/chrome/browser/download/download_crx_util.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/webstore_installer.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_notification_types.h" +#include "chrome/common/extensions/extension_switch_utils.h" #include "content/public/browser/download_item.h" #include "content/public/browser/notification_service.h" @@ -50,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) { 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 6cb748e..ddc9c9d 100644 --- a/chrome/browser/download/download_shelf_context_menu.cc +++ b/chrome/browser/download/download_shelf_context_menu.cc @@ -5,6 +5,7 @@ #include "chrome/browser/download/download_shelf_context_menu.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/download/download_crx_util.h" #include "chrome/browser/download/download_item_model.h" #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/safe_browsing/download_protection_service.h" @@ -43,12 +44,13 @@ ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { switch (command_id) { case SHOW_IN_FOLDER: - case OPEN_WHEN_COMPLETE: - // Don't enable "Open when complete" if the download is no longer - // available or if it is temporary. We explicitly ignore "Open when - // complete" for temporary downloads. return download_item_->CanShowInFolder() && !download_item_->IsTemporary(); + case OPEN_WHEN_COMPLETE: + return download_item_->CanShowInFolder() && + !download_item_->IsTemporary() && + (!Extension::IsExtension(download_item_->GetTargetName()) || + 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 diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index ba60bf0..7e00dd2 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -140,6 +140,8 @@ 'common/extensions/extension_resource.h', 'common/extensions/extension_set.cc', 'common/extensions/extension_set.h', + 'common/extensions/extension_switch_utils.cc', + 'common/extensions/extension_switch_utils.h', 'common/extensions/extension_unpacker.cc', 'common/extensions/extension_unpacker.h', 'common/extensions/feature.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 007bdb3..d8ed129 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -330,6 +330,11 @@ const char kDisableLoginAnimations[] = "disable-login-animations"; // Disables the menu on the NTP for accessing sessions from other devices. const char kDisableNTPOtherSessionsMenu[] = "disable-ntp-other-sessions-menu"; +// Disables the inline off-store extension installation UI. With this switch, +// users must use a new out-of-band installation UI from chrome://extensions/. +const char kDisableOffStoreExtensionInstall[] = + "disable-off-store-extension-install"; + // Disable speculative TCP/IP preconnection. const char kDisablePreconnect[] = "disable-preconnect"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 98e5418..348344f 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -98,6 +98,7 @@ extern const char kDisableIPv6[]; extern const char kDisableIPPooling[]; extern const char kDisableNTPOtherSessionsMenu[]; extern const char kDisableLoginAnimations[]; +extern const char kDisableOffStoreExtensionInstall[]; extern const char kDisablePreconnect[]; extern const char kDisablePromptOnRepost[]; extern const char kDisableRestoreBackgroundContents[]; diff --git a/chrome/common/extensions/extension_switch_utils.cc b/chrome/common/extensions/extension_switch_utils.cc new file mode 100644 index 0000000..77bac1c --- /dev/null +++ b/chrome/common/extensions/extension_switch_utils.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/extensions/extension_switch_utils.h" + +#include "base/command_line.h" +#include "chrome/common/chrome_switches.h" + +namespace extensions { + +namespace switch_utils { + +bool IsOffStoreInstallEnabled() { + return !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableOffStoreExtensionInstall); +} + +} // switch_utils + +} // extensions diff --git a/chrome/common/extensions/extension_switch_utils.h b/chrome/common/extensions/extension_switch_utils.h new file mode 100644 index 0000000..c52879f --- /dev/null +++ b/chrome/common/extensions/extension_switch_utils.h @@ -0,0 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_SWITCH_UTILS_H_ +#define CHROME_COMMON_EXTENSIONS_EXTENSION_SWITCH_UTILS_H_ +#pragma once + +namespace extensions { + +namespace switch_utils { + +bool IsOffStoreInstallEnabled(); + +} // switch_utils + +} // extensions + +#endif // CHROME_COMMON_EXTENSIONS_EXTENSION_SWITCH_UTILS_H_ |