| Index: chrome/browser/ui/views/hung_renderer_view.cc
|
| ===================================================================
|
| --- chrome/browser/ui/views/hung_renderer_view.cc (revision 147682)
|
| +++ chrome/browser/ui/views/hung_renderer_view.cc (working copy)
|
| @@ -2,7 +2,7 @@
|
| // 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"
|
| +#include "chrome/browser/ui/views/hung_renderer_view.h"
|
|
|
| #if defined(OS_WIN) && !defined(USE_AURA)
|
| #include <windows.h>
|
| @@ -14,14 +14,13 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "chrome/browser/favicon/favicon_tab_helper.h"
|
| #include "chrome/browser/platform_util.h"
|
| +#include "chrome/browser/ui/browser_dialogs.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"
|
| @@ -29,16 +28,12 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.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"
|
| @@ -48,91 +43,9 @@
|
| #include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
|
| #endif
|
|
|
| -class HungRendererDialogView;
|
| +HungRendererDialogView* HungRendererDialogView::g_instance_ = NULL;
|
|
|
| -using content::RenderViewHost;
|
| -using content::WebContents;
|
| -
|
| -namespace {
|
| -// We only support showing one of these at a time per app.
|
| -HungRendererDialogView* g_instance = NULL;
|
| -}
|
| -
|
| ///////////////////////////////////////////////////////////////////////////////
|
| -// HungPagesTableModel
|
| -
|
| -class HungPagesTableModel : public views::GroupTableModel {
|
| - public:
|
| - // The Delegate is notified any time a WebContents the model is listening to
|
| - // is destroyed.
|
| - class Delegate {
|
| - public:
|
| - virtual void TabDestroyed() = 0;
|
| -
|
| - protected:
|
| - virtual ~Delegate() {}
|
| - };
|
| -
|
| - explicit HungPagesTableModel(Delegate* delegate);
|
| - virtual ~HungPagesTableModel();
|
| -
|
| - void InitForWebContents(WebContents* hung_contents);
|
| -
|
| - // Returns the first RenderProcessHost, or NULL if there aren't any
|
| - // WebContents.
|
| - content::RenderProcessHost* GetRenderProcessHost();
|
| -
|
| - // Returns the first RenderViewHost, or NULL if there aren't any WebContents.
|
| - 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);
|
| -
|
| - private:
|
| - // Used to track a single WebContents. If the WebContents is destroyed
|
| - // TabDestroyed() is invoked on the model.
|
| - class WebContentsObserverImpl : public content::WebContentsObserver {
|
| - public:
|
| - WebContentsObserverImpl(HungPagesTableModel* model,
|
| - TabContents* tab);
|
| -
|
| - WebContents* web_contents() const {
|
| - return content::WebContentsObserver::web_contents();
|
| - }
|
| -
|
| - FaviconTabHelper* favicon_tab_helper() {
|
| - return tab_->favicon_tab_helper();
|
| - }
|
| -
|
| - // WebContentsObserver overrides:
|
| - virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
|
| - virtual void WebContentsDestroyed(WebContents* tab) OVERRIDE;
|
| -
|
| - private:
|
| - HungPagesTableModel* model_;
|
| - TabContents* tab_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(WebContentsObserverImpl);
|
| - };
|
| -
|
| - // Invoked when a WebContents is destroyed. Cleans up |tab_observers_| and
|
| - // notifies the observer and delegate.
|
| - void TabDestroyed(WebContentsObserverImpl* tab);
|
| -
|
| - typedef ScopedVector<WebContentsObserverImpl> TabObservers;
|
| - TabObservers tab_observers_;
|
| -
|
| - ui::TableModelObserver* observer_;
|
| - Delegate* delegate_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(HungPagesTableModel);
|
| -};
|
| -
|
| -///////////////////////////////////////////////////////////////////////////////
|
| // HungPagesTableModel, public:
|
|
|
| HungPagesTableModel::HungPagesTableModel(Delegate* delegate)
|
| @@ -246,71 +159,6 @@
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // HungRendererDialogView
|
|
|
| -class HungRendererDialogView : public views::DialogDelegateView,
|
| - public views::ButtonListener,
|
| - public HungPagesTableModel::Delegate {
|
| - public:
|
| - HungRendererDialogView();
|
| - ~HungRendererDialogView();
|
| -
|
| - void ShowForWebContents(WebContents* contents);
|
| - void EndForWebContents(WebContents* contents);
|
| -
|
| - // views::DialogDelegateView overrides:
|
| - virtual string16 GetWindowTitle() const OVERRIDE;
|
| - virtual void WindowClosing() OVERRIDE;
|
| - virtual int GetDialogButtons() const OVERRIDE;
|
| - virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE;
|
| - virtual views::View* GetExtraView() OVERRIDE;
|
| - virtual bool Accept(bool window_closing) OVERRIDE;
|
| - virtual views::View* GetContentsView() OVERRIDE;
|
| -
|
| - // views::ButtonListener overrides:
|
| - virtual void ButtonPressed(views::Button* sender,
|
| - const views::Event& event) OVERRIDE;
|
| -
|
| - // HungPagesTableModel::Delegate overrides:
|
| - virtual void TabDestroyed() OVERRIDE;
|
| -
|
| - protected:
|
| - // views::View overrides:
|
| - virtual void ViewHierarchyChanged(bool is_add,
|
| - views::View* parent,
|
| - views::View* child) OVERRIDE;
|
| -
|
| - private:
|
| - // Initialize the controls in this dialog.
|
| - void Init();
|
| - void CreateKillButtonView();
|
| -
|
| - // Returns the bounds the dialog should be displayed at to be meaningfully
|
| - // associated with the specified WebContents.
|
| - gfx::Rect GetDisplayBounds(WebContents* contents);
|
| -
|
| - static void InitClass();
|
| -
|
| - // Controls within the dialog box.
|
| - views::GroupTableView* hung_pages_table_;
|
| -
|
| - // The button we insert into the ClientView to kill the errant process. This
|
| - // is parented to a container view that uses a grid layout to align it
|
| - // properly.
|
| - views::TextButton* kill_button_;
|
| - views::View* kill_button_container_;
|
| -
|
| - // The model that provides the contents of the table that shows a list of
|
| - // pages affected by the hang.
|
| - scoped_ptr<HungPagesTableModel> hung_pages_table_model_;
|
| -
|
| - // Whether or not we've created controls for ourself.
|
| - bool initialized_;
|
| -
|
| - // An amusing icon image.
|
| - static gfx::ImageSkia* frozen_icon_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(HungRendererDialogView);
|
| -};
|
| -
|
| // static
|
| gfx::ImageSkia* HungRendererDialogView::frozen_icon_ = NULL;
|
|
|
| @@ -325,6 +173,23 @@
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // HungRendererDialogView, public:
|
|
|
| +#if !defined(OS_WIN)
|
| +
|
| +// static
|
| +HungRendererDialogView* HungRendererDialogView::Create() {
|
| + if (!g_instance_) {
|
| + g_instance_ = new HungRendererDialogView;
|
| + views::Widget::CreateWindow(g_instance_);
|
| + }
|
| + return g_instance_;
|
| +}
|
| +#endif // defined(OS_WIN)
|
| +
|
| +// static
|
| +HungRendererDialogView* HungRendererDialogView::GetInstance() {
|
| + return g_instance_;
|
| +}
|
| +
|
| HungRendererDialogView::HungRendererDialogView()
|
| : hung_pages_table_(NULL),
|
| kill_button_(NULL),
|
| @@ -343,15 +208,15 @@
|
| // 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())) {
|
| + if (!IsFrameActive(contents))
|
| return;
|
| - }
|
|
|
| if (!GetWidget()->IsActive()) {
|
| gfx::Rect bounds = GetDisplayBounds(contents);
|
| +
|
| + gfx::NativeView frame_view =
|
| + platform_util::GetTopLevel(contents->GetNativeView());
|
| +
|
| views::Widget* insert_after =
|
| views::Widget::GetWidgetForNativeView(frame_view);
|
| GetWidget()->SetBoundsConstrained(bounds);
|
| @@ -390,7 +255,7 @@
|
|
|
| void HungRendererDialogView::WindowClosing() {
|
| // We are going to be deleted soon, so make sure our instance is destroyed.
|
| - g_instance = NULL;
|
| + g_instance_ = NULL;
|
| }
|
|
|
| int HungRendererDialogView::GetDialogButtons() const {
|
| @@ -468,6 +333,16 @@
|
| Init();
|
| }
|
|
|
| +bool HungRendererDialogView::IsFrameActive(WebContents* contents) {
|
| + gfx::NativeView frame_view =
|
| + platform_util::GetTopLevel(contents->GetNativeView());
|
| + if (!platform_util::IsWindowActive(frame_view) &&
|
| + !platform_util::IsWindowActive(GetWidget()->GetNativeWindow())) {
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // HungRendererDialogView, private:
|
|
|
| @@ -574,25 +449,19 @@
|
| }
|
| }
|
|
|
| -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);
|
| + HungRendererDialogView* view = HungRendererDialogView::Create();
|
| + view->ShowForWebContents(contents);
|
| }
|
| }
|
|
|
| void HideHungRendererDialog(WebContents* contents) {
|
| - if (!logging::DialogsAreSuppressed() && g_instance)
|
| - g_instance->EndForWebContents(contents);
|
| + if (!logging::DialogsAreSuppressed() &&
|
| + HungRendererDialogView::GetInstance())
|
| + HungRendererDialogView::GetInstance()->EndForWebContents(contents);
|
| }
|
|
|
| } // namespace chrome
|
|
|