Commit 2573ac31 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Uses SadTab box in clean.

This CL implements the Sad Tab functionality for the new architecture.

-Adds a delegate setter to SadTab helper since the helper needs to
outlive the Webstate. Since the delegate could previously only be set
on init. This meant that the delegate had to persist until Webstate 
destruction, which is not ideal since we don't want the delegate to be
a coordinator close to root. For this reason the helper is created
as soon as a Webstate is Added and its delegate is added when the Tab is
being displayed.

Screenshot:
https://drive.google.com/open?id=0Byo6-Nuda2jgeHZhbFBYQTl6Qnc

Bug: 
Change-Id: I42c3c6710233b2148cc3bb696e0017db9c3c205f
Reviewed-on: https://chromium-review.googlesource.com/656518Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501641}
parent d63c2034
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "ios/chrome/browser/find_in_page/find_tab_helper.h" #import "ios/chrome/browser/find_in_page/find_tab_helper.h"
#import "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h" #import "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h"
#import "ios/chrome/browser/ssl/ios_security_state_tab_helper.h" #import "ios/chrome/browser/ssl/ios_security_state_tab_helper.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h" #import "ios/chrome/browser/web/tab_id_tab_helper.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -20,6 +21,7 @@ BrowserWebStateListDelegate::~BrowserWebStateListDelegate() = default; ...@@ -20,6 +21,7 @@ BrowserWebStateListDelegate::~BrowserWebStateListDelegate() = default;
void BrowserWebStateListDelegate::WillAddWebState(web::WebState* web_state) { void BrowserWebStateListDelegate::WillAddWebState(web::WebState* web_state) {
FindTabHelper::CreateForWebState(web_state, nil); FindTabHelper::CreateForWebState(web_state, nil);
SadTabTabHelper::CreateForWebState(web_state, nil);
IOSChromeSessionTabHelper::CreateForWebState(web_state); IOSChromeSessionTabHelper::CreateForWebState(web_state);
IOSSecurityStateTabHelper::CreateForWebState(web_state); IOSSecurityStateTabHelper::CreateForWebState(web_state);
TabIdTabHelper::CreateForWebState(web_state); TabIdTabHelper::CreateForWebState(web_state);
......
...@@ -30,6 +30,9 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>, ...@@ -30,6 +30,9 @@ class SadTabTabHelper : public web::WebStateUserData<SadTabTabHelper>,
double repeat_failure_interval, double repeat_failure_interval,
id<SadTabTabHelperDelegate> delegate); id<SadTabTabHelperDelegate> delegate);
// Sets the SadTabHelper delegate.
void SetDelegate(id<SadTabTabHelperDelegate> delegate);
~SadTabTabHelper() override; ~SadTabTabHelper() override;
private: private:
......
...@@ -68,6 +68,10 @@ void SadTabTabHelper::CreateForWebState(web::WebState* web_state, ...@@ -68,6 +68,10 @@ void SadTabTabHelper::CreateForWebState(web::WebState* web_state,
} }
} }
void SadTabTabHelper::SetDelegate(id<SadTabTabHelperDelegate> delegate) {
delegate_ = delegate;
}
void SadTabTabHelper::WasShown() { void SadTabTabHelper::WasShown() {
is_visible_ = true; is_visible_ = true;
......
...@@ -18,6 +18,9 @@ source_set("web_contents") { ...@@ -18,6 +18,9 @@ source_set("web_contents") {
"//ios/chrome/browser/ui/browser_list", "//ios/chrome/browser/ui/browser_list",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators", "//ios/chrome/browser/ui/coordinators",
"//ios/chrome/browser/ui/sad_tab",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web:tab_helper_delegates",
"//ios/clean/chrome/browser/ui/commands", "//ios/clean/chrome/browser/ui/commands",
"//ios/clean/chrome/browser/ui/dialogs/context_menu", "//ios/clean/chrome/browser/ui/dialogs/context_menu",
"//ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs", "//ios/clean/chrome/browser/ui/dialogs/http_auth_dialogs",
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h"
@protocol ApplicationCommands;
namespace web { namespace web {
class WebState; class WebState;
} }
...@@ -14,7 +17,7 @@ class WebState; ...@@ -14,7 +17,7 @@ class WebState;
// A mediator object that provides the relevant properties of a web state // A mediator object that provides the relevant properties of a web state
// to a consumer. // to a consumer.
@interface WebContentsMediator : NSObject @interface WebContentsMediator : NSObject<SadTabTabHelperDelegate>
// Updates to this webState are mediated to the consumer. This can change // Updates to this webState are mediated to the consumer. This can change
// during the lifetime of this object and may be nil. // during the lifetime of this object and may be nil.
...@@ -24,6 +27,9 @@ class WebState; ...@@ -24,6 +27,9 @@ class WebState;
// object and may be nil. // object and may be nil.
@property(nonatomic, weak) id<WebContentsConsumer> consumer; @property(nonatomic, weak) id<WebContentsConsumer> consumer;
// The dispatcher for this mediator.
@property(nonatomic, weak) id<ApplicationCommands> dispatcher;
@end @end
#endif // IOS_CLEAN_CHROME_BROWSER_UI_WEB_CONTENTS_WEB_CONTENTS_MEDIATOR_H_ #endif // IOS_CLEAN_CHROME_BROWSER_UI_WEB_CONTENTS_WEB_CONTENTS_MEDIATOR_H_
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h"
#import "ios/clean/chrome/browser/ui/web_contents/web_contents_consumer.h" #import "ios/clean/chrome/browser/ui/web_contents/web_contents_consumer.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#import "ios/web/public/web_state/ui/crw_generic_content_view.h"
#include "ios/web/public/web_state/web_state.h" #include "ios/web/public/web_state/web_state.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
@implementation WebContentsMediator @implementation WebContentsMediator
@synthesize webState = _webState; @synthesize webState = _webState;
@synthesize consumer = _consumer; @synthesize consumer = _consumer;
@synthesize dispatcher = _dispatcher;
#pragma mark - Properties #pragma mark - Properties
...@@ -60,4 +63,18 @@ ...@@ -60,4 +63,18 @@
} }
} }
#pragma mark - SadTabTabHelperDelegate
- (void)presentSadTabForRepeatedFailure:(BOOL)repeatedFailure {
// Create a SadTabView so |webstate| presents it.
SadTabView* sadTabview = [[SadTabView alloc]
initWithMode:repeatedFailure ? SadTabViewMode::FEEDBACK
: SadTabViewMode::RELOAD
navigationManager:self.webState->GetNavigationManager()];
sadTabview.dispatcher = self.dispatcher;
CRWContentView* contentView =
[[CRWGenericContentView alloc] initWithView:sadTabview];
self.webState->ShowTransientContentView(contentView);
}
@end @end
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "ios/chrome/browser/ui/browser_list/browser.h" #import "ios/chrome/browser/ui/browser_list/browser.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/coordinators/browser_coordinator+internal.h" #import "ios/chrome/browser/ui/coordinators/browser_coordinator+internal.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper.h"
#import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h" #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h"
#import "ios/clean/chrome/browser/ui/dialogs/context_menu/context_menu_dialog_coordinator.h" #import "ios/clean/chrome/browser/ui/dialogs/context_menu/context_menu_dialog_coordinator.h"
#import "ios/clean/chrome/browser/ui/dialogs/context_menu/context_menu_dialog_request.h" #import "ios/clean/chrome/browser/ui/dialogs/context_menu/context_menu_dialog_request.h"
...@@ -60,6 +61,13 @@ ...@@ -60,6 +61,13 @@
self.webState->SetDelegate(_webStateDelegate.get()); self.webState->SetDelegate(_webStateDelegate.get());
self.mediator.webState = self.webState; self.mediator.webState = self.webState;
[self setWebStateOverlayParent]; [self setWebStateOverlayParent];
SadTabTabHelper* sadTabHelper = SadTabTabHelper::FromWebState(self.webState);
// Set the mediator as a SadTabHelper delegate, and set the mediator's
// dispatcher.
if (sadTabHelper) {
sadTabHelper->SetDelegate(self.mediator);
self.mediator.dispatcher = static_cast<id>(self.dispatcher);
}
} }
- (void)start { - (void)start {
...@@ -73,6 +81,9 @@ ...@@ -73,6 +81,9 @@
- (void)stop { - (void)stop {
[self resetWebStateOverlayParent]; [self resetWebStateOverlayParent];
SadTabTabHelper* sadTabHelper = SadTabTabHelper::FromWebState(self.webState);
if (sadTabHelper)
sadTabHelper->SetDelegate(nil);
[super stop]; [super stop];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment