blob: 54c4c9d31aa2ff76ee70b373fd11c0523ee95f9c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "app/resource_bundle.h"
#include "app/l10n_util_mac.h"
#include "base/mac_util.h"
#include "base/process_util.h"
#include "base/sys_string_conversions.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/hung_renderer_dialog.h"
#import "chrome/browser/cocoa/hung_renderer_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/logging_chrome.h"
#include "chrome/common/result_codes.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
namespace {
// We only support showing one of these at a time per app. The
// controller owns itself and is released when its window is closed.
HungRendererController* g_instance = NULL;
} // end namespace
@implementation HungRendererController
- (id)initWithWindowNibName:(NSString*)nibName {
NSString* nibpath = [mac_util::MainAppBundle() pathForResource:nibName
ofType:@"nib"];
self = [super initWithWindowNibPath:nibpath owner:self];
if (self) {
[tableView_ setDataSource:self];
}
return self;
}
- (void)dealloc {
DCHECK(!g_instance);
[super dealloc];
}
- (void)awakeFromNib {
// Load in the image
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
NSImage* backgroundImage = rb.GetNSImageNamed(IDR_FROZEN_TAB_ICON);
DCHECK(backgroundImage);
[imageView_ setImage:backgroundImage];
// Make the message fit.
CGFloat messageShift =
[GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:messageView_];
// Move the graphic up to be top even with the message.
NSRect graphicFrame = [imageView_ frame];
graphicFrame.origin.y += messageShift;
[imageView_ setFrame:graphicFrame];
// Make the window taller to fit everything.
NSSize windowDelta = NSMakeSize(0, messageShift);
[GTMUILocalizerAndLayoutTweaker
resizeWindowWithoutAutoResizingSubViews:[self window]
delta:windowDelta];
}
- (IBAction)kill:(id)sender {
if (hungContents_)
base::KillProcess(hungContents_->process()->process().handle(),
ResultCodes::HUNG, false);
// Cannot call performClose:, because the close button is disabled.
[self close];
}
- (IBAction)wait:(id)sender {
if (hungContents_ && hungContents_->render_view_host())
hungContents_->render_view_host()->RestartHangMonitorTimeout();
// Cannot call performClose:, because the close button is disabled.
[self close];
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return hungRenderers_.size();
}
- (id)tableView:(NSTableView*)aTableView
objectValueForTableColumn:(NSTableColumn*)column
row:(int)rowIndex {
// TODO(rohitrao): Add favicons.
TabContents* contents = hungRenderers_[rowIndex];
string16 title = contents->GetTitle();
if (!title.empty())
return base::SysUTF16ToNSString(title);
return l10n_util::GetNSStringWithFixup(IDS_TAB_UNTITLED_TITLE);
}
- (void)windowWillClose:(NSNotification*)notification {
// We have to reset g_instance before autoreleasing the window,
// because we want to avoid reusing the same dialog if someone calls
// HungRendererDialog::ShowForTabContents() between the autorelease
// call and the actual dealloc.
g_instance = nil;
[self autorelease];
}
- (void)showForTabContents:(TabContents*)contents {
DCHECK(contents);
hungContents_ = contents;
hungRenderers_.clear();
for (TabContentsIterator it; !it.done(); ++it) {
if (it->process() == hungContents_->process())
hungRenderers_.push_back(*it);
}
[tableView_ reloadData];
[[self window] center];
[self showWindow:self];
}
- (void)endForTabContents:(TabContents*)contents {
DCHECK(contents);
DCHECK(hungContents_);
if (hungContents_ && hungContents_->process() == contents->process()) {
// Cannot call performClose:, because the close button is disabled.
[self close];
}
}
@end
@implementation HungRendererController (JustForTesting)
- (NSButton*)killButton {
return killButton_;
}
- (NSButton*)waitButton {
return waitButton_;
}
@end
// static
void HungRendererDialog::ShowForTabContents(TabContents* contents) {
if (!logging::DialogsAreSuppressed()) {
if (!g_instance)
g_instance = [[HungRendererController alloc]
initWithWindowNibName:@"HungRendererDialog"];
[g_instance showForTabContents:contents];
}
}
// static
void HungRendererDialog::HideForTabContents(TabContents* contents) {
if (!logging::DialogsAreSuppressed() && g_instance)
[g_instance endForTabContents:contents];
}
|