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

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.mm

Issue 2247493003: [Mac] Clean up SadTabView and let SadTabController provide its content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use base::mac::ObjCCast Created 4 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/cocoa/tab_contents/sad_tab_controller.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h"
6 6
7 #include "base/mac/bundle_locations.h"
8 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view_cocoa.h" 7 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_view_cocoa.h"
9 #include "chrome/common/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/strings/grit/components_strings.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 12
12 using content::OpenURLParams; 13 using content::OpenURLParams;
13 using content::Referrer; 14 using content::Referrer;
14 15
15 namespace chrome { 16 namespace chrome {
16 17
17 SadTab* SadTab::Create(content::WebContents* web_contents, SadTabKind kind) { 18 SadTab* SadTab::Create(content::WebContents* web_contents, SadTabKind kind) {
18 return new SadTabCocoa(web_contents); 19 return new SadTabCocoa(web_contents);
19 } 20 }
20 21
21 SadTabCocoa::SadTabCocoa(content::WebContents* web_contents) 22 SadTabCocoa::SadTabCocoa(content::WebContents* web_contents)
22 : web_contents_(web_contents) { 23 : web_contents_(web_contents) {
23 } 24 }
24 25
25 SadTabCocoa::~SadTabCocoa() { 26 SadTabCocoa::~SadTabCocoa() {
26 } 27 }
27 28
28 void SadTabCocoa::Show() { 29 void SadTabCocoa::Show() {
29 sad_tab_controller_.reset( 30 sad_tab_controller_.reset(
30 [[SadTabController alloc] initWithWebContents:web_contents_]); 31 [[SadTabController alloc] initWithWebContents:web_contents_]);
31 } 32 }
32 33
33 void SadTabCocoa::Close() { 34 void SadTabCocoa::Close() {
34 [[sad_tab_controller_ view] removeFromSuperview]; 35 [[sad_tab_controller_ view] removeFromSuperview];
35 } 36 }
36 37
37 } // namespace chrome 38 } // namespace chrome
38 39
39 @implementation SadTabController 40 @interface SadTabController ()<SadTabViewDelegate>
41 @end
42
43 @implementation SadTabController {
44 content::WebContents* webContents_;
45 SadTabView* sadTabView_;
46 }
40 47
41 - (id)initWithWebContents:(content::WebContents*)webContents { 48 - (id)initWithWebContents:(content::WebContents*)webContents {
42 if ((self = [super init])) { 49 if ((self = [super init])) {
43 DCHECK(webContents); 50 DCHECK(webContents);
44 webContents_ = webContents; 51 webContents_ = webContents;
45 52
46 if (webContents_) { // NULL in unit_tests. 53 if (webContents_) { // NULL in unit_tests.
47 NSView* ns_view = webContents_->GetNativeView(); 54 NSView* ns_view = webContents_->GetNativeView();
48 [[self view] setAutoresizingMask: 55 [[self view] setAutoresizingMask:
49 (NSViewWidthSizable | NSViewHeightSizable)]; 56 (NSViewWidthSizable | NSViewHeightSizable)];
50 [ns_view addSubview:[self view]]; 57 [ns_view addSubview:[self view]];
51 [[self view] setFrame:[ns_view bounds]]; 58 [[self view] setFrame:[ns_view bounds]];
52 } 59 }
53 } 60 }
54 61
55 return self; 62 return self;
56 } 63 }
57 64
58 - (void)dealloc { 65 - (void)dealloc {
59 [[sadTabView_ reloadButton] setTarget:nil]; 66 sadTabView_.delegate = nil;
60 [super dealloc]; 67 [super dealloc];
61 } 68 }
62 69
63 - (void)loadView { 70 - (void)loadView {
64 sadTabView_.reset([[SadTabView alloc] init]); 71 sadTabView_ = [[SadTabView new] autorelease];
65 [[sadTabView_ reloadButton] setTarget:self]; 72 sadTabView_.delegate = self;
66 [[sadTabView_ reloadButton] setAction:@selector(reloadPage:)]; 73
67 [self setView:sadTabView_]; 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_;
68 } 81 }
69 82
70 - (content::WebContents*)webContents { 83 - (content::WebContents*)webContents {
71 return webContents_; 84 return webContents_;
72 } 85 }
73 86
74 - (IBAction)reloadPage:(id)sender { 87 - (void)sadTabViewButtonClicked:(SadTabView*)sadTabView {
75 webContents_->GetController().Reload(true); 88 webContents_->GetController().Reload(true);
76 } 89 }
77 90
78 - (void)openLearnMoreAboutCrashLink:(id)sender { 91 - (void)sadTabView:(SadTabView*)sadTabView
79 OpenURLParams params(GURL(chrome::kCrashReasonURL), Referrer(), CURRENT_TAB, 92 helpLinkClickedWithURL:(NSString*)url {
93 OpenURLParams params(GURL(url.UTF8String), Referrer(), CURRENT_TAB,
80 ui::PAGE_TRANSITION_LINK, false); 94 ui::PAGE_TRANSITION_LINK, false);
81 webContents_->OpenURL(params); 95 webContents_->OpenURL(params);
82 } 96 }
83 97
84 @end 98 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698