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 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 <gtk/gtk.h> 9 10#include "base/string_util.h" 11#include "base/utf_string_conversions.h" 12#include "chrome/browser/extensions/extension_uninstall_dialog.h" 13#include "chrome/browser/ui/browser_list.h" 14#include "chrome/browser/ui/browser_window.h" 15#include "chrome/browser/ui/gtk/browser_window_gtk.h" 16#include "chrome/browser/ui/gtk/gtk_util.h" 17#include "chrome/common/extensions/extension.h" 18#include "grit/generated_resources.h" 19#include "ui/base/l10n/l10n_util.h" 20#include "ui/gfx/gtk_util.h" 21 22class Profile; 23 24namespace { 25 26// Left or right margin. 27const int kPanelHorizMargin = 13; 28 29void OnResponse(GtkWidget* dialog, int response_id, 30 ExtensionUninstallDialog::Delegate* delegate) { 31 if (response_id == GTK_RESPONSE_ACCEPT) 32 delegate->ExtensionDialogAccepted(); 33 else 34 delegate->ExtensionDialogCanceled(); 35 36 gtk_widget_destroy(dialog); 37} 38 39void ShowUninstallDialogGtk(GtkWindow* parent, 40 SkBitmap* skia_icon, 41 const Extension* extension, 42 ExtensionUninstallDialog::Delegate *delegate) { 43 // Build the dialog. 44 GtkWidget* dialog = gtk_dialog_new_with_buttons( 45 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(), 46 parent, 47 GTK_DIALOG_MODAL, 48 GTK_STOCK_CANCEL, 49 GTK_RESPONSE_CLOSE, 50 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(), 51 GTK_RESPONSE_ACCEPT, 52 NULL); 53 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); 54 55 // Create a two column layout. 56 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; 57 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); 58 59 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, gtk_util::kContentAreaSpacing); 60 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); 61 62 // Put Icon in the left column. 63 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon); 64 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); 65 g_object_unref(pixbuf); 66 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); 67 68 // Create a new vbox for the right column. 69 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); 70 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); 71 72 std::string heading_text = l10n_util::GetStringFUTF8( 73 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name())); 74 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); 75 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); 77 78 g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), delegate); 79 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); 80 gtk_widget_show_all(dialog); 81} 82 83} // namespace 84 85// static 86void ExtensionUninstallDialog::Show( 87 Profile* profile, 88 ExtensionUninstallDialog::Delegate* delegate, 89 const Extension* extension, 90 SkBitmap* icon) { 91 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 92 if (!browser) { 93 delegate->ExtensionDialogCanceled(); 94 return; 95 } 96 97 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( 98 browser->window()); 99 if (!browser_window) { 100 delegate->ExtensionDialogCanceled(); 101 return; 102 } 103 104 ShowUninstallDialogGtk(browser_window->window(), icon, extension, delegate); 105} 106