summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions
diff options
context:
space:
mode:
authorjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-18 05:38:54 +0000
committerjorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-18 05:38:54 +0000
commit140debc9ab97da79036d70db21859d771cecf134 (patch)
treebb5a7ab2e15869ee14cc4a9c77a2848fb089d325 /chrome/browser/extensions
parentedc53eb89220666a85fac4fe4fee9f0de52bd4ab (diff)
downloadchromium_src-140debc9ab97da79036d70db21859d771cecf134.zip
chromium_src-140debc9ab97da79036d70db21859d771cecf134.tar.gz
chromium_src-140debc9ab97da79036d70db21859d771cecf134.tar.bz2
Select and close previous theme info bars when resetting to default theme via the options dialog. As a nice side effect if one tab is showing a theme info bar and the user switches to a different theme in another tab, this change closes the previous theme info bars as well.
BUG=35607 TEST=Install a theme, and with the theme info bar visible open Preferences dialog and click 'reset to default theme' and check the info bar. (full steps given in the above bug entry) Landing http://codereview.chromium.org/1622017/show for Satish. Review URL: http://codereview.chromium.org/1600030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44885 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions')
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.cc35
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.h19
2 files changed, 49 insertions, 5 deletions
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
index 196f9ff..345a57f 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
@@ -14,20 +14,28 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/notification_service.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
TabContents* tab_contents, const Extension* new_theme,
const std::string& previous_theme_id)
- : ConfirmInfoBarDelegate(tab_contents),
- profile_(tab_contents->profile()),
- name_(new_theme->name()),
- previous_theme_id_(previous_theme_id) {
+ : ConfirmInfoBarDelegate(tab_contents),
+ profile_(tab_contents->profile()),
+ name_(new_theme->name()),
+ theme_id_(new_theme->id()),
+ previous_theme_id_(previous_theme_id),
+ tab_contents_(tab_contents) {
profile_->GetThemeProvider()->OnInfobarDisplayed();
+ registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
+ NotificationService::AllSources());
}
ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() {
+ // We don't want any notifications while we're running our destructor.
+ registrar_.RemoveAll();
+
profile_->GetThemeProvider()->OnInfobarDestroyed();
}
@@ -85,3 +93,22 @@ bool ThemeInstalledInfoBarDelegate::Cancel() {
profile_->ClearTheme();
return true;
}
+
+void ThemeInstalledInfoBarDelegate::Observe(
+ NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::BROWSER_THEME_CHANGED: {
+ // If the new theme is different from what this info bar is associated
+ // with, close this info bar since it is no longer relevant.
+ Extension* extension = Details<Extension>(details).ptr();
+ if (!extension || theme_id_ != extension->id())
+ tab_contents_->RemoveInfoBar(this);
+ break;
+ }
+
+ default:
+ NOTREACHED();
+ }
+}
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h
index b8baf41..beb99c6 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.h
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_EXTENSIONS_THEME_INSTALLED_INFOBAR_DELEGATE_H_
#include "chrome/browser/tab_contents/infobar_delegate.h"
+#include "chrome/common/notification_registrar.h"
class Extension;
class SkBitmap;
@@ -13,7 +14,8 @@ class TabContents;
// When a user installs a theme, we display it immediately, but provide an
// infobar allowing them to cancel.
-class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate {
+class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
+ public NotificationObserver {
public:
ThemeInstalledInfoBarDelegate(TabContents* tab_contents,
const Extension* new_theme,
@@ -28,15 +30,30 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate {
ConfirmInfoBarDelegate::InfoBarButton button) const;
virtual bool Cancel();
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
protected:
Profile* profile() { return profile_; }
private:
Profile* profile_;
+
// Name of theme that's just been installed.
std::string name_;
+
+ // ID of theme that's just been installed.
+ std::string theme_id_;
+
// Used to undo theme install.
std::string previous_theme_id_;
+
+ // Tab to which this info bar is associated.
+ TabContents* tab_contents_;
+
+ // Registers and unregisters us for notifications.
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_EXTENSIONS_THEME_INSTALLED_INFOBAR_DELEGATE_H_