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

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

Issue 7670041: Add --use-more-webui runtime flag to toggle WebUI replacements for native dialogs. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge with trunk. 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
« no previous file with comments | « chrome/browser/ui/webui/hung_renderer_dialog.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/browser_dialogs.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
17 #include "chrome/browser/ui/webui/html_dialog_ui.h"
15 #include "chrome/common/logging_chrome.h" 18 #include "chrome/common/logging_chrome.h"
16 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
17 #include "content/browser/renderer_host/render_view_host.h" 20 #include "content/browser/renderer_host/render_view_host.h"
18 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
19 #include "content/common/result_codes.h" 22 #include "content/common/result_codes.h"
20 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
21 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
22 #include "views/widget/widget.h"
23 25
24 namespace { 26 namespace {
25 HungRendererDialog* g_instance = NULL; 27 HungRendererDialog* g_instance = NULL;
26 const int kHungRendererDialogWidth = 425; 28 const int kHungRendererDialogWidth = 425;
27 const int kHungRendererDialogHeight = 200; 29 const int kHungRendererDialogHeight = 200;
28 } 30 }
29 31
30 namespace browser { 32 namespace browser {
31 33
32 void ShowHungRendererDialog(TabContents* contents) { 34 void ShowHungRendererDialog(TabContents* contents) {
33 HungRendererDialog::ShowHungRendererDialog(contents); 35 if (ChromeWebUI::IsMoreWebUI()) {
36 HungRendererDialog::ShowHungRendererDialog(contents);
37 return;
38 }
39
40 ShowNativeHungRendererDialog(contents);
34 } 41 }
35 42
36 void HideHungRendererDialog(TabContents* contents) { 43 void HideHungRendererDialog(TabContents* contents) {
37 HungRendererDialog::HideHungRendererDialog(contents); 44 if (ChromeWebUI::IsMoreWebUI()) {
45 HungRendererDialog::HideHungRendererDialog(contents);
46 return;
47 }
48
49 HideNativeHungRendererDialog(contents);
38 } 50 }
39 51
40 } // namespace browser 52 } // namespace browser
41 53
42 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
43 // HungRendererDialog public static methods 55 // HungRendererDialog public static methods
44 56
45 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) { 57 void HungRendererDialog::ShowHungRendererDialog(TabContents* contents) {
46 if (!logging::DialogsAreSuppressed()) { 58 if (!logging::DialogsAreSuppressed()) {
47 if (g_instance) 59 if (g_instance)
48 return; 60 return;
49 g_instance = new HungRendererDialog(); 61 g_instance = new HungRendererDialog();
50 g_instance->ShowDialog(contents); 62 g_instance->ShowDialog(contents);
51 } 63 }
52 } 64 }
53 65
54 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) { 66 void HungRendererDialog::HideHungRendererDialog(TabContents* contents) {
55 if (!logging::DialogsAreSuppressed() && g_instance) 67 if (!logging::DialogsAreSuppressed() && g_instance)
56 g_instance->HideDialog(contents); 68 g_instance->HideDialog(contents);
57 } 69 }
58 70
59 71
60 //////////////////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////////////////
61 // HungRendererDialog private methods 73 // HungRendererDialog private methods
62 74
63 HungRendererDialog::HungRendererDialog() 75 HungRendererDialog::HungRendererDialog()
64 : contents_(NULL), 76 : contents_(NULL),
77 handler_(NULL),
65 window_(NULL) { 78 window_(NULL) {
66 } 79 }
67 80
68 void HungRendererDialog::ShowDialog(TabContents* contents) { 81 void HungRendererDialog::ShowDialog(TabContents* contents) {
69 DCHECK(contents); 82 DCHECK(contents);
70 contents_ = contents; 83 contents_ = contents;
71 Browser* browser = BrowserList::GetLastActive(); 84 Browser* browser = BrowserList::GetLastActive();
72 DCHECK(browser); 85 DCHECK(browser);
86 handler_ = new HungRendererDialogHandler(contents_);
73 window_ = browser->BrowserShowHtmlDialog(this, NULL); 87 window_ = browser->BrowserShowHtmlDialog(this, NULL);
74 } 88 }
75 89
76 void HungRendererDialog::HideDialog(TabContents* contents) { 90 void HungRendererDialog::HideDialog(TabContents* contents) {
77 DCHECK(contents); 91 DCHECK(contents);
78 // Don't close the dialog if it's a TabContents for some other renderer. 92 // Don't close the dialog if it's a TabContents for some other renderer.
79 if (contents_ && contents_->GetRenderProcessHost() != 93 if (contents_ && contents_->GetRenderProcessHost() !=
80 contents->GetRenderProcessHost()) 94 contents->GetRenderProcessHost())
81 return; 95 return;
82 // Settings |contents_| to NULL prevents the hang monitor from restarting. 96 // Settings |contents_| to NULL prevents the hang monitor from restarting.
83 // We do this because the close dialog handler runs whether it is trigged by 97 // We do this because the close dialog handler runs whether it is trigged by
84 // the user closing the box, or by being closed externally with widget->Close. 98 // the user closing the box, or by being closed externally with widget->Close.
85 contents_ = NULL; 99 contents_ = NULL;
86 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window_); 100 DCHECK(handler_);
87 DCHECK(widget); 101 handler_->CloseDialog();
88 widget->Close();
89 } 102 }
90 103
91 bool HungRendererDialog::IsDialogModal() const { 104 bool HungRendererDialog::IsDialogModal() const {
92 return false; 105 return false;
93 } 106 }
94 107
95 string16 HungRendererDialog::GetDialogTitle() const { 108 string16 HungRendererDialog::GetDialogTitle() const {
96 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE); 109 return l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE);
97 } 110 }
98 111
99 GURL HungRendererDialog::GetDialogContentURL() const { 112 GURL HungRendererDialog::GetDialogContentURL() const {
100 return GURL(chrome::kChromeUIHungRendererDialogURL); 113 return GURL(chrome::kChromeUIHungRendererDialogURL);
101 } 114 }
102 115
103 void HungRendererDialog::GetWebUIMessageHandlers( 116 void HungRendererDialog::GetWebUIMessageHandlers(
104 std::vector<WebUIMessageHandler*>* handlers) const { 117 std::vector<WebUIMessageHandler*>* handlers) const {
105 handlers->push_back(new HungRendererDialogHandler(contents_)); 118 handlers->push_back(handler_);
106 } 119 }
107 120
108 void HungRendererDialog::GetDialogSize(gfx::Size* size) const { 121 void HungRendererDialog::GetDialogSize(gfx::Size* size) const {
109 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight); 122 size->SetSize(kHungRendererDialogWidth, kHungRendererDialogHeight);
110 } 123 }
111 124
112 std::string HungRendererDialog::GetDialogArgs() const { 125 std::string HungRendererDialog::GetDialogArgs() const {
113 return std::string(); // There are no args used. 126 return std::string(); // There are no args used.
114 } 127 }
115 128
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 161 }
149 162
150 //////////////////////////////////////////////////////////////////////////////// 163 ////////////////////////////////////////////////////////////////////////////////
151 // HungRendererDialogHandler methods 164 // HungRendererDialogHandler methods
152 165
153 HungRendererDialogHandler::HungRendererDialogHandler( 166 HungRendererDialogHandler::HungRendererDialogHandler(
154 TabContents* contents) 167 TabContents* contents)
155 : contents_(contents) { 168 : contents_(contents) {
156 } 169 }
157 170
171 void HungRendererDialogHandler::CloseDialog() {
172 DCHECK(web_ui_);
173 static_cast<HtmlDialogUI*>(web_ui_)->CloseDialog(NULL);
174 }
175
158 void HungRendererDialogHandler::RegisterMessages() { 176 void HungRendererDialogHandler::RegisterMessages() {
159 web_ui_->RegisterMessageCallback("requestTabContentsList", 177 web_ui_->RegisterMessageCallback("requestTabContentsList",
160 NewCallback(this, 178 NewCallback(this,
161 &HungRendererDialogHandler::RequestTabContentsList)); 179 &HungRendererDialogHandler::RequestTabContentsList));
162 } 180 }
163 181
164 void HungRendererDialogHandler::RequestTabContentsList( 182 void HungRendererDialogHandler::RequestTabContentsList(
165 const base::ListValue* args) { 183 const base::ListValue* args) {
166 ListValue tab_contents_list; 184 ListValue tab_contents_list;
167 for (TabContentsIterator it; !it.done(); ++it) { 185 for (TabContentsIterator it; !it.done(); ++it) {
168 if (it->tab_contents()->GetRenderProcessHost() == 186 if (it->tab_contents()->GetRenderProcessHost() ==
169 contents_->GetRenderProcessHost()) { 187 contents_->GetRenderProcessHost()) {
170 string16 title = it->tab_contents()->GetTitle(); 188 string16 title = it->tab_contents()->GetTitle();
171 if (title.empty()) 189 if (title.empty())
172 title = TabContentsWrapper::GetDefaultTitle(); 190 title = TabContentsWrapper::GetDefaultTitle();
173 // Add details for |url| and |title|. 191 // Add details for |url| and |title|.
174 DictionaryValue* dict = new DictionaryValue(); 192 DictionaryValue* dict = new DictionaryValue();
175 dict->SetString("url", it->tab_contents()->GetURL().spec()); 193 dict->SetString("url", it->tab_contents()->GetURL().spec());
176 dict->SetString("title", title); 194 dict->SetString("title", title);
177 tab_contents_list.Append(dict); 195 tab_contents_list.Append(dict);
178 } 196 }
179 } 197 }
180 // Send list of tab contents details to javascript. 198 // Send list of tab contents details to javascript.
181 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList", 199 web_ui_->CallJavascriptFunction("hungRendererDialog.setTabContentsList",
182 tab_contents_list); 200 tab_contents_list);
183 } 201 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/hung_renderer_dialog.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698