Try again to commit r21622: Add infobar preview for themes,
remove --enable-extension requirement.
Review URL: http://codereview.chromium.org/159390
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21626 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index ee5fc8c..970ddc0 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -28,7 +28,9 @@
#include "chrome/browser/extensions/extension_updater.h"
#include "chrome/browser/extensions/external_extension_provider.h"
#include "chrome/browser/extensions/external_pref_extension_provider.h"
+#include "chrome/browser/extensions/theme_preview_infobar_delegate.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/utility_process_host.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension.h"
@@ -85,6 +87,7 @@
const char* kSignatureVerificationInitFailed =
"Signature verification initialization failed. This is most likely "
"caused by a public key in the wrong format (should encode algorithm).";
+
}
// static
@@ -249,7 +252,8 @@
MessageLoop* frontend_loop,
MessageLoop* backend_loop,
bool autoupdate_enabled)
- : extension_prefs_(new ExtensionPrefs(prefs, install_directory)),
+ : profile_(profile),
+ extension_prefs_(new ExtensionPrefs(prefs, install_directory)),
backend_loop_(backend_loop),
install_directory_(install_directory),
extensions_enabled_(false),
@@ -512,6 +516,7 @@
// If the extension is a theme, tell the profile (and therefore ThemeProvider)
// to apply it.
if (extension->IsTheme()) {
+ ShowThemePreviewInfobar(extension);
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
Source<ExtensionsService>(this),
@@ -543,6 +548,7 @@
FireInstallCallback(path, NULL);
Extension* extension = GetExtensionById(id);
if (extension && extension->IsTheme()) {
+ ShowThemePreviewInfobar(extension);
NotificationService::current()->Notify(
NotificationType::THEME_INSTALLED,
Source<ExtensionsService>(this),
@@ -577,6 +583,23 @@
location, test_provider));
}
+bool ExtensionsService::ShowThemePreviewInfobar(Extension* extension) {
+ if (!profile_)
+ return false;
+
+ Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
+ if (!browser)
+ return false;
+
+ TabContents* tab_contents = browser->GetSelectedTabContents();
+ if (!tab_contents)
+ return false;
+
+ tab_contents->AddInfoBar(new ThemePreviewInfobarDelegate(tab_contents,
+ extension->name()));
+ return true;
+}
+
// ExtensionsServicesBackend
ExtensionsServiceBackend::ExtensionsServiceBackend(
@@ -1125,15 +1148,15 @@
Extension::Location location = Extension::INTERNAL;
LookupExternalExtension(extension.id(), NULL, &location);
- // We allow themes from our minigallery or externally-registered
- // extensions to be installed, even without --enable-extensions.
bool allow_install = false;
if (extensions_enabled_)
allow_install = true;
- if (extension.IsTheme() && from_gallery)
+ // Always allow themes.
+ if (extension.IsTheme())
allow_install = true;
+ // Always allow externally installed extensions (partners use this).
if (Extension::IsExternalLocation(location))
allow_install = true;
@@ -1146,12 +1169,12 @@
// TODO(extensions): Make better extensions UI. http://crbug.com/12116
// We also skip the dialog for a few special cases:
- // - themes from the gallery
+ // - themes (because we show the preview infobar for them)
// - externally registered extensions
// - during tests (!frontend->show_extension_prompts())
// - autoupdate (silent).
bool show_dialog = true;
- if (extension.IsTheme() && from_gallery)
+ if (extension.IsTheme())
show_dialog = false;
if (Extension::IsExternalLocation(location))