OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/hung_renderer_dialog.h" | 5 #include "chrome/browser/ui/webui/hung_renderer_dialog.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/common/logging_chrome.h" | 15 #include "chrome/common/logging_chrome.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
18 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
19 #include "content/common/result_codes.h" | 19 #include "content/common/result_codes.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "views/widget/widget.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 HungRendererDialog* g_instance = NULL; | 25 HungRendererDialog* g_instance = NULL; |
25 const int kHungRendererDialogWidth = 425; | 26 const int kHungRendererDialogWidth = 425; |
26 const int kHungRendererDialogHeight = 200; | 27 const int kHungRendererDialogHeight = 200; |
27 } | 28 } |
28 | 29 |
29 namespace browser { | 30 namespace browser { |
30 | 31 |
31 void ShowHungRendererDialog(TabContents* contents) { | 32 void ShowHungRendererDialog(TabContents* contents) { |
32 if (!logging::DialogsAreSuppressed()) { | 33 HungRendererDialog::ShowHungRendererDialog(contents); |
33 if (!g_instance) { | |
34 g_instance = new HungRendererDialog(); | |
35 } else { | |
36 NOTIMPLEMENTED() << " ShowHungRendererDialog called twice."; | |
37 return; | |
38 } | |
39 g_instance->ShowDialog(NULL, contents); | |
40 } | |
41 } | 34 } |
42 | 35 |
43 void HideHungRendererDialog(TabContents* contents) { | 36 void HideHungRendererDialog(TabContents* contents) { |
44 if (!logging::DialogsAreSuppressed() && g_instance) { | 37 HungRendererDialog::HideHungRendererDialog(contents); |
45 // TODO(wyck): Hide the webui hung renderer dialog. | |
46 NOTIMPLEMENTED() << " TODO: Hide the webui hung renderer dialog."; | |
47 } | |
48 } | 38 } |
49 | 39 |
50 } // namespace browser | 40 } // namespace browser |
51 | 41 |
52 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
53 // HungRendererDialog methods | 43 // HungRendererDialog public static methods |
| 44 |
| 45 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { |
| 46 if (!logging::DialogsAreSuppressed()) { |
| 47 if (g_instance) |
| 48 return; |
| 49 g_instance = new HungRendererDialog(); |
| 50 g_instance->ShowDialog(contents); |
| 51 } |
| 52 } |
| 53 |
| 54 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { |
| 55 if (!logging::DialogsAreSuppressed() && g_instance) |
| 56 g_instance->HideDialog(contents); |
| 57 } |
| 58 |
| 59 |
| 60 //////////////////////////////////////////////////////////////////////////////// |
| 61 // HungRendererDialog private methods |
54 | 62 |
55 HungRendererDialog::HungRendererDialog() | 63 HungRendererDialog::HungRendererDialog() |
56 : contents_(NULL) { | 64 : contents_(NULL), |
| 65 window_(NULL) { |
57 } | 66 } |
58 | 67 |
59 void HungRendererDialog::ShowDialog(gfx::NativeWindow owning_window, | 68 void HungRendererDialog::ShowDialog(TabContents* contents) { |
60 TabContents* contents) { | |
61 DCHECK(contents); | 69 DCHECK(contents); |
62 contents_ = contents; | 70 contents_ = contents; |
63 Browser* browser = BrowserList::GetLastActive(); | 71 Browser* browser = BrowserList::GetLastActive(); |
64 DCHECK(browser); | 72 DCHECK(browser); |
65 browser->BrowserShowHtmlDialog(this, owning_window); | 73 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| 74 } |
| 75 |
| 76 void HungRendererDialog::HideDialog(TabContents* contents) { |
| 77 DCHECK(contents); |
| 78 // Don't close the dialog if it's a TabContents for some other renderer. |
| 79 if (contents_ && contents_->GetRenderProcessHost() != |
| 80 contents->GetRenderProcessHost()) |
| 81 return; |
| 82 // Settings |contents_| to NULL prevents the hang monitor from restarting. |
| 83 // We do this because the close dialog handler runs whether it is trigged by |
| 84 // the user closing the box, or by being closed externally with widget->Close. |
| 85 contents_ = NULL; |
| 86 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); |
| 87 DCHECK(widget); |
| 88 widget->Close(); |
66 } | 89 } |
67 | 90 |
68 bool HungRendererDialog::IsDialogModal() const { | 91 bool HungRendererDialog::IsDialogModal() const { |
69 return false; | 92 return false; |
70 } | 93 } |
71 | 94 |
72 string16 HungRendererDialog::GetDialogTitle() const { | 95 string16 HungRendererDialog::GetDialogTitle() const { |
73 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); | 96 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); |
74 } | 97 } |
75 | 98 |
(...skipping 11 matching lines...) Expand all Loading... |
87 } | 110 } |
88 | 111 |
89 std::string HungRendererDialog::GetDialogArgs() const { | 112 std::string HungRendererDialog::GetDialogArgs() const { |
90 return std::string(); // There are no args used. | 113 return std::string(); // There are no args used. |
91 } | 114 } |
92 | 115 |
93 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 116 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
94 // Figure out what the response was. | 117 // Figure out what the response was. |
95 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 118 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
96 bool response = false; | 119 bool response = false; |
97 ListValue* list; | 120 ListValue* list = NULL; |
98 if (!root.get() || !root->GetAsList(&list) || !list || | 121 // If the dialog closes because of a button click then the json is a list |
99 !list->GetBoolean(0, &response)) { | 122 // containing a single bool. If the dialog closes some other way, then we |
100 NOTREACHED() << "json does not describe a valid result"; | 123 // assume it means no permission was given to kill tabs. |
101 } | 124 if (root.get() && root->GetAsList(&list) && list && |
102 | 125 list->GetBoolean(0, &response) && response) { |
103 if (response) { | |
104 // The user indicated that it is OK to kill the renderer process. | 126 // The user indicated that it is OK to kill the renderer process. |
105 if (contents_ && contents_->GetRenderProcessHost()) { | 127 if (contents_ && contents_->GetRenderProcessHost()) { |
106 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 128 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
107 content::RESULT_CODE_HUNG, false); | 129 content::RESULT_CODE_HUNG, false); |
108 } | 130 } |
109 } else { | 131 } else { |
110 // No indication from the user that it is ok to kill anything. Just wait. | 132 // No indication from the user that it is ok to kill anything. Just wait. |
111 // Start waiting again for responsiveness. | 133 // Start waiting again for responsiveness. |
112 if (contents_ && contents_->render_view_host()) | 134 if (contents_ && contents_->render_view_host()) |
113 contents_->render_view_host()->RestartHangMonitorTimeout(); | 135 contents_->render_view_host()->RestartHangMonitorTimeout(); |
114 } | 136 } |
115 | |
116 g_instance = NULL; | 137 g_instance = NULL; |
117 delete this; | 138 delete this; |
118 } | 139 } |
119 | 140 |
120 void HungRendererDialog::OnCloseContents(TabContents* source, | 141 void HungRendererDialog::OnCloseContents(TabContents* source, |
121 bool* out_close_dialog) { | 142 bool* out_close_dialog) { |
122 NOTIMPLEMENTED(); | 143 NOTIMPLEMENTED(); |
123 } | 144 } |
124 | 145 |
125 bool HungRendererDialog::ShouldShowDialogTitle() const { | 146 bool HungRendererDialog::ShouldShowDialogTitle() const { |
(...skipping 27 matching lines...) Expand all Loading... |
153 DictionaryValue* dict = new DictionaryValue(); | 174 DictionaryValue* dict = new DictionaryValue(); |
154 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 175 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
155 dict->SetString("title", title); | 176 dict->SetString("title", title); |
156 tab_contents_list.Append(dict); | 177 tab_contents_list.Append(dict); |
157 } | 178 } |
158 } | 179 } |
159 // Send list of tab contents details to javascript. | 180 // Send list of tab contents details to javascript. |
160 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 181 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
161 tab_contents_list); | 182 tab_contents_list); |
162 } | 183 } |
163 | |
OLD | NEW |