OLD | NEW |
| (Empty) |
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 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | |
6 | |
7 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view_cocoa.h" | |
8 #include "chrome/common/url_constants.h" | |
9 #include "chrome/grit/generated_resources.h" | |
10 #include "components/strings/grit/components_strings.h" | |
11 #include "content/public/browser/web_contents.h" | |
12 | |
13 using content::OpenURLParams; | |
14 using content::Referrer; | |
15 | |
16 namespace chrome { | |
17 | |
18 SadTab* SadTab::Create(content::WebContents* web_contents, SadTabKind kind) { | |
19 return new SadTabCocoa(web_contents); | |
20 } | |
21 | |
22 SadTabCocoa::SadTabCocoa(content::WebContents* web_contents) | |
23 : web_contents_(web_contents) { | |
24 } | |
25 | |
26 SadTabCocoa::~SadTabCocoa() { | |
27 } | |
28 | |
29 void SadTabCocoa::Show() { | |
30 sad_tab_controller_.reset( | |
31 [[SadTabController alloc] initWithWebContents:web_contents_]); | |
32 } | |
33 | |
34 void SadTabCocoa::Close() { | |
35 [[sad_tab_controller_ view] removeFromSuperview]; | |
36 } | |
37 | |
38 } // namespace chrome | |
39 | |
40 @interface SadTabController ()<SadTabViewDelegate> | |
41 @end | |
42 | |
43 @implementation SadTabController { | |
44 content::WebContents* webContents_; | |
45 SadTabView* sadTabView_; | |
46 } | |
47 | |
48 - (id)initWithWebContents:(content::WebContents*)webContents { | |
49 if ((self = [super init])) { | |
50 DCHECK(webContents); | |
51 webContents_ = webContents; | |
52 | |
53 if (webContents_) { // NULL in unit_tests. | |
54 NSView* ns_view = webContents_->GetNativeView(); | |
55 [[self view] setAutoresizingMask: | |
56 (NSViewWidthSizable | NSViewHeightSizable)]; | |
57 [ns_view addSubview:[self view]]; | |
58 [[self view] setFrame:[ns_view bounds]]; | |
59 } | |
60 } | |
61 | |
62 return self; | |
63 } | |
64 | |
65 - (void)dealloc { | |
66 sadTabView_.delegate = nil; | |
67 [super dealloc]; | |
68 } | |
69 | |
70 - (void)loadView { | |
71 sadTabView_ = [[SadTabView new] autorelease]; | |
72 sadTabView_.delegate = self; | |
73 | |
74 [sadTabView_ setTitle:IDS_SAD_TAB_TITLE]; | |
75 [sadTabView_ setMessage:IDS_SAD_TAB_MESSAGE]; | |
76 [sadTabView_ setButtonTitle:IDS_SAD_TAB_RELOAD_LABEL]; | |
77 [sadTabView_ setHelpLinkTitle:IDS_SAD_TAB_LEARN_MORE_LINK | |
78 URL:@(chrome::kCrashReasonURL)]; | |
79 | |
80 self.view = sadTabView_; | |
81 } | |
82 | |
83 - (content::WebContents*)webContents { | |
84 return webContents_; | |
85 } | |
86 | |
87 - (void)sadTabViewButtonClicked:(SadTabView*)sadTabView { | |
88 webContents_->GetController().Reload(true); | |
89 } | |
90 | |
91 - (void)sadTabView:(SadTabView*)sadTabView | |
92 helpLinkClickedWithURL:(NSString*)url { | |
93 OpenURLParams params(GURL(url.UTF8String), Referrer(), CURRENT_TAB, | |
94 ui::PAGE_TRANSITION_LINK, false); | |
95 webContents_->OpenURL(params); | |
96 } | |
97 | |
98 @end | |
OLD | NEW |