Commit 6ae47ad1 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Boxes SadTabView inside SadTabLegacyCoordinator.

Removes all Tab dependencies on displaying the SadTab View.
This is done by creating a SadTabLegacyCoordinator that
encapsulates the SadTabView presentation. This coordinator is owned
and created by BrowserViewController. 

Bug: 
Change-Id: Ic263f26af1ea81a293c05f0944d97e996ff7a6b2
Reviewed-on: https://chromium-review.googlesource.com/651756
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#500000}
parent ab7212bf
...@@ -118,7 +118,6 @@ source_set("tabs_internal") { ...@@ -118,7 +118,6 @@ source_set("tabs_internal") {
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/downloads", "//ios/chrome/browser/ui/downloads",
"//ios/chrome/browser/ui/overscroll_actions", "//ios/chrome/browser/ui/overscroll_actions",
"//ios/chrome/browser/ui/sad_tab",
"//ios/chrome/browser/ui/toolbar", "//ios/chrome/browser/ui/toolbar",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web", "//ios/chrome/browser/web",
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#import "components/signin/ios/browser/manage_accounts_delegate.h" #import "components/signin/ios/browser/manage_accounts_delegate.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper_delegate.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper_delegate.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h"
#include "ios/net/request_tracker.h" #include "ios/net/request_tracker.h"
#include "ios/web/public/user_agent.h" #include "ios/web/public/user_agent.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
...@@ -86,9 +85,8 @@ extern NSString* const kProxyPassthroughHeaderValue; ...@@ -86,9 +85,8 @@ extern NSString* const kProxyPassthroughHeaderValue;
// Chrome's WebContents in that it encapsulates rendering. Acts as the // Chrome's WebContents in that it encapsulates rendering. Acts as the
// delegate for the WebState in order to process info about pages having // delegate for the WebState in order to process info about pages having
// loaded. // loaded.
@interface Tab : NSObject<ManageAccountsDelegate, @interface Tab
PagePlaceholderTabHelperDelegate, : NSObject<ManageAccountsDelegate, PagePlaceholderTabHelperDelegate>
SadTabTabHelperDelegate>
// Browser state associated with this Tab. // Browser state associated with this Tab.
@property(nonatomic, readonly) ios::ChromeBrowserState* browserState; @property(nonatomic, readonly) ios::ChromeBrowserState* browserState;
......
...@@ -93,14 +93,12 @@ ...@@ -93,14 +93,12 @@
#import "ios/chrome/browser/ui/open_in_controller.h" #import "ios/chrome/browser/ui/open_in_controller.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h" #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/prerender_delegate.h" #import "ios/chrome/browser/ui/prerender_delegate.h"
#import "ios/chrome/browser/ui/sad_tab/sad_tab_view.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/web/auto_reload_bridge.h" #import "ios/chrome/browser/web/auto_reload_bridge.h"
#import "ios/chrome/browser/web/external_app_launcher.h" #import "ios/chrome/browser/web/external_app_launcher.h"
#import "ios/chrome/browser/web/navigation_manager_util.h" #import "ios/chrome/browser/web/navigation_manager_util.h"
#import "ios/chrome/browser/web/passkit_dialog_provider.h" #import "ios/chrome/browser/web/passkit_dialog_provider.h"
#include "ios/chrome/browser/web/print_observer.h" #include "ios/chrome/browser/web/print_observer.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"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/web/navigation/navigation_manager_impl.h" #import "ios/web/navigation/navigation_manager_impl.h"
...@@ -1652,21 +1650,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar, ...@@ -1652,21 +1650,6 @@ void TabInfoBarObserver::OnInfoBarReplaced(infobars::InfoBar* old_infobar,
}]; }];
} }
#pragma mark - SadTabTabHelperDelegate
- (void)sadTabHelper:(SadTabTabHelper*)tabHelper
presentSadTabForRepeatedFailure:(BOOL)repeatedFailure {
// Create a SadTabView so |webstate| presents it.
SadTabView* sadTabview = [[SadTabView alloc]
initWithMode:repeatedFailure ? SadTabViewMode::FEEDBACK
: SadTabViewMode::RELOAD
navigationManager:tabHelper->web_state()->GetNavigationManager()];
sadTabview.dispatcher = self.dispatcher;
CRWContentView* contentView =
[[CRWGenericContentView alloc] initWithView:sadTabview];
tabHelper->web_state()->ShowTransientContentView(contentView);
}
@end @end
#pragma mark - TestingSupport #pragma mark - TestingSupport
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h" #import "ios/chrome/browser/web/network_activity_indicator_tab_helper.h"
#import "ios/chrome/browser/web/page_placeholder_tab_helper.h" #import "ios/chrome/browser/web/page_placeholder_tab_helper.h"
#import "ios/chrome/browser/web/repost_form_tab_helper.h" #import "ios/chrome/browser/web/repost_form_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"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
...@@ -67,7 +66,6 @@ void AttachTabHelpers(web::WebState* web_state) { ...@@ -67,7 +66,6 @@ void AttachTabHelpers(web::WebState* web_state) {
BlockedPopupTabHelper::CreateForWebState(web_state); BlockedPopupTabHelper::CreateForWebState(web_state);
FindTabHelper::CreateForWebState(web_state, tab.findInPageControllerDelegate); FindTabHelper::CreateForWebState(web_state, tab.findInPageControllerDelegate);
StoreKitTabHelper::CreateForWebState(web_state); StoreKitTabHelper::CreateForWebState(web_state);
SadTabTabHelper::CreateForWebState(web_state, tab);
PagePlaceholderTabHelper::CreateForWebState(web_state, tab); PagePlaceholderTabHelper::CreateForWebState(web_state, tab);
CaptivePortalDetectorTabHelper::CreateForWebState(web_state); CaptivePortalDetectorTabHelper::CreateForWebState(web_state);
......
...@@ -318,6 +318,7 @@ source_set("ui_internal") { ...@@ -318,6 +318,7 @@ source_set("ui_internal") {
"//ios/chrome/browser/ui/qr_scanner:coordinator", "//ios/chrome/browser/ui/qr_scanner:coordinator",
"//ios/chrome/browser/ui/qr_scanner/requirements", "//ios/chrome/browser/ui/qr_scanner/requirements",
"//ios/chrome/browser/ui/reading_list", "//ios/chrome/browser/ui/reading_list",
"//ios/chrome/browser/ui/sad_tab:coordinator",
"//ios/chrome/browser/ui/stack_view", "//ios/chrome/browser/ui/stack_view",
"//ios/chrome/browser/ui/static_content", "//ios/chrome/browser/ui/static_content",
"//ios/chrome/browser/ui/sync", "//ios/chrome/browser/ui/sync",
......
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
#import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h" #import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h"
#include "ios/chrome/browser/ui/rtl_geometry.h" #include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/sad_tab/sad_tab_legacy_coordinator.h"
#import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h" #import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h"
#import "ios/chrome/browser/ui/stack_view/card_view.h" #import "ios/chrome/browser/ui/stack_view/card_view.h"
#import "ios/chrome/browser/ui/stack_view/page_animation_util.h" #import "ios/chrome/browser/ui/stack_view/page_animation_util.h"
...@@ -172,6 +173,7 @@ ...@@ -172,6 +173,7 @@
#import "ios/chrome/browser/web/error_page_content.h" #import "ios/chrome/browser/web/error_page_content.h"
#import "ios/chrome/browser/web/passkit_dialog_provider.h" #import "ios/chrome/browser/web/passkit_dialog_provider.h"
#import "ios/chrome/browser/web/repost_form_tab_helper.h" #import "ios/chrome/browser/web/repost_form_tab_helper.h"
#import "ios/chrome/browser/web/sad_tab_tab_helper.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_opener.h" #import "ios/chrome/browser/web_state_list/web_state_opener.h"
#include "ios/chrome/grit/ios_chromium_strings.h" #include "ios/chrome/grit/ios_chromium_strings.h"
...@@ -540,6 +542,9 @@ bool IsURLAllowedInIncognito(const GURL& url) { ...@@ -540,6 +542,9 @@ bool IsURLAllowedInIncognito(const GURL& url) {
// Coordinator for Tab History Popup. // Coordinator for Tab History Popup.
LegacyTabHistoryCoordinator* _tabHistoryCoordinator; LegacyTabHistoryCoordinator* _tabHistoryCoordinator;
// Coordinator for displaying Sad Tab.
SadTabLegacyCoordinator* _sadTabCoordinator;
} }
// The browser's side swipe controller. Lazily instantiated on the first call. // The browser's side swipe controller. Lazily instantiated on the first call.
...@@ -1872,6 +1877,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint { ...@@ -1872,6 +1877,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_tabHistoryCoordinator.presentationProvider = self; _tabHistoryCoordinator.presentationProvider = self;
_tabHistoryCoordinator.tabHistoryUIUpdater = _toolbarController; _tabHistoryCoordinator.tabHistoryUIUpdater = _toolbarController;
_sadTabCoordinator = [[SadTabLegacyCoordinator alloc] init];
_sadTabCoordinator.dispatcher = _dispatcher;
if (base::FeatureList::IsEnabled(payments::features::kWebPayments)) { if (base::FeatureList::IsEnabled(payments::features::kWebPayments)) {
_paymentRequestManager = [[PaymentRequestManager alloc] _paymentRequestManager = [[PaymentRequestManager alloc]
initWithBaseViewController:self initWithBaseViewController:self
...@@ -2351,6 +2359,9 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -2351,6 +2359,9 @@ bubblePresenterForFeature:(const base::Feature&)feature
if (tabHelper) if (tabHelper)
tabHelper->SetLauncher(self); tabHelper->SetLauncher(self);
tab.webState->SetDelegate(_webStateDelegate.get()); tab.webState->SetDelegate(_webStateDelegate.get());
// BrowserViewController owns the coordinator that displays the Sad Tab.
if (!SadTabTabHelper::FromWebState(tab.webState))
SadTabTabHelper::CreateForWebState(tab.webState, _sadTabCoordinator);
} }
- (void)uninstallDelegatesForTab:(Tab*)tab { - (void)uninstallDelegatesForTab:(Tab*)tab {
...@@ -4724,6 +4735,10 @@ bubblePresenterForFeature:(const base::Feature&)feature ...@@ -4724,6 +4735,10 @@ bubblePresenterForFeature:(const base::Feature&)feature
[_paymentRequestManager setActiveWebState:newTab.webState]; [_paymentRequestManager setActiveWebState:newTab.webState];
// Update the Sad Tab coordinator webstate so it matches the current tab
// webstate.
_sadTabCoordinator.webState = newTab.webState;
[self tabSelected:newTab]; [self tabSelected:newTab];
DCHECK_EQ(newTab, [model currentTab]); DCHECK_EQ(newTab, [model currentTab]);
[self installDelegatesForTab:newTab]; [self installDelegatesForTab:newTab];
......
...@@ -28,6 +28,19 @@ source_set("sad_tab") { ...@@ -28,6 +28,19 @@ source_set("sad_tab") {
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
} }
source_set("coordinator") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"sad_tab_legacy_coordinator.h",
"sad_tab_legacy_coordinator.mm",
]
deps = [
":sad_tab",
"//ios/chrome/browser/web:tab_helper_delegates",
"//ios/web",
]
}
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
......
// 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.
#ifndef IOS_CHROME_BROWSER_UI_SAD_TAB_SAD_TAB_LEGACY_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_SAD_TAB_SAD_TAB_LEGACY_COORDINATOR_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/web/sad_tab_tab_helper_delegate.h"
@class CommandDispatcher;
namespace web {
class WebState;
}
// Coordinator that displays a SadTab view.
@interface SadTabLegacyCoordinator : NSObject<SadTabTabHelperDelegate>
// The dispatcher for this Coordinator.
@property(nonatomic, weak) CommandDispatcher* dispatcher;
// The web state this SadTabLegacyCoordinator is handling. This might change
// during the life of the Coordinator and might be null.
@property(nonatomic, assign) web::WebState* webState;
@end
#endif // IOS_CHROME_BROWSER_UI_SAD_TAB_SAD_TAB_LEGACY_COORDINATOR_H_
// 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/ui/sad_tab/sad_tab_legacy_coordinator.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"
#include "ios/web/public/web_state/web_state.h"
@implementation SadTabLegacyCoordinator
@synthesize dispatcher = _dispatcher;
@synthesize webState = _webState;
#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 = static_cast<id<ApplicationCommands>>(self.dispatcher);
CRWContentView* contentView =
[[CRWGenericContentView alloc] initWithView:sadTabview];
self.webState->ShowTransientContentView(contentView);
}
@end
...@@ -120,8 +120,7 @@ void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) { ...@@ -120,8 +120,7 @@ void SadTabTabHelper::PresentSadTab(const GURL& url_causing_failure) {
(url_causing_failure.EqualsIgnoringRef(last_failed_url_) && (url_causing_failure.EqualsIgnoringRef(last_failed_url_) &&
seconds_since_last_failure < repeat_failure_interval_); seconds_since_last_failure < repeat_failure_interval_);
[delegate_ sadTabHelper:this [delegate_ presentSadTabForRepeatedFailure:repeated_failure];
presentSadTabForRepeatedFailure:repeated_failure];
last_failed_url_ = url_causing_failure; last_failed_url_ = url_causing_failure;
last_failed_timer_ = base::MakeUnique<base::ElapsedTimer>(); last_failed_timer_ = base::MakeUnique<base::ElapsedTimer>();
......
...@@ -7,14 +7,11 @@ ...@@ -7,14 +7,11 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
class SadTabTabHelper;
// Delegate for SadTabTabHelper. // Delegate for SadTabTabHelper.
@protocol SadTabTabHelperDelegate<NSObject> @protocol SadTabTabHelperDelegate<NSObject>
// Asks the delegate to present a SadTabView. // Asks the delegate to present a SadTabView.
- (void)sadTabHelper:(SadTabTabHelper*)tabHelper - (void)presentSadTabForRepeatedFailure:(BOOL)repeatedFailure;
presentSadTabForRepeatedFailure:(BOOL)repeatedFailure;
@end @end
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
@synthesize sadTabShown = sadTabShown; @synthesize sadTabShown = sadTabShown;
@synthesize repeatedFailure = _repeatedFailure; @synthesize repeatedFailure = _repeatedFailure;
- (void)sadTabHelper:(SadTabTabHelper*)tabHelper - (void)presentSadTabForRepeatedFailure:(BOOL)repeatedFailure {
presentSadTabForRepeatedFailure:(BOOL)repeatedFailure {
self.sadTabShown = YES; self.sadTabShown = YES;
self.repeatedFailure = repeatedFailure; self.repeatedFailure = repeatedFailure;
} }
......
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