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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/ui/views/update_recommended_message_box.h" 6 7 #include "chrome/browser/lifetime/application_lifetime.h" 8 #include "chrome/browser/ui/views/constrained_window_views.h" 9 #include "grit/chromium_strings.h" 10 #include "grit/generated_resources.h" 11 #include "ui/base/l10n/l10n_util.h" 12 #include "ui/views/controls/message_box_view.h" 13 #include "ui/views/widget/widget.h" 14 15 #if defined(OS_CHROMEOS) 16 #include "chromeos/dbus/dbus_thread_manager.h" 17 #include "chromeos/dbus/power_manager_client.h" 18 #endif 19 20 //////////////////////////////////////////////////////////////////////////////// 21 // UpdateRecommendedMessageBox, public: 22 23 // static Show(gfx::NativeWindow parent_window)24void UpdateRecommendedMessageBox::Show(gfx::NativeWindow parent_window) { 25 // When the window closes, it will delete itself. 26 CreateBrowserModalDialogViews(new UpdateRecommendedMessageBox(), 27 parent_window)->Show(); 28 } 29 30 //////////////////////////////////////////////////////////////////////////////// 31 // UpdateRecommendedMessageBox, private: 32 UpdateRecommendedMessageBox()33UpdateRecommendedMessageBox::UpdateRecommendedMessageBox() { 34 const int kDialogWidth = 400; 35 #if defined(OS_CHROMEOS) 36 const int kProductNameID = IDS_SHORT_PRODUCT_OS_NAME; 37 #else 38 const int kProductNameID = IDS_PRODUCT_NAME; 39 #endif 40 const base::string16 product_name = l10n_util::GetStringUTF16(kProductNameID); 41 views::MessageBoxView::InitParams params( 42 l10n_util::GetStringFUTF16(IDS_UPDATE_RECOMMENDED, product_name)); 43 params.message_width = kDialogWidth; 44 // Also deleted when the window closes. 45 message_box_view_ = new views::MessageBoxView(params); 46 } 47 ~UpdateRecommendedMessageBox()48UpdateRecommendedMessageBox::~UpdateRecommendedMessageBox() { 49 } 50 Accept()51bool UpdateRecommendedMessageBox::Accept() { 52 #if defined(OS_CHROMEOS) 53 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RequestRestart(); 54 // If running the Chrome OS build, but we're not on the device, fall through 55 #endif 56 chrome::AttemptRestart(); 57 return true; 58 } 59 GetDialogButtonLabel(ui::DialogButton button) const60base::string16 UpdateRecommendedMessageBox::GetDialogButtonLabel( 61 ui::DialogButton button) const { 62 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? 63 IDS_RELAUNCH_AND_UPDATE : IDS_NOT_NOW); 64 } 65 ShouldShowWindowTitle() const66bool UpdateRecommendedMessageBox::ShouldShowWindowTitle() const { 67 #if defined(OS_CHROMEOS) 68 return false; 69 #else 70 return true; 71 #endif 72 } 73 GetWindowTitle() const74base::string16 UpdateRecommendedMessageBox::GetWindowTitle() const { 75 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); 76 } 77 DeleteDelegate()78void UpdateRecommendedMessageBox::DeleteDelegate() { 79 delete this; 80 } 81 GetModalType() const82ui::ModalType UpdateRecommendedMessageBox::GetModalType() const { 83 return ui::MODAL_TYPE_WINDOW; 84 } 85 GetContentsView()86views::View* UpdateRecommendedMessageBox::GetContentsView() { 87 return message_box_view_; 88 } 89 GetWidget()90views::Widget* UpdateRecommendedMessageBox::GetWidget() { 91 return message_box_view_->GetWidget(); 92 } 93 GetWidget() const94const views::Widget* UpdateRecommendedMessageBox::GetWidget() const { 95 return message_box_view_->GetWidget(); 96 } 97