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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
7 #include "base/mac/bundle_locations.h"
8 #include "base/mac/mac_util.h"
9 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_view.h"
15 SadTab* SadTab::Create(content::WebContents* web_contents, SadTabKind kind) {
16 return new SadTabCocoa(web_contents);
19 SadTabCocoa::SadTabCocoa(content::WebContents* web_contents)
20 : web_contents_(web_contents) {
23 SadTabCocoa::~SadTabCocoa() {
26 void SadTabCocoa::Show() {
27 sad_tab_controller_.reset(
28 [[SadTabController alloc] initWithWebContents:web_contents_]);
31 void SadTabCocoa::Close() {
32 [[sad_tab_controller_ view] removeFromSuperview];
37 @implementation SadTabController
39 - (id)initWithWebContents:(content::WebContents*)webContents {
40 if ((self = [super initWithNibName:@"SadTab"
41 bundle:base::mac::FrameworkBundle()])) {
42 webContents_ = webContents;
44 if (webContents_) { // NULL in unit_tests.
45 NSView* ns_view = webContents_->GetView()->GetNativeView();
46 [[self view] setAutoresizingMask:
47 (NSViewWidthSizable | NSViewHeightSizable)];
48 [ns_view addSubview:[self view]];
49 [[self view] setFrame:[ns_view bounds]];
56 - (void)awakeFromNib {
57 // If webContents_ is nil, ask view to remove link.
59 SadTabView* sad_view = static_cast<SadTabView*>([self view]);
60 [sad_view removeHelpText];
64 - (content::WebContents*)webContents {
68 - (void)openLearnMoreAboutCrashLink:(id)sender {
69 // Send the action up through the responder chain.
70 [NSApp sendAction:@selector(openLearnMoreAboutCrashLink:) to:nil from:self];