| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace { | 28 namespace { |
| 29 HungRendererDialog* g_instance = NULL; | 29 HungRendererDialog* g_instance = NULL; |
| 30 const int kHungRendererDialogWidth = 425; | 30 const int kHungRendererDialogWidth = 425; |
| 31 const int kHungRendererDialogHeight = 200; | 31 const int kHungRendererDialogHeight = 200; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace browser { | 34 namespace browser { |
| 35 | 35 |
| 36 void ShowHungRendererDialog(TabContents* contents) { | 36 void ShowHungRendererDialog(TabContents* contents) { |
| 37 #if defined(OS_CHROMEOS) || defined(USE_AURA) | 37 #if defined(OS_CHROMEOS) || defined(USE_AURA) |
| 38 HungRendererDialog::ShowHungRendererDialog(contents, true); | 38 HungRendererDialog::ShowHungRendererDialog(contents); |
| 39 #else | 39 #else |
| 40 // TODO(rbyers): Remove IsMoreWebUI check once we decide for sure which | 40 // TODO(rbyers): Remove IsMoreWebUI check once we decide for sure which |
| 41 // platforms will use the WebUI version of this dialog. | 41 // platforms will use the WebUI version of this dialog. |
| 42 if (ChromeWebUI::IsMoreWebUI()) | 42 if (ChromeWebUI::IsMoreWebUI()) |
| 43 HungRendererDialog::ShowHungRendererDialog(contents); | 43 HungRendererDialog::ShowHungRendererDialog(contents); |
| 44 else | 44 else |
| 45 ShowNativeHungRendererDialog(contents); | 45 ShowNativeHungRendererDialog(contents); |
| 46 #endif | 46 #endif |
| 47 } | 47 } |
| 48 | 48 |
| 49 void HideHungRendererDialog(TabContents* contents) { | 49 void HideHungRendererDialog(TabContents* contents) { |
| 50 #if defined(OS_CHROMEOS) || defined(USE_AURA) | 50 #if defined(OS_CHROMEOS) || defined(USE_AURA) |
| 51 HungRendererDialog::HideHungRendererDialog(contents); | 51 HungRendererDialog::HideHungRendererDialog(contents); |
| 52 #else | 52 #else |
| 53 if (ChromeWebUI::IsMoreWebUI()) | 53 if (ChromeWebUI::IsMoreWebUI()) |
| 54 HungRendererDialog::HideHungRendererDialog(contents); | 54 HungRendererDialog::HideHungRendererDialog(contents); |
| 55 else | 55 else |
| 56 HideNativeHungRendererDialog(contents); | 56 HideNativeHungRendererDialog(contents); |
| 57 #endif | 57 #endif |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace browser | 60 } // namespace browser |
| 61 | 61 |
| 62 //////////////////////////////////////////////////////////////////////////////// | 62 //////////////////////////////////////////////////////////////////////////////// |
| 63 // HungRendererDialog public static methods | 63 // HungRendererDialog public static methods |
| 64 | 64 |
| 65 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { | 65 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { |
| 66 ShowHungRendererDialogInternal(contents, true); | 66 if (!logging::DialogsAreSuppressed()) { |
| 67 if (g_instance) |
| 68 return; |
| 69 g_instance = new HungRendererDialog(); |
| 70 g_instance->ShowDialog(contents); |
| 71 } |
| 67 } | 72 } |
| 68 | 73 |
| 69 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { | 74 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { |
| 70 if (!logging::DialogsAreSuppressed() && g_instance) | 75 if (!logging::DialogsAreSuppressed() && g_instance) |
| 71 g_instance->HideDialog(contents); | 76 g_instance->HideDialog(contents); |
| 72 } | 77 } |
| 73 | 78 |
| 74 //////////////////////////////////////////////////////////////////////////////// | |
| 75 // HungRendererDialog::TabContentsObserverImpl | |
| 76 | |
| 77 HungRendererDialog::TabContentsObserverImpl::TabContentsObserverImpl( | |
| 78 HungRendererDialog* dialog, | |
| 79 TabContents* contents) | |
| 80 : TabContentsObserver(contents), | |
| 81 contents_(contents), | |
| 82 dialog_(dialog) { | |
| 83 } | |
| 84 | |
| 85 void HungRendererDialog::TabContentsObserverImpl::RenderViewGone() { | |
| 86 dialog_->HideDialog(contents_); | |
| 87 } | |
| 88 | |
| 89 void HungRendererDialog::TabContentsObserverImpl::TabContentsDestroyed( | |
| 90 TabContents* tab) { | |
| 91 dialog_->HideDialog(contents_); | |
| 92 } | |
| 93 | 79 |
| 94 //////////////////////////////////////////////////////////////////////////////// | 80 //////////////////////////////////////////////////////////////////////////////// |
| 95 // HungRendererDialog private methods | 81 // HungRendererDialog private methods |
| 96 | 82 |
| 97 HungRendererDialog::HungRendererDialog(bool is_enabled) | 83 HungRendererDialog::HungRendererDialog() |
| 98 : contents_(NULL), | 84 : contents_(NULL), |
| 99 handler_(NULL), | 85 handler_(NULL), |
| 100 is_enabled_(is_enabled), | |
| 101 window_(NULL) { | 86 window_(NULL) { |
| 102 } | 87 } |
| 103 | 88 |
| 104 HungRendererDialog::~HungRendererDialog() { | |
| 105 } | |
| 106 | |
| 107 void HungRendererDialog::ShowHungRendererDialogInternal(TabContents* contents, | |
| 108 bool is_enabled) { | |
| 109 if (!logging::DialogsAreSuppressed()) { | |
| 110 if (g_instance) | |
| 111 return; | |
| 112 g_instance = new HungRendererDialog(is_enabled); | |
| 113 g_instance->ShowDialog(contents); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void HungRendererDialog::ShowDialog(TabContents* contents) { | 89 void HungRendererDialog::ShowDialog(TabContents* contents) { |
| 118 DCHECK(contents); | 90 DCHECK(contents); |
| 119 contents_ = contents; | 91 contents_ = contents; |
| 120 Browser* browser = BrowserList::GetLastActive(); | 92 Browser* browser = BrowserList::GetLastActive(); |
| 121 DCHECK(browser); | 93 DCHECK(browser); |
| 122 handler_ = new HungRendererDialogHandler(contents_); | 94 handler_ = new HungRendererDialogHandler(contents_); |
| 123 window_ = browser->BrowserShowHtmlDialog(this, NULL); | 95 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| 124 contents_observer_.reset(new TabContentsObserverImpl(this, contents_)); | |
| 125 } | 96 } |
| 126 | 97 |
| 127 void HungRendererDialog::HideDialog(TabContents* contents) { | 98 void HungRendererDialog::HideDialog(TabContents* contents) { |
| 128 DCHECK(contents); | 99 DCHECK(contents); |
| 129 // Don't close the dialog if it's a TabContents for some other renderer. | 100 // Don't close the dialog if it's a TabContents for some other renderer. |
| 130 if (contents_ && contents_->GetRenderProcessHost() != | 101 if (contents_ && contents_->GetRenderProcessHost() != |
| 131 contents->GetRenderProcessHost()) | 102 contents->GetRenderProcessHost()) |
| 132 return; | 103 return; |
| 133 // Settings |contents_| to NULL prevents the hang monitor from restarting. | 104 // Settings |contents_| to NULL prevents the hang monitor from restarting. |
| 134 // We do this because the close dialog handler runs whether it is trigged by | 105 // We do this because the close dialog handler runs whether it is trigged by |
| 135 // the user closing the box, or by being closed externally with widget->Close. | 106 // the user closing the box, or by being closed externally with widget->Close. |
| 136 contents_observer_.reset(); | |
| 137 contents_ = NULL; | 107 contents_ = NULL; |
| 138 DCHECK(handler_); | 108 DCHECK(handler_); |
| 139 handler_->CloseDialog(); | 109 handler_->CloseDialog(); |
| 140 } | 110 } |
| 141 | 111 |
| 142 bool HungRendererDialog::IsDialogModal() const { | 112 bool HungRendererDialog::IsDialogModal() const { |
| 143 return false; | 113 return false; |
| 144 } | 114 } |
| 145 | 115 |
| 146 string16 HungRendererDialog::GetDialogTitle() const { | 116 string16 HungRendererDialog::GetDialogTitle() const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 158 | 128 |
| 159 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { | 129 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { |
| 160 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); | 130 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); |
| 161 } | 131 } |
| 162 | 132 |
| 163 std::string HungRendererDialog::GetDialogArgs() const { | 133 std::string HungRendererDialog::GetDialogArgs() const { |
| 164 return std::string(); // There are no args used. | 134 return std::string(); // There are no args used. |
| 165 } | 135 } |
| 166 | 136 |
| 167 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 137 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
| 168 if (is_enabled_) { | 138 // Figure out what the response was. |
| 169 // Figure out what the response was. | 139 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
| 170 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 140 bool response = false; |
| 171 bool response = false; | 141 ListValue* list = NULL; |
| 172 ListValue* list = NULL; | 142 // If the dialog closes because of a button click then the json is a list |
| 173 // If the dialog closes because of a button click then the json is a list | 143 // containing a single bool. If the dialog closes some other way, then we |
| 174 // containing a single bool. If the dialog closes some other way, then we | 144 // assume it means no permission was given to kill tabs. |
| 175 // assume it means no permission was given to kill tabs. | 145 if (root.get() && root->GetAsList(&list) && list && |
| 176 if (root.get() && root->GetAsList(&list) && list && | 146 list->GetBoolean(0, &response) && response) { |
| 177 list->GetBoolean(0, &response) && response) { | 147 // The user indicated that it is OK to kill the renderer process. |
| 178 // The user indicated that it is OK to kill the renderer process. | 148 if (contents_ && contents_->GetRenderProcessHost()) { |
| 179 if (contents_ && contents_->GetRenderProcessHost()) { | 149 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
| 180 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 150 content::RESULT_CODE_HUNG, false); |
| 181 content::RESULT_CODE_HUNG, false); | |
| 182 } | |
| 183 } else { | |
| 184 // No indication from the user that it is ok to kill anything. Just wait. | |
| 185 // Start waiting again for responsiveness. | |
| 186 if (contents_ && contents_->render_view_host()) | |
| 187 contents_->render_view_host()->RestartHangMonitorTimeout(); | |
| 188 } | 151 } |
| 152 } else { |
| 153 // No indication from the user that it is ok to kill anything. Just wait. |
| 154 // Start waiting again for responsiveness. |
| 155 if (contents_ && contents_->render_view_host()) |
| 156 contents_->render_view_host()->RestartHangMonitorTimeout(); |
| 189 } | 157 } |
| 190 g_instance = NULL; | 158 g_instance = NULL; |
| 191 delete this; | 159 delete this; |
| 192 } | 160 } |
| 193 | 161 |
| 194 void HungRendererDialog::OnCloseContents(TabContents* source, | 162 void HungRendererDialog::OnCloseContents(TabContents* source, |
| 195 bool* out_close_dialog) { | 163 bool* out_close_dialog) { |
| 196 NOTIMPLEMENTED(); | 164 NOTIMPLEMENTED(); |
| 197 } | 165 } |
| 198 | 166 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 DictionaryValue* dict = new DictionaryValue(); | 200 DictionaryValue* dict = new DictionaryValue(); |
| 233 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 201 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
| 234 dict->SetString("title", title); | 202 dict->SetString("title", title); |
| 235 tab_contents_list.Append(dict); | 203 tab_contents_list.Append(dict); |
| 236 } | 204 } |
| 237 } | 205 } |
| 238 // Send list of tab contents details to javascript. | 206 // Send list of tab contents details to javascript. |
| 239 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 207 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
| 240 tab_contents_list); | 208 tab_contents_list); |
| 241 } | 209 } |
| OLD | NEW |