Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/extensions/theme_installed_infobar_delegate.cc

Issue 240193003: Move Infobars core files to the Infobars component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nib name on mac Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
13 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
16 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
17 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "components/infobars/core/infobar.h"
19 #include "content/public/browser/notification_source.h" 19 #include "content/public/browser/notification_source.h"
20 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
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,
(...skipping 12 matching lines...) Expand all
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<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( 51 scoped_ptr<infobars::InfoBar> new_infobar(
52 scoped_ptr<ConfirmInfoBarDelegate>(new ThemeInstalledInfoBarDelegate( 52 ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>(
53 profile->GetExtensionService(), theme_service, new_theme, 53 new ThemeInstalledInfoBarDelegate(
54 previous_theme_id, previous_using_native_theme)))); 54 profile->GetExtensionService(), theme_service, new_theme,
55 previous_theme_id, previous_using_native_theme))));
55 56
56 // 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
57 // new one. 58 // new one.
58 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { 59 for (size_t i = 0; i < infobar_service->infobar_count(); ++i) {
59 InfoBar* old_infobar = infobar_service->infobar_at(i); 60 infobars::InfoBar* old_infobar = infobar_service->infobar_at(i);
60 ThemeInstalledInfoBarDelegate* theme_infobar = 61 ThemeInstalledInfoBarDelegate* theme_infobar =
61 old_infobar->delegate()->AsThemePreviewInfobarDelegate(); 62 old_infobar->delegate()->AsThemePreviewInfobarDelegate();
62 if (theme_infobar) { 63 if (theme_infobar) {
63 // 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
64 // 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
65 // get back the previous theme. 66 // get back the previous theme.
66 if (theme_infobar->theme_id_ != new_theme->id()) { 67 if (theme_infobar->theme_id_ != new_theme->id()) {
67 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); 68 infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass());
68 theme_service->OnInfobarDisplayed(); 69 theme_service->OnInfobarDisplayed();
69 } 70 }
(...skipping 29 matching lines...) Expand all
99 100
100 theme_service_->OnInfobarDestroyed(); 101 theme_service_->OnInfobarDestroyed();
101 } 102 }
102 103
103 int ThemeInstalledInfoBarDelegate::GetIconID() const { 104 int ThemeInstalledInfoBarDelegate::GetIconID() const {
104 // TODO(aa): Reply with the theme's icon, but this requires reading it 105 // TODO(aa): Reply with the theme's icon, but this requires reading it
105 // asynchronously from disk. 106 // asynchronously from disk.
106 return IDR_INFOBAR_THEME; 107 return IDR_INFOBAR_THEME;
107 } 108 }
108 109
109 InfoBarDelegate::Type ThemeInstalledInfoBarDelegate::GetInfoBarType() const { 110 infobars::InfoBarDelegate::Type ThemeInstalledInfoBarDelegate::GetInfoBarType()
111 const {
110 return PAGE_ACTION_TYPE; 112 return PAGE_ACTION_TYPE;
111 } 113 }
112 114
113 ThemeInstalledInfoBarDelegate* 115 ThemeInstalledInfoBarDelegate*
114 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() { 116 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() {
115 return this; 117 return this;
116 } 118 }
117 119
118 base::string16 ThemeInstalledInfoBarDelegate::GetMessageText() const { 120 base::string16 ThemeInstalledInfoBarDelegate::GetMessageText() const {
119 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL, 121 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL,
(...skipping 30 matching lines...) Expand all
150 void ThemeInstalledInfoBarDelegate::Observe( 152 void ThemeInstalledInfoBarDelegate::Observe(
151 int type, 153 int type,
152 const content::NotificationSource& source, 154 const content::NotificationSource& source,
153 const content::NotificationDetails& details) { 155 const content::NotificationDetails& details) {
154 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); 156 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type);
155 // 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,
156 // close this info bar since it is no longer relevant. 158 // close this info bar since it is no longer relevant.
157 if (theme_id_ != theme_service_->GetThemeID()) 159 if (theme_id_ != theme_service_->GetThemeID())
158 infobar()->RemoveSelf(); 160 infobar()->RemoveSelf();
159 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698