OLD | NEW |
| (Empty) |
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. | |
7 | |
8 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | |
9 | |
10 #include <gtk/gtk.h> | |
11 | |
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" | |
22 | |
23 namespace { | |
24 | |
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; | |
32 | |
33 private: | |
34 virtual void Show() OVERRIDE; | |
35 | |
36 CHROMEGTK_CALLBACK_1(ExtensionUninstallDialogGtk, void, OnResponse, int); | |
37 | |
38 GtkWidget* dialog_; | |
39 }; | |
40 | |
41 ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk( | |
42 Profile* profile, | |
43 Browser* browser, | |
44 ExtensionUninstallDialog::Delegate* delegate) | |
45 : ExtensionUninstallDialog(profile, browser, delegate), | |
46 dialog_(NULL) {} | |
47 | |
48 void ExtensionUninstallDialogGtk::Show() { | |
49 if (!browser_) { | |
50 delegate_->ExtensionUninstallCanceled(); | |
51 return; | |
52 } | |
53 BrowserWindow* browser_window = browser_->window(); | |
54 if (!browser_window) { | |
55 delegate_->ExtensionUninstallCanceled(); | |
56 return; | |
57 } | |
58 | |
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 | |
72 | |
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); | |
76 | |
77 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); | |
78 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); | |
79 | |
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); | |
85 | |
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); | |
89 | |
90 GtkWidget* heading_label = gtk_label_new(GetHeadingText().c_str()); | |
91 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | |
92 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); | |
93 | |
94 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | |
95 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | |
96 gtk_widget_show_all(dialog_); | |
97 } | |
98 | |
99 ExtensionUninstallDialogGtk::~ExtensionUninstallDialogGtk() { | |
100 delegate_ = NULL; | |
101 if (dialog_) { | |
102 gtk_widget_destroy(dialog_); | |
103 dialog_ = NULL; | |
104 } | |
105 } | |
106 | |
107 void ExtensionUninstallDialogGtk::OnResponse( | |
108 GtkWidget* dialog, int response_id) { | |
109 CHECK_EQ(dialog_, dialog); | |
110 | |
111 gtk_widget_destroy(dialog_); | |
112 dialog_ = NULL; | |
113 | |
114 if (delegate_) { | |
115 if (response_id == GTK_RESPONSE_ACCEPT) | |
116 delegate_->ExtensionUninstallAccepted(); | |
117 else | |
118 delegate_->ExtensionUninstallCanceled(); | |
119 } | |
120 } | |
121 | |
122 } // namespace | |
123 | |
124 // static | |
125 // Platform specific implementation of the uninstall dialog show method. | |
126 ExtensionUninstallDialog* ExtensionUninstallDialog::Create( | |
127 Profile* profile, Browser* browser, Delegate* delegate) { | |
128 return new ExtensionUninstallDialogGtk(profile, browser, delegate); | |
129 } | |
OLD | NEW |