summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/hung_renderer_dialog.h
blob: 4885f01170e03d0b47dee68f7400add9299a1c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2012 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.

#ifndef CHROME_BROWSER_UI_WEBUI_HUNG_RENDERER_DIALOG_H_
#define CHROME_BROWSER_UI_WEBUI_HUNG_RENDERER_DIALOG_H_
#pragma once

#include <string>
#include <vector>

#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "base/values.h"
#include "chrome/browser/ui/webui/html_dialog_ui.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "ui/gfx/native_widget_types.h"

class HungRendererDialogHandler;

class HungRendererDialog : private HtmlDialogUIDelegate {
 public:
  // Shows a hung renderer dialog.
  static void ShowHungRendererDialog(content::WebContents* contents);

  // Hides a hung renderer dialog.
  static void HideHungRendererDialog(content::WebContents* contents);

 private:
  class WebContentsObserverImpl : public content::WebContentsObserver {
   public:
    WebContentsObserverImpl(HungRendererDialog* dialog,
                            content::WebContents* contents);

    // content::WebContentsObserver overrides:
    virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE;
    virtual void WebContentsDestroyed(content::WebContents* tab) OVERRIDE;

   private:
    HungRendererDialog* dialog_;  // weak

    DISALLOW_COPY_AND_ASSIGN(WebContentsObserverImpl);
  };

  friend class HungRendererDialogUITest;

  explicit HungRendererDialog(bool is_enabled);
  virtual ~HungRendererDialog();

  // Shows a hung renderer dialog that, if not enabled, won't kill processes
  // or restart hang timers.
  static void ShowHungRendererDialogInternal(content::WebContents* contents,
                                             bool is_enabled);

  // Shows the hung renderer dialog.
  void ShowDialog(content::WebContents* contents);

  // Hides the hung renderer dialog.
  void HideDialog(content::WebContents* contents);

  // HtmlDialogUIDelegate methods
  virtual ui::ModalType GetDialogModalType() const OVERRIDE;
  virtual string16 GetDialogTitle() const OVERRIDE;
  virtual GURL GetDialogContentURL() const OVERRIDE;
  virtual void GetWebUIMessageHandlers(
      std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
  virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
  virtual std::string GetDialogArgs() const OVERRIDE;
  virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
  virtual void OnCloseContents(content::WebContents* source,
                               bool* out_close_dialog) OVERRIDE;
  virtual bool ShouldShowDialogTitle() const OVERRIDE;

  // The web contents.
  content::WebContents* contents_;

  // The dialog handler.
  HungRendererDialogHandler* handler_;

  // A safety switch that must be enabled to allow actual killing of processes
  // or restarting of the hang timer.  This is necessary so that tests can
  // create a disabled version of this dialog that won't kill processes or
  // restart timers when the dialog closes at the end of the test.
  bool is_enabled_;

  // The dialog window.
  gfx::NativeWindow window_;

  scoped_ptr<WebContentsObserverImpl> contents_observer_;

  DISALLOW_COPY_AND_ASSIGN(HungRendererDialog);
};

// Dialog handler that handles calls from the JS WebUI code to get the details
// of the list of frozen tabs.
class HungRendererDialogHandler : public content::WebUIMessageHandler {
 public:
  explicit HungRendererDialogHandler(content::WebContents* contents);

  void CloseDialog();

  // Overridden from WebUIMessageHandler
  virtual void RegisterMessages() OVERRIDE;

 private:
  void RequestTabContentsList(const base::ListValue* args);

  // The web contents.
  content::WebContents* contents_;

  DISALLOW_COPY_AND_ASSIGN(HungRendererDialogHandler);
};


#endif  // CHROME_BROWSER_UI_WEBUI_HUNG_RENDERER_DIALOG_H_