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

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

Issue 10817009: Revert 147867 - Move the HungRendererDialogView and HungPagesTableModel classes into a header file … (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/hung_renderer_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
7
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/ui/tab_contents/tab_contents.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "ui/views/controls/button/text_button.h"
13 #include "ui/views/controls/table/group_table_model.h"
14 #include "ui/views/controls/table/group_table_view.h"
15 #include "ui/views/window/dialog_delegate.h"
16
17 using content::RenderViewHost;
18 using content::WebContents;
19
20 // Provides functionality to display information about a hung renderer.
21 class HungPagesTableModel : public views::GroupTableModel {
22 public:
23 // The Delegate is notified any time a WebContents the model is listening to
24 // is destroyed.
25 class Delegate {
26 public:
27 virtual void TabDestroyed() = 0;
28
29 protected:
30 virtual ~Delegate() {}
31 };
32
33 explicit HungPagesTableModel(Delegate* delegate);
34 virtual ~HungPagesTableModel();
35
36 void InitForWebContents(WebContents* hung_contents);
37
38 // Returns the first RenderProcessHost, or NULL if there aren't any
39 // WebContents.
40 content::RenderProcessHost* GetRenderProcessHost();
41
42 // Returns the first RenderViewHost, or NULL if there aren't any WebContents.
43 RenderViewHost* GetRenderViewHost();
44
45 // Overridden from views::GroupTableModel:
46 virtual int RowCount();
47 virtual string16 GetText(int row, int column_id);
48 virtual gfx::ImageSkia GetIcon(int row);
49 virtual void SetObserver(ui::TableModelObserver* observer);
50 virtual void GetGroupRangeForItem(int item, views::GroupRange* range);
51
52 private:
53 // Used to track a single WebContents. If the WebContents is destroyed
54 // TabDestroyed() is invoked on the model.
55 class WebContentsObserverImpl : public content::WebContentsObserver {
56 public:
57 WebContentsObserverImpl(HungPagesTableModel* model,
58 TabContents* tab);
59
60 WebContents* web_contents() const {
61 return content::WebContentsObserver::web_contents();
62 }
63
64 FaviconTabHelper* favicon_tab_helper() {
65 return tab_->favicon_tab_helper();
66 }
67
68 // WebContentsObserver overrides:
69 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
70 virtual void WebContentsDestroyed(WebContents* tab) OVERRIDE;
71
72 private:
73 HungPagesTableModel* model_;
74 TabContents* tab_;
75
76 DISALLOW_COPY_AND_ASSIGN(WebContentsObserverImpl);
77 };
78
79 // Invoked when a WebContents is destroyed. Cleans up |tab_observers_| and
80 // notifies the observer and delegate.
81 void TabDestroyed(WebContentsObserverImpl* tab);
82
83 typedef ScopedVector<WebContentsObserverImpl> TabObservers;
84 TabObservers tab_observers_;
85
86 ui::TableModelObserver* observer_;
87 Delegate* delegate_;
88
89 DISALLOW_COPY_AND_ASSIGN(HungPagesTableModel);
90 };
91
92 // This class displays a dialog which contains information about a hung
93 // renderer process.
94 class HungRendererDialogView : public views::DialogDelegateView,
95 public views::ButtonListener,
96 public HungPagesTableModel::Delegate {
97 public:
98 // Factory function for creating an instance of the HungRendererDialogView
99 // class. At any given point only one instance can be active.
100 static HungRendererDialogView* Create();
101 // Returns a pointer to the singleton instance if any.
102 static HungRendererDialogView* GetInstance();
103
104 virtual void ShowForWebContents(WebContents* contents);
105 virtual void EndForWebContents(WebContents* contents);
106
107 // views::DialogDelegateView overrides:
108 virtual string16 GetWindowTitle() const OVERRIDE;
109 virtual void WindowClosing() OVERRIDE;
110 virtual int GetDialogButtons() const OVERRIDE;
111 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
112 virtual views::View* GetExtraView() OVERRIDE;
113 virtual bool Accept(bool window_closing) OVERRIDE;
114 virtual views::View* GetContentsView() OVERRIDE;
115
116 // views::ButtonListener overrides:
117 virtual void ButtonPressed(views::Button* sender,
118 const views::Event& event) OVERRIDE;
119
120 // HungPagesTableModel::Delegate overrides:
121 virtual void TabDestroyed() OVERRIDE;
122
123 protected:
124 HungRendererDialogView();
125 virtual ~HungRendererDialogView();
126
127 // views::View overrides:
128 virtual void ViewHierarchyChanged(bool is_add,
129 views::View* parent,
130 views::View* child) OVERRIDE;
131
132 // Returns true if the frame is in the foreground.
133 bool IsFrameActive(WebContents* contents);
134
135 static HungRendererDialogView* g_instance_;
136
137 private:
138 // Initialize the controls in this dialog.
139 void Init();
140 void CreateKillButtonView();
141
142 // Returns the bounds the dialog should be displayed at to be meaningfully
143 // associated with the specified WebContents.
144 gfx::Rect GetDisplayBounds(WebContents* contents);
145
146 static void InitClass();
147
148 // Controls within the dialog box.
149 views::GroupTableView* hung_pages_table_;
150
151 // The button we insert into the ClientView to kill the errant process. This
152 // is parented to a container view that uses a grid layout to align it
153 // properly.
154 views::TextButton* kill_button_;
155 views::View* kill_button_container_;
156
157 // The model that provides the contents of the table that shows a list of
158 // pages affected by the hang.
159 scoped_ptr<HungPagesTableModel> hung_pages_table_model_;
160
161 // Whether or not we've created controls for ourself.
162 bool initialized_;
163
164 // An amusing icon image.
165 static gfx::ImageSkia* frozen_icon_;
166
167 DISALLOW_COPY_AND_ASSIGN(HungRendererDialogView);
168 };
169
170 #endif // CHROME_BROWSER_UI_VIEWS_HUNG_RENDERER_VIEW_H_
OLDNEW
« 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