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

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

Issue 2660553005: Harmony - convert hung renderer dialog. (Closed)
Patch Set: disable dialog test on osx Created 3 years, 10 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
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 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/browser/platform_util.h" 12 #include "chrome/browser/platform_util.h"
13 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h" 14 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" 15 #include "chrome/browser/ui/tab_contents/core_tab_helper.h"
16 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
17 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
18 #include "chrome/browser/ui/views/layout_utils.h"
17 #include "chrome/common/chrome_constants.h" 19 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/crash_keys.h" 20 #include "chrome/common/crash_keys.h"
19 #include "chrome/common/logging_chrome.h" 21 #include "chrome/common/logging_chrome.h"
20 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
21 #include "chrome/grit/theme_resources.h" 23 #include "chrome/grit/theme_resources.h"
22 #include "components/constrained_window/constrained_window_views.h" 24 #include "components/constrained_window/constrained_window_views.h"
23 #include "components/favicon/content/content_favicon_driver.h" 25 #include "components/favicon/content/content_favicon_driver.h"
24 #include "components/web_modal/web_contents_modal_dialog_host.h" 26 #include "components/web_modal/web_contents_modal_dialog_host.h"
25 #include "content/public/browser/render_process_host.h" 27 #include "content/public/browser/render_process_host.h"
26 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_widget_host.h" 29 #include "content/public/browser/render_widget_host.h"
28 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/result_codes.h" 31 #include "content/public/common/result_codes.h"
30 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 33 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
33 #include "ui/views/controls/button/md_text_button.h" 35 #include "ui/views/controls/button/md_text_button.h"
34 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
36 #include "ui/views/layout/grid_layout.h" 38 #include "ui/views/layout/grid_layout.h"
37 #include "ui/views/layout/layout_constants.h"
38 #include "ui/views/widget/widget.h" 39 #include "ui/views/widget/widget.h"
39 #include "ui/views/window/client_view.h" 40 #include "ui/views/window/client_view.h"
40 41
41 #if defined(OS_WIN) 42 #if defined(OS_WIN)
42 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h" 43 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
43 #include "chrome/browser/profiles/profile.h" 44 #include "chrome/browser/profiles/profile.h"
44 #include "chrome/browser/shell_integration_win.h" 45 #include "chrome/browser/shell_integration_win.h"
45 #include "ui/base/win/shell.h" 46 #include "ui/base/win/shell.h"
46 #include "ui/views/win/hwnd_util.h" 47 #include "ui/views/win/hwnd_util.h"
47 #endif 48 #endif
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 /////////////////////////////////////////////////////////////////////////////// 170 ///////////////////////////////////////////////////////////////////////////////
170 // HungRendererDialogView 171 // HungRendererDialogView
171 172
172 // static 173 // static
173 gfx::ImageSkia* HungRendererDialogView::frozen_icon_ = NULL; 174 gfx::ImageSkia* HungRendererDialogView::frozen_icon_ = NULL;
174 175
175 // The dimensions of the hung pages list table view, in pixels. 176 // The dimensions of the hung pages list table view, in pixels.
176 static const int kTableViewWidth = 300; 177 static const int kTableViewWidth = 300;
177 static const int kTableViewHeight = 100; 178 static const int kTableViewHeight = 100;
178 179
179 // Padding space in pixels between frozen icon to the info label, hung pages
180 // list table view and the Kill pages button.
181 static const int kCentralColumnPadding =
182 views::kUnrelatedControlLargeHorizontalSpacing;
183
184 /////////////////////////////////////////////////////////////////////////////// 180 ///////////////////////////////////////////////////////////////////////////////
185 // HungRendererDialogView, public: 181 // HungRendererDialogView, public:
186 182
187 // static 183 // static
188 HungRendererDialogView* HungRendererDialogView::Create( 184 HungRendererDialogView* HungRendererDialogView::Create(
189 gfx::NativeWindow context) { 185 gfx::NativeWindow context) {
190 if (!g_instance_) { 186 if (!g_instance_) {
191 g_instance_ = new HungRendererDialogView; 187 g_instance_ = new HungRendererDialogView;
192 views::DialogDelegate::CreateDialogWidget(g_instance_, context, NULL); 188 views::DialogDelegate::CreateDialogWidget(g_instance_, context, NULL);
193 } 189 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 222 }
227 223
228 // static 224 // static
229 bool HungRendererDialogView::IsFrameActive(WebContents* contents) { 225 bool HungRendererDialogView::IsFrameActive(WebContents* contents) {
230 gfx::NativeWindow window = 226 gfx::NativeWindow window =
231 platform_util::GetTopLevel(contents->GetNativeView()); 227 platform_util::GetTopLevel(contents->GetNativeView());
232 return platform_util::IsWindowActive(window); 228 return platform_util::IsWindowActive(window);
233 } 229 }
234 230
235 HungRendererDialogView::HungRendererDialogView() 231 HungRendererDialogView::HungRendererDialogView()
236 : info_label_(nullptr), 232 : info_label_(nullptr), hung_pages_table_(nullptr), initialized_(false) {
237 hung_pages_table_(nullptr),
238 kill_button_(nullptr),
239 initialized_(false),
240 kill_button_clicked_(false) {
241 InitClass(); 233 InitClass();
242 } 234 }
243 235
244 HungRendererDialogView::~HungRendererDialogView() { 236 HungRendererDialogView::~HungRendererDialogView() {
245 hung_pages_table_->SetModel(NULL); 237 hung_pages_table_->SetModel(NULL);
246 } 238 }
247 239
248 void HungRendererDialogView::ShowForWebContents( 240 void HungRendererDialogView::ShowForWebContents(
249 WebContents* contents, 241 WebContents* contents,
250 const content::WebContentsUnresponsiveState& unresponsive_state) { 242 const content::WebContentsUnresponsiveState& unresponsive_state) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 IDS_BROWSER_HANGMONITOR_RENDERER_TITLE, 319 IDS_BROWSER_HANGMONITOR_RENDERER_TITLE,
328 hung_pages_table_model_->RowCount()); 320 hung_pages_table_model_->RowCount());
329 } 321 }
330 322
331 void HungRendererDialogView::WindowClosing() { 323 void HungRendererDialogView::WindowClosing() {
332 // We are going to be deleted soon, so make sure our instance is destroyed. 324 // We are going to be deleted soon, so make sure our instance is destroyed.
333 g_instance_ = NULL; 325 g_instance_ = NULL;
334 } 326 }
335 327
336 int HungRendererDialogView::GetDialogButtons() const { 328 int HungRendererDialogView::GetDialogButtons() const {
337 return ui::DIALOG_BUTTON_CANCEL; 329 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
338 } 330 }
339 331
340 base::string16 HungRendererDialogView::GetDialogButtonLabel( 332 base::string16 HungRendererDialogView::GetDialogButtonLabel(
341 ui::DialogButton button) const { 333 ui::DialogButton button) const {
342 DCHECK_EQ(ui::DIALOG_BUTTON_CANCEL, button); 334 return l10n_util::GetStringUTF16(button == ui::DIALOG_BUTTON_OK
343 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT); 335 ? IDS_BROWSER_HANGMONITOR_RENDERER_WAIT
344 } 336 : IDS_BROWSER_HANGMONITOR_RENDERER_END);
345
346 views::View* HungRendererDialogView::CreateExtraView() {
347 DCHECK(!kill_button_);
348 kill_button_ = views::MdTextButton::CreateSecondaryUiButton(this,
349 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_END));
350 return kill_button_;
351 } 337 }
352 338
353 bool HungRendererDialogView::Cancel() { 339 bool HungRendererDialogView::Cancel() {
354 // Start waiting again for responsiveness. 340 content::RenderProcessHost* rph =
355 if (!kill_button_clicked_ && 341 hung_pages_table_model_->GetRenderProcessHost();
356 hung_pages_table_model_->GetRenderViewHost()) { 342 if (rph) {
357 hung_pages_table_model_->GetRenderViewHost() 343 #if defined(OS_WIN)
358 ->GetWidget() 344 base::StringPairs crash_keys;
359 ->RestartHangMonitorTimeoutIfNecessary(); 345
346 crash_keys.push_back(std::make_pair(
347 crash_keys::kHungRendererOutstandingAckCount,
348 base::IntToString(unresponsive_state_.outstanding_ack_count)));
349 crash_keys.push_back(std::make_pair(
350 crash_keys::kHungRendererOutstandingEventType,
351 base::IntToString(unresponsive_state_.outstanding_event_type)));
352 crash_keys.push_back(
353 std::make_pair(crash_keys::kHungRendererLastEventType,
354 base::IntToString(unresponsive_state_.last_event_type)));
355 crash_keys.push_back(
356 std::make_pair(crash_keys::kHungRendererReason,
357 base::IntToString(unresponsive_state_.reason)));
358
359 // Try to generate a crash report for the hung process.
360 CrashDumpAndTerminateHungChildProcess(rph->GetHandle(), crash_keys);
361 #else
362 rph->Shutdown(content::RESULT_CODE_HUNG, false);
363 #endif
360 } 364 }
361 return true; 365 return true;
362 } 366 }
363 367
368 bool HungRendererDialogView::Accept() {
369 // Start waiting again for responsiveness.
370 auto* render_view_host = hung_pages_table_model_->GetRenderViewHost();
371 if (render_view_host)
372 render_view_host->GetWidget()->RestartHangMonitorTimeoutIfNecessary();
373 return true;
374 }
375
376 bool HungRendererDialogView::Close() {
377 return Accept();
378 }
379
364 bool HungRendererDialogView::ShouldUseCustomFrame() const { 380 bool HungRendererDialogView::ShouldUseCustomFrame() const {
365 #if defined(OS_WIN) 381 #if defined(OS_WIN)
366 // Use the old dialog style without Aero glass, otherwise the dialog will be 382 // Use the old dialog style without Aero glass, otherwise the dialog will be
367 // visually constrained to browser window bounds. See http://crbug.com/323278 383 // visually constrained to browser window bounds. See http://crbug.com/323278
368 return ui::win::IsAeroGlassEnabled(); 384 return ui::win::IsAeroGlassEnabled();
369 #else 385 #else
370 return views::DialogDelegateView::ShouldUseCustomFrame(); 386 return views::DialogDelegateView::ShouldUseCustomFrame();
371 #endif 387 #endif
372 } 388 }
373 389
374 /////////////////////////////////////////////////////////////////////////////// 390 ///////////////////////////////////////////////////////////////////////////////
375 // HungRendererDialogView, views::ButtonListener implementation:
376
377 void HungRendererDialogView::ButtonPressed(
378 views::Button* sender, const ui::Event& event) {
379 DCHECK_EQ(kill_button_, sender);
380 kill_button_clicked_ = true;
381 content::RenderProcessHost* rph =
382 hung_pages_table_model_->GetRenderProcessHost();
383 if (!rph)
384 return;
385 #if defined(OS_WIN)
386 base::StringPairs crash_keys;
387
388 crash_keys.push_back(std::make_pair(
389 crash_keys::kHungRendererOutstandingAckCount,
390 base::IntToString(unresponsive_state_.outstanding_ack_count)));
391 crash_keys.push_back(std::make_pair(
392 crash_keys::kHungRendererOutstandingEventType,
393 base::IntToString(unresponsive_state_.outstanding_event_type)));
394 crash_keys.push_back(
395 std::make_pair(crash_keys::kHungRendererLastEventType,
396 base::IntToString(unresponsive_state_.last_event_type)));
397 crash_keys.push_back(
398 std::make_pair(crash_keys::kHungRendererReason,
399 base::IntToString(unresponsive_state_.reason)));
400
401 // Try to generate a crash report for the hung process.
402 CrashDumpAndTerminateHungChildProcess(rph->GetHandle(), crash_keys);
403 #else
404 rph->Shutdown(content::RESULT_CODE_HUNG, false);
405 #endif
406 }
407
408 ///////////////////////////////////////////////////////////////////////////////
409 // HungRendererDialogView, HungPagesTableModel::Delegate overrides: 391 // HungRendererDialogView, HungPagesTableModel::Delegate overrides:
410 392
411 void HungRendererDialogView::TabDestroyed() { 393 void HungRendererDialogView::TabDestroyed() {
412 GetWidget()->Close(); 394 GetWidget()->Close();
413 } 395 }
414 396
415 /////////////////////////////////////////////////////////////////////////////// 397 ///////////////////////////////////////////////////////////////////////////////
416 // HungRendererDialogView, views::View overrides: 398 // HungRendererDialogView, views::View overrides:
417 399
418 void HungRendererDialogView::ViewHierarchyChanged( 400 void HungRendererDialogView::ViewHierarchyChanged(
(...skipping 17 matching lines...) Expand all
436 hung_pages_table_model_.reset(new HungPagesTableModel(this)); 418 hung_pages_table_model_.reset(new HungPagesTableModel(this));
437 std::vector<ui::TableColumn> columns; 419 std::vector<ui::TableColumn> columns;
438 columns.push_back(ui::TableColumn()); 420 columns.push_back(ui::TableColumn());
439 hung_pages_table_ = new views::TableView( 421 hung_pages_table_ = new views::TableView(
440 hung_pages_table_model_.get(), columns, views::ICON_AND_TEXT, true); 422 hung_pages_table_model_.get(), columns, views::ICON_AND_TEXT, true);
441 hung_pages_table_->SetGrouper(hung_pages_table_model_.get()); 423 hung_pages_table_->SetGrouper(hung_pages_table_model_.get());
442 424
443 using views::GridLayout; 425 using views::GridLayout;
444 using views::ColumnSet; 426 using views::ColumnSet;
445 427
446 GridLayout* layout = GridLayout::CreatePanel(this); 428 GridLayout* layout = layout_utils::CreatePanelLayout(this);
447 SetLayoutManager(layout); 429 LayoutDelegate* delegate = LayoutDelegate::Get();
448 430
449 const int double_column_set_id = 0; 431 const int double_column_set_id = 0;
450 ColumnSet* column_set = layout->AddColumnSet(double_column_set_id); 432 ColumnSet* column_set = layout->AddColumnSet(double_column_set_id);
451 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, 433 column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
452 GridLayout::FIXED, frozen_icon_->width(), 0); 434 GridLayout::FIXED, frozen_icon_->width(), 0);
453 column_set->AddPaddingColumn(0, kCentralColumnPadding); 435 column_set->AddPaddingColumn(
436 0,
437 delegate->GetMetric(
438 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING_LARGE));
454 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, 439 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
455 GridLayout::USE_PREF, 0, 0); 440 GridLayout::USE_PREF, 0, 0);
456 441
457 layout->StartRow(0, double_column_set_id); 442 layout->StartRow(0, double_column_set_id);
458 layout->AddView(frozen_icon_view, 1, 3); 443 layout->AddView(frozen_icon_view, 1, 3);
459 // Add the label with a preferred width of 1, this way it doesn't affect the 444 // Add the label with a preferred width of 1, this way it doesn't affect the
460 // overall preferred size of the dialog. 445 // overall preferred size of the dialog.
461 layout->AddView( 446 layout->AddView(
462 info_label_, 1, 1, GridLayout::FILL, GridLayout::LEADING, 1, 0); 447 info_label_, 1, 1, GridLayout::FILL, GridLayout::LEADING, 1, 0);
463 448
464 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 449 layout->AddPaddingRow(
450 0, delegate->GetMetric(
451 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING));
465 452
466 layout->StartRow(0, double_column_set_id); 453 layout->StartRow(0, double_column_set_id);
467 layout->SkipColumns(1); 454 layout->SkipColumns(1);
468 layout->AddView(hung_pages_table_->CreateParentIfNecessary(), 1, 1, 455 layout->AddView(hung_pages_table_->CreateParentIfNecessary(), 1, 1,
469 views::GridLayout::FILL, 456 views::GridLayout::FILL,
470 views::GridLayout::FILL, kTableViewWidth, kTableViewHeight); 457 views::GridLayout::FILL, kTableViewWidth, kTableViewHeight);
471 458
472 initialized_ = true; 459 initialized_ = true;
473 } 460 }
474 461
475 // static 462 // static
476 void HungRendererDialogView::InitClass() { 463 void HungRendererDialogView::InitClass() {
477 static bool initialized = false; 464 static bool initialized = false;
478 if (!initialized) { 465 if (!initialized) {
479 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 466 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
480 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON); 467 frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON);
481 initialized = true; 468 initialized = true;
482 } 469 }
483 } 470 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/hung_renderer_view.h ('k') | chrome/browser/ui/views/hung_renderer_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698