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

Side by Side Diff: ios/chrome/browser/web/sad_tab_tab_helper.mm

Issue 2807843002: Refactor creation of SadTabView into a tab helper object (Closed)
Patch Set: Change to delegate interface and other misc review changes. Created 3 years, 8 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
(Empty)
1 // Copyright 2017 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 "ios/chrome/browser/web/sad_tab_tab_helper.h"
6
7 #import <Foundation/Foundation.h>
8
9 #import "base/strings/sys_string_conversions.h"
10 #import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h"
11 #import "ios/web/public/navigation_manager.h"
12 #import "ios/web/public/web_state/ui/crw_generic_content_view.h"
13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
18 DEFINE_WEB_STATE_USER_DATA_KEY(SadTabTabHelper);
19
20 NSString* const SadTabTabHelperID = @"SadTabTabHelper";
21
22 SadTabTabHelper::SadTabTabHelper(web::WebState* web_state,
23 id<SadTabTabHelperDelegate> delegate)
24 : web::WebStateObserver(web_state) {
kkhorimoto 2017/04/11 02:13:15 You can use initialization lists to set |delegate_
PL 2017/04/11 03:08:56 Done! (That's cool).
25 delegate_ = delegate;
26 }
27
28 SadTabTabHelper::~SadTabTabHelper() = default;
29
30 void SadTabTabHelper::CreateForWebState(web::WebState* web_state,
31 id<SadTabTabHelperDelegate> delegate) {
32 DCHECK(web_state);
33 if (!FromWebState(web_state)) {
34 web_state->SetUserData(UserDataKey(),
35 new SadTabTabHelper(web_state, delegate));
36 }
37 }
38
39 void SadTabTabHelper::RenderProcessGone() {
40 if (!delegate_ || [delegate_ isTabVisibleForTabHelper:this]) {
41 GURL lastCommittedURL = web_state()->GetLastCommittedURL();
42 PresentSadTab(lastCommittedURL);
43 }
44 }
45
46 void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) {
47 SadTabView* sadTabView = [[SadTabView alloc] initWithReloadHandler:^{
48 web_state()->GetNavigationManager()->Reload(web::ReloadType::NORMAL, true);
49 }];
50
51 CRWContentView* contentView =
52 [[CRWGenericContentView alloc] initWithView:sadTabView];
53
54 web_state()->ShowTransientContentView(contentView);
55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698