| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 5 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_theme_provider.h" | 12 #include "chrome/browser/browser_theme_provider.h" |
| 13 #include "chrome/browser/extensions/extensions_service.h" | 13 #include "chrome/browser/extensions/extensions_service.h" |
| 14 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/common/notification_service.h" | |
| 18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 20 | 19 |
| 21 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( | 20 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( |
| 22 TabContents* tab_contents, const Extension* new_theme, | 21 TabContents* tab_contents, const Extension* new_theme, |
| 23 const std::string& previous_theme_id) | 22 const std::string& previous_theme_id) |
| 24 : ConfirmInfoBarDelegate(tab_contents), | 23 : ConfirmInfoBarDelegate(tab_contents), |
| 25 profile_(tab_contents->profile()), | 24 profile_(tab_contents->profile()), |
| 26 name_(new_theme->name()), | 25 name_(new_theme->name()), |
| 27 theme_id_(new_theme->id()), | 26 previous_theme_id_(previous_theme_id) { |
| 28 previous_theme_id_(previous_theme_id), | |
| 29 tab_contents_(tab_contents) { | |
| 30 profile_->GetThemeProvider()->OnInfobarDisplayed(); | 27 profile_->GetThemeProvider()->OnInfobarDisplayed(); |
| 31 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
| 32 NotificationService::AllSources()); | |
| 33 } | 28 } |
| 34 | 29 |
| 35 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { | 30 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { |
| 36 // We don't want any notifications while we're running our destructor. | |
| 37 registrar_.RemoveAll(); | |
| 38 | |
| 39 profile_->GetThemeProvider()->OnInfobarDestroyed(); | 31 profile_->GetThemeProvider()->OnInfobarDestroyed(); |
| 40 } | 32 } |
| 41 | 33 |
| 42 void ThemeInstalledInfoBarDelegate::InfoBarClosed() { | 34 void ThemeInstalledInfoBarDelegate::InfoBarClosed() { |
| 43 delete this; | 35 delete this; |
| 44 } | 36 } |
| 45 | 37 |
| 46 std::wstring ThemeInstalledInfoBarDelegate::GetMessageText() const { | 38 std::wstring ThemeInstalledInfoBarDelegate::GetMessageText() const { |
| 47 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL, | 39 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL, |
| 48 UTF8ToWide(name_)); | 40 UTF8ToWide(name_)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (previous_theme) { | 78 if (previous_theme) { |
| 87 profile_->SetTheme(previous_theme); | 79 profile_->SetTheme(previous_theme); |
| 88 return true; | 80 return true; |
| 89 } | 81 } |
| 90 } | 82 } |
| 91 } | 83 } |
| 92 | 84 |
| 93 profile_->ClearTheme(); | 85 profile_->ClearTheme(); |
| 94 return true; | 86 return true; |
| 95 } | 87 } |
| 96 | |
| 97 void ThemeInstalledInfoBarDelegate::Observe( | |
| 98 NotificationType type, | |
| 99 const NotificationSource& source, | |
| 100 const NotificationDetails& details) { | |
| 101 switch (type.value) { | |
| 102 case NotificationType::BROWSER_THEME_CHANGED: { | |
| 103 // If the new theme is different from what this info bar is associated | |
| 104 // with, close this info bar since it is no longer relevant. | |
| 105 Extension* extension = Details<Extension>(details).ptr(); | |
| 106 if (!extension || theme_id_ != extension->id()) | |
| 107 tab_contents_->RemoveInfoBar(this); | |
| 108 break; | |
| 109 } | |
| 110 | |
| 111 default: | |
| 112 NOTREACHED(); | |
| 113 } | |
| 114 } | |
| OLD | NEW |