Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: chrome/browser/ui/webui/hung_renderer_dialog.cc

Issue 7824039: Implement function that hides the WebUI Hung Renderer Dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed timeout behaviour. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 13 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/common/logging_chrome.h" 15 #include "chrome/common/logging_chrome.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "content/browser/renderer_host/render_view_host.h" 17 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/tab_contents/tab_contents.h" 18 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/common/result_codes.h" 19 #include "content/common/result_codes.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "views/widget/widget.h"
22 23
23 namespace { 24 namespace {
24 HungRendererDialog* g_instance = NULL; 25 HungRendererDialog* g_instance = NULL;
25 const int kHungRendererDialogWidth = 425; 26 const int kHungRendererDialogWidth = 425;
26 const int kHungRendererDialogHeight = 200; 27 const int kHungRendererDialogHeight = 200;
27 } 28 }
28 29
29 namespace browser { 30 namespace browser {
30 31
31 void ShowHungRendererDialog(TabContents* contents) { 32 void ShowHungRendererDialog(TabContents* contents) {
32 if (!logging::DialogsAreSuppressed()) { 33 if (!logging::DialogsAreSuppressed()) {
33 if (!g_instance) { 34 if (!g_instance) {
34 g_instance = new HungRendererDialog(); 35 g_instance = new HungRendererDialog();
35 } else { 36 } else {
36 NOTIMPLEMENTED() << " ShowHungRendererDialog called twice."; 37 NOTIMPLEMENTED() << " ShowHungRendererDialog called twice.";
flackr 2011/09/03 17:51:31 This was the case that you said can occur if anoth
wyck 2011/09/06 18:07:35 Now that 'hide' is implemented, this doesn't happe
37 return; 38 return;
38 } 39 }
39 g_instance->ShowDialog(NULL, contents); 40 g_instance->ShowDialog(NULL, contents);
40 } 41 }
41 } 42 }
42 43
43 void HideHungRendererDialog(TabContents* contents) { 44 void HideHungRendererDialog(TabContents* contents) {
44 if (!logging::DialogsAreSuppressed() && g_instance) { 45 if (!logging::DialogsAreSuppressed() && g_instance)
45 // TODO(wyck): Hide the webui hung renderer dialog. 46 g_instance->HideDialog(contents);
46 NOTIMPLEMENTED() << " TODO: Hide the webui hung renderer dialog.";
47 }
48 } 47 }
49 48
50 } // namespace browser 49 } // namespace browser
51 50
52 //////////////////////////////////////////////////////////////////////////////// 51 ////////////////////////////////////////////////////////////////////////////////
53 // HungRendererDialog methods 52 // HungRendererDialog methods
54 53
55 HungRendererDialog::HungRendererDialog() 54 HungRendererDialog::HungRendererDialog()
56 : contents_(NULL) { 55 : contents_(NULL),
56 window_(NULL) {
57 } 57 }
58 58
59 void HungRendererDialog::ShowDialog(gfx::NativeWindow owning_window, 59 void HungRendererDialog::ShowDialog(gfx::NativeWindow owning_window,
60 TabContents* contents) { 60 TabContents* contents) {
61 DCHECK(contents); 61 DCHECK(contents);
62 contents_ = contents; 62 contents_ = contents;
63 Browser* browser = BrowserList::GetLastActive(); 63 Browser* browser = BrowserList::GetLastActive();
64 DCHECK(browser); 64 DCHECK(browser);
65 browser->BrowserShowHtmlDialog(this, owning_window); 65 window_ = browser->BrowserShowHtmlDialog(this, owning_window);
66 }
67
68 void HungRendererDialog::HideDialog(TabContents* contents) {
flackr 2011/09/03 17:51:31 You should check that (contents_->GetRenderProcess
wyck 2011/09/06 18:07:35 Done.
69 // Settings |contents_| to NULL prevents the hang monitor from restarting.
70 contents_ = NULL;
71 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_);
72 DCHECK(widget);
73 widget->Close();
66 } 74 }
67 75
68 bool HungRendererDialog::IsDialogModal() const { 76 bool HungRendererDialog::IsDialogModal() const {
69 return false; 77 return false;
70 } 78 }
71 79
72 string16 HungRendererDialog::GetDialogTitle() const { 80 string16 HungRendererDialog::GetDialogTitle() const {
73 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); 81 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE);
74 } 82 }
75 83
(...skipping 11 matching lines...) Expand all
87 } 95 }
88 96
89 std::string HungRendererDialog::GetDialogArgs() const { 97 std::string HungRendererDialog::GetDialogArgs() const {
90 return std::string(); // There are no args used. 98 return std::string(); // There are no args used.
91 } 99 }
92 100
93 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) { 101 void HungRendererDialog::OnDialogClosed(const std::string& json_retval) {
94 // Figure out what the response was. 102 // Figure out what the response was.
95 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false)); 103 scoped_ptr<Value> root(base::JSONReader::Read(json_retval, false));
96 bool response = false; 104 bool response = false;
97 ListValue* list; 105 ListValue* list = NULL;
wyck 2011/09/02 19:18:43 Decided to initialize this too.
98 if (!root.get() || !root->GetAsList(&list) || !list || 106 // If the dialog closes because of a button click then the json is a list
99 !list->GetBoolean(0, &response)) { 107 // containing a single bool. If the dialog closes some other way, then we
100 NOTREACHED() << "json does not describe a valid result"; 108 // assume it means no permission was given to kill tabs.
101 } 109 if (root.get() && root->GetAsList(&list) && list &&
wyck 2011/09/02 19:18:43 Folded into one statement.
102 110 list->GetBoolean(0, &response) && response) {
flackr 2011/09/03 17:51:31 Why not use the result from list->GetBoolean to kn
wyck 2011/09/06 18:07:35 Because if you click the X on the dialog, it close
103 if (response) {
104 // The user indicated that it is OK to kill the renderer process. 111 // The user indicated that it is OK to kill the renderer process.
105 if (contents_ && contents_->GetRenderProcessHost()) { 112 if (contents_ && contents_->GetRenderProcessHost()) {
106 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(), 113 base::KillProcess(contents_->GetRenderProcessHost()->GetHandle(),
107 content::RESULT_CODE_HUNG, false); 114 content::RESULT_CODE_HUNG, false);
108 } 115 }
109 } else { 116 } else {
110 // No indication from the user that it is ok to kill anything. Just wait. 117 // No indication from the user that it is ok to kill anything. Just wait.
111 // Start waiting again for responsiveness. 118 // Start waiting again for responsiveness.
112 if (contents_ && contents_->render_view_host()) 119 if (contents_ && contents_->render_view_host())
113 contents_->render_view_host()->RestartHangMonitorTimeout(); 120 contents_->render_view_host()->RestartHangMonitorTimeout();
114 } 121 }
115
116 g_instance = NULL; 122 g_instance = NULL;
117 delete this; 123 delete this;
118 } 124 }
119 125
120 void HungRendererDialog::OnCloseContents(TabContents* source, 126 void HungRendererDialog::OnCloseContents(TabContents* source,
121 bool* out_close_dialog) { 127 bool* out_close_dialog) {
122 NOTIMPLEMENTED(); 128 NOTIMPLEMENTED();
123 } 129 }
124 130
125 bool HungRendererDialog::ShouldShowDialogTitle() const { 131 bool HungRendererDialog::ShouldShowDialogTitle() const {
(...skipping 27 matching lines...) Expand all
153 DictionaryValue* dict = new DictionaryValue(); 159 DictionaryValue* dict = new DictionaryValue();
154 dict->SetString("url", it->tab_contents()->GetURL().spec()); 160 dict->SetString("url", it->tab_contents()->GetURL().spec());
155 dict->SetString("title", title); 161 dict->SetString("title", title);
156 tab_contents_list.Append(dict); 162 tab_contents_list.Append(dict);
157 } 163 }
158 } 164 }
159 // Send list of tab contents details to javascript. 165 // Send list of tab contents details to javascript.
160 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", 166 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList",
161 tab_contents_list); 167 tab_contents_list);
162 } 168 }
163
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698