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

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

Issue 1600030: Select and close previous theme info bars when resetting to default theme via... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
« no previous file with comments | « chrome/browser/extensions/theme_installed_infobar_delegate.h ('k') | chrome/chrome_tests.gypi » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser_theme_provider.h" 12 #include "chrome/browser/browser_theme_provider.h"
13 #include "chrome/browser/extensions/extensions_service.h" 13 #include "chrome/browser/extensions/extensions_service.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/browser/tab_contents/tab_contents.h" 15 #include "chrome/browser/tab_contents/tab_contents.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/notification_service.h"
17 #include "grit/generated_resources.h" 18 #include "grit/generated_resources.h"
18 #include "grit/theme_resources.h" 19 #include "grit/theme_resources.h"
19 20
20 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( 21 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
21 TabContents* tab_contents, const Extension* new_theme, 22 TabContents* tab_contents, const Extension* new_theme,
22 const std::string& previous_theme_id) 23 const std::string& previous_theme_id)
23 : ConfirmInfoBarDelegate(tab_contents), 24 : ConfirmInfoBarDelegate(tab_contents),
24 profile_(tab_contents->profile()), 25 profile_(tab_contents->profile()),
25 name_(new_theme->name()), 26 name_(new_theme->name()),
26 previous_theme_id_(previous_theme_id) { 27 theme_id_(new_theme->id()),
28 previous_theme_id_(previous_theme_id),
29 tab_contents_(tab_contents) {
27 profile_->GetThemeProvider()->OnInfobarDisplayed(); 30 profile_->GetThemeProvider()->OnInfobarDisplayed();
31 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
32 NotificationService::AllSources());
28 } 33 }
29 34
30 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { 35 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() {
36 // We don't want any notifications while we're running our destructor.
37 registrar_.RemoveAll();
38
31 profile_->GetThemeProvider()->OnInfobarDestroyed(); 39 profile_->GetThemeProvider()->OnInfobarDestroyed();
32 } 40 }
33 41
34 void ThemeInstalledInfoBarDelegate::InfoBarClosed() { 42 void ThemeInstalledInfoBarDelegate::InfoBarClosed() {
35 delete this; 43 delete this;
36 } 44 }
37 45
38 std::wstring ThemeInstalledInfoBarDelegate::GetMessageText() const { 46 std::wstring ThemeInstalledInfoBarDelegate::GetMessageText() const {
39 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL, 47 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL,
40 UTF8ToWide(name_)); 48 UTF8ToWide(name_));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 if (previous_theme) { 86 if (previous_theme) {
79 profile_->SetTheme(previous_theme); 87 profile_->SetTheme(previous_theme);
80 return true; 88 return true;
81 } 89 }
82 } 90 }
83 } 91 }
84 92
85 profile_->ClearTheme(); 93 profile_->ClearTheme();
86 return true; 94 return true;
87 } 95 }
96
97 void ThemeInstalledInfoBarDelegate::Observe(
98 NotificationType type,
99 const NotificationSource& source,
100 const NotificationDetails& details) {
101 switch (type.value) {
102 case NotificationType::BROWSER_THEME_CHANGED: {
103 // If the new theme is different from what this info bar is associated
104 // with, close this info bar since it is no longer relevant.
105 Extension* extension = Details<Extension>(details).ptr();
106 if (!extension || theme_id_ != extension->id())
107 tab_contents_->RemoveInfoBar(this);
108 break;
109 }
110
111 default:
112 NOTREACHED();
113 }
114 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/theme_installed_infobar_delegate.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698