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..94615644193d37e331c20bfaa1b0989924e26bc9 |
--- /dev/null |
+++ b/ios/chrome/browser/web/sad_tab_tab_helper.mm |
@@ -0,0 +1,62 @@ |
+// 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"; |
kkhorimoto
2017/04/10 22:31:10
If we continue with the delegate approach, please
PL
2017/04/11 01:35:21
Done: I removed the notion of a tabID altogether.
|
+ |
+SadTabTabHelper::SadTabTabHelper(web::WebState* web_state) |
+ : web::WebStateObserver(web_state) {} |
kkhorimoto
2017/04/10 22:31:10
Since we only want these objects to be constructed
PL
2017/04/11 01:35:21
Done: I've removed these entirely (is this satisfa
kkhorimoto
2017/04/11 02:13:15
A SadTabTabHelper could still be created via WebSt
PL
2017/04/11 03:08:56
Done. Thanks!
|
+ |
+SadTabTabHelper::SadTabTabHelper(web::WebState* web_state, |
+ id<TabHelperDelegate> delegate) |
+ : web::WebStateObserver(web_state) { |
+ this->delegate = delegate; |
kkhorimoto
2017/04/10 22:31:10
After you rename the |delegate| ivar to |delegate_
PL
2017/04/11 01:35:21
Thanks! I wanted to provide for some flexibility a
kkhorimoto
2017/04/11 02:13:15
There's definitely some benefit to using defensive
PL
2017/04/11 03:08:56
Done; makes sense, thanks.
|
+} |
+ |
+SadTabTabHelper::~SadTabTabHelper() = default; |
+ |
+void SadTabTabHelper::CreateForWebState(web::WebState* web_state, |
+ id<TabHelperDelegate> delegate) { |
+ DCHECK(web_state); |
+ if (!FromWebState(web_state)) { |
+ web_state->SetUserData(UserDataKey(), |
+ new SadTabTabHelper(web_state, delegate)); |
+ } |
+} |
+ |
+void SadTabTabHelper::RenderProcessGone() { |
+ if (!delegate || [delegate tabHelperShouldBeActive:helperID()]) { |
+ GURL lastCommittedURL = web_state()->GetLastCommittedURL(); |
+ presentSadTab(lastCommittedURL); |
+ } |
+} |
+ |
+void SadTabTabHelper::presentSadTab(const GURL& urlCausingFailure) { |
+ SadTabView* sadTabView = [[SadTabView alloc] initWithReloadHandler:^{ |
+ web_state()->GetNavigationManager()->Reload(web::ReloadType::NORMAL, true); |
+ }]; |
+ |
+ CRWContentView* contentView = |
+ [[CRWGenericContentView alloc] initWithView:sadTabView]; |
+ |
+ web_state()->ShowTransientContentView(contentView); |
+} |
+ |
+NSString* SadTabTabHelper::helperID() { |
+ return SadTabTabHelperID; |
+} |