Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / download / download_in_progress_dialog_view.cc
blob69b61d043f34ab064e07d71e4c3cdcfe69530b5a
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"
7 #include <algorithm>
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"
20 // static
21 void DownloadInProgressDialogView::Show(
22 gfx::NativeWindow parent,
23 int download_count,
24 Browser::DownloadClosePreventionType dialog_type,
25 bool app_modal,
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(
33 int download_count,
34 Browser::DownloadClosePreventionType dialog_type,
35 bool app_modal,
36 const base::Callback<void(bool)>& callback)
37 : app_modal_(app_modal),
38 callback_(callback),
39 message_box_view_(NULL) {
40 // This dialog should have been created within the same thread invocation
41 // as the original test, so it's never ok to close.
42 DCHECK_NE(Browser::DOWNLOAD_CLOSE_OK, dialog_type);
43 base::string16 explanation_text(l10n_util::GetPluralStringFUTF16(
44 (dialog_type == Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN)
45 ? IDS_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION
46 : IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION,
47 download_count));
48 title_text_ = l10n_util::GetPluralStringFUTF16(
49 IDS_DOWNLOAD_REMOVE_CONFIRM_TITLE, download_count);
50 ok_button_text_ = l10n_util::GetPluralStringFUTF16(
51 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL, download_count);
52 cancel_button_text_ = l10n_util::GetPluralStringFUTF16(
53 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL, download_count);
55 message_box_view_ = new views::MessageBoxView(
56 views::MessageBoxView::InitParams(explanation_text));
59 DownloadInProgressDialogView::~DownloadInProgressDialogView() {}
61 int DownloadInProgressDialogView::GetDefaultDialogButton() const {
62 return ui::DIALOG_BUTTON_CANCEL;
65 base::string16 DownloadInProgressDialogView::GetDialogButtonLabel(
66 ui::DialogButton button) const {
67 return (button == ui::DIALOG_BUTTON_OK) ?
68 ok_button_text_ : cancel_button_text_;
71 bool DownloadInProgressDialogView::Cancel() {
72 callback_.Run(false);
73 return true;
76 bool DownloadInProgressDialogView::Accept() {
77 callback_.Run(true);
78 return true;
81 ui::ModalType DownloadInProgressDialogView::GetModalType() const {
82 return app_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW;
85 base::string16 DownloadInProgressDialogView::GetWindowTitle() const {
86 return title_text_;
89 void DownloadInProgressDialogView::DeleteDelegate() {
90 delete this;
93 views::Widget* DownloadInProgressDialogView::GetWidget() {
94 return message_box_view_->GetWidget();
97 const views::Widget* DownloadInProgressDialogView::GetWidget() const {
98 return message_box_view_->GetWidget();
101 views::View* DownloadInProgressDialogView::GetContentsView() {
102 return message_box_view_;