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/gtk/download/download_in_progress_dialog_gtk.h"
9 #include "base/callback.h"
10 #include "base/strings/string16.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
18 void DownloadInProgressDialogGtk::Show(
19 gfx::NativeWindow parent_window
,
21 Browser::DownloadClosePreventionType dialog_type
,
23 const base::Callback
<void(bool)>& callback
) {
24 new DownloadInProgressDialogGtk(parent_window
, download_count
, dialog_type
,
28 DownloadInProgressDialogGtk::DownloadInProgressDialogGtk(
29 gfx::NativeWindow parent_window
,
31 Browser::DownloadClosePreventionType dialog_type
,
33 const base::Callback
<void(bool)>& callback
)
34 : app_modal_(app_modal
),
36 std::string title_text
;
37 std::string explanation_text
;
38 std::string ok_button_text
;
39 switch (dialog_type
) {
40 case Browser::DOWNLOAD_CLOSE_BROWSER_SHUTDOWN
:
41 if (download_count
== 1) {
42 title_text
= l10n_util::GetStringUTF8(
43 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_TITLE
);
44 explanation_text
= l10n_util::GetStringUTF8(
45 IDS_SINGLE_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION
);
47 title_text
= l10n_util::GetStringUTF8(
48 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_TITLE
);
49 explanation_text
= l10n_util::GetStringUTF8(
50 IDS_MULTIPLE_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION
);
52 ok_button_text
= l10n_util::GetStringUTF8(
53 IDS_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL
);
55 case Browser::DOWNLOAD_CLOSE_LAST_WINDOW_IN_INCOGNITO_PROFILE
:
56 if (download_count
== 1) {
57 title_text
= l10n_util::GetStringUTF8(
58 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_TITLE
);
59 explanation_text
= l10n_util::GetStringUTF8(
60 IDS_SINGLE_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_EXPLANATION
);
62 title_text
= l10n_util::GetStringUTF8(
63 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_TITLE
);
64 explanation_text
= l10n_util::GetStringUTF8(
65 IDS_MULTIPLE_INCOGNITO_DOWNLOADS_REMOVE_CONFIRM_EXPLANATION
);
67 ok_button_text
= l10n_util::GetStringUTF8(
68 IDS_INCOGNITO_DOWNLOAD_REMOVE_CONFIRM_OK_BUTTON_LABEL
);
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
76 std::string cancel_button_text
= l10n_util::GetStringUTF8(
77 IDS_DOWNLOAD_REMOVE_CONFIRM_CANCEL_BUTTON_LABEL
);
80 gtk_util::MakeAppModalWindowGroup();
81 GtkWidget
* dialog
= gtk_message_dialog_new(
83 static_cast<GtkDialogFlags
>(GTK_DIALOG_MODAL
),
88 gtk_dialog_add_button(GTK_DIALOG(dialog
),
89 cancel_button_text
.c_str(), GTK_RESPONSE_REJECT
);
90 gtk_dialog_add_button(GTK_DIALOG(dialog
),
91 ok_button_text
.c_str(), GTK_RESPONSE_ACCEPT
);
93 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog
),
95 explanation_text
.c_str());
97 g_signal_connect(dialog
, "response", G_CALLBACK(OnResponseThunk
), this);
99 gtk_widget_show_all(dialog
);
102 DownloadInProgressDialogGtk::~DownloadInProgressDialogGtk() {
105 void DownloadInProgressDialogGtk::OnResponse(GtkWidget
* dialog
,
107 gtk_widget_destroy(dialog
);
109 gtk_util::AppModalDismissedUngroupWindows();
110 callback_
.Run(response_id
== GTK_RESPONSE_ACCEPT
);