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

Unified 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698