Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / download / download_in_progress_dialog_view.cc
blob6027ad235260a0515141c6091949034433c6c596
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/browser/ui/views/constrained_window_views.h"
11 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h"
13 #include "grit/locale_settings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/size.h"
17 #include "ui/views/border.h"
18 #include "ui/views/controls/message_box_view.h"
19 #include "ui/views/layout/grid_layout.h"
20 #include "ui/views/widget/widget.h"
22 // static
23 void DownloadInProgressDialogView::Show(
24 gfx::NativeWindow parent,
25 int download_count,
26 Browser::DownloadClosePreventionType dialog_type,
27 bool app_modal,
28 const base::Callback<void(bool)>& callback) {
29 DownloadInProgressDialogView* window = new DownloadInProgressDialogView(
30 download_count, dialog_type, app_modal, callback);
31 CreateBrowserModalDialogViews(window, parent)->Show();
34 DownloadInProgressDialogView::DownloadInProgressDialogView(
35 int download_count,
36 Browser::DownloadClosePreventionType dialog_type,
37 bool app_modal,
38 const base::Callback<void(bool)>& callback)
39 : app_modal_(app_modal),
40 callback_(callback),
41 message_box_view_(NULL) {
42 base::string16 explanation_text;
43 switch (dialog_type) {
44 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN:
45 if (download_count == 1) {
46 title_text_ = l10n_util::GetStringUTF16(
47 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE);
48 explanation_text = l10n_util::GetStringUTF16(
49 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION);
50 } else {
51 title_text_ = l10n_util::GetStringUTF16(
52 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE);
53 explanation_text = l10n_util::GetStringUTF16(
54 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION);
56 ok_button_text_ = l10n_util::GetStringUTF16(
57 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
58 break;
59 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE:
60 if (download_count == 1) {
61 title_text_ = l10n_util::GetStringUTF16(
62 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE);
63 explanation_text = l10n_util::GetStringUTF16(
64 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION);
65 } else {
66 title_text_ = l10n_util::GetStringUTF16(
67 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE);
68 explanation_text = l10n_util::GetStringUTF16(
69 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION);
71 ok_button_text_ = l10n_util::GetStringUTF16(
72 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL);
73 break;
74 default:
75 // This dialog should have been created within the same thread invocation
76 // as the original test that lead to us, so it should always not be ok
77 // to close.
78 NOTREACHED();
80 cancel_button_text_ = l10n_util::GetStringUTF16(
81 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL);
83 message_box_view_ = new views::MessageBoxView(
84 views::MessageBoxView::InitParams(explanation_text));
87 DownloadInProgressDialogView::~DownloadInProgressDialogView() {}
89 int DownloadInProgressDialogView::GetDefaultDialogButton() const {
90 return ui::DIALOG_BUTTON_CANCEL;
93 base::string16 DownloadInProgressDialogView::GetDialogButtonLabel(
94 ui::DialogButton button) const {
95 return (button == ui::DIALOG_BUTTON_OK) ?
96 ok_button_text_ : cancel_button_text_;
99 bool DownloadInProgressDialogView::Cancel() {
100 callback_.Run(false);
101 return true;
104 bool DownloadInProgressDialogView::Accept() {
105 callback_.Run(true);
106 return true;
109 ui::ModalType DownloadInProgressDialogView::GetModalType() const {
110 return app_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_WINDOW;
113 base::string16 DownloadInProgressDialogView::GetWindowTitle() const {
114 return title_text_;
117 void DownloadInProgressDialogView::DeleteDelegate() {
118 delete this;
121 views::Widget* DownloadInProgressDialogView::GetWidget() {
122 return message_box_view_->GetWidget();
125 const views::Widget* DownloadInProgressDialogView::GetWidget() const {
126 return message_box_view_->GetWidget();
129 views::View* DownloadInProgressDialogView::GetContentsView() {
130 return message_box_view_;