OLD | NEW |
1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 14 matching lines...) Expand all Loading... |
26 profile_(tab_contents->profile()), | 26 profile_(tab_contents->profile()), |
27 name_(new_theme->name()), | 27 name_(new_theme->name()), |
28 theme_id_(new_theme->id()), | 28 theme_id_(new_theme->id()), |
29 previous_theme_id_(previous_theme_id), | 29 previous_theme_id_(previous_theme_id), |
30 tab_contents_(tab_contents) { | 30 tab_contents_(tab_contents) { |
31 profile_->GetThemeProvider()->OnInfobarDisplayed(); | 31 profile_->GetThemeProvider()->OnInfobarDisplayed(); |
32 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 32 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
33 NotificationService::AllSources()); | 33 NotificationService::AllSources()); |
34 } | 34 } |
35 | 35 |
| 36 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) { |
| 37 return theme && (theme->id() == theme_id_); |
| 38 } |
| 39 |
36 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { | 40 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { |
37 // We don't want any notifications while we're running our destructor. | 41 // We don't want any notifications while we're running our destructor. |
38 registrar_.RemoveAll(); | 42 registrar_.RemoveAll(); |
39 | 43 |
40 profile_->GetThemeProvider()->OnInfobarDestroyed(); | 44 profile_->GetThemeProvider()->OnInfobarDestroyed(); |
41 } | 45 } |
42 | 46 |
| 47 bool ThemeInstalledInfoBarDelegate::Cancel() { |
| 48 if (!previous_theme_id_.empty()) { |
| 49 ExtensionService* service = profile_->GetExtensionService(); |
| 50 if (service) { |
| 51 const Extension* previous_theme = |
| 52 service->GetExtensionById(previous_theme_id_, true); |
| 53 if (previous_theme) { |
| 54 profile_->SetTheme(previous_theme); |
| 55 return true; |
| 56 } |
| 57 } |
| 58 } |
| 59 |
| 60 profile_->ClearTheme(); |
| 61 return true; |
| 62 } |
| 63 |
43 void ThemeInstalledInfoBarDelegate::InfoBarClosed() { | 64 void ThemeInstalledInfoBarDelegate::InfoBarClosed() { |
44 delete this; | 65 delete this; |
45 } | 66 } |
46 | 67 |
47 string16 ThemeInstalledInfoBarDelegate::GetMessageText() const { | |
48 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL, | |
49 UTF8ToUTF16(name_)); | |
50 } | |
51 | |
52 SkBitmap* ThemeInstalledInfoBarDelegate::GetIcon() const { | 68 SkBitmap* ThemeInstalledInfoBarDelegate::GetIcon() const { |
53 // TODO(aa): Reply with the theme's icon, but this requires reading it | 69 // TODO(aa): Reply with the theme's icon, but this requires reading it |
54 // asynchronously from disk. | 70 // asynchronously from disk. |
55 return ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_INFOBAR_THEME); | 71 return ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_INFOBAR_THEME); |
56 } | 72 } |
57 | 73 |
58 ThemeInstalledInfoBarDelegate* | 74 ThemeInstalledInfoBarDelegate* |
59 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() { | 75 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() { |
60 return this; | 76 return this; |
61 } | 77 } |
62 | 78 |
| 79 string16 ThemeInstalledInfoBarDelegate::GetMessageText() const { |
| 80 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL, |
| 81 UTF8ToUTF16(name_)); |
| 82 } |
| 83 |
63 int ThemeInstalledInfoBarDelegate::GetButtons() const { | 84 int ThemeInstalledInfoBarDelegate::GetButtons() const { |
64 return BUTTON_CANCEL; | 85 return BUTTON_CANCEL; |
65 } | 86 } |
66 | 87 |
67 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel( | 88 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel( |
68 ConfirmInfoBarDelegate::InfoBarButton button) const { | 89 InfoBarButton button) const { |
69 // The InfoBar will create a default OK button and make it invisible. | 90 DCHECK_EQ(BUTTON_CANCEL, button); |
70 // TODO(mirandac): remove the default OK button from ConfirmInfoBar. | 91 return l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); |
71 return (button == BUTTON_CANCEL) ? | |
72 l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON) : | |
73 string16(); | |
74 } | |
75 | |
76 bool ThemeInstalledInfoBarDelegate::Cancel() { | |
77 if (!previous_theme_id_.empty()) { | |
78 ExtensionService* service = profile_->GetExtensionService(); | |
79 if (service) { | |
80 const Extension* previous_theme = | |
81 service->GetExtensionById(previous_theme_id_, true); | |
82 if (previous_theme) { | |
83 profile_->SetTheme(previous_theme); | |
84 return true; | |
85 } | |
86 } | |
87 } | |
88 | |
89 profile_->ClearTheme(); | |
90 return true; | |
91 } | 92 } |
92 | 93 |
93 void ThemeInstalledInfoBarDelegate::Observe( | 94 void ThemeInstalledInfoBarDelegate::Observe( |
94 NotificationType type, | 95 NotificationType type, |
95 const NotificationSource& source, | 96 const NotificationSource& source, |
96 const NotificationDetails& details) { | 97 const NotificationDetails& details) { |
97 DCHECK_EQ(NotificationType::BROWSER_THEME_CHANGED, type.value); | 98 DCHECK_EQ(NotificationType::BROWSER_THEME_CHANGED, type.value); |
98 // If the new theme is different from what this info bar is associated | 99 // If the new theme is different from what this info bar is associated |
99 // with, close this info bar since it is no longer relevant. | 100 // with, close this info bar since it is no longer relevant. |
100 const Extension* extension = Details<const Extension>(details).ptr(); | 101 const Extension* extension = Details<const Extension>(details).ptr(); |
101 if (!extension || theme_id_ != extension->id()) { | 102 if (!extension || theme_id_ != extension->id()) { |
102 if (tab_contents_ && !tab_contents_->is_being_destroyed()) { | 103 if (tab_contents_ && !tab_contents_->is_being_destroyed()) { |
103 tab_contents_->RemoveInfoBar(this); | 104 tab_contents_->RemoveInfoBar(this); |
104 // The infobar is gone so there is no reason for this delegate to keep | 105 // The infobar is gone so there is no reason for this delegate to keep |
105 // a pointer to the TabContents (the TabContents has deleted its | 106 // a pointer to the TabContents (the TabContents has deleted its |
106 // reference to this delegate and a new delegate will be created if | 107 // reference to this delegate and a new delegate will be created if |
107 // a new infobar is created). | 108 // a new infobar is created). |
108 tab_contents_ = NULL; | 109 tab_contents_ = NULL; |
109 // Although it's not being used anymore, this delegate is never deleted. | 110 // Although it's not being used anymore, this delegate is never deleted. |
110 // It can not be deleted now because it is still needed if we | 111 // It can not be deleted now because it is still needed if we |
111 // "undo" the theme change that triggered this notification | 112 // "undo" the theme change that triggered this notification |
112 // (when InfoBar::OnBackgroundExpose() is called). This will likely | 113 // (when InfoBar::OnBackgroundExpose() is called). This will likely |
113 // be fixed when infobar delegate deletion is cleaned up for | 114 // be fixed when infobar delegate deletion is cleaned up for |
114 // http://crbug.com/62154. | 115 // http://crbug.com/62154. |
115 } | 116 } |
116 } | 117 } |
117 } | 118 } |
118 | |
119 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) { | |
120 return (theme && theme->id() == theme_id_); | |
121 } | |
OLD | NEW |