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 // Currently this file is only used for the uninstall prompt. The install prompt
6 // code is in extension_install_prompt2_gtk.cc.
8 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
17 #include "extensions/common/extension.h"
18 #include "grit/generated_resources.h"
19 #include "ui/base/gtk/gtk_hig_constants.h"
20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/gfx/gtk_util.h"
25 // GTK implementation of the uninstall dialog.
26 class ExtensionUninstallDialogGtk
: public ExtensionUninstallDialog
{
28 ExtensionUninstallDialogGtk(Profile
* profile
,
31 virtual ~ExtensionUninstallDialogGtk() OVERRIDE
;
34 virtual void Show() OVERRIDE
;
36 CHROMEGTK_CALLBACK_1(ExtensionUninstallDialogGtk
, void, OnResponse
, int);
41 ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk(
44 ExtensionUninstallDialog::Delegate
* delegate
)
45 : ExtensionUninstallDialog(profile
, browser
, delegate
),
48 void ExtensionUninstallDialogGtk::Show() {
50 delegate_
->ExtensionUninstallCanceled();
53 BrowserWindow
* browser_window
= browser_
->window();
54 if (!browser_window
) {
55 delegate_
->ExtensionUninstallCanceled();
60 dialog_
= gtk_dialog_new_with_buttons(
61 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE
).c_str(),
62 browser_window
->GetNativeWindow(),
66 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON
).c_str(),
69 #if !GTK_CHECK_VERSION(2, 22, 0)
70 gtk_dialog_set_has_separator(GTK_DIALOG(dialog_
), FALSE
);
73 // Create a two column layout.
74 GtkWidget
* content_area
= gtk_dialog_get_content_area(GTK_DIALOG(dialog_
));
75 gtk_box_set_spacing(GTK_BOX(content_area
), ui::kContentAreaSpacing
);
77 GtkWidget
* icon_hbox
= gtk_hbox_new(FALSE
, ui::kContentAreaSpacing
);
78 gtk_box_pack_start(GTK_BOX(content_area
), icon_hbox
, TRUE
, TRUE
, 0);
80 // Put Icon in the left column.
81 GdkPixbuf
* pixbuf
= gfx::GdkPixbufFromSkBitmap(*icon_
.bitmap());
82 GtkWidget
* icon
= gtk_image_new_from_pixbuf(pixbuf
);
83 g_object_unref(pixbuf
);
84 gtk_box_pack_start(GTK_BOX(icon_hbox
), icon
, TRUE
, TRUE
, 0);
86 // Create a new vbox for the right column.
87 GtkWidget
* right_column_area
= gtk_vbox_new(FALSE
, 0);
88 gtk_box_pack_start(GTK_BOX(icon_hbox
), right_column_area
, TRUE
, TRUE
, 0);
90 std::string heading_text
= l10n_util::GetStringFUTF8(
91 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING
,
92 base::UTF8ToUTF16(extension_
->name()));
93 GtkWidget
* heading_label
= gtk_label_new(heading_text
.c_str());
94 gtk_misc_set_alignment(GTK_MISC(heading_label
), 0.0, 0.5);
95 gtk_box_pack_start(GTK_BOX(right_column_area
), heading_label
, TRUE
, TRUE
, 0);
97 g_signal_connect(dialog_
, "response", G_CALLBACK(OnResponseThunk
), this);
98 gtk_window_set_resizable(GTK_WINDOW(dialog_
), FALSE
);
99 gtk_widget_show_all(dialog_
);
102 ExtensionUninstallDialogGtk::~ExtensionUninstallDialogGtk() {
105 gtk_widget_destroy(dialog_
);
110 void ExtensionUninstallDialogGtk::OnResponse(
111 GtkWidget
* dialog
, int response_id
) {
112 CHECK_EQ(dialog_
, dialog
);
114 gtk_widget_destroy(dialog_
);
118 if (response_id
== GTK_RESPONSE_ACCEPT
)
119 delegate_
->ExtensionUninstallAccepted();
121 delegate_
->ExtensionUninstallCanceled();
128 // Platform specific implementation of the uninstall dialog show method.
129 ExtensionUninstallDialog
* ExtensionUninstallDialog::Create(
130 Profile
* profile
, Browser
* browser
, Delegate
* delegate
) {
131 return new ExtensionUninstallDialogGtk(profile
, browser
, delegate
);