OLD | NEW |
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 Loading... |
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) | |
43 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h" | |
44 #endif | |
45 | |
46 HungRendererDialogView* HungRendererDialogView::g_instance_ = NULL; | 42 HungRendererDialogView* HungRendererDialogView::g_instance_ = NULL; |
47 | 43 |
48 /////////////////////////////////////////////////////////////////////////////// | 44 /////////////////////////////////////////////////////////////////////////////// |
49 // HungPagesTableModel, public: | 45 // HungPagesTableModel, public: |
50 | 46 |
51 HungPagesTableModel::HungPagesTableModel(Delegate* delegate) | 47 HungPagesTableModel::HungPagesTableModel(Delegate* delegate) |
52 : observer_(NULL), | 48 : observer_(NULL), |
53 delegate_(delegate) { | 49 delegate_(delegate) { |
54 } | 50 } |
55 | 51 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 HungRendererDialogView::~HungRendererDialogView() { | 197 HungRendererDialogView::~HungRendererDialogView() { |
202 hung_pages_table_->SetModel(NULL); | 198 hung_pages_table_->SetModel(NULL); |
203 } | 199 } |
204 | 200 |
205 void HungRendererDialogView::ShowForWebContents(WebContents* contents) { | 201 void HungRendererDialogView::ShowForWebContents(WebContents* contents) { |
206 DCHECK(contents && GetWidget()); | 202 DCHECK(contents && GetWidget()); |
207 | 203 |
208 // Don't show the warning unless the foreground window is the frame, or this | 204 // 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 | 205 // window (but still invisible). If the user has another window or |
210 // application selected, activating ourselves is rude. | 206 // application selected, activating ourselves is rude. |
211 if (!IsFrameActive(contents)) | 207 if (!IsFrameActive(contents) && |
| 208 !platform_util::IsWindowActive(GetWidget()->GetNativeWindow())) |
212 return; | 209 return; |
213 | 210 |
214 if (!GetWidget()->IsActive()) { | 211 if (!GetWidget()->IsActive()) { |
215 gfx::Rect bounds = GetDisplayBounds(contents); | 212 gfx::Rect bounds = GetDisplayBounds(contents); |
216 | 213 |
217 gfx::NativeView frame_view = | 214 gfx::NativeView frame_view = |
218 platform_util::GetTopLevel(contents->GetNativeView()); | 215 platform_util::GetTopLevel(contents->GetNativeView()); |
219 | 216 |
220 views::Widget* insert_after = | 217 views::Widget* insert_after = |
221 views::Widget::GetWidgetForNativeView(frame_view); | 218 views::Widget::GetWidgetForNativeView(frame_view); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // HungRendererDialogView, views::ButtonListener implementation: | 296 // HungRendererDialogView, views::ButtonListener implementation: |
300 | 297 |
301 void HungRendererDialogView::ButtonPressed( | 298 void HungRendererDialogView::ButtonPressed( |
302 views::Button* sender, const views::Event& event) { | 299 views::Button* sender, const views::Event& event) { |
303 if (sender == kill_button_ && | 300 if (sender == kill_button_ && |
304 hung_pages_table_model_->GetRenderProcessHost()) { | 301 hung_pages_table_model_->GetRenderProcessHost()) { |
305 | 302 |
306 base::ProcessHandle process_handle = | 303 base::ProcessHandle process_handle = |
307 hung_pages_table_model_->GetRenderProcessHost()->GetHandle(); | 304 hung_pages_table_model_->GetRenderProcessHost()->GetHandle(); |
308 | 305 |
309 #if defined(OS_WIN) | 306 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 } | 307 } |
317 } | 308 } |
318 | 309 |
319 /////////////////////////////////////////////////////////////////////////////// | 310 /////////////////////////////////////////////////////////////////////////////// |
320 // HungRendererDialogView, HungPagesTableModel::Delegate overrides: | 311 // HungRendererDialogView, HungPagesTableModel::Delegate overrides: |
321 | 312 |
322 void HungRendererDialogView::TabDestroyed() { | 313 void HungRendererDialogView::TabDestroyed() { |
323 GetWidget()->Close(); | 314 GetWidget()->Close(); |
324 } | 315 } |
325 | 316 |
326 /////////////////////////////////////////////////////////////////////////////// | 317 /////////////////////////////////////////////////////////////////////////////// |
327 // HungRendererDialogView, views::View overrides: | 318 // HungRendererDialogView, views::View overrides: |
328 | 319 |
329 void HungRendererDialogView::ViewHierarchyChanged(bool is_add, | 320 void HungRendererDialogView::ViewHierarchyChanged(bool is_add, |
330 views::View* parent, | 321 views::View* parent, |
331 views::View* child) { | 322 views::View* child) { |
332 if (!initialized_ && is_add && child == this && GetWidget()) | 323 if (!initialized_ && is_add && child == this && GetWidget()) |
333 Init(); | 324 Init(); |
334 } | 325 } |
335 | 326 |
336 bool HungRendererDialogView::IsFrameActive(WebContents* contents) { | 327 bool HungRendererDialogView::IsFrameActive(WebContents* contents) { |
337 gfx::NativeView frame_view = | 328 gfx::NativeView frame_view = |
338 platform_util::GetTopLevel(contents->GetNativeView()); | 329 platform_util::GetTopLevel(contents->GetNativeView()); |
339 if (!platform_util::IsWindowActive(frame_view) && | 330 return platform_util::IsWindowActive(frame_view); |
340 !platform_util::IsWindowActive(GetWidget()->GetNativeWindow())) { | |
341 return false; | |
342 } | |
343 return true; | |
344 } | 331 } |
345 | 332 |
346 /////////////////////////////////////////////////////////////////////////////// | 333 /////////////////////////////////////////////////////////////////////////////// |
347 // HungRendererDialogView, private: | 334 // HungRendererDialogView, private: |
348 | 335 |
349 void HungRendererDialogView::Init() { | 336 void HungRendererDialogView::Init() { |
350 views::ImageView* frozen_icon_view = new views::ImageView; | 337 views::ImageView* frozen_icon_view = new views::ImageView; |
351 frozen_icon_view->SetImage(frozen_icon_); | 338 frozen_icon_view->SetImage(frozen_icon_); |
352 | 339 |
353 views::Label* info_label = new views::Label( | 340 views::Label* info_label = new views::Label( |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 // static | 429 // static |
443 void HungRendererDialogView::InitClass() { | 430 void HungRendererDialogView::InitClass() { |
444 static bool initialized = false; | 431 static bool initialized = false; |
445 if (!initialized) { | 432 if (!initialized) { |
446 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 433 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
447 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON); | 434 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON); |
448 initialized = true; | 435 initialized = true; |
449 } | 436 } |
450 } | 437 } |
451 | 438 |
| 439 #if !defined(OS_WIN) |
| 440 // static |
| 441 void HungRendererDialogView::KillRendererProcess( |
| 442 base::ProcessHandle process_handle) { |
| 443 base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false); |
| 444 } |
| 445 #endif // OS_WIN |
| 446 |
452 namespace chrome { | 447 namespace chrome { |
453 | 448 |
454 void ShowHungRendererDialog(WebContents* contents) { | 449 void ShowHungRendererDialog(WebContents* contents) { |
455 if (!logging::DialogsAreSuppressed()) { | 450 if (!logging::DialogsAreSuppressed()) { |
456 HungRendererDialogView* view = HungRendererDialogView::Create(); | 451 HungRendererDialogView* view = HungRendererDialogView::Create(); |
457 view->ShowForWebContents(contents); | 452 view->ShowForWebContents(contents); |
458 } | 453 } |
459 } | 454 } |
460 | 455 |
461 void HideHungRendererDialog(WebContents* contents) { | 456 void HideHungRendererDialog(WebContents* contents) { |
462 if (!logging::DialogsAreSuppressed() && | 457 if (!logging::DialogsAreSuppressed() && |
463 HungRendererDialogView::GetInstance()) | 458 HungRendererDialogView::GetInstance()) |
464 HungRendererDialogView::GetInstance()->EndForWebContents(contents); | 459 HungRendererDialogView::GetInstance()->EndForWebContents(contents); |
465 } | 460 } |
466 | 461 |
467 } // namespace chrome | 462 } // namespace chrome |
OLD | NEW |