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

Unified Diff: chrome/browser/ui/views/hung_renderer_view.h

Issue 10815060: Relanding this as the initial attempt was reverted because of linux chrome os compile failures. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/views/hung_renderer_view.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/hung_renderer_view.h
===================================================================
--- chrome/browser/ui/views/hung_renderer_view.h (revision 147879)
+++ chrome/browser/ui/views/hung_renderer_view.h (working copy)
@@ -1,66 +1,23 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/browser_dialogs.h"
+#ifndef CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
+#define CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
-#if defined(OS_WIN) && !defined(USE_AURA)
-#include <windows.h>
-#endif
-
-#include "base/i18n/rtl.h"
#include "base/memory/scoped_vector.h"
-#include "base/process_util.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/browser/favicon/favicon_tab_helper.h"
-#include "chrome/browser/platform_util.h"
-#include "chrome/browser/ui/tab_contents/core_tab_helper.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
-#include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/logging_chrome.h"
-#include "content/public/browser/render_process_host.h"
-#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/common/result_codes.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas.h"
+#include "content/public/browser/web_contents_observer.h"
#include "ui/views/controls/button/text_button.h"
-#include "ui/views/controls/image_view.h"
-#include "ui/views/controls/label.h"
#include "ui/views/controls/table/group_table_model.h"
#include "ui/views/controls/table/group_table_view.h"
-#include "ui/views/layout/grid_layout.h"
-#include "ui/views/layout/layout_constants.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/window/client_view.h"
#include "ui/views/window/dialog_delegate.h"
-#if defined(USE_AURA)
-#include "ui/aura/window.h"
-#endif
-
-#if defined(OS_WIN)
-#include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
-#endif
-
-class HungRendererDialogView;
-
using content::RenderViewHost;
using content::WebContents;
-namespace {
-// We only support showing one of these at a time per app.
-HungRendererDialogView* g_instance = NULL;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungPagesTableModel
-
+// Provides functionality to display information about a hung renderer.
class HungPagesTableModel : public views::GroupTableModel {
public:
// The Delegate is notified any time a WebContents the model is listening to
@@ -86,11 +43,12 @@
RenderViewHost* GetRenderViewHost();
// Overridden from views::GroupTableModel:
- virtual int RowCount();
- virtual string16 GetText(int row, int column_id);
- virtual gfx::ImageSkia GetIcon(int row);
- virtual void SetObserver(ui::TableModelObserver* observer);
- virtual void GetGroupRangeForItem(int item, views::GroupRange* range);
+ virtual int RowCount() OVERRIDE;
+ virtual string16 GetText(int row, int column_id) OVERRIDE;
+ virtual gfx::ImageSkia GetIcon(int row) OVERRIDE;
+ virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
+ virtual void GetGroupRangeForItem(int item, views::GroupRange* range)
+ OVERRIDE;
private:
// Used to track a single WebContents. If the WebContents is destroyed
@@ -132,129 +90,20 @@
DISALLOW_COPY_AND_ASSIGN(HungPagesTableModel);
};
-///////////////////////////////////////////////////////////////////////////////
-// HungPagesTableModel, public:
-
-HungPagesTableModel::HungPagesTableModel(Delegate* delegate)
- : observer_(NULL),
- delegate_(delegate) {
-}
-
-HungPagesTableModel::~HungPagesTableModel() {
-}
-
-content::RenderProcessHost* HungPagesTableModel::GetRenderProcessHost() {
- return tab_observers_.empty() ? NULL :
- tab_observers_[0]->web_contents()->GetRenderProcessHost();
-}
-
-RenderViewHost* HungPagesTableModel::GetRenderViewHost() {
- return tab_observers_.empty() ? NULL :
- tab_observers_[0]->web_contents()->GetRenderViewHost();
-}
-
-void HungPagesTableModel::InitForWebContents(WebContents* hung_contents) {
- tab_observers_.clear();
- if (hung_contents) {
- // Force hung_contents to be first.
- TabContents* hung_tab_contents =
- TabContents::FromWebContents(hung_contents);
- if (hung_tab_contents) {
- tab_observers_.push_back(new WebContentsObserverImpl(this,
- hung_tab_contents));
- }
- for (TabContentsIterator it; !it.done(); ++it) {
- if (*it != hung_tab_contents &&
- it->web_contents()->GetRenderProcessHost() ==
- hung_contents->GetRenderProcessHost())
- tab_observers_.push_back(new WebContentsObserverImpl(this, *it));
- }
- }
- // The world is different.
- if (observer_)
- observer_->OnModelChanged();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungPagesTableModel, views::GroupTableModel implementation:
-
-int HungPagesTableModel::RowCount() {
- return static_cast<int>(tab_observers_.size());
-}
-
-string16 HungPagesTableModel::GetText(int row, int column_id) {
- DCHECK(row >= 0 && row < RowCount());
- string16 title = tab_observers_[row]->web_contents()->GetTitle();
- if (title.empty())
- title = CoreTabHelper::GetDefaultTitle();
- // TODO(xji): Consider adding a special case if the title text is a URL,
- // since those should always have LTR directionality. Please refer to
- // http://crbug.com/6726 for more information.
- base::i18n::AdjustStringForLocaleDirection(&title);
- return title;
-}
-
-gfx::ImageSkia HungPagesTableModel::GetIcon(int row) {
- DCHECK(row >= 0 && row < RowCount());
- return tab_observers_[row]->favicon_tab_helper()->GetFavicon();
-}
-
-void HungPagesTableModel::SetObserver(ui::TableModelObserver* observer) {
- observer_ = observer;
-}
-
-void HungPagesTableModel::GetGroupRangeForItem(int item,
- views::GroupRange* range) {
- DCHECK(range);
- range->start = 0;
- range->length = RowCount();
-}
-
-void HungPagesTableModel::TabDestroyed(WebContentsObserverImpl* tab) {
- // Clean up tab_observers_ and notify our observer.
- TabObservers::iterator i = std::find(
- tab_observers_.begin(), tab_observers_.end(), tab);
- DCHECK(i != tab_observers_.end());
- int index = static_cast<int>(i - tab_observers_.begin());
- tab_observers_.erase(i);
- if (observer_)
- observer_->OnItemsRemoved(index, 1);
-
- // Notify the delegate.
- delegate_->TabDestroyed();
- // WARNING: we've likely been deleted.
-}
-
-HungPagesTableModel::WebContentsObserverImpl::WebContentsObserverImpl(
- HungPagesTableModel* model,
- TabContents* tab)
- : content::WebContentsObserver(tab->web_contents()),
- model_(model),
- tab_(tab) {
-}
-
-void HungPagesTableModel::WebContentsObserverImpl::RenderViewGone(
- base::TerminationStatus status) {
- model_->TabDestroyed(this);
-}
-
-void HungPagesTableModel::WebContentsObserverImpl::WebContentsDestroyed(
- WebContents* tab) {
- model_->TabDestroyed(this);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView
-
+// This class displays a dialog which contains information about a hung
+// renderer process.
class HungRendererDialogView : public views::DialogDelegateView,
public views::ButtonListener,
public HungPagesTableModel::Delegate {
public:
- HungRendererDialogView();
- ~HungRendererDialogView();
+ // Factory function for creating an instance of the HungRendererDialogView
+ // class. At any given point only one instance can be active.
+ static HungRendererDialogView* Create();
+ // Returns a pointer to the singleton instance if any.
+ static HungRendererDialogView* GetInstance();
- void ShowForWebContents(WebContents* contents);
- void EndForWebContents(WebContents* contents);
+ virtual void ShowForWebContents(WebContents* contents);
+ virtual void EndForWebContents(WebContents* contents);
// views::DialogDelegateView overrides:
virtual string16 GetWindowTitle() const OVERRIDE;
@@ -273,11 +122,19 @@
virtual void TabDestroyed() OVERRIDE;
protected:
+ HungRendererDialogView();
+ virtual ~HungRendererDialogView();
+
// views::View overrides:
virtual void ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child) OVERRIDE;
+ // Returns true if the frame is in the foreground.
+ bool IsFrameActive(WebContents* contents);
+
+ static HungRendererDialogView* g_instance_;
+
private:
// Initialize the controls in this dialog.
void Init();
@@ -311,288 +168,4 @@
DISALLOW_COPY_AND_ASSIGN(HungRendererDialogView);
};
-// static
-gfx::ImageSkia* HungRendererDialogView::frozen_icon_ = NULL;
-
-// The distance in pixels from the top of the relevant contents to place the
-// warning window.
-static const int kOverlayContentsOffsetY = 50;
-
-// The dimensions of the hung pages list table view, in pixels.
-static const int kTableViewWidth = 300;
-static const int kTableViewHeight = 100;
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, public:
-
-HungRendererDialogView::HungRendererDialogView()
- : hung_pages_table_(NULL),
- kill_button_(NULL),
- kill_button_container_(NULL),
- initialized_(false) {
- InitClass();
-}
-
-HungRendererDialogView::~HungRendererDialogView() {
- hung_pages_table_->SetModel(NULL);
-}
-
-void HungRendererDialogView::ShowForWebContents(WebContents* contents) {
- DCHECK(contents && GetWidget());
-
- // Don't show the warning unless the foreground window is the frame, or this
- // window (but still invisible). If the user has another window or
- // application selected, activating ourselves is rude.
- gfx::NativeView frame_view =
- platform_util::GetTopLevel(contents->GetNativeView());
- if (!platform_util::IsWindowActive(frame_view) &&
- !platform_util::IsWindowActive(GetWidget()->GetNativeWindow())) {
- return;
- }
-
- if (!GetWidget()->IsActive()) {
- gfx::Rect bounds = GetDisplayBounds(contents);
- views::Widget* insert_after =
- views::Widget::GetWidgetForNativeView(frame_view);
- GetWidget()->SetBoundsConstrained(bounds);
- if (insert_after)
- GetWidget()->StackAboveWidget(insert_after);
-
- // We only do this if the window isn't active (i.e. hasn't been shown yet,
- // or is currently shown but deactivated for another WebContents). This is
- // because this window is a singleton, and it's possible another active
- // renderer may hang while this one is showing, and we don't want to reset
- // the list of hung pages for a potentially unrelated renderer while this
- // one is showing.
- hung_pages_table_model_->InitForWebContents(contents);
- GetWidget()->Show();
- }
-}
-
-void HungRendererDialogView::EndForWebContents(WebContents* contents) {
- DCHECK(contents);
- if (hung_pages_table_model_->RowCount() == 0 ||
- hung_pages_table_model_->GetRenderProcessHost() ==
- contents->GetRenderProcessHost()) {
- GetWidget()->Close();
- // Close is async, make sure we drop our references to the tab immediately
- // (it may be going away).
- hung_pages_table_model_->InitForWebContents(NULL);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, views::DialogDelegate implementation:
-
-string16 HungRendererDialogView::GetWindowTitle() const {
- return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE);
-}
-
-void HungRendererDialogView::WindowClosing() {
- // We are going to be deleted soon, so make sure our instance is destroyed.
- g_instance = NULL;
-}
-
-int HungRendererDialogView::GetDialogButtons() const {
- // We specifically don't want a CANCEL button here because that code path is
- // also called when the window is closed by the user clicking the X button in
- // the window's titlebar, and also if we call Window::Close. Rather, we want
- // the OK button to wait for responsiveness (and close the dialog) and our
- // additional button (which we create) to kill the process (which will result
- // in the dialog being destroyed).
- return ui::DIALOG_BUTTON_OK;
-}
-
-string16 HungRendererDialogView::GetDialogButtonLabel(
- ui::DialogButton button) const {
- if (button == ui::DIALOG_BUTTON_OK)
- return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT);
- return string16();
-}
-
-views::View* HungRendererDialogView::GetExtraView() {
- return kill_button_container_;
-}
-
-bool HungRendererDialogView::Accept(bool window_closing) {
- // Don't do anything if we're being called only because the dialog is being
- // destroyed and we don't supply a Cancel function...
- if (window_closing)
- return true;
-
- // Start waiting again for responsiveness.
- if (hung_pages_table_model_->GetRenderViewHost())
- hung_pages_table_model_->GetRenderViewHost()->RestartHangMonitorTimeout();
- return true;
-}
-
-views::View* HungRendererDialogView::GetContentsView() {
- return this;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, views::ButtonListener implementation:
-
-void HungRendererDialogView::ButtonPressed(
- views::Button* sender, const views::Event& event) {
- if (sender == kill_button_ &&
- hung_pages_table_model_->GetRenderProcessHost()) {
-
- base::ProcessHandle process_handle =
- hung_pages_table_model_->GetRenderProcessHost()->GetHandle();
-
-#if defined(OS_WIN)
- // Try to generate a crash report for the hung process.
- CrashDumpAndTerminateHungChildProcess(process_handle);
-#else
- // Kill the process.
- base::KillProcess(process_handle, content::RESULT_CODE_HUNG, false);
-#endif
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, HungPagesTableModel::Delegate overrides:
-
-void HungRendererDialogView::TabDestroyed() {
- GetWidget()->Close();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, views::View overrides:
-
-void HungRendererDialogView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (!initialized_ && is_add && child == this && GetWidget())
- Init();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// HungRendererDialogView, private:
-
-void HungRendererDialogView::Init() {
- views::ImageView* frozen_icon_view = new views::ImageView;
- frozen_icon_view->SetImage(frozen_icon_);
-
- views::Label* info_label = new views::Label(
- l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER));
- info_label->SetMultiLine(true);
- info_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
-
- hung_pages_table_model_.reset(new HungPagesTableModel(this));
- std::vector<ui::TableColumn> columns;
- columns.push_back(ui::TableColumn());
- hung_pages_table_ = new views::GroupTableView(
- hung_pages_table_model_.get(), columns, views::ICON_AND_TEXT, true,
- false, true, false);
-
- CreateKillButtonView();
-
- using views::GridLayout;
- using views::ColumnSet;
-
- GridLayout* layout = GridLayout::CreatePanel(this);
- SetLayoutManager(layout);
-
- const int double_column_set_id = 0;
- ColumnSet* column_set = layout->AddColumnSet(double_column_set_id);
- column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
- GridLayout::FIXED, frozen_icon_->width(), 0);
- column_set->AddPaddingColumn(
- 0, views::kUnrelatedControlLargeHorizontalSpacing);
- column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
- GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, double_column_set_id);
- layout->AddView(frozen_icon_view, 1, 3);
- // Add the label with a preferred width of 1, this way it doesn't effect the
- // overall preferred size of the dialog.
- layout->AddView(
- info_label, 1, 1, GridLayout::FILL, GridLayout::LEADING, 1, 0);
-
- layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
-
- layout->StartRow(0, double_column_set_id);
- layout->SkipColumns(1);
- layout->AddView(hung_pages_table_->CreateParentIfNecessary(), 1, 1,
- views::GridLayout::FILL,
- views::GridLayout::FILL, kTableViewWidth, kTableViewHeight);
-
- initialized_ = true;
-}
-
-void HungRendererDialogView::CreateKillButtonView() {
- kill_button_ = new views::NativeTextButton(this,
- l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_END));
-
- kill_button_container_ = new View;
-
- using views::GridLayout;
- using views::ColumnSet;
-
- GridLayout* layout = new GridLayout(kill_button_container_);
- kill_button_container_->SetLayoutManager(layout);
-
- const int single_column_set_id = 0;
- ColumnSet* column_set = layout->AddColumnSet(single_column_set_id);
- column_set->AddPaddingColumn(0, frozen_icon_->width() +
- views::kPanelHorizMargin + views::kUnrelatedControlHorizontalSpacing);
- column_set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0,
- GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, single_column_set_id);
- layout->AddView(kill_button_);
-}
-
-gfx::Rect HungRendererDialogView::GetDisplayBounds(
- WebContents* contents) {
-#if defined(USE_AURA)
- gfx::Rect contents_bounds(contents->GetNativeView()->GetBoundsInRootWindow());
-#elif defined(OS_WIN)
- HWND contents_hwnd = contents->GetNativeView();
- RECT contents_bounds_rect;
- GetWindowRect(contents_hwnd, &contents_bounds_rect);
- gfx::Rect contents_bounds(contents_bounds_rect);
-#endif
- gfx::Rect window_bounds = GetWidget()->GetWindowBoundsInScreen();
-
- int window_x = contents_bounds.x() +
- (contents_bounds.width() - window_bounds.width()) / 2;
- int window_y = contents_bounds.y() + kOverlayContentsOffsetY;
- return gfx::Rect(window_x, window_y, window_bounds.width(),
- window_bounds.height());
-}
-
-// static
-void HungRendererDialogView::InitClass() {
- static bool initialized = false;
- if (!initialized) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- frozen_icon_ = rb.GetImageSkiaNamed(IDR_FROZEN_TAB_ICON);
- initialized = true;
- }
-}
-
-static HungRendererDialogView* CreateHungRendererDialogView() {
- HungRendererDialogView* cv = new HungRendererDialogView;
- views::Widget::CreateWindow(cv);
- return cv;
-}
-
-namespace chrome {
-
-void ShowHungRendererDialog(WebContents* contents) {
- if (!logging::DialogsAreSuppressed()) {
- if (!g_instance)
- g_instance = CreateHungRendererDialogView();
- g_instance->ShowForWebContents(contents);
- }
-}
-
-void HideHungRendererDialog(WebContents* contents) {
- if (!logging::DialogsAreSuppressed() && g_instance)
- g_instance->EndForWebContents(contents);
-}
-
-} // namespace chrome
+#endif // CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
« no previous file with comments | « no previous file | chrome/browser/ui/views/hung_renderer_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698