Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Add the --disable-off-store-extension-install switch.
Browse files Browse the repository at this point in the history
Subsequent changes will add a first-class UI in chrome://extensions/
to meet this use case.

BUG=55584

Review URL: https://chromiumcodereview.appspot.com/10266015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134980 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aa@chromium.org committed May 2, 2012
1 parent aea8089 commit 4766606
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 6 deletions.
8 changes: 6 additions & 2 deletions chrome/browser/download/chrome_download_manager_delegate.cc
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/download/download_crx_util.cc
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/download/download_crx_util.h
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/download/download_shelf_context_menu.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions chrome/chrome_common.gypi
Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions chrome/common/chrome_switches.cc
Expand Up @@ -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";

Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Expand Up @@ -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[];
Expand Down
21 changes: 21 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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_

0 comments on commit 4766606

Please sign in to comment.