Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5003)

Unified Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 11087071: Making ShowExtensionInstallDialog a callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1b667c19ac38b13aa85bddca3fd31a75cc8cce1b 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"
@@ -95,6 +94,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 +126,39 @@ SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
GetRepresentation(max_scale_factor).sk_bitmap();
}
+void AutoConfirmTask(ExtensionInstallPrompt::Delegate* delegate, bool proceed) {
Aaron Boodman 2012/10/11 20:28:50 This is a bit weird. Can check proceed in DoAutoCo
sail 2012/10/11 21:18:47 Done.
+ 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 +387,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,
+ 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;
// 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 +581,27 @@ 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();
Aaron Boodman 2012/10/11 20:28:50 is there any reason for CheckAutoConfirmCommandLin
sail 2012/10/11 21:18:47 Done.
+ if (auto_confirm != DO_NOT_SKIP) {
+ DoAutoConfirm(auto_confirm, delegate_);
+ return;
}
+
+ if (show_dialog_callback_.is_null())
+ ShowExtensionInstallDialogImpl(parent_, navigator_, delegate_, prompt_);
+ else
+ show_dialog_callback_.Run(parent_, navigator_, delegate_, prompt_);
}
namespace chrome {

Powered by Google App Engine
This is Rietveld 408576698