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

Side by Side Diff: chrome/browser/ui/views/hung_renderer_view.cc

Issue 10806079: Add support for invoking the Windows 8 metro style hung renderer dialog box. The dialog box (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/hung_renderer_view.h" 5 #include "chrome/browser/ui/views/hung_renderer_view.h"
6 6
7 #if defined(OS_WIN) && !defined(USE_AURA) 7 #if defined(OS_WIN) && !defined(USE_AURA)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 21 matching lines...) Expand all
32 #include "ui/views/controls/label.h" 32 #include "ui/views/controls/label.h"
33 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
34 #include "ui/views/layout/layout_constants.h" 34 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
36 #include "ui/views/window/client_view.h" 36 #include "ui/views/window/client_view.h"
37 37
38 #if defined(USE_AURA) 38 #if defined(USE_AURA)
39 #include "ui/aura/window.h" 39 #include "ui/aura/window.h"
40 #endif 40 #endif
41 41
42 #if defined(OS_WIN) 42 // These functions allow certain chrome platforms to override the default hung
43 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h" 43 // renderer dialog. For e.g. Chrome on Windows 8 metro
44 #endif 44 bool PlatformShowCustomHungRendererDialog(WebContents* contents);
45 bool PlatformHideCustomHungRendererDialog(WebContents* contents);
46
47 #if !defined(OS_WIN)
48 bool PlatformShowCustomHungRendererDialog(WebContents* contents) {
49 return false;
50 }
51
52 bool PlatformHideCustomHungRendererDialog(WebContents* contents) {
53 return false;
54 }
55 #endif // OS_WIN
45 56
46 HungRendererDialogView* HungRendererDialogView::g_instance_ = NULL; 57 HungRendererDialogView* HungRendererDialogView::g_instance_ = NULL;
47 58
48 /////////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////////
49 // HungPagesTableModel, public: 60 // HungPagesTableModel, public:
50 61
51 HungPagesTableModel::HungPagesTableModel(Delegate* delegate) 62 HungPagesTableModel::HungPagesTableModel(Delegate* delegate)
52 : observer_(NULL), 63 : observer_(NULL),
53 delegate_(delegate) { 64 delegate_(delegate) {
54 } 65 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // warning window. 177 // warning window.
167 static const int kOverlayContentsOffsetY = 50; 178 static const int kOverlayContentsOffsetY = 50;
168 179
169 // The dimensions of the hung pages list table view, in pixels. 180 // The dimensions of the hung pages list table view, in pixels.
170 static const int kTableViewWidth = 300; 181 static const int kTableViewWidth = 300;
171 static const int kTableViewHeight = 100; 182 static const int kTableViewHeight = 100;
172 183
173 /////////////////////////////////////////////////////////////////////////////// 184 ///////////////////////////////////////////////////////////////////////////////
174 // HungRendererDialogView, public: 185 // HungRendererDialogView, public:
175 186
176 #if !defined(OS_WIN)
177
178 // static 187 // static
179 HungRendererDialogView* HungRendererDialogView::Create() { 188 HungRendererDialogView* HungRendererDialogView::Create() {
180 if (!g_instance_) { 189 if (!g_instance_) {
181 g_instance_ = new HungRendererDialogView; 190 g_instance_ = new HungRendererDialogView;
182 views::Widget::CreateWindow(g_instance_); 191 views::Widget::CreateWindow(g_instance_);
183 } 192 }
184 return g_instance_; 193 return g_instance_;
185 } 194 }
186 #endif // defined(OS_WIN)
187 195
188 // static 196 // static
189 HungRendererDialogView* HungRendererDialogView::GetInstance() { 197 HungRendererDialogView* HungRendererDialogView::GetInstance() {
190 return g_instance_; 198 return g_instance_;
191 } 199 }
192 200
201 // static
sky 2012/07/24 22:57:03 Make position of these two match header.
ananta 2012/07/24 23:16:37 Moved these declaration and impl of these function
202 bool HungRendererDialogView::IsFrameActive(WebContents* contents) {
203 gfx::NativeView frame_view =
204 platform_util::GetTopLevel(contents->GetNativeView());
205 return platform_util::IsWindowActive(frame_view);
206 }
207
208 #if !defined(OS_WIN)
209 // static
210 void HungRendererDialogView::KillRendererProcess(
211 base::ProcessHandle process_handle) {
212 base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false);
213 }
214 #endif // OS_WIN
215
193 HungRendererDialogView::HungRendererDialogView() 216 HungRendererDialogView::HungRendererDialogView()
194 : hung_pages_table_(NULL), 217 : hung_pages_table_(NULL),
195 kill_button_(NULL), 218 kill_button_(NULL),
196 kill_button_container_(NULL), 219 kill_button_container_(NULL),
197 initialized_(false) { 220 initialized_(false) {
198 InitClass(); 221 InitClass();
199 } 222 }
200 223
201 HungRendererDialogView::~HungRendererDialogView() { 224 HungRendererDialogView::~HungRendererDialogView() {
202 hung_pages_table_->SetModel(NULL); 225 hung_pages_table_->SetModel(NULL);
203 } 226 }
204 227
205 void HungRendererDialogView::ShowForWebContents(WebContents* contents) { 228 void HungRendererDialogView::ShowForWebContents(WebContents* contents) {
206 DCHECK(contents && GetWidget()); 229 DCHECK(contents && GetWidget());
207 230
208 // Don't show the warning unless the foreground window is the frame, or this 231 // Don't show the warning unless the foreground window is the frame, or this
209 // window (but still invisible). If the user has another window or 232 // window (but still invisible). If the user has another window or
210 // application selected, activating ourselves is rude. 233 // application selected, activating ourselves is rude.
211 if (!IsFrameActive(contents)) 234 if (!IsFrameActive(contents) &&
235 !platform_util::IsWindowActive(GetWidget()->GetNativeWindow()))
212 return; 236 return;
213 237
214 if (!GetWidget()->IsActive()) { 238 if (!GetWidget()->IsActive()) {
215 gfx::Rect bounds = GetDisplayBounds(contents); 239 gfx::Rect bounds = GetDisplayBounds(contents);
216 240
217 gfx::NativeView frame_view = 241 gfx::NativeView frame_view =
218 platform_util::GetTopLevel(contents->GetNativeView()); 242 platform_util::GetTopLevel(contents->GetNativeView());
219 243
220 views::Widget* insert_after = 244 views::Widget* insert_after =
221 views::Widget::GetWidgetForNativeView(frame_view); 245 views::Widget::GetWidgetForNativeView(frame_view);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // HungRendererDialogView, views::ButtonListener implementation: 323 // HungRendererDialogView, views::ButtonListener implementation:
300 324
301 void HungRendererDialogView::ButtonPressed( 325 void HungRendererDialogView::ButtonPressed(
302 views::Button* sender, const views::Event& event) { 326 views::Button* sender, const views::Event& event) {
303 if (sender == kill_button_ && 327 if (sender == kill_button_ &&
304 hung_pages_table_model_->GetRenderProcessHost()) { 328 hung_pages_table_model_->GetRenderProcessHost()) {
305 329
306 base::ProcessHandle process_handle = 330 base::ProcessHandle process_handle =
307 hung_pages_table_model_->GetRenderProcessHost()->GetHandle(); 331 hung_pages_table_model_->GetRenderProcessHost()->GetHandle();
308 332
309 #if defined(OS_WIN) 333 KillRendererProcess(process_handle);
310 // Try to generate a crash report for the hung process.
311 CrashDumpAndTerminateHungChildProcess(process_handle);
312 #else
313 // Kill the process.
314 base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false);
315 #endif
316 } 334 }
317 } 335 }
318 336
319 /////////////////////////////////////////////////////////////////////////////// 337 ///////////////////////////////////////////////////////////////////////////////
320 // HungRendererDialogView, HungPagesTableModel::Delegate overrides: 338 // HungRendererDialogView, HungPagesTableModel::Delegate overrides:
321 339
322 void HungRendererDialogView::TabDestroyed() { 340 void HungRendererDialogView::TabDestroyed() {
323 GetWidget()->Close(); 341 GetWidget()->Close();
324 } 342 }
325 343
326 /////////////////////////////////////////////////////////////////////////////// 344 ///////////////////////////////////////////////////////////////////////////////
327 // HungRendererDialogView, views::View overrides: 345 // HungRendererDialogView, views::View overrides:
328 346
329 void HungRendererDialogView::ViewHierarchyChanged(bool is_add, 347 void HungRendererDialogView::ViewHierarchyChanged(bool is_add,
330 views::View* parent, 348 views::View* parent,
331 views::View* child) { 349 views::View* child) {
332 if (!initialized_ && is_add && child == this && GetWidget()) 350 if (!initialized_ && is_add && child == this && GetWidget())
333 Init(); 351 Init();
334 } 352 }
335 353
336 bool HungRendererDialogView::IsFrameActive(WebContents* contents) {
337 gfx::NativeView frame_view =
338 platform_util::GetTopLevel(contents->GetNativeView());
339 if (!platform_util::IsWindowActive(frame_view) &&
340 !platform_util::IsWindowActive(GetWidget()->GetNativeWindow())) {
341 return false;
342 }
343 return true;
344 }
345
346 /////////////////////////////////////////////////////////////////////////////// 354 ///////////////////////////////////////////////////////////////////////////////
347 // HungRendererDialogView, private: 355 // HungRendererDialogView, private:
348 356
349 void HungRendererDialogView::Init() { 357 void HungRendererDialogView::Init() {
350 views::ImageView* frozen_icon_view = new views::ImageView; 358 views::ImageView* frozen_icon_view = new views::ImageView;
351 frozen_icon_view->SetImage(frozen_icon_); 359 frozen_icon_view->SetImage(frozen_icon_);
352 360
353 views::Label* info_label = new views::Label( 361 views::Label* info_label = new views::Label(
354 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER)); 362 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER));
355 info_label->SetMultiLine(true); 363 info_label->SetMultiLine(true);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if (!initialized) { 453 if (!initialized) {
446 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 454 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
447 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON); 455 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON);
448 initialized = true; 456 initialized = true;
449 } 457 }
450 } 458 }
451 459
452 namespace chrome { 460 namespace chrome {
453 461
454 void ShowHungRendererDialog(WebContents* contents) { 462 void ShowHungRendererDialog(WebContents* contents) {
455 if (!logging::DialogsAreSuppressed()) { 463 if (!logging::DialogsAreSuppressed() &&
464 !PlatformShowCustomHungRendererDialog(contents)) {
456 HungRendererDialogView* view = HungRendererDialogView::Create(); 465 HungRendererDialogView* view = HungRendererDialogView::Create();
457 view->ShowForWebContents(contents); 466 view->ShowForWebContents(contents);
458 } 467 }
459 } 468 }
460 469
461 void HideHungRendererDialog(WebContents* contents) { 470 void HideHungRendererDialog(WebContents* contents) {
462 if (!logging::DialogsAreSuppressed() && 471 if (!logging::DialogsAreSuppressed() &&
472 !PlatformHideCustomHungRendererDialog(contents) &&
463 HungRendererDialogView::GetInstance()) 473 HungRendererDialogView::GetInstance())
464 HungRendererDialogView::GetInstance()->EndForWebContents(contents); 474 HungRendererDialogView::GetInstance()->EndForWebContents(contents);
465 } 475 }
466 476
467 } // namespace chrome 477 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698