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

Side by Side Diff: chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc

Issue 6873082: Fix DELETE_EVENT handling in 3 places. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 8 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 #include "chrome/browser/ui/browser_dialogs.h" 5 #include "chrome/browser/ui/browser_dialogs.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 16 matching lines...) Expand all
27 namespace { 27 namespace {
28 28
29 // A wrapper class that represents the Gtk dialog. 29 // A wrapper class that represents the Gtk dialog.
30 class HungRendererDialogGtk { 30 class HungRendererDialogGtk {
31 public: 31 public:
32 HungRendererDialogGtk(); 32 HungRendererDialogGtk();
33 void ShowForTabContents(TabContents* hung_contents); 33 void ShowForTabContents(TabContents* hung_contents);
34 void EndForTabContents(TabContents* hung_contents); 34 void EndForTabContents(TabContents* hung_contents);
35 35
36 private: 36 private:
37 ~HungRendererDialogGtk();
38
37 // The GtkTreeView column ids. 39 // The GtkTreeView column ids.
38 enum { 40 enum {
39 COL_FAVICON, 41 COL_FAVICON,
40 COL_TITLE, 42 COL_TITLE,
41 COL_COUNT, 43 COL_COUNT,
42 }; 44 };
43 45
44 // Create the gtk dialog and add the widgets. 46 // Create the gtk dialog and add the widgets.
45 void Init(); 47 void Init();
46 48
(...skipping 11 matching lines...) Expand all
58 60
59 // The response ID for the "Kill pages" button. Anything positive should be 61 // The response ID for the "Kill pages" button. Anything positive should be
60 // fine (the built in GtkResponseTypes are negative numbers). 62 // fine (the built in GtkResponseTypes are negative numbers).
61 const int kKillPagesButtonResponse = 1; 63 const int kKillPagesButtonResponse = 1;
62 64
63 HungRendererDialogGtk::HungRendererDialogGtk() 65 HungRendererDialogGtk::HungRendererDialogGtk()
64 : dialog_(NULL), model_(NULL), contents_(NULL) { 66 : dialog_(NULL), model_(NULL), contents_(NULL) {
65 Init(); 67 Init();
66 } 68 }
67 69
70 HungRendererDialogGtk::~HungRendererDialogGtk() {
71 DCHECK(g_instance == this);
72 g_instance = NULL;
73
74 if (dialog_)
75 gtk_widget_destroy(GTK_WIDGET(dialog_));
76 }
77
68 void HungRendererDialogGtk::Init() { 78 void HungRendererDialogGtk::Init() {
69 dialog_ = GTK_DIALOG(gtk_dialog_new_with_buttons( 79 dialog_ = GTK_DIALOG(gtk_dialog_new_with_buttons(
70 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE).c_str(), 80 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE).c_str(),
71 NULL, // No parent because tabs can span multiple windows. 81 NULL, // No parent because tabs can span multiple windows.
72 GTK_DIALOG_NO_SEPARATOR, 82 GTK_DIALOG_NO_SEPARATOR,
73 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_END).c_str(), 83 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_END).c_str(),
74 kKillPagesButtonResponse, 84 kKillPagesButtonResponse,
75 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT).c_str(), 85 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT).c_str(),
76 GTK_RESPONSE_OK, 86 GTK_RESPONSE_OK,
77 NULL)); 87 NULL));
78 gtk_dialog_set_default_response(dialog_, GTK_RESPONSE_OK); 88 gtk_dialog_set_default_response(dialog_, GTK_RESPONSE_OK);
79 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); 89 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this);
90 // NULL out |dialog_| when it's destroyed.
91 g_signal_connect(dialog_, "destroy",
92 G_CALLBACK(gtk_widget_destroyed), &dialog_);
80 93
81 // We have an hbox with the frozen icon on the left. On the right, 94 // We have an hbox with the frozen icon on the left. On the right,
82 // we have a vbox with the unresponsive text on top and a table of 95 // we have a vbox with the unresponsive text on top and a table of
83 // tabs on bottom. 96 // tabs on bottom.
84 // ·-----------------------------------· 97 // ·-----------------------------------·
85 // |·---------------------------------·| 98 // |·---------------------------------·|
86 // ||·----·|·------------------------·|| 99 // ||·----·|·------------------------·||
87 // |||icon||| ||| 100 // |||icon||| |||
88 // ||·----·|| The folowing page(s).. ||| 101 // ||·----·|| The folowing page(s).. |||
89 // || || ||| 102 // || || |||
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 contents->GetRenderProcessHost()) { 189 contents->GetRenderProcessHost()) {
177 gtk_widget_hide(GTK_WIDGET(dialog_)); 190 gtk_widget_hide(GTK_WIDGET(dialog_));
178 // Since we're closing, we no longer need this TabContents. 191 // Since we're closing, we no longer need this TabContents.
179 contents_ = NULL; 192 contents_ = NULL;
180 } 193 }
181 } 194 }
182 195
183 // When the user clicks a button on the dialog or closes the dialog, this 196 // When the user clicks a button on the dialog or closes the dialog, this
184 // callback is called. 197 // callback is called.
185 void HungRendererDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { 198 void HungRendererDialogGtk::OnResponse(GtkWidget* dialog, int response_id) {
186 DCHECK(g_instance == this);
187 switch (response_id) { 199 switch (response_id) {
188 case kKillPagesButtonResponse: 200 case kKillPagesButtonResponse:
189 // Kill the process. 201 // Kill the process.
190 if (contents_ && contents_->GetRenderProcessHost()) { 202 if (contents_ && contents_->GetRenderProcessHost()) {
191 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), 203 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(),
192 ResultCodes::HUNG, false); 204 ResultCodes::HUNG, false);
193 } 205 }
194 break; 206 break;
195 207
196 case GTK_RESPONSE_OK: 208 case GTK_RESPONSE_OK:
197 case GTK_RESPONSE_DELETE_EVENT: 209 case GTK_RESPONSE_DELETE_EVENT:
198 // Start waiting again for responsiveness. 210 // Start waiting again for responsiveness.
199 if (contents_ && contents_->render_view_host()) 211 if (contents_ && contents_->render_view_host())
200 contents_->render_view_host()->RestartHangMonitorTimeout(); 212 contents_->render_view_host()->RestartHangMonitorTimeout();
201 break; 213 break;
202 default: 214 default:
203 NOTREACHED(); 215 NOTREACHED();
204 } 216 }
205 217
206 gtk_widget_destroy(GTK_WIDGET(dialog_)); 218 delete this;
207 delete g_instance;
208 g_instance = NULL;
209 } 219 }
210 220
211 } // namespace 221 } // namespace
212 222
213 namespace browser { 223 namespace browser {
214 224
215 void ShowHungRendererDialog(TabContents* contents) { 225 void ShowHungRendererDialog(TabContents* contents) {
216 if (!logging::DialogsAreSuppressed()) { 226 if (!logging::DialogsAreSuppressed()) {
217 if (!g_instance) 227 if (!g_instance)
218 g_instance = new HungRendererDialogGtk(); 228 g_instance = new HungRendererDialogGtk();
219 g_instance->ShowForTabContents(contents); 229 g_instance->ShowForTabContents(contents);
220 } 230 }
221 } 231 }
222 232
223 void HideHungRendererDialog(TabContents* contents) { 233 void HideHungRendererDialog(TabContents* contents) {
224 if (!logging::DialogsAreSuppressed() && g_instance) 234 if (!logging::DialogsAreSuppressed() && g_instance)
225 g_instance->EndForTabContents(contents); 235 g_instance->EndForTabContents(contents);
226 } 236 }
227 237
228 } // namespace browser 238 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698