| 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, true); |
| 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 bool isEnabled) { |
| 66 if (!logging::DialogsAreSuppressed()) { | 67 if (!logging::DialogsAreSuppressed()) { |
| 67 if (g_instance) | 68 if (g_instance) |
| 68 return; | 69 return; |
| 69 g_instance = new HungRendererDialog(); | 70 g_instance = new HungRendererDialog(isEnabled); |
| 70 g_instance->ShowDialog(contents); | 71 g_instance->ShowDialog(contents); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { | 75 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { |
| 75 if (!logging::DialogsAreSuppressed() && g_instance) | 76 if (!logging::DialogsAreSuppressed() && g_instance) |
| 76 g_instance->HideDialog(contents); | 77 g_instance->HideDialog(contents); |
| 77 } | 78 } |
| 78 | 79 |
| 79 | 80 |
| 80 //////////////////////////////////////////////////////////////////////////////// | 81 //////////////////////////////////////////////////////////////////////////////// |
| 81 // HungRendererDialog private methods | 82 // HungRendererDialog private methods |
| 82 | 83 |
| 83 HungRendererDialog::HungRendererDialog() | 84 HungRendererDialog::HungRendererDialog(bool is_enabled) |
| 84 : contents_(NULL), | 85 : contents_(NULL), |
| 85 handler_(NULL), | 86 handler_(NULL), |
| 87 is_enabled_(is_enabled), |
| 86 window_(NULL) { | 88 window_(NULL) { |
| 87 } | 89 } |
| 88 | 90 |
| 89 void HungRendererDialog::ShowDialog(TabContents* contents) { | 91 void HungRendererDialog::ShowDialog(TabContents* contents) { |
| 90 DCHECK(contents); | 92 DCHECK(contents); |
| 91 contents_ = contents; | 93 contents_ = contents; |
| 92 Browser* browser = BrowserList::GetLastActive(); | 94 Browser* browser = BrowserList::GetLastActive(); |
| 93 DCHECK(browser); | 95 DCHECK(browser); |
| 94 handler_ = new HungRendererDialogHandler(contents_); | 96 handler_ = new HungRendererDialogHandler(contents_); |
| 95 window_ = browser->BrowserShowHtmlDialog(this, NULL); | 97 window_ = browser->BrowserShowHtmlDialog(this, NULL); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 130 |
| 129 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { | 131 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { |
| 130 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); | 132 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); |
| 131 } | 133 } |
| 132 | 134 |
| 133 std::string HungRendererDialog::GetDialogArgs() const { | 135 std::string HungRendererDialog::GetDialogArgs() const { |
| 134 return std::string(); // There are no args used. | 136 return std::string(); // There are no args used. |
| 135 } | 137 } |
| 136 | 138 |
| 137 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { | 139 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { |
| 138 // Figure out what the response was. | 140 if (is_enabled_) { |
| 139 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); | 141 // Figure out what the response was. |
| 140 bool response = false; | 142 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); |
| 141 ListValue* list = NULL; | 143 bool response = false; |
| 142 // If the dialog closes because of a button click then the json is a list | 144 ListValue* list = NULL; |
| 143 // containing a single bool. If the dialog closes some other way, then we | 145 // 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. | 146 // containing a single bool. If the dialog closes some other way, then we |
| 145 if (root.get() && root->GetAsList(&list) && list && | 147 // assume it means no permission was given to kill tabs. |
| 146 list->GetBoolean(0, &response) && response) { | 148 if (root.get() && root->GetAsList(&list) && list && |
| 147 // The user indicated that it is OK to kill the renderer process. | 149 list->GetBoolean(0, &response) && response) { |
| 148 if (contents_ && contents_->GetRenderProcessHost()) { | 150 // The user indicated that it is OK to kill the renderer process. |
| 149 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), | 151 if (contents_ && contents_->GetRenderProcessHost()) { |
| 150 content::RESULT_CODE_HUNG, false); | 152 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), |
| 153 content::RESULT_CODE_HUNG, false); |
| 154 } |
| 155 } else { |
| 156 // No indication from the user that it is ok to kill anything. Just wait. |
| 157 // Start waiting again for responsiveness. |
| 158 if (contents_ && contents_->render_view_host()) |
| 159 contents_->render_view_host()->RestartHangMonitorTimeout(); |
| 151 } | 160 } |
| 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 } | 161 } |
| 158 g_instance = NULL; | 162 g_instance = NULL; |
| 159 delete this; | 163 delete this; |
| 160 } | 164 } |
| 161 | 165 |
| 162 void HungRendererDialog::OnCloseContents(TabContents* source, | 166 void HungRendererDialog::OnCloseContents(TabContents* source, |
| 163 bool* out_close_dialog) { | 167 bool* out_close_dialog) { |
| 164 NOTIMPLEMENTED(); | 168 NOTIMPLEMENTED(); |
| 165 } | 169 } |
| 166 | 170 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 DictionaryValue* dict = new DictionaryValue(); | 204 DictionaryValue* dict = new DictionaryValue(); |
| 201 dict->SetString("url", it->tab_contents()->GetURL().spec()); | 205 dict->SetString("url", it->tab_contents()->GetURL().spec()); |
| 202 dict->SetString("title", title); | 206 dict->SetString("title", title); |
| 203 tab_contents_list.Append(dict); | 207 tab_contents_list.Append(dict); |
| 204 } | 208 } |
| 205 } | 209 } |
| 206 // Send list of tab contents details to javascript. | 210 // Send list of tab contents details to javascript. |
| 207 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", | 211 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", |
| 208 tab_contents_list); | 212 tab_contents_list); |
| 209 } | 213 } |
| OLD | NEW |