diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 06:16:12 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-26 06:16:12 +0000 |
commit | 6ef635e4882c4f7af0e17bc525e5922d6d7f82f0 (patch) | |
tree | f6676862802e279b41eb66663b6c39874f9f6705 | |
parent | 9ceb0734baeac21d1560023475f381b8a21e6cfa (diff) | |
download | chromium_src-6ef635e4882c4f7af0e17bc525e5922d6d7f82f0.zip chromium_src-6ef635e4882c4f7af0e17bc525e5922d6d7f82f0.tar.gz chromium_src-6ef635e4882c4f7af0e17bc525e5922d6d7f82f0.tar.bz2 |
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
-rw-r--r-- | chrome/app/generated_resources.grd | 13 | ||||
-rw-r--r-- | chrome/browser/download/download_manager.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.cc | 35 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service.h | 12 | ||||
-rw-r--r-- | chrome/browser/extensions/extensions_service_unittest.cc | 35 | ||||
-rw-r--r-- | chrome/browser/extensions/theme_preview_infobar_delegate.cc | 72 | ||||
-rw-r--r-- | chrome/browser/extensions/theme_preview_infobar_delegate.h | 36 | ||||
-rw-r--r-- | chrome/browser/profile.cc | 3 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
9 files changed, 174 insertions, 40 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 5323db1..961188c 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -1946,7 +1946,18 @@ each locale. --> </message> <message name="IDS_EXTENSION_CRASHED_INFOBAR_MESSAGE" desc="Message displayed on the extension crashed infobar."> The following extension has crashed : <ph name="EXTENSION_NAME">$1<ex>Buildbot Monitor</ex></ph> - </message> + </message> + + <!-- Extension Crashed Info Bar--> + <message name="IDS_THEME_PREVIEW_INFOBAR_LABEL" desc="Text displayed on an infobar while previewing a theme."> + Previewing theme "<ph name="THEME_NAME">$1<ex>Snowflake Theme</ex></ph>" + </message> + <message name="IDS_THEME_PREVIEW_INFOBAR_OK_BUTTON" desc="Text displayed on the button to accept a theme preview."> + Keep this theme + </message> + <message name="IDS_THEME_PREVIEW_INFOBAR_CANCEL_BUTTON" desc="Text displayed on the button to reject a theme preview and go back to the default theme."> + Back to default + </message> <!-- Session Crashed Info Bar--> <message name="IDS_SESSION_CRASHED_VIEW_RESTORE_BUTTON" desc="Title of the restore button in the session crashed view."> diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc index d8e3237..ad8f16b 100644 --- a/chrome/browser/download/download_manager.cc +++ b/chrome/browser/download/download_manager.cc @@ -1235,8 +1235,10 @@ void DownloadManager::OpenDownload(const DownloadItem* download, void DownloadManager::OpenChromeExtension(const FilePath& full_path, const GURL& download_url, const GURL& referrer_url) { - profile_->GetOriginalProfile()->GetExtensionsService()-> - InstallExtension(full_path, download_url, referrer_url); + // We don't support extensions in OTR mode. + if (profile_->GetExtensionsService()) + profile_->GetExtensionsService()->InstallExtension(full_path, download_url, + referrer_url); } void DownloadManager::OpenDownloadInShell(const DownloadItem* download, 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* kSignatureVerificationFailed = "Signature verification failed"; 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 @@ ExtensionsService::ExtensionsService(Profile* profile, 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 @@ void ExtensionsService::OnExtensionInstalled(const FilePath& path, // 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 @@ void ExtensionsService::OnExtensionOverinstallAttempted(const std::string& id, 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 @@ void ExtensionsService::SetProviderForTesting( 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 @@ void ExtensionsServiceBackend::OnExtensionUnpacked( 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 @@ void ExtensionsServiceBackend::OnExtensionUnpacked( // 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)) diff --git a/chrome/browser/extensions/extensions_service.h b/chrome/browser/extensions/extensions_service.h index 8e0305f..4a57e41 100644 --- a/chrome/browser/extensions/extensions_service.h +++ b/chrome/browser/extensions/extensions_service.h @@ -208,6 +208,9 @@ class ExtensionsService return show_extensions_prompts_; } + // Profile calls this when it is destroyed so that we know not to call it. + void ProfileDestroyed() { profile_ = NULL; } + ExtensionPrefs* extension_prefs() { return extension_prefs_.get(); } // Whether the extension service is ready. @@ -239,6 +242,15 @@ class ExtensionsService void OnExtensionOverinstallAttempted(const std::string& id, const FilePath& path); + // Show a confirm installation infobar on the currently active tab. + // TODO(aa): This should be moved up into the UI and attached to the tab it + // actually occured in. This requires some modularization of + // ExtensionsService. + bool ShowThemePreviewInfobar(Extension* extension); + + // The profile this ExtensionsService is part of. + Profile* profile_; + // Preferences for the owning profile. scoped_ptr<ExtensionPrefs> extension_prefs_; diff --git a/chrome/browser/extensions/extensions_service_unittest.cc b/chrome/browser/extensions/extensions_service_unittest.cc index 99e43ea..f997894 100644 --- a/chrome/browser/extensions/extensions_service_unittest.cc +++ b/chrome/browser/extensions/extensions_service_unittest.cc @@ -342,15 +342,8 @@ class ExtensionsServiceTest void InstallExtension(const FilePath& path, bool should_succeed) { - InstallExtension(path, should_succeed, GURL(), GURL()); - } - - void InstallExtension(const FilePath& path, - bool should_succeed, - const GURL& download_url, - const GURL& referrer_url) { ASSERT_TRUE(file_util::PathExists(path)); - service_->InstallExtension(path, download_url, referrer_url); + service_->InstallExtension(path); loop_.RunAllPending(); std::vector<std::string> errors = GetErrors(); if (should_succeed) { @@ -803,35 +796,15 @@ TEST_F(ExtensionsServiceTest, InstallTheme) { ValidatePref(theme_crx, L"state", Extension::ENABLED); ValidatePref(theme_crx, L"location", Extension::INTERNAL); - // A theme when extensions are disabled. Themes cannot be installed when - // extensions are disabled... - SetExtensionsEnabled(false); - path = extensions_path.AppendASCII("theme2.crx"); - InstallExtension(path, false); - ValidatePrefKeyCount(pref_count); - - // ... unless they come from the gallery URL. + // A theme when extensions are disabled. Themes can be installed, even when + // extensions are disabled. SetExtensionsEnabled(false); path = extensions_path.AppendASCII("theme2.crx"); - InstallExtension(path, true, - GURL(std::string(ExtensionsService::kGalleryDownloadURLPrefix) + "f.crx"), - GURL(std::string(ExtensionsService::kGalleryURLPrefix) + "foobar")); + InstallExtension(path, true); ValidatePrefKeyCount(++pref_count); ValidatePref(theme2_crx, L"state", Extension::ENABLED); ValidatePref(theme2_crx, L"location", Extension::INTERNAL); - // also test this fails if either of the URLs is not correct - path = extensions_path.AppendASCII("theme2.crx"); - InstallExtension(path, false, - GURL(std::string(ExtensionsService::kGalleryDownloadURLPrefix) + "f.crx"), - GURL()); - ValidatePrefKeyCount(pref_count); - - path = extensions_path.AppendASCII("theme2.crx"); - InstallExtension(path, false, - GURL(), GURL(std::string(ExtensionsService::kGalleryURLPrefix) + "foobar")); - ValidatePrefKeyCount(pref_count); - // A theme with extension elements. Themes cannot have extension elements so // this test should fail. SetExtensionsEnabled(true); diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.cc b/chrome/browser/extensions/theme_preview_infobar_delegate.cc new file mode 100644 index 0000000..f985c1b --- /dev/null +++ b/chrome/browser/extensions/theme_preview_infobar_delegate.cc @@ -0,0 +1,72 @@ +// Copyright (c) 2009 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/browser/extensions/theme_preview_infobar_delegate.h" + +#include "app/l10n_util.h" +#include "base/string_util.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "grit/generated_resources.h" + +ThemePreviewInfobarDelegate::ThemePreviewInfobarDelegate( + TabContents* tab_contents, const std::string& name) + : ConfirmInfoBarDelegate(tab_contents), + profile_(tab_contents->profile()), name_(name), + selection_made_(false) { +} + +void ThemePreviewInfobarDelegate::InfoBarClosed() { + if (!selection_made_) + profile_->ClearTheme(); + + delete this; +} + +std::wstring ThemePreviewInfobarDelegate::GetMessageText() const { + return l10n_util::GetStringF(IDS_THEME_PREVIEW_INFOBAR_LABEL, + UTF8ToWide(name_)); +} + +SkBitmap* ThemePreviewInfobarDelegate::GetIcon() const { + // TODO(aa): Reply with the theme's icon, but this requires reading it + // asynchronously from disk. + return NULL; +} + +int ThemePreviewInfobarDelegate::GetButtons() const { + return BUTTON_OK | BUTTON_CANCEL; +} + +std::wstring ThemePreviewInfobarDelegate::GetButtonLabel( + ConfirmInfoBarDelegate::InfoBarButton button) const { + switch (button) { + case BUTTON_OK: + return l10n_util::GetString(IDS_THEME_PREVIEW_INFOBAR_OK_BUTTON); + case BUTTON_CANCEL: + return l10n_util::GetString(IDS_THEME_PREVIEW_INFOBAR_CANCEL_BUTTON); + default: + NOTREACHED(); + return L""; + } +} + +bool ThemePreviewInfobarDelegate::Accept() { + selection_made_ = true; + return true; +} + +bool ThemePreviewInfobarDelegate::Cancel() { + selection_made_ = true; + + // Blech, this is a total hack. + // + // a) We should be uninstalling via ExtensionsService, not + // Profile::ClearTheme(). + // b) We should be able to view the theme without installing it. This would + // help in edge cases like the user closing the window or tab before making + // a decision. + profile_->ClearTheme(); + return true; +} diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.h b/chrome/browser/extensions/theme_preview_infobar_delegate.h new file mode 100644 index 0000000..4fa4dd2 --- /dev/null +++ b/chrome/browser/extensions/theme_preview_infobar_delegate.h @@ -0,0 +1,36 @@ +// Copyright (c) 2009 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_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ +#define CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ + +#include "chrome/browser/tab_contents/infobar_delegate.h" + +class Extension; +class ExtensionsService; +class SkBitmap; +class TabContents; + +// When a user installs a theme, we display it immediately, but provide an +// infobar allowing them to cancel. +class ThemePreviewInfobarDelegate : public ConfirmInfoBarDelegate { + public: + ThemePreviewInfobarDelegate(TabContents* tab_contents, + const std::string& name); + virtual void InfoBarClosed(); + virtual std::wstring GetMessageText() const; + virtual SkBitmap* GetIcon() const; + virtual int GetButtons() const; + virtual std::wstring GetButtonLabel( + ConfirmInfoBarDelegate::InfoBarButton button) const; + virtual bool Accept(); + virtual bool Cancel(); + + private: + Profile* profile_; + std::string name_; // name of theme to install + bool selection_made_; // whether the user has made a selection yet +}; + +#endif // CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 1f7faf8..f32a7bd 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -671,6 +671,9 @@ ProfileImpl::~ProfileImpl() { extension_message_service_->ProfileDestroyed(); + if (extensions_service_) + extensions_service_->ProfileDestroyed(); + MarkAsCleanShutdown(); } diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index a3632a2f..571b364 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -977,6 +977,8 @@ 'browser/extensions/external_registry_extension_provider_win.h', 'browser/extensions/external_pref_extension_provider.cc', 'browser/extensions/external_pref_extension_provider.h', + 'browser/extensions/theme_preview_infobar_delegate.cc', + 'browser/extensions/theme_preview_infobar_delegate.h', 'browser/extensions/user_script_master.cc', 'browser/extensions/user_script_master.h', 'browser/external_protocol_handler.cc', |