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

Side by Side Diff: chrome/browser/ui/views/hung_renderer_view_win.cc

Issue 10806079: Add support for invoking the Windows 8 metro style hung renderer dialog box. The dialog box (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/hung_renderer_view_win.h" 5 #include "chrome/browser/ui/views/hung_renderer_view_win.h"
6 6
7 // static 7 #include "base/win/metro.h"
8 HungRendererDialogView* HungRendererDialogView::Create() { 8 #include "chrome/browser/hang_monitor/hang_crash_dump_win.h"
9 if (!g_instance_) 9 #include "chrome/browser/ui/views/hung_renderer_view.h"
10 g_instance_ = new HungRendererDialogViewWin(); 10 #include "content/public/browser/browser_thread.h"
11 return g_instance_; 11 #include "content/public/browser/render_process_host.h"
12 #include "grit/generated_resources.h"
13 #include "ui/base/l10n/l10n_util.h"
14
15 // Metro functions for displaying and dismissing a dialog box.
16 typedef void (*MetroShowDialogBox)(
17 const wchar_t* title,
18 const wchar_t* content,
19 const wchar_t* button1_label,
20 const wchar_t* button2_label,
21 base::win::MetroDialogButtonPressedHandler button1_handler,
22 base::win::MetroDialogButtonPressedHandler button2_handler);
23
24 typedef void (*MetroDismissDialogBox)();
25
26 using content::BrowserThread;
27 using content::WebContents;
28
29 HungRendererDialogMetro g_instance;
sky 2012/07/24 22:57:03 You need to make this a pointer.
ananta 2012/07/24 23:16:37 Done. This is now accessed via the statc Create an
30
31 bool PlatformShowCustomHungRendererDialog(WebContents* contents) {
32 if (!base::win::IsMetroProcess())
33 return false;
34 g_instance.Show(contents);
35 return true;
12 } 36 }
13 37
14 void HungRendererDialogViewWin::ShowForWebContents(WebContents* contents) { 38 bool PlatformHideCustomHungRendererDialog(WebContents* contents) {
15 HungRendererDialogView::ShowForWebContents(contents); 39 if (!base::win::IsMetroProcess())
40 return false;
41 g_instance.Hide(contents);
42 return true;
16 } 43 }
17 44
18 void HungRendererDialogViewWin::EndForWebContents(WebContents* contents) { 45 // static
19 HungRendererDialogView::EndForWebContents(contents); 46 void HungRendererDialogView::KillRendererProcess(
47 base::ProcessHandle process_handle) {
48 // Try to generate a crash report for the hung process.
49 CrashDumpAndTerminateHungChildProcess(process_handle);
20 } 50 }
51
52 HungRendererDialogMetro::HungRendererDialogMetro()
53 : contents_(NULL),
54 metro_dialog_displayed_(false) {
55 }
56
57 HungRendererDialogMetro::~HungRendererDialogMetro() {
58 }
59
60 void HungRendererDialogMetro::Show(WebContents* contents) {
61 if (!metro_dialog_displayed_ &&
62 HungRendererDialogView::IsFrameActive(contents)) {
63 HMODULE metro_dll = base::win::GetMetroModule();
64 DCHECK(metro_dll);
65 if (metro_dll) {
66 MetroShowDialogBox show_dialog_box = reinterpret_cast<MetroShowDialogBox>
67 (::GetProcAddress(metro_dll, "ShowDialogBox"));
68 DCHECK(show_dialog_box);
69 if (show_dialog_box) {
70 string16 dialog_box_title =
71 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_TITLE);
72
73 string16 kill_button_label =
74 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_END);
75
76 string16 wait_button_label =
77 l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT);
78
79 g_instance.contents_ = contents;
80 metro_dialog_displayed_ = true;
81
82 (*show_dialog_box)(dialog_box_title.c_str(),
83 contents->GetTitle().c_str(),
84 kill_button_label.c_str(),
85 wait_button_label.c_str(),
86 HungRendererDialogMetro::OnMetroKillProcess,
87 HungRendererDialogMetro::OnMetroWait);
88 }
89 }
90 }
91 }
92
93 void HungRendererDialogMetro::Hide(WebContents* contents) {
94 HMODULE metro_dll = base::win::GetMetroModule();
95 DCHECK(metro_dll);
96 if (metro_dll) {
97 MetroDismissDialogBox dismiss_dialog_box =
98 reinterpret_cast<MetroDismissDialogBox>
99 (::GetProcAddress(metro_dll, "DismissDialogBox"));
100 DCHECK(dismiss_dialog_box);
101 if (dismiss_dialog_box) {
102 (*dismiss_dialog_box)();
103 ResetMetroState();
104 }
105 }
106 }
107
108 void HungRendererDialogMetro::ResetMetroState() {
109 metro_dialog_displayed_ = false;
110 contents_ = NULL;
111 }
112
113 // static
114 void HungRendererDialogMetro::OnMetroKillProcess() {
115 // Metro chrome will invoke these handlers on the metro thread. Ensure that
116 // we switch to the UI thread.
117 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
118 BrowserThread::PostTask(
119 BrowserThread::UI, FROM_HERE,
120 base::Bind(HungRendererDialogMetro::OnMetroKillProcess));
121 return;
122 }
123
124 DCHECK(g_instance.contents_);
125
126 HungRendererDialogView::KillRendererProcess(
127 g_instance.contents_->GetRenderProcessHost()->GetHandle());
128
129 // The metro dialog box is dismissed when the button handlers are invoked.
130 g_instance.ResetMetroState();
131 }
132
133 // static
134 void HungRendererDialogMetro::OnMetroWait() {
135 // Metro chrome will invoke these handlers on the metro thread. Ensure that
136 // we switch to the UI thread.
137 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
138 BrowserThread::PostTask(
139 BrowserThread::UI, FROM_HERE,
140 base::Bind(HungRendererDialogMetro::OnMetroWait));
141 return;
142 }
143
144 g_instance.ResetMetroState();
145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698