Chromium Code Reviews| 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 #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 26 matching lines...) Expand all Loading... | |
| 37 // The GtkTreeView column ids. | 37 // The GtkTreeView column ids. |
| 38 enum { | 38 enum { |
| 39 COL_FAVICON, | 39 COL_FAVICON, |
| 40 COL_TITLE, | 40 COL_TITLE, |
| 41 COL_COUNT, | 41 COL_COUNT, |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 // Create the gtk dialog and add the widgets. | 44 // Create the gtk dialog and add the widgets. |
| 45 void Init(); | 45 void Init(); |
| 46 | 46 |
| 47 CHROMEGTK_CALLBACK_1(HungRendererDialogGtk, void, OnDialogResponse, gint); | 47 CHROMEGTK_CALLBACK_1(HungRendererDialogGtk, void, OnResponse, int); |
| 48 | 48 |
| 49 GtkDialog* dialog_; | 49 GtkDialog* dialog_; |
| 50 GtkListStore* model_; | 50 GtkListStore* model_; |
| 51 TabContents* contents_; | 51 TabContents* contents_; |
| 52 | 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(HungRendererDialogGtk); | 53 DISALLOW_COPY_AND_ASSIGN(HungRendererDialogGtk); |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // We only support showing one of these at a time per app. | 56 // We only support showing one of these at a time per app. |
| 57 HungRendererDialogGtk* g_instance = NULL; | 57 HungRendererDialogGtk* g_instance = NULL; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 69 dialog_ = GTK_DIALOG(gtk_dialog_new_with_buttons( | 69 dialog_ = GTK_DIALOG(gtk_dialog_new_with_buttons( |
| 70 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE).c_str(), | 70 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE).c_str(), |
| 71 NULL, // No parent because tabs can span multiple windows. | 71 NULL, // No parent because tabs can span multiple windows. |
| 72 GTK_DIALOG_NO_SEPARATOR, | 72 GTK_DIALOG_NO_SEPARATOR, |
| 73 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_END).c_str(), | 73 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_END).c_str(), |
| 74 kKillPagesButtonResponse, | 74 kKillPagesButtonResponse, |
| 75 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT).c_str(), | 75 l10n_util::GetStringUTF8(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT).c_str(), |
| 76 GTK_RESPONSE_OK, | 76 GTK_RESPONSE_OK, |
| 77 NULL)); | 77 NULL)); |
| 78 gtk_dialog_set_default_response(dialog_, GTK_RESPONSE_OK); | 78 gtk_dialog_set_default_response(dialog_, GTK_RESPONSE_OK); |
| 79 g_signal_connect(dialog_, "response", | 79 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
| 80 G_CALLBACK(OnDialogResponseThunk), this); | |
| 81 | 80 |
| 82 // We have an hbox with the frozen icon on the left. On the right, | 81 // We have an hbox with the frozen icon on the left. On the right, |
| 83 // we have a vbox with the unresponsive text on top and a table of | 82 // we have a vbox with the unresponsive text on top and a table of |
| 84 // tabs on bottom. | 83 // tabs on bottom. |
| 85 // ·-----------------------------------· | 84 // ·-----------------------------------· |
| 86 // |·---------------------------------·| | 85 // |·---------------------------------·| |
| 87 // ||·----·|·------------------------·|| | 86 // ||·----·|·------------------------·|| |
| 88 // |||icon||| ||| | 87 // |||icon||| ||| |
| 89 // ||·----·|| The folowing page(s).. ||| | 88 // ||·----·|| The folowing page(s).. ||| |
| 90 // || || ||| | 89 // || || ||| |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 if (contents_ && contents_->GetRenderProcessHost() == | 174 if (contents_ && contents_->GetRenderProcessHost() == |
| 176 contents->GetRenderProcessHost()) { | 175 contents->GetRenderProcessHost()) { |
| 177 gtk_widget_hide(GTK_WIDGET(dialog_)); | 176 gtk_widget_hide(GTK_WIDGET(dialog_)); |
| 178 // Since we're closing, we no longer need this TabContents. | 177 // Since we're closing, we no longer need this TabContents. |
| 179 contents_ = NULL; | 178 contents_ = NULL; |
| 180 } | 179 } |
| 181 } | 180 } |
| 182 | 181 |
| 183 // When the user clicks a button on the dialog or closes the dialog, this | 182 // When the user clicks a button on the dialog or closes the dialog, this |
| 184 // callback is called. | 183 // callback is called. |
| 185 void HungRendererDialogGtk::OnDialogResponse(GtkWidget* widget, | 184 void HungRendererDialogGtk::OnResponse(GtkWidget* dialog, int response_id) { |
| 186 gint response_id) { | |
| 187 DCHECK(g_instance == this); | 185 DCHECK(g_instance == this); |
| 188 switch (response_id) { | 186 switch (response_id) { |
| 189 case kKillPagesButtonResponse: | 187 case kKillPagesButtonResponse: |
| 190 // Kill the process. | 188 // Kill the process. |
| 191 if (contents_ && contents_->GetRenderProcessHost()) { | 189 if (contents_ && contents_->GetRenderProcessHost()) { |
| 192 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 190 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
| 193 ResultCodes::HUNG, false); | 191 ResultCodes::HUNG, false); |
| 194 } | 192 } |
| 195 break; | 193 break; |
| 196 | 194 |
| 197 case GTK_RESPONSE_OK: | 195 case GTK_RESPONSE_OK: |
| 198 case GTK_RESPONSE_DELETE_EVENT: | 196 case GTK_RESPONSE_DELETE_EVENT: |
| 199 // Start waiting again for responsiveness. | 197 // Start waiting again for responsiveness. |
| 200 if (contents_ && contents_->render_view_host()) | 198 if (contents_ && contents_->render_view_host()) |
| 201 contents_->render_view_host()->RestartHangMonitorTimeout(); | 199 contents_->render_view_host()->RestartHangMonitorTimeout(); |
| 202 break; | 200 break; |
| 203 default: | 201 default: |
| 204 NOTREACHED(); | 202 NOTREACHED(); |
| 205 } | 203 } |
| 206 | 204 |
| 207 gtk_widget_destroy(GTK_WIDGET(dialog_)); | 205 gtk_widget_destroy(GTK_WIDGET(dialog_)); |
|
tony
2011/03/07 19:43:53
Nit: Remove GTK_WIDGET?
tfarina
2011/03/07 19:52:17
Nope, unfortunately |dialog_| is GtkDialog*
And
tony
2011/03/07 19:54:18
You could use |dialog| instead of |dialog_|. If y
| |
| 208 delete g_instance; | 206 delete g_instance; |
| 209 g_instance = NULL; | 207 g_instance = NULL; |
| 210 } | 208 } |
| 211 | 209 |
| 212 } // namespace | 210 } // namespace |
| 213 | 211 |
| 214 namespace browser { | 212 namespace browser { |
| 215 | 213 |
| 216 void ShowHungRendererDialog(TabContents* contents) { | 214 void ShowHungRendererDialog(TabContents* contents) { |
| 217 if (!logging::DialogsAreSuppressed()) { | 215 if (!logging::DialogsAreSuppressed()) { |
| 218 if (!g_instance) | 216 if (!g_instance) |
| 219 g_instance = new HungRendererDialogGtk(); | 217 g_instance = new HungRendererDialogGtk(); |
| 220 g_instance->ShowForTabContents(contents); | 218 g_instance->ShowForTabContents(contents); |
| 221 } | 219 } |
| 222 } | 220 } |
| 223 | 221 |
| 224 void HideHungRendererDialog(TabContents* contents) { | 222 void HideHungRendererDialog(TabContents* contents) { |
| 225 if (!logging::DialogsAreSuppressed() && g_instance) | 223 if (!logging::DialogsAreSuppressed() && g_instance) |
| 226 g_instance->EndForTabContents(contents); | 224 g_instance->EndForTabContents(contents); |
| 227 } | 225 } |
| 228 | 226 |
| 229 } // namespace browser | 227 } // namespace browser |
| OLD | NEW |