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" |
11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/infobars/infobar.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/themes/theme_service.h" | 15 #include "chrome/browser/themes/theme_service.h" |
15 #include "chrome/browser/themes/theme_service_factory.h" | 16 #include "chrome/browser/themes/theme_service_factory.h" |
16 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
20 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
21 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
(...skipping 18 matching lines...) Expand all Loading... |
40 chrome::FindTabbedBrowser(profile, true, chrome::GetActiveDesktop()); | 41 chrome::FindTabbedBrowser(profile, true, chrome::GetActiveDesktop()); |
41 if (!browser) | 42 if (!browser) |
42 return; | 43 return; |
43 content::WebContents* web_contents = | 44 content::WebContents* web_contents = |
44 browser->tab_strip_model()->GetActiveWebContents(); | 45 browser->tab_strip_model()->GetActiveWebContents(); |
45 if (!web_contents) | 46 if (!web_contents) |
46 return; | 47 return; |
47 InfoBarService* infobar_service = | 48 InfoBarService* infobar_service = |
48 InfoBarService::FromWebContents(web_contents); | 49 InfoBarService::FromWebContents(web_contents); |
49 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); | 50 ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); |
50 scoped_ptr<InfoBarDelegate> new_infobar(new ThemeInstalledInfoBarDelegate( | 51 scoped_ptr<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( |
51 infobar_service, profile->GetExtensionService(), theme_service, new_theme, | 52 scoped_ptr<ConfirmInfoBarDelegate>(new ThemeInstalledInfoBarDelegate( |
52 previous_theme_id, previous_using_native_theme)); | 53 profile->GetExtensionService(), theme_service, new_theme, |
| 54 previous_theme_id, previous_using_native_theme)))); |
53 | 55 |
54 // If there's a previous theme infobar, just replace that instead of adding a | 56 // If there's a previous theme infobar, just replace that instead of adding a |
55 // new one. | 57 // new one. |
56 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { | 58 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { |
57 InfoBarDelegate* old_infobar = infobar_service->infobar_at(i); | 59 InfoBar* old_infobar = infobar_service->infobar_at(i); |
58 ThemeInstalledInfoBarDelegate* theme_infobar = | 60 ThemeInstalledInfoBarDelegate* theme_infobar = |
59 old_infobar->AsThemePreviewInfobarDelegate(); | 61 old_infobar->delegate()->AsThemePreviewInfobarDelegate(); |
60 if (theme_infobar) { | 62 if (theme_infobar) { |
61 // If the user installed the same theme twice, ignore the second install | 63 // If the user installed the same theme twice, ignore the second install |
62 // and keep the first install info bar, so that they can easily undo to | 64 // and keep the first install info bar, so that they can easily undo to |
63 // get back the previous theme. | 65 // get back the previous theme. |
64 if (theme_infobar->theme_id_ != new_theme->id()) { | 66 if (theme_infobar->theme_id_ != new_theme->id()) { |
65 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); | 67 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); |
66 theme_service->OnInfobarDisplayed(); | 68 theme_service->OnInfobarDisplayed(); |
67 } | 69 } |
68 return; | 70 return; |
69 } | 71 } |
70 } | 72 } |
71 | 73 |
72 // No previous theme infobar, so add this. | 74 // No previous theme infobar, so add this. |
73 infobar_service->AddInfoBar(new_infobar.Pass()); | 75 infobar_service->AddInfoBar(new_infobar.Pass()); |
74 theme_service->OnInfobarDisplayed(); | 76 theme_service->OnInfobarDisplayed(); |
75 } | 77 } |
76 | 78 |
77 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( | 79 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( |
78 InfoBarService* infobar_service, | |
79 ExtensionService* extension_service, | 80 ExtensionService* extension_service, |
80 ThemeService* theme_service, | 81 ThemeService* theme_service, |
81 const extensions::Extension* new_theme, | 82 const extensions::Extension* new_theme, |
82 const std::string& previous_theme_id, | 83 const std::string& previous_theme_id, |
83 bool previous_using_native_theme) | 84 bool previous_using_native_theme) |
84 : ConfirmInfoBarDelegate(infobar_service), | 85 : ConfirmInfoBarDelegate(), |
85 extension_service_(extension_service), | 86 extension_service_(extension_service), |
86 theme_service_(theme_service), | 87 theme_service_(theme_service), |
87 name_(new_theme->name()), | 88 name_(new_theme->name()), |
88 theme_id_(new_theme->id()), | 89 theme_id_(new_theme->id()), |
89 previous_theme_id_(previous_theme_id), | 90 previous_theme_id_(previous_theme_id), |
90 previous_using_native_theme_(previous_using_native_theme) { | 91 previous_using_native_theme_(previous_using_native_theme) { |
91 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 92 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
92 content::Source<ThemeService>(theme_service_)); | 93 content::Source<ThemeService>(theme_service_)); |
93 } | 94 } |
94 | 95 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 148 } |
148 | 149 |
149 void ThemeInstalledInfoBarDelegate::Observe( | 150 void ThemeInstalledInfoBarDelegate::Observe( |
150 int type, | 151 int type, |
151 const content::NotificationSource& source, | 152 const content::NotificationSource& source, |
152 const content::NotificationDetails& details) { | 153 const content::NotificationDetails& details) { |
153 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 154 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
154 // If the new theme is different from what this info bar is associated with, | 155 // If the new theme is different from what this info bar is associated with, |
155 // close this info bar since it is no longer relevant. | 156 // close this info bar since it is no longer relevant. |
156 if (theme_id_ != theme_service_->GetThemeID()) | 157 if (theme_id_ != theme_service_->GetThemeID()) |
157 RemoveSelf(); | 158 infobar()->RemoveSelf(); |
158 } | 159 } |
OLD | NEW |