Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/ui/gtk/extensions/extension_uninstall_dialog_gtk.cc

Issue 7920023: Fix crashes related to the extension uninstall dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class ExtensionUninstallDialogGtk : public ExtensionUninstallDialog {
30 ExtensionUninstallDialog::Delegate* delegate) { 30 public:
31 if (response_id == GTK_RESPONSE_ACCEPT) 31 ExtensionUninstallDialogGtk(GtkWindow* parent,
32 delegate->ExtensionDialogAccepted(); 32 Profile* profile,
33 else 33 ExtensionUninstallUI::Delegate* delegate,
34 delegate->ExtensionDialogCanceled(); 34 const Extension* extension,
35 SkBitmap* icon);
36 ~ExtensionUninstallDialogGtk();
35 37
36 gtk_widget_destroy(dialog); 38 private:
37 } 39 CHROMEGTK_CALLBACK_1(ExtensionUninstallDialogGtk, void, OnResponse, int);
38 40
39 void ShowUninstallDialogGtk(GtkWindow* parent, 41 GtkWidget* dialog_;
40 SkBitmap* skia_icon, 42 };
41 const Extension* extension, 43
42 ExtensionUninstallDialog::Delegate *delegate) { 44 ExtensionUninstallDialogGtk::ExtensionUninstallDialogGtk(
45 GtkWindow* parent,
46 Profile* profile,
47 ExtensionUninstallUI::Delegate* delegate,
48 const Extension* extension,
49 SkBitmap* skia_icon)
50 : ExtensionUninstallDialog(profile, delegate, extension, skia_icon) {
43 // Build the dialog. 51 // Build the dialog.
44 GtkWidget* dialog = gtk_dialog_new_with_buttons( 52 dialog_ = gtk_dialog_new_with_buttons(
45 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(), 53 l10n_util::GetStringUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_TITLE).c_str(),
46 parent, 54 parent,
47 GTK_DIALOG_MODAL, 55 GTK_DIALOG_MODAL,
48 GTK_STOCK_CANCEL, 56 GTK_STOCK_CANCEL,
49 GTK_RESPONSE_CLOSE, 57 GTK_RESPONSE_CLOSE,
50 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(), 58 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON).c_str(),
51 GTK_RESPONSE_ACCEPT, 59 GTK_RESPONSE_ACCEPT,
52 NULL); 60 NULL);
53 gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); 61 gtk_dialog_set_has_separator(GTK_DIALOG(dialog_), FALSE);
54 62
55 // Create a two column layout. 63 // Create a two column layout.
56 GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); 64 GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog_));
57 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing); 65 gtk_box_set_spacing(GTK_BOX(content_area), ui::kContentAreaSpacing);
58 66
59 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); 67 GtkWidget* icon_hbox = gtk_hbox_new(FALSE, ui::kContentAreaSpacing);
60 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0); 68 gtk_box_pack_start(GTK_BOX(content_area), icon_hbox, TRUE, TRUE, 0);
61 69
62 // Put Icon in the left column. 70 // Put Icon in the left column.
63 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon); 71 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_icon);
64 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf); 72 GtkWidget* icon = gtk_image_new_from_pixbuf(pixbuf);
65 g_object_unref(pixbuf); 73 g_object_unref(pixbuf);
66 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0); 74 gtk_box_pack_start(GTK_BOX(icon_hbox), icon, TRUE, TRUE, 0);
67 75
68 // Create a new vbox for the right column. 76 // Create a new vbox for the right column.
69 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0); 77 GtkWidget* right_column_area = gtk_vbox_new(FALSE, 0);
70 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0); 78 gtk_box_pack_start(GTK_BOX(icon_hbox), right_column_area, TRUE, TRUE, 0);
71 79
72 std::string heading_text = l10n_util::GetStringFUTF8( 80 std::string heading_text = l10n_util::GetStringFUTF8(
73 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name())); 81 IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, UTF8ToUTF16(extension->name()));
74 GtkWidget* heading_label = gtk_label_new(heading_text.c_str()); 82 GtkWidget* heading_label = gtk_label_new(heading_text.c_str());
75 gtk_misc_set_alignment(GTK_MISC(heading_label), 0.0, 0.5); 83 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); 84 gtk_box_pack_start(GTK_BOX(right_column_area), heading_label, TRUE, TRUE, 0);
77 85
78 g_signal_connect(dialog, "response", G_CALLBACK(OnResponse), delegate); 86 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
79 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); 87 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE);
80 gtk_widget_show_all(dialog); 88 gtk_widget_show_all(dialog_);
81 } 89 }
82 90
83 } // namespace 91 ExtensionUninstallDialogGtk::~ExtensionUninstallDialogGtk() {
92 // We close the dialog if our owner and delegate disappears.
93 if (dialog_)
94 gtk_widget_destroy(dialog_);
95 }
84 96
85 // static 97 void ExtensionUninstallDialogGtk::OnResponse(
86 void ExtensionUninstallDialog::Show( 98 GtkWidget* dialog, int response_id) {
87 Profile* profile, 99 CHECK_EQ(dialog_, dialog);
88 ExtensionUninstallDialog::Delegate* delegate, 100 CHECK(delegate_);
89 const Extension* extension, 101
90 SkBitmap* icon) { 102 if (response_id == GTK_RESPONSE_ACCEPT)
91 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 103 delegate_->ExtensionUninstallAccepted();
104 else
105 delegate_->ExtensionUninstallCanceled();
106
107 gtk_widget_destroy(dialog_);
108 dialog_ = NULL;
109 }
110
111 }
112
113 // Platform specific implementation of the uninstall dialog show method.
114 void ExtensionUninstallUI::ShowDialog() {
115 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_);
92 if (!browser) { 116 if (!browser) {
93 delegate->ExtensionDialogCanceled(); 117 delegate_->ExtensionUninstallCanceled();
94 return; 118 return;
95 } 119 }
96 120
97 BrowserWindow* browser_window = browser->window(); 121 BrowserWindow* browser_window = browser->window();
98 if (!browser_window) { 122 if (!browser_window) {
99 delegate->ExtensionDialogCanceled(); 123 delegate_->ExtensionUninstallCanceled();
100 return; 124 return;
101 } 125 }
102 126
103 ShowUninstallDialogGtk(browser_window->GetNativeHandle(), 127 uninstall_dialog_.reset(new ExtensionUninstallDialogGtk(
104 icon, extension, delegate); 128 browser_window->GetNativeHandle(),
129 profile_,
130 delegate_,
131 extension_,
132 &icon_));
105 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698