| Index: chrome/browser/extensions/extension_install_prompt.cc
|
| diff --git a/chrome/browser/extensions/extension_install_prompt.cc b/chrome/browser/extensions/extension_install_prompt.cc
|
| index aec3b6293f0e55ec747ac49aee55e1bcd61dd690..22a843269543121f8c82e7f8df5789ecd5c3a7c8 100644
|
| --- a/chrome/browser/extensions/extension_install_prompt.cc
|
| +++ b/chrome/browser/extensions/extension_install_prompt.cc
|
| @@ -95,6 +95,13 @@ namespace {
|
| // Size of extension icon in top left of dialog.
|
| const int kIconSize = 69;
|
|
|
| +// A flag used for SetExtensionInstallDialogAutoConfirmForTests
|
| +enum AutoConfirmForTest {
|
| + DO_NOT_SKIP = 0,
|
| + PROCEED,
|
| + ABORT
|
| +};
|
| +
|
| // Returns pixel size under maximal scale factor for the icon whose device
|
| // independent size is |size_in_dip|
|
| int GetSizeForMaxScaleFactor(int size_in_dip) {
|
| @@ -120,6 +127,39 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
|
| GetRepresentation(max_scale_factor).sk_bitmap();
|
| }
|
|
|
| +void AutoConfirmTask(ExtensionInstallPrompt::Delegate* delegate, bool proceed) {
|
| + if (proceed)
|
| + delegate->InstallUIProceed();
|
| + else
|
| + delegate->InstallUIAbort(true);
|
| +}
|
| +
|
| +void DoAutoConfirm(AutoConfirmForTest setting,
|
| + ExtensionInstallPrompt::Delegate* delegate) {
|
| + bool proceed = (setting == PROCEED);
|
| + // We use PostTask instead of calling the delegate directly here, because in
|
| + // the real implementations it's highly likely the message loop will be
|
| + // pumping a few times before the user clicks accept or cancel.
|
| + MessageLoop::current()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&AutoConfirmTask, delegate, proceed));
|
| +}
|
| +
|
| +AutoConfirmForTest CheckAutoConfirmCommandLineSwitch() {
|
| + const CommandLine* cmdline = CommandLine::ForCurrentProcess();
|
| + if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests))
|
| + return DO_NOT_SKIP;
|
| + std::string value = cmdline->GetSwitchValueASCII(
|
| + switches::kAppsGalleryInstallAutoConfirmForTests);
|
| + if (value == "accept")
|
| + return PROCEED;
|
| + else if (value == "cancel")
|
| + return ABORT;
|
| + else
|
| + NOTREACHED();
|
| + return DO_NOT_SKIP;
|
| +}
|
| +
|
| } // namespace
|
|
|
| ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type)
|
| @@ -348,23 +388,28 @@ void ExtensionInstallPrompt::ConfirmStandaloneInstall(
|
| FetchOAuthIssueAdviceIfNeeded();
|
| }
|
|
|
| -void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate,
|
| - const Extension* extension,
|
| - const SkBitmap* icon) {
|
| +void ExtensionInstallPrompt::ConfirmWebstoreInstall(
|
| + Delegate* delegate,
|
| + const Extension* extension,
|
| + const SkBitmap* icon,
|
| + scoped_refptr<ExtensionInstallDialog> dialog) {
|
| // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
|
| // remaining fields.
|
| extension_ = extension;
|
| SetIcon(icon);
|
| - ConfirmInstall(delegate, extension);
|
| + ConfirmInstall(delegate, extension, dialog);
|
| }
|
|
|
| -void ExtensionInstallPrompt::ConfirmInstall(Delegate* delegate,
|
| - const Extension* extension) {
|
| +void ExtensionInstallPrompt::ConfirmInstall(
|
| + Delegate* delegate,
|
| + const Extension* extension,
|
| + scoped_refptr<ExtensionInstallDialog> dialog) {
|
| DCHECK(ui_loop_ == MessageLoop::current());
|
| extension_ = extension;
|
| permissions_ = extension->GetActivePermissions();
|
| delegate_ = delegate;
|
| prompt_type_ = INSTALL_PROMPT;
|
| + dialog_ = dialog;
|
|
|
| // We special-case themes to not show any confirm UI. Instead they are
|
| // immediately installed, and then we show an infobar (see OnInstallSuccess)
|
| @@ -537,17 +582,31 @@ void ExtensionInstallPrompt::ShowConfirmation() {
|
| case INSTALL_PROMPT: {
|
| prompt_.set_extension(extension_);
|
| prompt_.set_icon(gfx::Image(icon_));
|
| - ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_);
|
| break;
|
| }
|
| case BUNDLE_INSTALL_PROMPT: {
|
| prompt_.set_bundle(bundle_);
|
| - ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_);
|
| break;
|
| }
|
| default:
|
| NOTREACHED() << "Unknown message";
|
| - break;
|
| + return;
|
| + }
|
| +
|
| + AutoConfirmForTest auto_confirm = CheckAutoConfirmCommandLineSwitch();
|
| + if (auto_confirm != DO_NOT_SKIP) {
|
| + DoAutoConfirm(auto_confirm, delegate_);
|
| + return;
|
| + }
|
| +
|
| + if (dialog_.get()) {
|
| + dialog_->ShowExtensionInstallDialog(
|
| + parent_, navigator_, delegate_, prompt_);
|
| + } else {
|
| + scoped_refptr<ExtensionInstallDialog> dialog(
|
| + ExtensionInstallDialog::CreateDefaultImpl());
|
| + dialog->ShowExtensionInstallDialog(
|
| + parent_, navigator_, delegate_, prompt_);
|
| }
|
| }
|
|
|
|
|