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..3f473495a2329fed20dcc124c58f05d8420edf69 100644 |
--- a/chrome/browser/extensions/extension_install_prompt.cc |
+++ b/chrome/browser/extensions/extension_install_prompt.cc |
@@ -14,7 +14,6 @@ |
#include "base/stringprintf.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/browser/extensions/bundle_installer.h" |
-#include "chrome/browser/extensions/extension_install_dialog.h" |
#include "chrome/browser/extensions/extension_install_ui.h" |
#include "chrome/browser/prefs/pref_service.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -120,6 +119,37 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
GetRepresentation(max_scale_factor).sk_bitmap(); |
} |
+// If auto confirm is enabled then posts a task to proceed with or cancel the install |
+// and returns true. Otherwise returns false. |
+bool DoAutoConfirm(ExtensionInstallPrompt::Delegate* delegate) { |
+ const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
+ if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) |
+ return false; |
+ std::string value = cmdline->GetSwitchValueASCII( |
+ switches::kAppsGalleryInstallAutoConfirmForTests); |
+ |
+ // 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. |
+ if (value == "accept") { |
+ MessageLoop::current()->PostTask( |
+ FROM_HERE, base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
Aaron Boodman
2012/10/11 21:44:47
Weird indent.
Aaron Boodman
2012/10/11 21:44:47
80 cols
sail
2012/10/11 21:49:38
Done.
sail
2012/10/11 21:49:38
Done.
|
+ base::Unretained(delegate))); |
+ return true; |
+ } |
+ |
+ if (value == "cancel") { |
+ MessageLoop::current()->PostTask( |
Aaron Boodman
2012/10/11 21:44:47
ditto
sail
2012/10/11 21:49:38
Done.
|
+ FROM_HERE, base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
+ base::Unretained(delegate), |
+ true)); |
+ return true; |
+ } |
+ |
+ NOTREACHED(); |
+ return false; |
+} |
+ |
} // namespace |
ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) |
@@ -348,23 +378,29 @@ 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, |
+ const ShowDialogCallback& show_dialog_callback) { |
// SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
// remaining fields. |
extension_ = extension; |
SetIcon(icon); |
- ConfirmInstall(delegate, extension); |
+ ConfirmInstall(delegate, extension, show_dialog_callback); |
} |
-void ExtensionInstallPrompt::ConfirmInstall(Delegate* delegate, |
- const Extension* extension) { |
+void ExtensionInstallPrompt::ConfirmInstall( |
+ Delegate* delegate, |
+ const Extension* extension, |
+ const ShowDialogCallback& show_dialog_callback) { |
DCHECK(ui_loop_ == MessageLoop::current()); |
extension_ = extension; |
permissions_ = extension->GetActivePermissions(); |
delegate_ = delegate; |
prompt_type_ = INSTALL_PROMPT; |
+ show_dialog_callback_ = show_dialog_callback; |
+ DCHECK(!show_dialog_callback_.is_null()); |
// We special-case themes to not show any confirm UI. Instead they are |
// immediately installed, and then we show an infobar (see OnInstallSuccess) |
@@ -537,18 +573,22 @@ 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; |
} |
+ |
Aaron Boodman
2012/10/11 21:44:47
naming: if (AutoConfirmPrompt()) ?
sail
2012/10/11 21:49:55
Done.
|
+ if (DoAutoConfirm(delegate_)) |
+ return; |
+ |
+ DCHECK(!show_dialog_callback_.is_null()); |
+ show_dialog_callback_.Run(parent_, navigator_, delegate_, prompt_); |
} |
namespace chrome { |