| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Currently this file is only used for the uninstall prompt. The install prompt | 5 // Currently this file is only used for the uninstall prompt. The install prompt |
| 6 // code is in extension_install_prompt2_gtk.cc. | 6 // code is in extension_install_prompt2_gtk.cc. |
| 7 | 7 |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 12 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 15 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 16 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "ui/base/gtk/gtk_hig_constants.h" | 18 #include "ui/base/gtk/gtk_hig_constants.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/gfx/gtk_util.h" | 20 #include "ui/gfx/gtk_util.h" |
| 21 | 21 |
| 22 class Profile; | 22 class Profile; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Left or right margin. | 26 // Left or right margin. |
| 27 const int kPanelHorizMargin = 13; | 27 const int kPanelHorizMargin = 13; |
| 28 | 28 |
| 29 void OnResponse(GtkWidget* dialog, int response_id, | 29 // GTK implementation of the uninstall dialog. |
| 30 ExtensionUninstallDialog::Delegate* delegate) { | 30 class ExtensionUninstallDialogGtk : public ExtensionUninstallDialog { |
| 31 if (response_id == GTK_RESPONSE_ACCEPT) | 31 public: |
| 32 delegate->ExtensionDialogAccepted(); | 32 ExtensionUninstallDialogGtk(Profile* profile, Delegate* delegate); |
| 33 else | 33 virtual ~ExtensionUninstallDialogGtk() OVERRIDE; |
| 34 delegate->ExtensionDialogCanceled(); | |
| 35 | 34 |
| 36 gtk_widget_destroy(dialog); | 35 private: |
| 37 } | 36 virtual void Show() OVERRIDE; |
| 38 | 37 |
| 39 void ShowUninstallDialogGtk(GtkWindow* parent, | 38 CHROMEGTK_CALLBACK_1(ExtensionUninstallDialogGtk, void, OnResponse, int); |
| 40 SkBitmap* skia_icon, | 39 |
| 41 const Extension* extension, | 40 GtkWidget* dialog_; |
| 42 ExtensionUninstallDialog::Delegate *delegate) { | 41 }; |
| 42 |
| 43 ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk( |
| 44 Profile* profile, ExtensionUninstallDialog::Delegate* delegate) |
| 45 : ExtensionUninstallDialog(profile, delegate), |
| 46 dialog_(NULL) {} |
| 47 |
| 48 void ExtensionUninstallDialogGtk::Show() { |
| 49 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
| 50 if (!browser) { |
| 51 delegate_->ExtensionUninstallCanceled(); |
| 52 return; |
| 53 } |
| 54 |
| 55 BrowserWindow* browser_window = browser->window(); |
| 56 if (!browser_window) { |
| 57 delegate_->ExtensionUninstallCanceled(); |
| 58 return; |
| 59 } |
| 60 |
| 43 // Build the dialog. | 61 // Build the dialog. |
| 44 GtkWidget* dialog = gtk_dialog_new_with_buttons( | 62 dialog_ = gtk_dialog_new_with_buttons( |
| 45 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(), | 63 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(), |
| 46 parent, | 64 browser_window->GetNativeHandle(), |
| 47 GTK_DIALOG_MODAL, | 65 GTK_DIALOG_MODAL, |
| 48 GTK_STOCK_CANCEL, | 66 GTK_STOCK_CANCEL, |
| 49 GTK_RESPONSE_CLOSE, | 67 GTK_RESPONSE_CLOSE, |
| 50 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(), | 68 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(), |
| 51 GTK_RESPONSE_ACCEPT, | 69 GTK_RESPONSE_ACCEPT, |
| 52 NULL); | 70 NULL); |
| 53 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); | 71 gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE); |
| 54 | 72 |
| 55 // Create a two column layout. | 73 // Create a two column layout. |
| 56 GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | 74 GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog_)); |
| 57 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); | 75 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); |
| 58 | 76 |
| 59 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); | 77 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); |
| 60 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); | 78 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); |
| 61 | 79 |
| 62 // Put Icon in the left column. | 80 // Put Icon in the left column. |
| 63 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon); | 81 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon_); |
| 64 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); | 82 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); |
| 65 g_object_unref(pixbuf); | 83 g_object_unref(pixbuf); |
| 66 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); | 84 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); |
| 67 | 85 |
| 68 // Create a new vbox for the right column. | 86 // Create a new vbox for the right column. |
| 69 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); | 87 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); |
| 70 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); | 88 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); |
| 71 | 89 |
| 72 std::string heading_text = l10n_util::GetStringFUTF8( | 90 std::string heading_text = l10n_util::GetStringFUTF8( |
| 73 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name())); | 91 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension_->name())); |
| 74 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); | 92 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); |
| 75 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 93 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
| 76 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); | 94 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); |
| 77 | 95 |
| 78 g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), delegate); | 96 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 79 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | 97 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
| 80 gtk_widget_show_all(dialog); | 98 gtk_widget_show_all(dialog_); |
| 99 } |
| 100 |
| 101 ExtensionUninstallDialogGtk::~ExtensionUninstallDialogGtk() { |
| 102 delegate_ = NULL; |
| 103 if (dialog_) { |
| 104 gtk_widget_destroy(dialog_); |
| 105 dialog_ = NULL; |
| 106 } |
| 107 } |
| 108 |
| 109 void ExtensionUninstallDialogGtk::OnResponse( |
| 110 GtkWidget* dialog, int response_id) { |
| 111 CHECK_EQ(dialog_, dialog); |
| 112 |
| 113 gtk_widget_destroy(dialog_); |
| 114 dialog_ = NULL; |
| 115 |
| 116 if (delegate_) { |
| 117 if (response_id == GTK_RESPONSE_ACCEPT) |
| 118 delegate_->ExtensionUninstallAccepted(); |
| 119 else |
| 120 delegate_->ExtensionUninstallCanceled(); |
| 121 } |
| 81 } | 122 } |
| 82 | 123 |
| 83 } // namespace | 124 } // namespace |
| 84 | 125 |
| 85 // static | 126 // static |
| 86 void ExtensionUninstallDialog::Show( | 127 // Platform specific implementation of the uninstall dialog show method. |
| 87 Profile* profile, | 128 ExtensionUninstallDialog* ExtensionUninstallDialog::Create( |
| 88 ExtensionUninstallDialog::Delegate* delegate, | 129 Profile* profile, Delegate* delegate) { |
| 89 const Extension* extension, | 130 return new ExtensionUninstallDialogGtk(profile, delegate); |
| 90 SkBitmap* icon) { | |
| 91 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | |
| 92 if (!browser) { | |
| 93 delegate->ExtensionDialogCanceled(); | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 BrowserWindow* browser_window = browser->window(); | |
| 98 if (!browser_window) { | |
| 99 delegate->ExtensionDialogCanceled(); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 ShowUninstallDialogGtk(browser_window->GetNativeHandle(), | |
| 104 icon, extension, delegate); | |
| 105 } | 131 } |
| OLD | NEW |