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/grit/chromium_strings.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/constrained_window/constrained_window_views.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/gfx/geometry/size.h"
15 #include "ui/views/border.h"
16 #include "ui/views/controls/message_box_view.h"
17 #include "ui/views/layout/grid_layout.h"
18 #include "ui/views/widget/widget.h"
21 void DownloadInProgressDialogView::Show(
22 gfx::NativeWindow parent
,
24 Browser::DownloadClosePreventionType dialog_type
,
26 const base::Callback
<void(bool)>& callback
) {
27 DownloadInProgressDialogView
* window
= new DownloadInProgressDialogView(
28 download_count
, dialog_type
, app_modal
, callback
);
29 constrained_window::CreateBrowserModalDialogViews(window
, parent
)->Show();
32 DownloadInProgressDialogView::DownloadInProgressDialogView(
34 Browser::DownloadClosePreventionType dialog_type
,
36 const base::Callback
<void(bool)>& callback
)
37 : app_modal_(app_modal
),
39 message_box_view_(NULL
) {
40 base::string16 explanation_text
;
41 switch (dialog_type
) {
42 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN
:
43 if (download_count
== 1) {
44 title_text_
= l10n_util::GetStringUTF16(
45 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE
);
46 explanation_text
= l10n_util::GetStringUTF16(
47 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION
);
49 title_text_
= l10n_util::GetStringUTF16(
50 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE
);
51 explanation_text
= l10n_util::GetStringUTF16(
52 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION
);
54 ok_button_text_
= l10n_util::GetStringUTF16(
55 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL
);
57 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE
:
58 if (download_count
== 1) {
59 title_text_
= l10n_util::GetStringUTF16(
60 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE
);
61 explanation_text
= l10n_util::GetStringUTF16(
62 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION
);
64 title_text_
= l10n_util::GetStringUTF16(
65 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE
);
66 explanation_text
= l10n_util::GetStringUTF16(
67 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION
);
69 ok_button_text_
= l10n_util::GetStringUTF16(
70 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL
);
73 // This dialog should have been created within the same thread invocation
74 // as the original test that lead to us, so it should always not be ok
78 cancel_button_text_
= l10n_util::GetStringUTF16(
79 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL
);
81 message_box_view_
= new views::MessageBoxView(
82 views::MessageBoxView::InitParams(explanation_text
));
85 DownloadInProgressDialogView::~DownloadInProgressDialogView() {}
87 int DownloadInProgressDialogView::GetDefaultDialogButton() const {
88 return ui::DIALOG_BUTTON_CANCEL
;
91 base::string16
DownloadInProgressDialogView::GetDialogButtonLabel(
92 ui::DialogButton button
) const {
93 return (button
== ui::DIALOG_BUTTON_OK
) ?
94 ok_button_text_
: cancel_button_text_
;
97 bool DownloadInProgressDialogView::Cancel() {
102 bool DownloadInProgressDialogView::Accept() {
107 ui::ModalType
DownloadInProgressDialogView::GetModalType() const {
108 return app_modal_
? ui::MODAL_TYPE_SYSTEM
: ui::MODAL_TYPE_WINDOW
;
111 base::string16
DownloadInProgressDialogView::GetWindowTitle() const {
115 void DownloadInProgressDialogView::DeleteDelegate() {
119 views::Widget
* DownloadInProgressDialogView::GetWidget() {
120 return message_box_view_
->GetWidget();
123 const views::Widget
* DownloadInProgressDialogView::GetWidget() const {
124 return message_box_view_
->GetWidget();
127 views::View
* DownloadInProgressDialogView::GetContentsView() {
128 return message_box_view_
;