Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / gtk / extensions / extension_uninstall_dialog_gtk.cc
blob51c25995ad9ae307df32040f0b403362dc71b1d3
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.
4 //
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"
10 #include <gtk/gtk.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"
23 namespace {
25 // GTK implementation of the uninstall dialog.
26 class ExtensionUninstallDialogGtk : public ExtensionUninstallDialog {
27 public:
28 ExtensionUninstallDialogGtk(Profile* profile,
29 Browser* browser,
30 Delegate* delegate);
31 virtual ~ExtensionUninstallDialogGtk() OVERRIDE;
33 private:
34 virtual void Show() OVERRIDE;
36 CHROMEGTK_CALLBACK_1(ExtensionUninstallDialogGtk, void, OnResponse, int);
38 GtkWidget* dialog_;
41 ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk(
42 Profile* profile,
43 Browser* browser,
44 ExtensionUninstallDialog::Delegate* delegate)
45 : ExtensionUninstallDialog(profile, browser, delegate),
46 dialog_(NULL) {}
48 void ExtensionUninstallDialogGtk::Show() {
49 if (!browser_) {
50 delegate_->ExtensionUninstallCanceled();
51 return;
53 BrowserWindow* browser_window = browser_->window();
54 if (!browser_window) {
55 delegate_->ExtensionUninstallCanceled();
56 return;
59 // Build the dialog.
60 dialog_ = gtk_dialog_new_with_buttons(
61 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(),
62 browser_window->GetNativeWindow(),
63 GTK_DIALOG_MODAL,
64 GTK_STOCK_CANCEL,
65 GTK_RESPONSE_CLOSE,
66 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(),
67 GTK_RESPONSE_ACCEPT,
68 NULL);
69 #if !GTK_CHECK_VERSION(2, 22, 0)
70 gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE);
71 #endif
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() {
103 delegate_ = NULL;
104 if (dialog_) {
105 gtk_widget_destroy(dialog_);
106 dialog_ = NULL;
110 void ExtensionUninstallDialogGtk::OnResponse(
111 GtkWidget* dialog, int response_id) {
112 CHECK_EQ(dialog_, dialog);
114 gtk_widget_destroy(dialog_);
115 dialog_ = NULL;
117 if (delegate_) {
118 if (response_id == GTK_RESPONSE_ACCEPT)
119 delegate_->ExtensionUninstallAccepted();
120 else
121 delegate_->ExtensionUninstallCanceled();
125 } // namespace
127 // static
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);