| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
| 15 #include "chrome/browser/extensions/extension_install_ui.h" | 15 #include "chrome/browser/extensions/extension_install_ui.h" |
| 16 #include "chrome/browser/gtk/browser_window_gtk.h" | 16 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 17 #include "chrome/browser/gtk/gtk_util.h" | 17 #include "chrome/browser/gtk/gtk_util.h" |
| 18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 19 #include "gfx/gtk_util.h" | 19 #include "gfx/gtk_util.h" |
| 20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.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 GtkWidget* MakeMarkupLabel(const char* format, const std::string& str) { | |
| 30 GtkWidget* label = gtk_label_new(NULL); | |
| 31 char* markup = g_markup_printf_escaped(format, str.c_str()); | |
| 32 gtk_label_set_markup(GTK_LABEL(label), markup); | |
| 33 g_free(markup); | |
| 34 | |
| 35 // Left align it. | |
| 36 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
| 37 | |
| 38 return label; | |
| 39 } | |
| 40 | |
| 41 void OnDialogResponse(GtkDialog* dialog, int response_id, | 29 void OnDialogResponse(GtkDialog* dialog, int response_id, |
| 42 ExtensionInstallUI::Delegate* delegate) { | 30 ExtensionInstallUI::Delegate* delegate) { |
| 43 if (response_id == GTK_RESPONSE_ACCEPT) { | 31 if (response_id == GTK_RESPONSE_ACCEPT) { |
| 44 delegate->InstallUIProceed(false); | 32 delegate->InstallUIProceed(false); |
| 45 } else { | 33 } else { |
| 46 delegate->InstallUIAbort(); | 34 delegate->InstallUIAbort(); |
| 47 } | 35 } |
| 48 | 36 |
| 49 gtk_widget_destroy(GTK_WIDGET(dialog)); | 37 gtk_widget_destroy(GTK_WIDGET(dialog)); |
| 50 } | 38 } |
| 51 | 39 |
| 52 void ShowInstallPromptDialog(GtkWindow* parent, SkBitmap* skia_icon, | 40 void ShowInstallPromptDialog(GtkWindow* parent, SkBitmap* skia_icon, |
| 53 Extension *extension, | 41 Extension *extension, |
| 54 ExtensionInstallUI::Delegate *delegate, | 42 ExtensionInstallUI::Delegate *delegate, |
| 55 const string16& warning_text, | |
| 56 ExtensionInstallUI::PromptType type) { | 43 ExtensionInstallUI::PromptType type) { |
| 57 // Build the dialog. | 44 // Build the dialog. |
| 58 int title_id = ExtensionInstallUI::kTitleIds[type]; | 45 int title_id = ExtensionInstallUI::kTitleIds[type]; |
| 59 int button_id = ExtensionInstallUI::kButtonIds[type]; | 46 int button_id = ExtensionInstallUI::kButtonIds[type]; |
| 60 GtkWidget* dialog = gtk_dialog_new_with_buttons( | 47 GtkWidget* dialog = gtk_dialog_new_with_buttons( |
| 61 l10n_util::GetStringUTF8(title_id).c_str(), | 48 l10n_util::GetStringUTF8(title_id).c_str(), |
| 62 parent, | 49 parent, |
| 63 GTK_DIALOG_MODAL, | 50 GTK_DIALOG_MODAL, |
| 64 GTK_STOCK_CANCEL, | 51 GTK_STOCK_CANCEL, |
| 65 GTK_RESPONSE_CLOSE, | 52 GTK_RESPONSE_CLOSE, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 g_object_unref(pixbuf); | 68 g_object_unref(pixbuf); |
| 82 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); | 69 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); |
| 83 | 70 |
| 84 // Create a new vbox for the right column. | 71 // Create a new vbox for the right column. |
| 85 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); | 72 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); |
| 86 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); | 73 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); |
| 87 | 74 |
| 88 int heading_id = ExtensionInstallUI::kHeadingIds[type]; | 75 int heading_id = ExtensionInstallUI::kHeadingIds[type]; |
| 89 std::string heading_text = l10n_util::GetStringFUTF8( | 76 std::string heading_text = l10n_util::GetStringFUTF8( |
| 90 heading_id, UTF8ToUTF16(extension->name())); | 77 heading_id, UTF8ToUTF16(extension->name())); |
| 91 GtkWidget* heading_label = MakeMarkupLabel("<span weight=\"bold\">%s</span>", | 78 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); |
| 92 heading_text); | |
| 93 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); | 79 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); |
| 94 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); | 80 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0); |
| 95 | 81 |
| 96 GtkWidget* warning_label = gtk_label_new(UTF16ToUTF8(warning_text).c_str()); | |
| 97 gtk_misc_set_alignment(GTK_MISC(warning_label), 0.0, 0.5); | |
| 98 gtk_box_pack_start(GTK_BOX(right_column_area), warning_label, TRUE, TRUE, 0); | |
| 99 | |
| 100 g_signal_connect(dialog, "response", G_CALLBACK(OnDialogResponse), delegate); | 82 g_signal_connect(dialog, "response", G_CALLBACK(OnDialogResponse), delegate); |
| 101 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | 83 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); |
| 102 gtk_widget_show_all(dialog); | 84 gtk_widget_show_all(dialog); |
| 103 } | 85 } |
| 104 | 86 |
| 105 } // namespace | 87 } // namespace |
| 106 | 88 |
| 107 void ExtensionInstallUI::ShowExtensionInstallUIPromptImpl( | 89 void ExtensionInstallUI::ShowExtensionInstallUIPromptImpl( |
| 108 Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, | 90 Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon, |
| 109 const string16& warning_text, ExtensionInstallUI::PromptType type) { | 91 ExtensionInstallUI::PromptType type) { |
| 110 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 92 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 111 if (!browser) { | 93 if (!browser) { |
| 112 delegate->InstallUIAbort(); | 94 delegate->InstallUIAbort(); |
| 113 return; | 95 return; |
| 114 } | 96 } |
| 115 | 97 |
| 116 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( | 98 BrowserWindowGtk* browser_window = static_cast<BrowserWindowGtk*>( |
| 117 browser->window()); | 99 browser->window()); |
| 118 if (!browser_window) { | 100 if (!browser_window) { |
| 119 delegate->InstallUIAbort(); | 101 delegate->InstallUIAbort(); |
| 120 return; | 102 return; |
| 121 } | 103 } |
| 122 | 104 |
| 123 ShowInstallPromptDialog(browser_window->window(), icon, extension, | 105 ShowInstallPromptDialog(browser_window->window(), icon, extension, delegate, |
| 124 delegate, warning_text, type); | 106 type); |
| 125 } | 107 } |
| OLD | NEW |