download_in_progress_dialog_view.cc revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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/download/download_in_progress_dialog_view.h" 6 7#include <algorithm> 8 9#include "base/strings/string_number_conversions.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/ui/browser.h" 12#include "grit/chromium_strings.h" 13#include "grit/generated_resources.h" 14#include "grit/locale_settings.h" 15#include "ui/base/l10n/l10n_util.h" 16#include "ui/base/resource/resource_bundle.h" 17#include "ui/gfx/size.h" 18#include "ui/views/border.h" 19#include "ui/views/controls/message_box_view.h" 20#include "ui/views/layout/grid_layout.h" 21#include "ui/views/widget/widget.h" 22 23// static 24void DownloadInProgressDialogView::Show(Browser* browser, 25 gfx::NativeWindow parent) { 26 DownloadInProgressDialogView* window = 27 new DownloadInProgressDialogView(browser); 28 views::DialogDelegate::CreateDialogWidget(window, NULL, parent)->Show(); 29} 30 31DownloadInProgressDialogView::DownloadInProgressDialogView(Browser* browser) 32 : browser_(browser), 33 message_box_view_(NULL) { 34 int download_count; 35 Browser::DownloadClosePreventionType dialog_type = 36 browser_->OkToCloseWithInProgressDownloads(&download_count); 37 38 string16 explanation_text; 39 switch (dialog_type) { 40 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN: 41 if (download_count == 1) { 42 title_text_ = l10n_util::GetStringUTF16( 43 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE); 44 explanation_text = l10n_util::GetStringUTF16( 45 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); 46 } else { 47 title_text_ = l10n_util::GetStringUTF16( 48 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE); 49 explanation_text = l10n_util::GetStringUTF16( 50 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); 51 } 52 ok_button_text_ = l10n_util::GetStringUTF16( 53 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); 54 break; 55 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE: 56 if (download_count == 1) { 57 title_text_ = l10n_util::GetStringUTF16( 58 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE); 59 explanation_text = l10n_util::GetStringUTF16( 60 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION); 61 } else { 62 title_text_ = l10n_util::GetStringUTF16( 63 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE); 64 explanation_text = l10n_util::GetStringUTF16( 65 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION); 66 } 67 ok_button_text_ = l10n_util::GetStringUTF16( 68 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL); 69 break; 70 default: 71 // This dialog should have been created within the same thread invocation 72 // as the original test that lead to us, so it should always not be ok 73 // to close. 74 NOTREACHED(); 75 } 76 cancel_button_text_ = l10n_util::GetStringUTF16( 77 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL); 78 79 views::MessageBoxView::InitParams params(explanation_text); 80 params.clipboard_source_tag = 81 content::BrowserContext::GetMarkerForOffTheRecordContext( 82 browser_->profile()); 83 message_box_view_ = new views::MessageBoxView(params); 84} 85 86DownloadInProgressDialogView::~DownloadInProgressDialogView() {} 87 88int DownloadInProgressDialogView::GetDefaultDialogButton() const { 89 return ui::DIALOG_BUTTON_CANCEL; 90} 91 92string16 DownloadInProgressDialogView::GetDialogButtonLabel( 93 ui::DialogButton button) const { 94 return (button == ui::DIALOG_BUTTON_OK) ? 95 ok_button_text_ : cancel_button_text_; 96} 97 98bool DownloadInProgressDialogView::Cancel() { 99 browser_->InProgressDownloadResponse(false); 100 return true; 101} 102 103bool DownloadInProgressDialogView::Accept() { 104 browser_->InProgressDownloadResponse(true); 105 return true; 106} 107 108ui::ModalType DownloadInProgressDialogView::GetModalType() const { 109 return ui::MODAL_TYPE_WINDOW; 110} 111 112string16 DownloadInProgressDialogView::GetWindowTitle() const { 113 return title_text_; 114} 115 116void DownloadInProgressDialogView::DeleteDelegate() { 117 delete this; 118} 119 120views::Widget* DownloadInProgressDialogView::GetWidget() { 121 return message_box_view_->GetWidget(); 122} 123 124const views::Widget* DownloadInProgressDialogView::GetWidget() const { 125 return message_box_view_->GetWidget(); 126} 127 128views::View* DownloadInProgressDialogView::GetContentsView() { 129 return message_box_view_; 130} 131