- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / tab_contents / sad_tab_controller.mm
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.
4
5 #include "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
6
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"
12
13 namespace chrome {
14
15 SadTab* SadTab::Create(content::WebContents* web_contents, SadTabKind kind) {
16   return new SadTabCocoa(web_contents);
17 }
18
19 SadTabCocoa::SadTabCocoa(content::WebContents* web_contents)
20     : web_contents_(web_contents) {
21 }
22
23 SadTabCocoa::~SadTabCocoa() {
24 }
25
26 void SadTabCocoa::Show() {
27   sad_tab_controller_.reset(
28       [[SadTabController alloc] initWithWebContents:web_contents_]);
29 }
30
31 void SadTabCocoa::Close() {
32   [[sad_tab_controller_ view] removeFromSuperview];
33 }
34
35 }  // namespace chrome
36
37 @implementation SadTabController
38
39 - (id)initWithWebContents:(content::WebContents*)webContents {
40   if ((self = [super initWithNibName:@"SadTab"
41                               bundle:base::mac::FrameworkBundle()])) {
42     webContents_ = webContents;
43
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]];
50     }
51   }
52
53   return self;
54 }
55
56 - (void)awakeFromNib {
57   // If webContents_ is nil, ask view to remove link.
58   if (!webContents_) {
59     SadTabView* sad_view = static_cast<SadTabView*>([self view]);
60     [sad_view removeHelpText];
61   }
62 }
63
64 - (content::WebContents*)webContents {
65   return webContents_;
66 }
67
68 - (void)openLearnMoreAboutCrashLink:(id)sender {
69   // Send the action up through the responder chain.
70   [NSApp sendAction:@selector(openLearnMoreAboutCrashLink:) to:nil from:self];
71 }
72
73 @end