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.
5 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "chrome/grit/chromium_strings.h"
12 #include "chrome/grit/generated_resources.h"
13 #include "chrome/grit/locale_settings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/gfx/size.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/message_box_view.h"
18 #include "ui/views/layout/grid_layout.h"
19 #include "ui/views/widget/widget.h"
22 void DownloadInProgressDialogView::Show(
23 gfx::NativeWindow parent,
25 Browser::DownloadClosePreventionType dialog_type,
27 const base::Callback<void(bool)>& callback) {
28 DownloadInProgressDialogView* window = new DownloadInProgressDialogView(
29 download_count, dialog_type, app_modal, callback);
30 CreateBrowserModalDialogViews(window, parent)->Show();
33 DownloadInProgressDialogView::DownloadInProgressDialogView(
35 Browser::DownloadClosePreventionType dialog_type,
37 const base::Callback<void(bool)>& callback)
38 : app_modal_(app_modal),
40 message_box_view_(NULL) {
41 base::string16 explanation_text;
42 switch (dialog_type) {
43 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN:
44 if (download_count == 1) {
45 title_text_ = l10n_util::GetStringUTF16(
46 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE);
47 explanation_text = l10n_util::GetStringUTF16(
48 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION);
50 title_text_ = l10n_util::GetStringUTF16(
51 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE);
52 explanation_text = l10n_util::GetStringUTF16(
53 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION);
55 ok_button_text_ = l10n_util::GetStringUTF16(
56 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
58 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE:
59 if (download_count == 1) {
60 title_text_ = l10n_util::GetStringUTF16(
61 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE);
62 explanation_text = l10n_util::GetStringUTF16(
63 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION);
65 title_text_ = l10n_util::GetStringUTF16(
66 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE);
67 explanation_text = l10n_util::GetStringUTF16(
68 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION);
70 ok_button_text_ = l10n_util::GetStringUTF16(
71 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
74 // This dialog should have been created within the same thread invocation
75 // as the original test that lead to us, so it should always not be ok
79 cancel_button_text_ = l10n_util::GetStringUTF16(
80 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
82 message_box_view_ = new views::MessageBoxView(
83 views::MessageBoxView::InitParams(explanation_text));
86 DownloadInProgressDialogView::~DownloadInProgressDialogView() {}
88 int DownloadInProgressDialogView::GetDefaultDialogButton() const {
89 return ui::DIALOG_BUTTON_CANCEL;
92 base::string16 DownloadInProgressDialogView::GetDialogButtonLabel(
93 ui::DialogButton button) const {
94 return (button == ui::DIALOG_BUTTON_OK) ?
95 ok_button_text_ : cancel_button_text_;
98 bool DownloadInProgressDialogView::Cancel() {
103 bool DownloadInProgressDialogView::Accept() {
108 ui::ModalType DownloadInProgressDialogView::GetModalType() const {
109 return app_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW;
112 base::string16 DownloadInProgressDialogView::GetWindowTitle() const {
116 void DownloadInProgressDialogView::DeleteDelegate() {
120 views::Widget* DownloadInProgressDialogView::GetWidget() {
121 return message_box_view_->GetWidget();
124 const views::Widget* DownloadInProgressDialogView::GetWidget() const {
125 return message_box_view_->GetWidget();
128 views::View* DownloadInProgressDialogView::GetContentsView() {
129 return message_box_view_;