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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/favicon/favicon_tab_helper.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "ui/base/models/table_model.h"
12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/table/table_grouper.h"
14 #include "ui/views/controls/table/table_view.h"
15 #include "ui/views/window/dialog_delegate.h"
25 // Provides functionality to display information about a hung renderer.
26 class HungPagesTableModel
: public ui::TableModel
, public views::TableGrouper
{
28 // The Delegate is notified any time a WebContents the model is listening to
32 virtual void TabDestroyed() = 0;
35 virtual ~Delegate() {}
38 explicit HungPagesTableModel(Delegate
* delegate
);
39 ~HungPagesTableModel() override
;
41 void InitForWebContents(content::WebContents
* hung_contents
);
43 // Returns the first RenderProcessHost, or NULL if there aren't any
45 content::RenderProcessHost
* GetRenderProcessHost();
47 // Returns the first RenderViewHost, or NULL if there aren't any WebContents.
48 content::RenderViewHost
* GetRenderViewHost();
50 // Overridden from ui::TableModel:
51 int RowCount() override
;
52 base::string16
GetText(int row
, int column_id
) override
;
53 gfx::ImageSkia
GetIcon(int row
) override
;
54 void SetObserver(ui::TableModelObserver
* observer
) override
;
56 // Overridden from views::TableGrouper:
57 void GetGroupRange(int model_index
, views::GroupRange
* range
) override
;
60 // Used to track a single WebContents. If the WebContents is destroyed
61 // TabDestroyed() is invoked on the model.
62 class WebContentsObserverImpl
: public content::WebContentsObserver
{
64 WebContentsObserverImpl(HungPagesTableModel
* model
,
65 content::WebContents
* tab
);
67 FaviconTabHelper
* favicon_tab_helper() {
68 return FaviconTabHelper::FromWebContents(web_contents());
71 // WebContentsObserver overrides:
72 void RenderProcessGone(base::TerminationStatus status
) override
;
73 void WebContentsDestroyed() override
;
76 HungPagesTableModel
* model_
;
78 DISALLOW_COPY_AND_ASSIGN(WebContentsObserverImpl
);
81 // Invoked when a WebContents is destroyed. Cleans up |tab_observers_| and
82 // notifies the observer and delegate.
83 void TabDestroyed(WebContentsObserverImpl
* tab
);
85 typedef ScopedVector
<WebContentsObserverImpl
> TabObservers
;
86 TabObservers tab_observers_
;
88 ui::TableModelObserver
* observer_
;
91 DISALLOW_COPY_AND_ASSIGN(HungPagesTableModel
);
94 // This class displays a dialog which contains information about a hung
96 class HungRendererDialogView
: public views::DialogDelegateView
,
97 public views::ButtonListener
,
98 public HungPagesTableModel::Delegate
{
100 // Factory function for creating an instance of the HungRendererDialogView
101 // class. At any given point only one instance can be active.
102 static HungRendererDialogView
* Create(gfx::NativeWindow context
);
104 // Returns a pointer to the singleton instance if any.
105 static HungRendererDialogView
* GetInstance();
107 // Shows or hides the hung renderer dialog for the given WebContents.
108 static void Show(content::WebContents
* contents
);
109 static void Hide(content::WebContents
* contents
);
111 // Platform specific function to kill the renderer process identified by the
112 // render process host passed in.
113 static void KillRendererProcess(content::RenderProcessHost
* rph
);
115 // Returns true if the frame is in the foreground.
116 static bool IsFrameActive(content::WebContents
* contents
);
118 virtual void ShowForWebContents(content::WebContents
* contents
);
119 virtual void EndForWebContents(content::WebContents
* contents
);
121 // views::DialogDelegateView overrides:
122 base::string16
GetWindowTitle() const override
;
123 void WindowClosing() override
;
124 int GetDialogButtons() const override
;
125 base::string16
GetDialogButtonLabel(ui::DialogButton button
) const override
;
126 views::View
* CreateExtraView() override
;
127 bool Accept(bool window_closing
) override
;
128 bool UseNewStyleForThisDialog() const override
;
130 // views::ButtonListener overrides:
131 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
133 // HungPagesTableModel::Delegate overrides:
134 void TabDestroyed() override
;
137 HungRendererDialogView();
138 ~HungRendererDialogView() override
;
140 // views::View overrides:
141 void ViewHierarchyChanged(
142 const ViewHierarchyChangedDetails
& details
) override
;
144 static HungRendererDialogView
* g_instance_
;
147 // Initialize the controls in this dialog.
150 static void InitClass();
152 // Controls within the dialog box.
153 views::TableView
* hung_pages_table_
;
155 // The extra button inserted into the ClientView to kill the errant process.
156 views::LabelButton
* kill_button_
;
158 // The model that provides the contents of the table that shows a list of
159 // pages affected by the hang.
160 scoped_ptr
<HungPagesTableModel
> hung_pages_table_model_
;
162 // Whether or not we've created controls for ourself.
165 // An amusing icon image.
166 static gfx::ImageSkia
* frozen_icon_
;
168 DISALLOW_COPY_AND_ASSIGN(HungRendererDialogView
);
171 #endif // CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_