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..51d065a552eea5fa99245c43101a2dff0feb1ac2 |
--- /dev/null |
+++ b/ios/chrome/browser/web/sad_tab_tab_helper.mm |
@@ -0,0 +1,55 @@ |
+// 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" |
+#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"; |
+ |
+SadTabTabHelper::SadTabTabHelper(web::WebState* web_state, |
+ id<SadTabTabHelperDelegate> delegate) |
+ : 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).
|
+ delegate_ = 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(); |
+ PresentSadTab(lastCommittedURL); |
+ } |
+} |
+ |
+void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) { |
+ SadTabView* sadTabView = [[SadTabView alloc] initWithReloadHandler:^{ |
+ web_state()->GetNavigationManager()->Reload(web::ReloadType::NORMAL, true); |
+ }]; |
+ |
+ CRWContentView* contentView = |
+ [[CRWGenericContentView alloc] initWithView:sadTabView]; |
+ |
+ web_state()->ShowTransientContentView(contentView); |
+} |