diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 18:37:38 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 18:37:38 +0000 |
commit | 1e09a50056d013f04f980855e8c0c5a424070985 (patch) | |
tree | 1b86f0df4c12e0098be5790b26c56cf23571d943 | |
parent | 601298ebd4745c16d156c0a85fcf800acf110997 (diff) | |
download | chromium_src-1e09a50056d013f04f980855e8c0c5a424070985.zip chromium_src-1e09a50056d013f04f980855e8c0c5a424070985.tar.gz chromium_src-1e09a50056d013f04f980855e8c0c5a424070985.tar.bz2 |
Make the theme install infobar have an 'undo' button instead
of a 'back to default' button.
BUG=18986
TEST=none
Review URL: http://codereview.chromium.org/164312
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23055 0039d316-1c4b-4281-b951-d872f2087c98
5 files changed, 36 insertions, 19 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index beeb358..98b07bf 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -2079,8 +2079,8 @@ each locale. --> <message name="IDS_THEME_INSTALL_INFOBAR_LABEL" desc="Text displayed on an infobar when a theme has been installed."> Installed theme "<ph name="THEME_NAME">$1<ex>Snowflake Theme</ex></ph>" </message> - <message name="IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON" desc="Text displayed on the button to undo a theme installation and go back to the default theme."> - Back to default + <message name="IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON" desc="Text displayed on the button to undo a theme installation and go back to the previous theme."> + Undo </message> <!-- Extesion install prompt --> diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index cfc5e54..a2c9258 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -37,6 +37,11 @@ void ExtensionInstallUI::ConfirmInstall(CrxInstaller* installer, // immediately installed, and then we show an infobar (see OnInstallSuccess) // to allow the user to revert if they don't like it. if (extension->IsTheme()) { + // Remember the current theme in case the user pressed undo. + Extension* previous_theme = profile_->GetTheme(); + if (previous_theme) + previous_theme_id_ = previous_theme->id(); + installer->ContinueInstall(); return; } @@ -100,8 +105,8 @@ void ExtensionInstallUI::OnOverinstallAttempted(Extension* extension) { ShowThemeInfoBar(extension); } -void ExtensionInstallUI::ShowThemeInfoBar(Extension* extension) { - if (!extension->IsTheme()) +void ExtensionInstallUI::ShowThemeInfoBar(Extension* new_theme) { + if (!new_theme->IsTheme()) return; Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); @@ -124,7 +129,7 @@ void ExtensionInstallUI::ShowThemeInfoBar(Extension* extension) { // Then either replace that old one or add a new one. InfoBarDelegate* new_delegate = new ThemePreviewInfobarDelegate(tab_contents, - extension->name()); + new_theme->name(), previous_theme_id_); if (old_delegate) tab_contents->ReplaceInfoBar(old_delegate, new_delegate); diff --git a/chrome/browser/extensions/extension_install_ui.h b/chrome/browser/extensions/extension_install_ui.h index 9cdc5ac..6ca224d 100644 --- a/chrome/browser/extensions/extension_install_ui.h +++ b/chrome/browser/extensions/extension_install_ui.h @@ -34,10 +34,11 @@ class ExtensionInstallUI : public CrxInstallerClient { virtual void OnInstallFailure(const std::string& error); virtual void OnOverinstallAttempted(Extension* extension); - void ShowThemeInfoBar(Extension* extension); + void ShowThemeInfoBar(Extension* new_theme); Profile* profile_; MessageLoop* ui_loop_; + std::string previous_theme_id_; // Used to undo theme installation. }; #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_INSTALL_UI_H_ diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.cc b/chrome/browser/extensions/theme_preview_infobar_delegate.cc index a1a179f..ac71aa9 100644 --- a/chrome/browser/extensions/theme_preview_infobar_delegate.cc +++ b/chrome/browser/extensions/theme_preview_infobar_delegate.cc @@ -6,14 +6,18 @@ #include "app/l10n_util.h" #include "base/string_util.h" +#include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/extensions/extension.h" #include "grit/generated_resources.h" ThemePreviewInfobarDelegate::ThemePreviewInfobarDelegate( - TabContents* tab_contents, const std::string& name) + TabContents* tab_contents, const std::string& name, + const std::string& previous_theme_id) : ConfirmInfoBarDelegate(tab_contents), - profile_(tab_contents->profile()), name_(name) { + profile_(tab_contents->profile()), name_(name), + previous_theme_id_(previous_theme_id) { } void ThemePreviewInfobarDelegate::InfoBarClosed() { @@ -44,20 +48,27 @@ std::wstring ThemePreviewInfobarDelegate::GetButtonLabel( ConfirmInfoBarDelegate::InfoBarButton button) const { switch (button) { case BUTTON_CANCEL: - return l10n_util::GetString(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); + // TODO(aa): Reusing IDS_UNDO is hack to get around string freeze. This + // should be changed back to IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON at some + // point. + return l10n_util::GetString(IDS_UNDO); default: return L""; } } bool ThemePreviewInfobarDelegate::Cancel() { - // 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. + if (!previous_theme_id_.empty()) { + ExtensionsService* service = profile_->GetExtensionsService(); + if (service) { + Extension* previous_theme = service->GetExtensionById(previous_theme_id_); + if (previous_theme) { + profile_->SetTheme(previous_theme); + return true; + } + } + } + profile_->ClearTheme(); return true; } diff --git a/chrome/browser/extensions/theme_preview_infobar_delegate.h b/chrome/browser/extensions/theme_preview_infobar_delegate.h index dcc34b6..9b214bb 100644 --- a/chrome/browser/extensions/theme_preview_infobar_delegate.h +++ b/chrome/browser/extensions/theme_preview_infobar_delegate.h @@ -7,8 +7,6 @@ #include "chrome/browser/tab_contents/infobar_delegate.h" -class Extension; -class ExtensionsService; class SkBitmap; class TabContents; @@ -20,7 +18,8 @@ class TabContents; class ThemePreviewInfobarDelegate : public ConfirmInfoBarDelegate { public: ThemePreviewInfobarDelegate(TabContents* tab_contents, - const std::string& name); + const std::string& name, + const std::string& previous_theme); virtual void InfoBarClosed(); virtual std::wstring GetMessageText() const; virtual SkBitmap* GetIcon() const; @@ -33,6 +32,7 @@ class ThemePreviewInfobarDelegate : public ConfirmInfoBarDelegate { private: Profile* profile_; std::string name_; // name of theme to install + std::string previous_theme_id_; // used to undo theme install }; #endif // CHROME_BROWSER_VIEWS_EXTENSIONS_THEME_PREVIEW_INFOBAR_DELEGATE_H_ |