| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
| 13 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources_standard.h" | 18 #include "grit/theme_resources_standard.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 | 21 |
| 22 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( | 22 ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( |
| 23 InfoBarTabHelper* infobar_helper, | 23 InfoBarTabHelper* infobar_helper, |
| 24 ExtensionService* extension_service, | 24 ExtensionService* extension_service, |
| 25 ThemeService* theme_service, | 25 ThemeService* theme_service, |
| 26 const Extension* new_theme, | 26 const extensions::Extension* new_theme, |
| 27 const std::string& previous_theme_id, | 27 const std::string& previous_theme_id, |
| 28 bool previous_using_native_theme) | 28 bool previous_using_native_theme) |
| 29 : ConfirmInfoBarDelegate(infobar_helper), | 29 : ConfirmInfoBarDelegate(infobar_helper), |
| 30 extension_service_(extension_service), | 30 extension_service_(extension_service), |
| 31 theme_service_(theme_service), | 31 theme_service_(theme_service), |
| 32 name_(new_theme->name()), | 32 name_(new_theme->name()), |
| 33 theme_id_(new_theme->id()), | 33 theme_id_(new_theme->id()), |
| 34 previous_theme_id_(previous_theme_id), | 34 previous_theme_id_(previous_theme_id), |
| 35 previous_using_native_theme_(previous_using_native_theme) { | 35 previous_using_native_theme_(previous_using_native_theme) { |
| 36 theme_service_->OnInfobarDisplayed(); | 36 theme_service_->OnInfobarDisplayed(); |
| 37 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 37 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 38 content::Source<ThemeService>(theme_service_)); | 38 content::Source<ThemeService>(theme_service_)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool ThemeInstalledInfoBarDelegate::MatchesTheme(const Extension* theme) const { | 41 bool ThemeInstalledInfoBarDelegate::MatchesTheme( |
| 42 const extensions::Extension* theme) const { |
| 42 return theme && (theme->id() == theme_id_); | 43 return theme && (theme->id() == theme_id_); |
| 43 } | 44 } |
| 44 | 45 |
| 45 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { | 46 ThemeInstalledInfoBarDelegate::~ThemeInstalledInfoBarDelegate() { |
| 46 // We don't want any notifications while we're running our destructor. | 47 // We don't want any notifications while we're running our destructor. |
| 47 registrar_.RemoveAll(); | 48 registrar_.RemoveAll(); |
| 48 | 49 |
| 49 theme_service_->OnInfobarDestroyed(); | 50 theme_service_->OnInfobarDestroyed(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 bool ThemeInstalledInfoBarDelegate::Cancel() { | 53 bool ThemeInstalledInfoBarDelegate::Cancel() { |
| 53 if (!previous_theme_id_.empty()) { | 54 if (!previous_theme_id_.empty()) { |
| 54 const Extension* previous_theme = | 55 const extensions::Extension* previous_theme = |
| 55 extension_service_->GetExtensionById(previous_theme_id_, true); | 56 extension_service_->GetExtensionById(previous_theme_id_, true); |
| 56 if (previous_theme) { | 57 if (previous_theme) { |
| 57 theme_service_->SetTheme(previous_theme); | 58 theme_service_->SetTheme(previous_theme); |
| 58 return false; // The theme change will close us. | 59 return false; // The theme change will close us. |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 | 62 |
| 62 if (previous_using_native_theme_) | 63 if (previous_using_native_theme_) |
| 63 theme_service_->SetNativeTheme(); | 64 theme_service_->SetNativeTheme(); |
| 64 else | 65 else |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void ThemeInstalledInfoBarDelegate::Observe( | 101 void ThemeInstalledInfoBarDelegate::Observe( |
| 101 int type, | 102 int type, |
| 102 const content::NotificationSource& source, | 103 const content::NotificationSource& source, |
| 103 const content::NotificationDetails& details) { | 104 const content::NotificationDetails& details) { |
| 104 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); | 105 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
| 105 // If the new theme is different from what this info bar is associated with, | 106 // If the new theme is different from what this info bar is associated with, |
| 106 // close this info bar since it is no longer relevant. | 107 // close this info bar since it is no longer relevant. |
| 107 if (theme_id_ != theme_service_->GetThemeID()) | 108 if (theme_id_ != theme_service_->GetThemeID()) |
| 108 RemoveSelf(); | 109 RemoveSelf(); |
| 109 } | 110 } |
| OLD | NEW |