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 if (!logging::DialogsAreSuppressed()) { |
33 if (!g_instance) { | 34 if (!g_instance) { |
34 g_instance = new HungRendererDialog(); | 35 g_instance = new HungRendererDialog(); |
35 } else { | 36 } else { |
36 NOTIMPLEMENTED() << " ShowHungRendererDialog called twice."; | 37 NOTIMPLEMENTED() << " ShowHungRendererDialog called twice."; |
37 return; | 38 return; |
38 } | 39 } |
39 g_instance->ShowDialog(NULL, contents); | 40 g_instance->ShowDialog(NULL, contents); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 void HideHungRendererDialog(TabContents* contents) { | 44 void HideHungRendererDialog(TabContents* contents) { |
44 if (!logging::DialogsAreSuppressed() && g_instance) { | 45 if (!logging::DialogsAreSuppressed() && g_instance) |
45 // TODO(wyck): Hide the webui hung renderer dialog. | 46 g_instance->HideDialog(contents); |
46 NOTIMPLEMENTED() << " TODO: Hide the webui hung renderer dialog."; | |
47 } | |
48 } | 47 } |
49 | 48 |
50 } // namespace browser | 49 } // namespace browser |
51 | 50 |
52 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
53 // HungRendererDialog methods | 52 // HungRendererDialog methods |
54 | 53 |
55 HungRendererDialog::HungRendererDialog() | 54 HungRendererDialog::HungRendererDialog() |
56 : contents_(NULL) { | 55 : contents_(NULL), |
56 window_(NULL) { | |
57 } | 57 } |
58 | 58 |
59 void HungRendererDialog::ShowDialog(gfx::NativeWindow owning_window, | 59 void HungRendererDialog::ShowDialog(gfx::NativeWindow owning_window, |
60 TabContents* contents) { | 60 TabContents* contents) { |
61 DCHECK(contents); | 61 DCHECK(contents); |
62 contents_ = contents; | 62 contents_ = contents; |
63 Browser* browser = BrowserList::GetLastActive(); | 63 Browser* browser = BrowserList::GetLastActive(); |
64 DCHECK(browser); | 64 DCHECK(browser); |
65 browser->BrowserShowHtmlDialog(this, owning_window); | 65 window_ = browser->BrowserShowHtmlDialog(this, owning_window); |
66 } | |
67 | |
68 void HungRendererDialog::HideDialog(TabContents* contents) { | |
69 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); | |
70 DCHECK(widget); | |
71 widget->Close(); | |
66 } | 72 } |
67 | 73 |
68 bool HungRendererDialog::IsDialogModal() const { | 74 bool HungRendererDialog::IsDialogModal() const { |
69 return false; | 75 return false; |
70 } | 76 } |
71 | 77 |
72 string16 HungRendererDialog::GetDialogTitle() const { | 78 string16 HungRendererDialog::GetDialogTitle() const { |
73 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); | 79 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); |
74 } | 80 } |
75 | 81 |
(...skipping 14 matching lines...) Expand all Loading... | |
90 return std::string(); // There are no args used. | 96 return std::string(); // There are no args used. |
91 } | 97 } |
92 | 98 |
93 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 99 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
94 // Figure out what the response was. | 100 // Figure out what the response was. |
95 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 101 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
96 bool response = false; | 102 bool response = false; |
97 ListValue* list; | 103 ListValue* list; |
98 if (!root.get() || !root->GetAsList(&list) || !list || | 104 if (!root.get() || !root->GetAsList(&list) || !list || |
99 !list->GetBoolean(0, &response)) { | 105 !list->GetBoolean(0, &response)) { |
100 NOTREACHED() << "json does not describe a valid result"; | 106 DLOG(INFO) << "json does not describe a valid result"; |
wyck
2011/09/02 15:57:48
This is now reached when the dialog is closed with
flackr
2011/09/02 16:39:55
Since this is an expected case you should remove t
wyck
2011/09/02 19:18:43
Done.
| |
101 } | 107 } |
102 | 108 |
103 if (response) { | 109 if (response) { |
104 // The user indicated that it is OK to kill the renderer process. | 110 // The user indicated that it is OK to kill the renderer process. |
105 if (contents_ && contents_->GetRenderProcessHost()) { | 111 if (contents_ && contents_->GetRenderProcessHost()) { |
106 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 112 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
107 content::RESULT_CODE_HUNG, false); | 113 content::RESULT_CODE_HUNG, false); |
108 } | 114 } |
109 } else { | 115 } else { |
110 // No indication from the user that it is ok to kill anything. Just wait. | 116 // No indication from the user that it is ok to kill anything. Just wait. |
111 // Start waiting again for responsiveness. | 117 // Start waiting again for responsiveness. |
112 if (contents_ && contents_->render_view_host()) | 118 if (contents_ && contents_->render_view_host()) |
flackr
2011/09/02 16:39:55
When the dialog is closed by HideDialog, won't thi
wyck
2011/09/02 19:18:43
Fixed by setting |contents_| to NULL before closin
| |
113 contents_->render_view_host()->RestartHangMonitorTimeout(); | 119 contents_->render_view_host()->RestartHangMonitorTimeout(); |
114 } | 120 } |
115 | 121 |
116 g_instance = NULL; | 122 g_instance = NULL; |
117 delete this; | 123 delete this; |
118 } | 124 } |
119 | 125 |
120 void HungRendererDialog::OnCloseContents(TabContents* source, | 126 void HungRendererDialog::OnCloseContents(TabContents* source, |
121 bool* out_close_dialog) { | 127 bool* out_close_dialog) { |
122 NOTIMPLEMENTED(); | 128 NOTIMPLEMENTED(); |
(...skipping 29 matching lines...) Expand all Loading... | |
152 // Add details for |url| and |title|. | 158 // Add details for |url| and |title|. |
153 DictionaryValue* dict = new DictionaryValue(); | 159 DictionaryValue* dict = new DictionaryValue(); |
154 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 160 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
155 dict->SetString("title", title); | 161 dict->SetString("title", title); |
156 tab_contents_list.Append(dict); | 162 tab_contents_list.Append(dict); |
157 } | 163 } |
158 } | 164 } |
159 // Send list of tab contents details to javascript. | 165 // Send list of tab contents details to javascript. |
160 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 166 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
161 tab_contents_list); | 167 tab_contents_list); |
162 } | 168 } |
flackr
2011/09/02 16:39:55
Was lint okay with not having a newline here even
wyck
2011/09/02 19:18:43
Ya, lint didn't mind me removing the newline here.
| |
163 | |
OLD | NEW |