Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / views / hung_renderer_view.h
blob9c216ebc5deadfbbe229d36bbc54832829c8d342
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 "components/favicon/content/content_favicon_driver.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"
17 namespace content {
18 class WebContents;
21 namespace views {
22 class Label;
23 class LabelButton;
26 // Provides functionality to display information about a hung renderer.
27 class HungPagesTableModel : public ui::TableModel, public views::TableGrouper {
28 public:
29 // The Delegate is notified any time a WebContents the model is listening to
30 // is destroyed.
31 class Delegate {
32 public:
33 virtual void TabDestroyed() = 0;
35 protected:
36 virtual ~Delegate() {}
39 explicit HungPagesTableModel(Delegate* delegate);
40 ~HungPagesTableModel() override;
42 void InitForWebContents(content::WebContents* hung_contents);
44 // Returns the first RenderProcessHost, or NULL if there aren't any
45 // WebContents.
46 content::RenderProcessHost* GetRenderProcessHost();
48 // Returns the first RenderViewHost, or NULL if there aren't any WebContents.
49 content::RenderViewHost* GetRenderViewHost();
51 // Overridden from ui::TableModel:
52 int RowCount() override;
53 base::string16 GetText(int row, int column_id) override;
54 gfx::ImageSkia GetIcon(int row) override;
55 void SetObserver(ui::TableModelObserver* observer) override;
57 // Overridden from views::TableGrouper:
58 void GetGroupRange(int model_index, views::GroupRange* range) override;
60 private:
61 // Used to track a single WebContents. If the WebContents is destroyed
62 // TabDestroyed() is invoked on the model.
63 class WebContentsObserverImpl : public content::WebContentsObserver {
64 public:
65 WebContentsObserverImpl(HungPagesTableModel* model,
66 content::WebContents* tab);
68 favicon::FaviconDriver* favicon_driver() {
69 return favicon::ContentFaviconDriver::FromWebContents(web_contents());
72 // WebContentsObserver overrides:
73 void RenderProcessGone(base::TerminationStatus status) override;
74 void WebContentsDestroyed() override;
76 private:
77 HungPagesTableModel* model_;
79 DISALLOW_COPY_AND_ASSIGN(WebContentsObserverImpl);
82 // Invoked when a WebContents is destroyed. Cleans up |tab_observers_| and
83 // notifies the observer and delegate.
84 void TabDestroyed(WebContentsObserverImpl* tab);
86 typedef ScopedVector<WebContentsObserverImpl> TabObservers;
87 TabObservers tab_observers_;
89 ui::TableModelObserver* observer_;
90 Delegate* delegate_;
92 DISALLOW_COPY_AND_ASSIGN(HungPagesTableModel);
95 // This class displays a dialog which contains information about a hung
96 // renderer process.
97 class HungRendererDialogView : public views::DialogDelegateView,
98 public views::ButtonListener,
99 public HungPagesTableModel::Delegate {
100 public:
101 // Factory function for creating an instance of the HungRendererDialogView
102 // class. At any given point only one instance can be active.
103 static HungRendererDialogView* Create(gfx::NativeWindow context);
105 // Returns a pointer to the singleton instance if any.
106 static HungRendererDialogView* GetInstance();
108 // Shows or hides the hung renderer dialog for the given WebContents.
109 static void Show(content::WebContents* contents);
110 static void Hide(content::WebContents* contents);
112 // Platform specific function to kill the renderer process identified by the
113 // render process host passed in.
114 static void KillRendererProcess(content::RenderProcessHost* rph);
116 // Returns true if the frame is in the foreground.
117 static bool IsFrameActive(content::WebContents* contents);
119 virtual void ShowForWebContents(content::WebContents* contents);
120 virtual void EndForWebContents(content::WebContents* contents);
122 // views::DialogDelegateView overrides:
123 base::string16 GetWindowTitle() const override;
124 void WindowClosing() override;
125 int GetDialogButtons() const override;
126 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
127 views::View* CreateExtraView() override;
128 bool Accept(bool window_closing) override;
129 bool UseNewStyleForThisDialog() const override;
131 // views::ButtonListener overrides:
132 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
134 // HungPagesTableModel::Delegate overrides:
135 void TabDestroyed() override;
137 protected:
138 HungRendererDialogView();
139 ~HungRendererDialogView() override;
141 // views::View overrides:
142 void ViewHierarchyChanged(
143 const ViewHierarchyChangedDetails& details) override;
145 static HungRendererDialogView* g_instance_;
147 private:
148 // Initialize the controls in this dialog.
149 void Init();
151 static void InitClass();
153 // An amusing icon image.
154 static gfx::ImageSkia* frozen_icon_;
156 // The label describing the list.
157 views::Label* info_label_;
159 // Controls within the dialog box.
160 views::TableView* hung_pages_table_;
162 // The extra button inserted into the ClientView to kill the errant process.
163 views::LabelButton* kill_button_;
165 // The model that provides the contents of the table that shows a list of
166 // pages affected by the hang.
167 scoped_ptr<HungPagesTableModel> hung_pages_table_model_;
169 // Whether or not we've created controls for ourself.
170 bool initialized_;
172 DISALLOW_COPY_AND_ASSIGN(HungRendererDialogView);
175 #endif // CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_