OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
13 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "content/common/notification_service.h" | 17 #include "content/common/notification_service.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources_standard.h" | 19 #include "grit/theme_resources_standard.h" |
19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
21 | 22 |
22 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( | 23 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( |
23 TabContents* tab_contents, | 24 TabContents* tab_contents, |
24 const Extension* new_theme, | 25 const Extension* new_theme, |
25 const std::string& previous_theme_id, | 26 const std::string& previous_theme_id, |
26 bool previous_using_native_theme) | 27 bool previous_using_native_theme) |
27 : ConfirmInfoBarDelegate(tab_contents), | 28 : ConfirmInfoBarDelegate(tab_contents), |
28 profile_(tab_contents->profile()), | 29 profile_(tab_contents->profile()), |
29 theme_service_(ThemeServiceFactory::GetForProfile(profile_)), | 30 theme_service_(ThemeServiceFactory::GetForProfile(profile_)), |
30 name_(new_theme->name()), | 31 name_(new_theme->name()), |
31 theme_id_(new_theme->id()), | 32 theme_id_(new_theme->id()), |
32 previous_theme_id_(previous_theme_id), | 33 previous_theme_id_(previous_theme_id), |
33 previous_using_native_theme_(previous_using_native_theme), | 34 previous_using_native_theme_(previous_using_native_theme), |
34 tab_contents_(tab_contents) { | 35 tab_contents_(tab_contents) { |
35 theme_service_->OnInfobarDisplayed(); | 36 theme_service_->OnInfobarDisplayed(); |
36 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 37 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
37 Source<ThemeService>(theme_service_)); | 38 Source<ThemeService>(theme_service_)); |
38 } | 39 } |
39 | 40 |
40 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) const { | 41 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) const { |
41 return theme && (theme->id() == theme_id_); | 42 return theme && (theme->id() == theme_id_); |
42 } | 43 } |
43 | 44 |
44 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { | 45 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { |
45 // We don't want any notifications while we're running our destructor. | 46 // We don't want any notifications while we're running our destructor. |
46 registrar_.RemoveAll(); | 47 registrar_.RemoveAll(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return BUTTON_CANCEL; | 91 return BUTTON_CANCEL; |
91 } | 92 } |
92 | 93 |
93 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel( | 94 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel( |
94 InfoBarButton button) const { | 95 InfoBarButton button) const { |
95 DCHECK_EQ(BUTTON_CANCEL, button); | 96 DCHECK_EQ(BUTTON_CANCEL, button); |
96 return l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); | 97 return l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); |
97 } | 98 } |
98 | 99 |
99 void ThemeInstalledInfoBarDelegate::Observe( | 100 void ThemeInstalledInfoBarDelegate::Observe( |
100 NotificationType type, | 101 int type, |
101 const NotificationSource& source, | 102 const NotificationSource& source, |
102 const NotificationDetails& details) { | 103 const NotificationDetails& details) { |
103 DCHECK_EQ(NotificationType::BROWSER_THEME_CHANGED, type.value); | 104 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
104 // If the new theme is different from what this info bar is associated | 105 // If the new theme is different from what this info bar is associated |
105 // with, close this info bar since it is no longer relevant. | 106 // with, close this info bar since it is no longer relevant. |
106 if (theme_id_ != theme_service_->GetThemeID()) { | 107 if (theme_id_ != theme_service_->GetThemeID()) { |
107 if (tab_contents_ && !tab_contents_->is_being_destroyed()) { | 108 if (tab_contents_ && !tab_contents_->is_being_destroyed()) { |
108 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> | 109 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> |
109 RemoveInfoBar(this); | 110 RemoveInfoBar(this); |
110 // The infobar is gone so there is no reason for this delegate to keep | 111 // The infobar is gone so there is no reason for this delegate to keep |
111 // a pointer to the TabContents (the TabContents has deleted its | 112 // a pointer to the TabContents (the TabContents has deleted its |
112 // reference to this delegate and a new delegate will be created if | 113 // reference to this delegate and a new delegate will be created if |
113 // a new infobar is created). | 114 // a new infobar is created). |
114 tab_contents_ = NULL; | 115 tab_contents_ = NULL; |
115 // Although it's not being used anymore, this delegate is never deleted. | 116 // Although it's not being used anymore, this delegate is never deleted. |
116 // It can not be deleted now because it is still needed if we | 117 // It can not be deleted now because it is still needed if we |
117 // "undo" the theme change that triggered this notification | 118 // "undo" the theme change that triggered this notification |
118 // (when InfoBar::OnBackgroundExpose() is called). This will likely | 119 // (when InfoBar::OnBackgroundExpose() is called). This will likely |
119 // be fixed when infobar delegate deletion is cleaned up for | 120 // be fixed when infobar delegate deletion is cleaned up for |
120 // http://crbug.com/62154. | 121 // http://crbug.com/62154. |
121 } | 122 } |
122 } | 123 } |
123 } | 124 } |
OLD | NEW |