| 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); |
| 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 |
| 79 | 74 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 75 //////////////////////////////////////////////////////////////////////////////// |
| 81 // HungRendererDialog private methods | 76 // HungRendererDialog private methods |
| 82 | 77 |
| 83 HungRendererDialog::HungRendererDialog() | 78 void HungRendererDialog::ShowHungRendererDialogInternal(TabContents* contents, |
| 79 bool is_enabled) { |
| 80 if (!logging::DialogsAreSuppressed()) { |
| 81 if (g_instance) |
| 82 return; |
| 83 g_instance = new HungRendererDialog(is_enabled); |
| 84 g_instance->ShowDialog(contents); |
| 85 } |
| 86 } |
| 87 |
| 88 HungRendererDialog::HungRendererDialog(bool is_enabled) |
| 84 : contents_(NULL), | 89 : contents_(NULL), |
| 85 handler_(NULL), | 90 handler_(NULL), |
| 91 is_enabled_(is_enabled), |
| 86 window_(NULL) { | 92 window_(NULL) { |
| 87 } | 93 } |
| 88 | 94 |
| 95 HungRendererDialog::~HungRendererDialog() { |
| 96 } |
| 97 |
| 89 void HungRendererDialog::ShowDialog(TabContents* contents) { | 98 void HungRendererDialog::ShowDialog(TabContents* contents) { |
| 90 DCHECK(contents); | 99 DCHECK(contents); |
| 91 contents_ = contents; | 100 contents_ = contents; |
| 92 Browser* browser = BrowserList::GetLastActive(); | 101 Browser* browser = BrowserList::GetLastActive(); |
| 93 DCHECK(browser); | 102 DCHECK(browser); |
| 94 handler_ = new HungRendererDialogHandler(contents_); | 103 handler_ = new HungRendererDialogHandler(contents_); |
| 95 window_ = browser->BrowserShowHtmlDialog(this, NULL); | 104 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| 105 contents_observer_.reset(new TabContentsObserverImpl(this, contents_)); |
| 96 } | 106 } |
| 97 | 107 |
| 98 void HungRendererDialog::HideDialog(TabContents* contents) { | 108 void HungRendererDialog::HideDialog(TabContents* contents) { |
| 99 DCHECK(contents); | 109 DCHECK(contents); |
| 100 // Don't close the dialog if it's a TabContents for some other renderer. | 110 // Don't close the dialog if it's a TabContents for some other renderer. |
| 101 if (contents_ && contents_->GetRenderProcessHost() != | 111 if (contents_ && contents_->GetRenderProcessHost() != |
| 102 contents->GetRenderProcessHost()) | 112 contents->GetRenderProcessHost()) |
| 103 return; | 113 return; |
| 104 // Settings |contents_| to NULL prevents the hang monitor from restarting. | 114 // 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 | 115 // 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. | 116 // the user closing the box, or by being closed externally with widget->Close. |
| 117 contents_observer_.reset(); |
| 107 contents_ = NULL; | 118 contents_ = NULL; |
| 108 DCHECK(handler_); | 119 DCHECK(handler_); |
| 109 handler_->CloseDialog(); | 120 handler_->CloseDialog(); |
| 110 } | 121 } |
| 111 | 122 |
| 112 bool HungRendererDialog::IsDialogModal() const { | 123 bool HungRendererDialog::IsDialogModal() const { |
| 113 return false; | 124 return false; |
| 114 } | 125 } |
| 115 | 126 |
| 116 string16 HungRendererDialog::GetDialogTitle() const { | 127 string16 HungRendererDialog::GetDialogTitle() const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 128 | 139 |
| 129 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { | 140 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { |
| 130 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); | 141 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); |
| 131 } | 142 } |
| 132 | 143 |
| 133 std::string HungRendererDialog::GetDialogArgs() const { | 144 std::string HungRendererDialog::GetDialogArgs() const { |
| 134 return std::string(); // There are no args used. | 145 return std::string(); // There are no args used. |
| 135 } | 146 } |
| 136 | 147 |
| 137 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 148 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
| 138 // Figure out what the response was. | 149 if (is_enabled_) { |
| 139 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 150 // Figure out what the response was. |
| 140 bool response = false; | 151 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
| 141 ListValue* list = NULL; | 152 bool response = false; |
| 142 // If the dialog closes because of a button click then the json is a list | 153 ListValue* list = NULL; |
| 143 // containing a single bool. If the dialog closes some other way, then we | 154 // 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. | 155 // containing a single bool. If the dialog closes some other way, then we |
| 145 if (root.get() && root->GetAsList(&list) && list && | 156 // assume it means no permission was given to kill tabs. |
| 146 list->GetBoolean(0, &response) && response) { | 157 if (root.get() && root->GetAsList(&list) && list && |
| 147 // The user indicated that it is OK to kill the renderer process. | 158 list->GetBoolean(0, &response) && response) { |
| 148 if (contents_ && contents_->GetRenderProcessHost()) { | 159 // The user indicated that it is OK to kill the renderer process. |
| 149 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 160 if (contents_ && contents_->GetRenderProcessHost()) { |
| 150 content::RESULT_CODE_HUNG, false); | 161 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
| 162 content::RESULT_CODE_HUNG, false); |
| 163 } |
| 164 } else { |
| 165 // No indication from the user that it is ok to kill anything. Just wait. |
| 166 // Start waiting again for responsiveness. |
| 167 if (contents_ && contents_->render_view_host()) |
| 168 contents_->render_view_host()->RestartHangMonitorTimeout(); |
| 151 } | 169 } |
| 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 } | 170 } |
| 158 g_instance = NULL; | 171 g_instance = NULL; |
| 159 delete this; | 172 delete this; |
| 160 } | 173 } |
| 161 | 174 |
| 162 void HungRendererDialog::OnCloseContents(TabContents* source, | 175 void HungRendererDialog::OnCloseContents(TabContents* source, |
| 163 bool* out_close_dialog) { | 176 bool* out_close_dialog) { |
| 164 NOTIMPLEMENTED(); | 177 NOTIMPLEMENTED(); |
| 165 } | 178 } |
| 166 | 179 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 DictionaryValue* dict = new DictionaryValue(); | 213 DictionaryValue* dict = new DictionaryValue(); |
| 201 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 214 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
| 202 dict->SetString("title", title); | 215 dict->SetString("title", title); |
| 203 tab_contents_list.Append(dict); | 216 tab_contents_list.Append(dict); |
| 204 } | 217 } |
| 205 } | 218 } |
| 206 // Send list of tab contents details to javascript. | 219 // Send list of tab contents details to javascript. |
| 207 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 220 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
| 208 tab_contents_list); | 221 tab_contents_list); |
| 209 } | 222 } |
| OLD | NEW |