| OLD | NEW |
| 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_preview_infobar_delegate.h" | 5 #include "chrome/browser/extensions/theme_preview_infobar_delegate.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/extensions/extensions_service.h" |
| 9 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| 10 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/extensions/extension.h" |
| 11 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
| 12 | 14 |
| 13 ThemePreviewInfobarDelegate::ThemePreviewInfobarDelegate( | 15 ThemePreviewInfobarDelegate::ThemePreviewInfobarDelegate( |
| 14 TabContents* tab_contents, const std::string& name) | 16 TabContents* tab_contents, const std::string& name, |
| 17 const std::string& previous_theme_id) |
| 15 : ConfirmInfoBarDelegate(tab_contents), | 18 : ConfirmInfoBarDelegate(tab_contents), |
| 16 profile_(tab_contents->profile()), name_(name) { | 19 profile_(tab_contents->profile()), name_(name), |
| 20 previous_theme_id_(previous_theme_id) { |
| 17 } | 21 } |
| 18 | 22 |
| 19 void ThemePreviewInfobarDelegate::InfoBarClosed() { | 23 void ThemePreviewInfobarDelegate::InfoBarClosed() { |
| 20 delete this; | 24 delete this; |
| 21 } | 25 } |
| 22 | 26 |
| 23 std::wstring ThemePreviewInfobarDelegate::GetMessageText() const { | 27 std::wstring ThemePreviewInfobarDelegate::GetMessageText() const { |
| 24 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL, | 28 return l10n_util::GetStringF(IDS_THEME_INSTALL_INFOBAR_LABEL, |
| 25 UTF8ToWide(name_)); | 29 UTF8ToWide(name_)); |
| 26 } | 30 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 ConfirmInfoBarDelegate::InfoBarButton button) const { | 48 ConfirmInfoBarDelegate::InfoBarButton button) const { |
| 45 switch (button) { | 49 switch (button) { |
| 46 case BUTTON_CANCEL: | 50 case BUTTON_CANCEL: |
| 47 return l10n_util::GetString(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); | 51 return l10n_util::GetString(IDS_THEME_INSTALL_INFOBAR_UNDO_BUTTON); |
| 48 default: | 52 default: |
| 49 return L""; | 53 return L""; |
| 50 } | 54 } |
| 51 } | 55 } |
| 52 | 56 |
| 53 bool ThemePreviewInfobarDelegate::Cancel() { | 57 bool ThemePreviewInfobarDelegate::Cancel() { |
| 54 // Blech, this is a total hack. | 58 if (!previous_theme_id_.empty()) { |
| 55 // | 59 ExtensionsService* service = profile_->GetExtensionsService(); |
| 56 // a) We should be uninstalling via ExtensionsService, not | 60 if (service) { |
| 57 // Profile::ClearTheme(). | 61 Extension* previous_theme = service->GetExtensionById(previous_theme_id_); |
| 58 // b) We should be able to view the theme without installing it. This would | 62 if (previous_theme) { |
| 59 // help in edge cases like the user closing the window or tab before making | 63 profile_->SetTheme(previous_theme); |
| 60 // a decision. | 64 return true; |
| 65 } |
| 66 } |
| 67 } |
| 68 |
| 61 profile_->ClearTheme(); | 69 profile_->ClearTheme(); |
| 62 return true; | 70 return true; |
| 63 } | 71 } |
| OLD | NEW |