Chromium Code Reviews| 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); | 38 HungRendererDialog::ShowHungRendererDialog(contents, true); |
|
wyck
2011/11/15 01:56:44
Aw Snap! This shouldn't be here. This caused the
| |
| 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 if (!logging::DialogsAreSuppressed()) { | 66 ShowHungRendererDialogInternal(contents, true); |
| 67 if (g_instance) | |
| 68 return; | |
| 69 g_instance = new HungRendererDialog(); | |
| 70 g_instance->ShowDialog(contents); | |
| 71 } | |
| 72 } | 67 } |
| 73 | 68 |
| 74 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { | 69 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { |
| 75 if (!logging::DialogsAreSuppressed() && g_instance) | 70 if (!logging::DialogsAreSuppressed() && g_instance) |
| 76 g_instance->HideDialog(contents); | 71 g_instance->HideDialog(contents); |
| 77 } | 72 } |
| 78 | 73 |
| 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 } | |
| 79 | 93 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
| 81 // HungRendererDialog private methods | 95 // HungRendererDialog private methods |
| 82 | 96 |
| 83 HungRendererDialog::HungRendererDialog() | 97 HungRendererDialog::HungRendererDialog(bool is_enabled) |
| 84 : contents_(NULL), | 98 : contents_(NULL), |
| 85 handler_(NULL), | 99 handler_(NULL), |
| 100 is_enabled_(is_enabled), | |
| 86 window_(NULL) { | 101 window_(NULL) { |
| 87 } | 102 } |
| 88 | 103 |
| 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 | |
| 89 void HungRendererDialog::ShowDialog(TabContents* contents) { | 117 void HungRendererDialog::ShowDialog(TabContents* contents) { |
| 90 DCHECK(contents); | 118 DCHECK(contents); |
| 91 contents_ = contents; | 119 contents_ = contents; |
| 92 Browser* browser = BrowserList::GetLastActive(); | 120 Browser* browser = BrowserList::GetLastActive(); |
| 93 DCHECK(browser); | 121 DCHECK(browser); |
| 94 handler_ = new HungRendererDialogHandler(contents_); | 122 handler_ = new HungRendererDialogHandler(contents_); |
| 95 window_ = browser->BrowserShowHtmlDialog(this, NULL); | 123 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| 124 contents_observer_.reset(new TabContentsObserverImpl(this, contents_)); | |
| 96 } | 125 } |
| 97 | 126 |
| 98 void HungRendererDialog::HideDialog(TabContents* contents) { | 127 void HungRendererDialog::HideDialog(TabContents* contents) { |
| 99 DCHECK(contents); | 128 DCHECK(contents); |
| 100 // Don't close the dialog if it's a TabContents for some other renderer. | 129 // Don't close the dialog if it's a TabContents for some other renderer. |
| 101 if (contents_ && contents_->GetRenderProcessHost() != | 130 if (contents_ && contents_->GetRenderProcessHost() != |
| 102 contents->GetRenderProcessHost()) | 131 contents->GetRenderProcessHost()) |
| 103 return; | 132 return; |
| 104 // Settings |contents_| to NULL prevents the hang monitor from restarting. | 133 // Settings |contents_| to NULL prevents the hang monitor from restarting. |
| 105 // We do this because the close dialog handler runs whether it is trigged by | 134 // We do this because the close dialog handler runs whether it is trigged by |
| 106 // the user closing the box, or by being closed externally with widget->Close. | 135 // the user closing the box, or by being closed externally with widget->Close. |
| 136 contents_observer_.reset(); | |
| 107 contents_ = NULL; | 137 contents_ = NULL; |
| 108 DCHECK(handler_); | 138 DCHECK(handler_); |
| 109 handler_->CloseDialog(); | 139 handler_->CloseDialog(); |
| 110 } | 140 } |
| 111 | 141 |
| 112 bool HungRendererDialog::IsDialogModal() const { | 142 bool HungRendererDialog::IsDialogModal() const { |
| 113 return false; | 143 return false; |
| 114 } | 144 } |
| 115 | 145 |
| 116 string16 HungRendererDialog::GetDialogTitle() const { | 146 string16 HungRendererDialog::GetDialogTitle() const { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 128 | 158 |
| 129 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { | 159 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { |
| 130 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); | 160 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); |
| 131 } | 161 } |
| 132 | 162 |
| 133 std::string HungRendererDialog::GetDialogArgs() const { | 163 std::string HungRendererDialog::GetDialogArgs() const { |
| 134 return std::string(); // There are no args used. | 164 return std::string(); // There are no args used. |
| 135 } | 165 } |
| 136 | 166 |
| 137 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 167 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
| 138 // Figure out what the response was. | 168 if (is_enabled_) { |
| 139 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 169 // Figure out what the response was. |
| 140 bool response = false; | 170 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
| 141 ListValue* list = NULL; | 171 bool response = false; |
| 142 // If the dialog closes because of a button click then the json is a list | 172 ListValue* list = NULL; |
| 143 // containing a single bool. If the dialog closes some other way, then we | 173 // If the dialog closes because of a button click then the json is a list |
| 144 // assume it means no permission was given to kill tabs. | 174 // containing a single bool. If the dialog closes some other way, then we |
| 145 if (root.get() && root->GetAsList(&list) && list && | 175 // assume it means no permission was given to kill tabs. |
| 146 list->GetBoolean(0, &response) && response) { | 176 if (root.get() && root->GetAsList(&list) && list && |
| 147 // The user indicated that it is OK to kill the renderer process. | 177 list->GetBoolean(0, &response) && response) { |
| 148 if (contents_ && contents_->GetRenderProcessHost()) { | 178 // The user indicated that it is OK to kill the renderer process. |
| 149 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 179 if (contents_ && contents_->GetRenderProcessHost()) { |
| 150 content::RESULT_CODE_HUNG, false); | 180 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
| 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(); | |
| 151 } | 188 } |
| 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(); | |
| 157 } | 189 } |
| 158 g_instance = NULL; | 190 g_instance = NULL; |
| 159 delete this; | 191 delete this; |
| 160 } | 192 } |
| 161 | 193 |
| 162 void HungRendererDialog::OnCloseContents(TabContents* source, | 194 void HungRendererDialog::OnCloseContents(TabContents* source, |
| 163 bool* out_close_dialog) { | 195 bool* out_close_dialog) { |
| 164 NOTIMPLEMENTED(); | 196 NOTIMPLEMENTED(); |
| 165 } | 197 } |
| 166 | 198 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 DictionaryValue* dict = new DictionaryValue(); | 232 DictionaryValue* dict = new DictionaryValue(); |
| 201 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 233 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
| 202 dict->SetString("title", title); | 234 dict->SetString("title", title); |
| 203 tab_contents_list.Append(dict); | 235 tab_contents_list.Append(dict); |
| 204 } | 236 } |
| 205 } | 237 } |
| 206 // Send list of tab contents details to javascript. | 238 // Send list of tab contents details to javascript. |
| 207 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 239 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
| 208 tab_contents_list); | 240 tab_contents_list); |
| 209 } | 241 } |
| OLD | NEW |