Chromium Code Reviews| Index: ios/chrome/browser/web/sad_tab_tab_helper.mm |
| diff --git a/ios/chrome/browser/web/sad_tab_tab_helper.mm b/ios/chrome/browser/web/sad_tab_tab_helper.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..162de0fa1e9917f3da28d7835e843589c72e808f |
| --- /dev/null |
| +++ b/ios/chrome/browser/web/sad_tab_tab_helper.mm |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/web/sad_tab_tab_helper.h" |
| + |
| +#import <Foundation/Foundation.h> |
| + |
| +#import "base/strings/sys_string_conversions.h" |
|
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
s/import/include (because Objective-C code is guar
peterlaurens
2017/04/11 21:57:27
Done. Interesting too, thanks!
|
| +#import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h" |
| +#import "ios/web/public/navigation_manager.h" |
| +#import "ios/web/public/web_state/ui/crw_generic_content_view.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +DEFINE_WEB_STATE_USER_DATA_KEY(SadTabTabHelper); |
| + |
| +NSString* const SadTabTabHelperID = @"SadTabTabHelper"; |
|
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
Do we still need this?
peterlaurens
2017/04/11 21:57:27
Done. Good catch, thanks!
|
| + |
| +SadTabTabHelper::SadTabTabHelper(web::WebState* web_state) |
| + : web::WebStateObserver(web_state) { |
| + NOTREACHED(); |
| +} |
| + |
| +SadTabTabHelper::SadTabTabHelper(web::WebState* web_state, |
| + id<SadTabTabHelperDelegate> delegate) |
| + : web::WebStateObserver(web_state), delegate_(delegate) { |
| + DCHECK(delegate_); |
| +} |
| + |
| +SadTabTabHelper::~SadTabTabHelper() = default; |
| + |
| +void SadTabTabHelper::CreateForWebState(web::WebState* web_state, |
| + id<SadTabTabHelperDelegate> delegate) { |
| + DCHECK(web_state); |
| + if (!FromWebState(web_state)) { |
| + web_state->SetUserData(UserDataKey(), |
| + new SadTabTabHelper(web_state, delegate)); |
| + } |
| +} |
| + |
| +void SadTabTabHelper::RenderProcessGone() { |
| + if (!delegate_ || [delegate_ isTabVisibleForTabHelper:this]) { |
| + GURL lastCommittedURL = web_state()->GetLastCommittedURL(); |
|
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
s/lastCommittedURL/last_committed_url (because thi
peterlaurens
2017/04/11 21:57:27
Done, thanks!
|
| + PresentSadTab(lastCommittedURL); |
| + } |
| +} |
| + |
| +void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) { |
| + SadTabView* sadTabView = [[SadTabView alloc] initWithReloadHandler:^{ |
|
Eugene But (OOO till 7-30)
2017/04/11 15:17:00
s/sadTabView/sad_tab_view
peterlaurens
2017/04/11 21:57:27
Done!
|
| + web_state()->GetNavigationManager()->Reload(web::ReloadType::NORMAL, true); |
| + }]; |
| + |
| + CRWContentView* contentView = |
| + [[CRWGenericContentView alloc] initWithView:sadTabView]; |
| + |
| + web_state()->ShowTransientContentView(contentView); |
| +} |