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/utf_string_conversions.h" | |
12 #include "base/values.h" | 11 #include "base/values.h" |
13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
15 #include "chrome/browser/ui/browser_dialogs.h" | |
16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
17 #include "chrome/browser/ui/webui/html_dialog_ui.h" | |
18 #include "chrome/common/logging_chrome.h" | 15 #include "chrome/common/logging_chrome.h" |
19 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
20 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
21 #include "content/browser/tab_contents/tab_contents.h" | 18 #include "content/browser/tab_contents/tab_contents.h" |
22 #include "content/common/result_codes.h" | 19 #include "content/common/result_codes.h" |
23 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "views/widget/widget.h" |
25 | 23 |
26 namespace { | 24 namespace { |
27 HungRendererDialog* g_instance = NULL; | 25 HungRendererDialog* g_instance = NULL; |
28 const int kHungRendererDialogWidth = 425; | 26 const int kHungRendererDialogWidth = 425; |
29 const int kHungRendererDialogHeight = 200; | 27 const int kHungRendererDialogHeight = 200; |
30 } | 28 } |
31 | 29 |
32 namespace browser { | 30 namespace browser { |
33 | 31 |
34 void ShowHungRendererDialog(TabContents* contents) { | 32 void ShowHungRendererDialog(TabContents* contents) { |
35 if (ChromeWebUI::IsMoreWebUI()) { | 33 HungRendererDialog::ShowHungRendererDialog(contents); |
36 HungRendererDialog::ShowHungRendererDialog(contents); | |
37 return; | |
38 } | |
39 | |
40 ShowNativeHungRendererDialog(contents); | |
41 } | 34 } |
42 | 35 |
43 void HideHungRendererDialog(TabContents* contents) { | 36 void HideHungRendererDialog(TabContents* contents) { |
44 if (ChromeWebUI::IsMoreWebUI()) { | 37 HungRendererDialog::HideHungRendererDialog(contents); |
45 HungRendererDialog::HideHungRendererDialog(contents); | |
46 return; | |
47 } | |
48 | |
49 HideNativeHungRendererDialog(contents); | |
50 } | 38 } |
51 | 39 |
52 } // namespace browser | 40 } // namespace browser |
53 | 41 |
54 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
55 // HungRendererDialog public static methods | 43 // HungRendererDialog public static methods |
56 | 44 |
57 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { | 45 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { |
58 if (!logging::DialogsAreSuppressed()) { | 46 if (!logging::DialogsAreSuppressed()) { |
59 if (g_instance) | 47 if (g_instance) |
60 return; | 48 return; |
61 g_instance = new HungRendererDialog(); | 49 g_instance = new HungRendererDialog(); |
62 g_instance->ShowDialog(contents); | 50 g_instance->ShowDialog(contents); |
63 } | 51 } |
64 } | 52 } |
65 | 53 |
66 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { | 54 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { |
67 if (!logging::DialogsAreSuppressed() && g_instance) | 55 if (!logging::DialogsAreSuppressed() && g_instance) |
68 g_instance->HideDialog(contents); | 56 g_instance->HideDialog(contents); |
69 } | 57 } |
70 | 58 |
71 | 59 |
72 //////////////////////////////////////////////////////////////////////////////// | 60 //////////////////////////////////////////////////////////////////////////////// |
73 // HungRendererDialog private methods | 61 // HungRendererDialog private methods |
74 | 62 |
75 HungRendererDialog::HungRendererDialog() | 63 HungRendererDialog::HungRendererDialog() |
76 : contents_(NULL), | 64 : contents_(NULL), |
77 handler_(NULL), | |
78 window_(NULL) { | 65 window_(NULL) { |
79 } | 66 } |
80 | 67 |
81 void HungRendererDialog::ShowDialog(TabContents* contents) { | 68 void HungRendererDialog::ShowDialog(TabContents* contents) { |
82 DCHECK(contents); | 69 DCHECK(contents); |
83 contents_ = contents; | 70 contents_ = contents; |
84 Browser* browser = BrowserList::GetLastActive(); | 71 Browser* browser = BrowserList::GetLastActive(); |
85 DCHECK(browser); | 72 DCHECK(browser); |
86 handler_ = new HungRendererDialogHandler(contents_); | |
87 window_ = browser->BrowserShowHtmlDialog(this, NULL); | 73 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
88 } | 74 } |
89 | 75 |
90 void HungRendererDialog::HideDialog(TabContents* contents) { | 76 void HungRendererDialog::HideDialog(TabContents* contents) { |
91 DCHECK(contents); | 77 DCHECK(contents); |
92 // Don't close the dialog if it's a TabContents for some other renderer. | 78 // Don't close the dialog if it's a TabContents for some other renderer. |
93 if (contents_ && contents_->GetRenderProcessHost() != | 79 if (contents_ && contents_->GetRenderProcessHost() != |
94 contents->GetRenderProcessHost()) | 80 contents->GetRenderProcessHost()) |
95 return; | 81 return; |
96 // Settings |contents_| to NULL prevents the hang monitor from restarting. | 82 // Settings |contents_| to NULL prevents the hang monitor from restarting. |
97 // We do this because the close dialog handler runs whether it is trigged by | 83 // We do this because the close dialog handler runs whether it is trigged by |
98 // the user closing the box, or by being closed externally with widget->Close. | 84 // the user closing the box, or by being closed externally with widget->Close. |
99 contents_ = NULL; | 85 contents_ = NULL; |
100 DCHECK(handler_); | 86 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); |
101 handler_->CloseDialog(); | 87 DCHECK(widget); |
| 88 widget->Close(); |
102 } | 89 } |
103 | 90 |
104 bool HungRendererDialog::IsDialogModal() const { | 91 bool HungRendererDialog::IsDialogModal() const { |
105 return false; | 92 return false; |
106 } | 93 } |
107 | 94 |
108 string16 HungRendererDialog::GetDialogTitle() const { | 95 string16 HungRendererDialog::GetDialogTitle() const { |
109 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); | 96 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); |
110 } | 97 } |
111 | 98 |
112 GURL HungRendererDialog::GetDialogContentURL() const { | 99 GURL HungRendererDialog::GetDialogContentURL() const { |
113 return GURL(chrome::kChromeUIHungRendererDialogURL); | 100 return GURL(chrome::kChromeUIHungRendererDialogURL); |
114 } | 101 } |
115 | 102 |
116 void HungRendererDialog::GetWebUIMessageHandlers( | 103 void HungRendererDialog::GetWebUIMessageHandlers( |
117 std::vector<WebUIMessageHandler*>* handlers) const { | 104 std::vector<WebUIMessageHandler*>* handlers) const { |
118 handlers->push_back(handler_); | 105 handlers->push_back(new HungRendererDialogHandler(contents_)); |
119 } | 106 } |
120 | 107 |
121 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { | 108 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { |
122 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); | 109 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); |
123 } | 110 } |
124 | 111 |
125 std::string HungRendererDialog::GetDialogArgs() const { | 112 std::string HungRendererDialog::GetDialogArgs() const { |
126 return std::string(); // There are no args used. | 113 return std::string(); // There are no args used. |
127 } | 114 } |
128 | 115 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 148 } |
162 | 149 |
163 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
164 // HungRendererDialogHandler methods | 151 // HungRendererDialogHandler methods |
165 | 152 |
166 HungRendererDialogHandler::HungRendererDialogHandler( | 153 HungRendererDialogHandler::HungRendererDialogHandler( |
167 TabContents* contents) | 154 TabContents* contents) |
168 : contents_(contents) { | 155 : contents_(contents) { |
169 } | 156 } |
170 | 157 |
171 void HungRendererDialogHandler::CloseDialog() { | |
172 DCHECK(web_ui_); | |
173 static_cast<HtmlDialogUI*>(web_ui_)->CloseDialog(NULL); | |
174 } | |
175 | |
176 void HungRendererDialogHandler::RegisterMessages() { | 158 void HungRendererDialogHandler::RegisterMessages() { |
177 web_ui_->RegisterMessageCallback("requestTabContentsList", | 159 web_ui_->RegisterMessageCallback("requestTabContentsList", |
178 NewCallback(this, | 160 NewCallback(this, |
179 &HungRendererDialogHandler::RequestTabContentsList)); | 161 &HungRendererDialogHandler::RequestTabContentsList)); |
180 } | 162 } |
181 | 163 |
182 void HungRendererDialogHandler::RequestTabContentsList( | 164 void HungRendererDialogHandler::RequestTabContentsList( |
183 const base::ListValue* args) { | 165 const base::ListValue* args) { |
184 ListValue tab_contents_list; | 166 ListValue tab_contents_list; |
185 for (TabContentsIterator it; !it.done(); ++it) { | 167 for (TabContentsIterator it; !it.done(); ++it) { |
186 if (it->tab_contents()->GetRenderProcessHost() == | 168 if (it->tab_contents()->GetRenderProcessHost() == |
187 contents_->GetRenderProcessHost()) { | 169 contents_->GetRenderProcessHost()) { |
188 string16 title = it->tab_contents()->GetTitle(); | 170 string16 title = it->tab_contents()->GetTitle(); |
189 if (title.empty()) | 171 if (title.empty()) |
190 title = TabContentsWrapper::GetDefaultTitle(); | 172 title = TabContentsWrapper::GetDefaultTitle(); |
191 // Add details for |url| and |title|. | 173 // Add details for |url| and |title|. |
192 DictionaryValue* dict = new DictionaryValue(); | 174 DictionaryValue* dict = new DictionaryValue(); |
193 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 175 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
194 dict->SetString("title", title); | 176 dict->SetString("title", title); |
195 tab_contents_list.Append(dict); | 177 tab_contents_list.Append(dict); |
196 } | 178 } |
197 } | 179 } |
198 // Send list of tab contents details to javascript. | 180 // Send list of tab contents details to javascript. |
199 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 181 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
200 tab_contents_list); | 182 tab_contents_list); |
201 } | 183 } |
OLD | NEW |