OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 | 24 |
25 | 25 |
26 // static | 26 // static |
27 void ThemeInstalledInfoBarDelegate::Create( | 27 void ThemeInstalledInfoBarDelegate::Create( |
28 const extensions::Extension* new_theme, | 28 const extensions::Extension* new_theme, |
29 Profile* profile, | 29 Profile* profile, |
30 const std::string& previous_theme_id, | 30 const std::string& previous_theme_id, |
31 bool previous_using_native_theme) { | 31 bool previous_using_system_theme) { |
32 DCHECK(new_theme); | 32 DCHECK(new_theme); |
33 if (!new_theme->is_theme()) | 33 if (!new_theme->is_theme()) |
34 return; | 34 return; |
35 | 35 |
36 // Create the new infobar. | 36 // Create the new infobar. |
37 // FindTabbedBrowser() is called with |match_original_profiles| true because a | 37 // FindTabbedBrowser() is called with |match_original_profiles| true because a |
38 // theme install in either a normal or incognito window for a profile affects | 38 // theme install in either a normal or incognito window for a profile affects |
39 // all normal and incognito windows for that profile. | 39 // all normal and incognito windows for that profile. |
40 Browser* browser = | 40 Browser* browser = |
41 chrome::FindTabbedBrowser(profile, true, chrome::GetActiveDesktop()); | 41 chrome::FindTabbedBrowser(profile, true, chrome::GetActiveDesktop()); |
42 if (!browser) | 42 if (!browser) |
43 return; | 43 return; |
44 content::WebContents* web_contents = | 44 content::WebContents* web_contents = |
45 browser->tab_strip_model()->GetActiveWebContents(); | 45 browser->tab_strip_model()->GetActiveWebContents(); |
46 if (!web_contents) | 46 if (!web_contents) |
47 return; | 47 return; |
48 InfoBarService* infobar_service = | 48 InfoBarService* infobar_service = |
49 InfoBarService::FromWebContents(web_contents); | 49 InfoBarService::FromWebContents(web_contents); |
50 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | 50 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); |
51 scoped_ptr<infobars::InfoBar> new_infobar( | 51 scoped_ptr<infobars::InfoBar> new_infobar( |
52 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( | 52 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( |
53 new ThemeInstalledInfoBarDelegate( | 53 new ThemeInstalledInfoBarDelegate( |
54 profile->GetExtensionService(), theme_service, new_theme, | 54 profile->GetExtensionService(), theme_service, new_theme, |
55 previous_theme_id, previous_using_native_theme)))); | 55 previous_theme_id, previous_using_system_theme)))); |
56 | 56 |
57 // If there's a previous theme infobar, just replace that instead of adding a | 57 // If there's a previous theme infobar, just replace that instead of adding a |
58 // new one. | 58 // new one. |
59 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 59 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
60 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); | 60 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i); |
61 ThemeInstalledInfoBarDelegate* theme_infobar = | 61 ThemeInstalledInfoBarDelegate* theme_infobar = |
62 old_infobar->delegate()->AsThemePreviewInfobarDelegate(); | 62 old_infobar->delegate()->AsThemePreviewInfobarDelegate(); |
63 if (theme_infobar) { | 63 if (theme_infobar) { |
64 // If the user installed the same theme twice, ignore the second install | 64 // If the user installed the same theme twice, ignore the second install |
65 // and keep the first install info bar, so that they can easily undo to | 65 // and keep the first install info bar, so that they can easily undo to |
66 // get back the previous theme. | 66 // get back the previous theme. |
67 if (theme_infobar->theme_id_ != new_theme->id()) { | 67 if (theme_infobar->theme_id_ != new_theme->id()) { |
68 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); | 68 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); |
69 theme_service->OnInfobarDisplayed(); | 69 theme_service->OnInfobarDisplayed(); |
70 } | 70 } |
71 return; | 71 return; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 // No previous theme infobar, so add this. | 75 // No previous theme infobar, so add this. |
76 infobar_service->AddInfoBar(new_infobar.Pass()); | 76 infobar_service->AddInfoBar(new_infobar.Pass()); |
77 theme_service->OnInfobarDisplayed(); | 77 theme_service->OnInfobarDisplayed(); |
78 } | 78 } |
79 | 79 |
80 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( | 80 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( |
81 ExtensionService* extension_service, | 81 ExtensionService* extension_service, |
82 ThemeService* theme_service, | 82 ThemeService* theme_service, |
83 const extensions::Extension* new_theme, | 83 const extensions::Extension* new_theme, |
84 const std::string& previous_theme_id, | 84 const std::string& previous_theme_id, |
85 bool previous_using_native_theme) | 85 bool previous_using_system_theme) |
86 : ConfirmInfoBarDelegate(), | 86 : ConfirmInfoBarDelegate(), |
87 extension_service_(extension_service), | 87 extension_service_(extension_service), |
88 theme_service_(theme_service), | 88 theme_service_(theme_service), |
89 name_(new_theme->name()), | 89 name_(new_theme->name()), |
90 theme_id_(new_theme->id()), | 90 theme_id_(new_theme->id()), |
91 previous_theme_id_(previous_theme_id), | 91 previous_theme_id_(previous_theme_id), |
92 previous_using_native_theme_(previous_using_native_theme) { | 92 previous_using_system_theme_(previous_using_system_theme) { |
93 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 93 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
94 content::Source<ThemeService>(theme_service_)); | 94 content::Source<ThemeService>(theme_service_)); |
95 } | 95 } |
96 | 96 |
97 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { | 97 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { |
98 // We don't want any notifications while we're running our destructor. | 98 // We don't want any notifications while we're running our destructor. |
99 registrar_.RemoveAll(); | 99 registrar_.RemoveAll(); |
100 | 100 |
101 theme_service_->OnInfobarDestroyed(); | 101 theme_service_->OnInfobarDestroyed(); |
102 } | 102 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 bool ThemeInstalledInfoBarDelegate::Cancel() { | 135 bool ThemeInstalledInfoBarDelegate::Cancel() { |
136 if (!previous_theme_id_.empty()) { | 136 if (!previous_theme_id_.empty()) { |
137 const extensions::Extension* previous_theme = | 137 const extensions::Extension* previous_theme = |
138 extension_service_->GetExtensionById(previous_theme_id_, true); | 138 extension_service_->GetExtensionById(previous_theme_id_, true); |
139 if (previous_theme) { | 139 if (previous_theme) { |
140 theme_service_->SetTheme(previous_theme); | 140 theme_service_->SetTheme(previous_theme); |
141 return false; // The theme change will close us. | 141 return false; // The theme change will close us. |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 if (previous_using_native_theme_) | 145 if (previous_using_system_theme_) |
146 theme_service_->SetNativeTheme(); | 146 theme_service_->UseSystemTheme(); |
147 else | 147 else |
148 theme_service_->UseDefaultTheme(); | 148 theme_service_->UseDefaultTheme(); |
149 return false; // The theme change will close us. | 149 return false; // The theme change will close us. |
150 } | 150 } |
151 | 151 |
152 void ThemeInstalledInfoBarDelegate::Observe( | 152 void ThemeInstalledInfoBarDelegate::Observe( |
153 int type, | 153 int type, |
154 const content::NotificationSource& source, | 154 const content::NotificationSource& source, |
155 const content::NotificationDetails& details) { | 155 const content::NotificationDetails& details) { |
156 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 156 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
157 // If the new theme is different from what this info bar is associated with, | 157 // If the new theme is different from what this info bar is associated with, |
158 // close this info bar since it is no longer relevant. | 158 // close this info bar since it is no longer relevant. |
159 if (theme_id_ != theme_service_->GetThemeID()) | 159 if (theme_id_ != theme_service_->GetThemeID()) |
160 infobar()->RemoveSelf(); | 160 infobar()->RemoveSelf(); |
161 } | 161 } |
OLD | NEW |