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

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

Issue 5034004: Misc. cleanup (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 1 month 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
« no previous file with comments | « no previous file | chrome/browser/translate/languages_menu_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/profile.h" 13 #include "chrome/browser/profile.h"
14 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
15 #include "chrome/browser/themes/browser_theme_provider.h" 15 #include "chrome/browser/themes/browser_theme_provider.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
18 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
20 20
21 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( 21 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
22 TabContents* tab_contents, const Extension* new_theme, 22 TabContents* tab_contents,
23 const Extension* new_theme,
23 const std::string& previous_theme_id) 24 const std::string& previous_theme_id)
24 : ConfirmInfoBarDelegate(tab_contents), 25 : ConfirmInfoBarDelegate(tab_contents),
25 profile_(tab_contents->profile()), 26 profile_(tab_contents->profile()),
26 name_(new_theme->name()), 27 name_(new_theme->name()),
27 theme_id_(new_theme->id()), 28 theme_id_(new_theme->id()),
28 previous_theme_id_(previous_theme_id), 29 previous_theme_id_(previous_theme_id),
29 tab_contents_(tab_contents) { 30 tab_contents_(tab_contents) {
30 profile_->GetThemeProvider()->OnInfobarDisplayed(); 31 profile_->GetThemeProvider()->OnInfobarDisplayed();
31 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, 32 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
32 NotificationService::AllSources()); 33 NotificationService::AllSources());
(...skipping 11 matching lines...) Expand all
44 } 45 }
45 46
46 string16 ThemeInstalledInfoBarDelegate::GetMessageText() const { 47 string16 ThemeInstalledInfoBarDelegate::GetMessageText() const {
47 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL, 48 return l10n_util::GetStringFUTF16(IDS_THEME_INSTALL_INFOBAR_LABEL,
48 UTF8ToUTF16(name_)); 49 UTF8ToUTF16(name_));
49 } 50 }
50 51
51 SkBitmap* ThemeInstalledInfoBarDelegate::GetIcon() const { 52 SkBitmap* ThemeInstalledInfoBarDelegate::GetIcon() const {
52 // TODO(aa): Reply with the theme's icon, but this requires reading it 53 // TODO(aa): Reply with the theme's icon, but this requires reading it
53 // asynchronously from disk. 54 // asynchronously from disk.
54 return ResourceBundle::GetSharedInstance().GetBitmapNamed( 55 return ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_INFOBAR_THEME);
55 IDR_INFOBAR_THEME);
56 } 56 }
57 57
58 ThemeInstalledInfoBarDelegate* 58 ThemeInstalledInfoBarDelegate*
59 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() { 59 ThemeInstalledInfoBarDelegate::AsThemePreviewInfobarDelegate() {
60 return this; 60 return this;
61 } 61 }
62 62
63 int ThemeInstalledInfoBarDelegate::GetButtons() const { 63 int ThemeInstalledInfoBarDelegate::GetButtons() const {
64 return BUTTON_CANCEL; 64 return BUTTON_CANCEL;
65 } 65 }
66 66
67 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel( 67 string16 ThemeInstalledInfoBarDelegate::GetButtonLabel(
68 ConfirmInfoBarDelegate::InfoBarButton button) const { 68 ConfirmInfoBarDelegate::InfoBarButton button) const {
69 switch (button) { 69 // The InfoBar will create a default OK button and make it invisible.
70 case BUTTON_CANCEL: { 70 // TODO(mirandac): remove the default OK button from ConfirmInfoBar.
71 return l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); 71 return (button == BUTTON_CANCEL) ?
72 } 72 l10n_util::GetStringUTF16(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON) :
73 default: 73 string16();
74 // The InfoBar will create a default OK button and make it invisible.
75 // TODO(mirandac): remove the default OK button from ConfirmInfoBar.
76 return string16();
77 }
78 } 74 }
79 75
80 bool ThemeInstalledInfoBarDelegate::Cancel() { 76 bool ThemeInstalledInfoBarDelegate::Cancel() {
81 if (!previous_theme_id_.empty()) { 77 if (!previous_theme_id_.empty()) {
82 ExtensionsService* service = profile_->GetExtensionsService(); 78 ExtensionsService* service = profile_->GetExtensionsService();
83 if (service) { 79 if (service) {
84 const Extension* previous_theme = 80 const Extension* previous_theme =
85 service->GetExtensionById(previous_theme_id_, true); 81 service->GetExtensionById(previous_theme_id_, true);
86 if (previous_theme) { 82 if (previous_theme) {
87 profile_->SetTheme(previous_theme); 83 profile_->SetTheme(previous_theme);
88 return true; 84 return true;
89 } 85 }
90 } 86 }
91 } 87 }
92 88
93 profile_->ClearTheme(); 89 profile_->ClearTheme();
94 return true; 90 return true;
95 } 91 }
96 92
97 void ThemeInstalledInfoBarDelegate::Observe( 93 void ThemeInstalledInfoBarDelegate::Observe(
98 NotificationType type, 94 NotificationType type,
99 const NotificationSource& source, 95 const NotificationSource& source,
100 const NotificationDetails& details) { 96 const NotificationDetails& details) {
101 switch (type.value) { 97 DCHECK_EQ(NotificationType::BROWSER_THEME_CHANGED, type.value);
102 case NotificationType::BROWSER_THEME_CHANGED: { 98 // If the new theme is different from what this info bar is associated
103 // 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.
104 // with, close this info bar since it is no longer relevant. 100 const Extension* extension = Details<const Extension>(details).ptr();
105 const Extension* extension = Details<const Extension>(details).ptr(); 101 if (!extension || theme_id_ != extension->id())
106 if (!extension || theme_id_ != extension->id()) 102 tab_contents_->RemoveInfoBar(this);
107 tab_contents_->RemoveInfoBar(this);
108 break;
109 }
110
111 default:
112 NOTREACHED();
113 }
114 } 103 }
115 104
116 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) { 105 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) {
117 return (theme && theme->id() == theme_id_); 106 return (theme && theme->id() == theme_id_);
118 } 107 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/translate/languages_menu_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698