Commit f663b438 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS][multiball] Clean up MainControllerGuts

Moves a bunch of methdos and properties that aren't used in
MainController to SceneController and updates call sites.

Bug: none
Change-Id: Ib5b26f5cd402cb435426f23f060c53dac522104a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2012382
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734533}
parent 02d5da92
......@@ -130,7 +130,6 @@
#include "ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
#import "ios/chrome/browser/ui/tab_grid/view_controller_swapping.h"
#import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -348,8 +347,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// browser has started up to the FOREGROUND stage.
@property(nonatomic, readonly) TabGridCoordinator* mainCoordinator;
// Starts a voice search on the current BVC.
- (void)startVoiceSearchInCurrentBVC;
// Returns whether the restore infobar should be displayed.
- (bool)mustShowRestoreInfobar;
// Switch all global states for the given mode (normal or incognito).
......@@ -430,10 +427,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
@implementation MainController
// Defined by MainControllerGuts.
@synthesize historyCoordinator;
@synthesize appURLLoadingService;
@synthesize isProcessingTabSwitcherCommand;
@synthesize isProcessingVoiceSearchCommand;
@synthesize dismissingTabSwitcher = _dismissingTabSwitcher;
@synthesize restoreHelper = _restoreHelper;
......@@ -448,11 +442,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
@synthesize appLaunchTime = _appLaunchTime;
// Defined in private interface
@synthesize mainCoordinator = _mainCoordinator;
@synthesize NTPActionAfterTabSwitcherDismissal =
_NTPActionAfterTabSwitcherDismissal;
@synthesize tabSwitcherIsActive;
@synthesize modeToDisplayOnTabSwitcherDismissal =
_modeToDisplayOnTabSwitcherDismissal;
#pragma mark - Application lifecycle
......@@ -815,9 +805,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
_extensionSearchEngineDataUpdater = nullptr;
[self.historyCoordinator stop];
self.historyCoordinator = nil;
ios::GetChromeBrowserProvider()
->GetMailtoHandlerProvider()
->RemoveMailtoHandling();
......@@ -1426,20 +1413,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
[self switchGlobalStateToMode:mode];
}
- (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox {
ProceduralBlock completion = nil;
if (focusOmnibox) {
__weak BrowserViewController* weakCurrentBVC = self.currentBVC;
completion = ^{
[weakCurrentBVC.dispatcher focusOmnibox];
};
}
[self.mainCoordinator showTabViewController:self.currentBVC
completion:completion];
[self.currentBVC.dispatcher
setIncognitoContentVisible:(self.currentBVC == self.otrBVC)];
}
- (TabModel*)currentTabModel {
return self.currentBVC.tabModel;
}
......@@ -1452,29 +1425,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
return self.currentBVC.browserState;
}
#pragma mark - Tab opening utility methods.
- (ProceduralBlock)completionBlockForTriggeringAction:
(NTPTabOpeningPostOpeningAction)action {
switch (action) {
case START_VOICE_SEARCH:
return ^{
[self startVoiceSearchInCurrentBVC];
};
case START_QR_CODE_SCANNER:
return ^{
[self.currentBVC.dispatcher showQRScanner];
};
case FOCUS_OMNIBOX:
return ^{
[self.currentBVC.dispatcher focusOmnibox];
};
default:
return nil;
}
}
- (bool)mustShowRestoreInfobar {
if ([self isFirstLaunchAfterUpgrade])
return false;
......@@ -1513,18 +1463,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}
#pragma mark - ApplicationCommands helpers
- (void)startVoiceSearchInCurrentBVC {
// If the background (non-current) BVC is playing TTS audio, call
// -startVoiceSearch on it to stop the TTS.
BrowserViewController* backgroundBVC =
self.mainBVC == self.currentBVC ? self.otrBVC : self.mainBVC;
if (backgroundBVC.playingTTS)
[backgroundBVC startVoiceSearch];
else
[self.currentBVC startVoiceSearch];
}
#pragma mark - SceneController plumbing
......
......@@ -13,46 +13,23 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state_forward.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remove_mask.h"
#import "ios/chrome/browser/crash_report/crash_restore_helper.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
@class BrowserViewController;
@class BrowserViewWrangler;
@class HistoryCoordinator;
@class TabGridCoordinator;
@protocol BrowserInterfaceProvider;
@protocol TabSwitcher;
class AppUrlLoadingService;
// Used to update the current BVC mode if a new tab is added while the tab
// switcher view is being dismissed. This is different than ApplicationMode in
// that it can be set to |NONE| when not in use.
enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
// TODO(crbug.com/1012697): Remove this protocol when SceneController is
// operational. Move the private internals back into MainController, and pass
// ownership of Scene-related objects to SceneController.
@protocol MainControllerGuts
// Coordinator for displaying history.
@property(nonatomic, strong) HistoryCoordinator* historyCoordinator;
// The application level component for url loading. Is passed down to
// browser state level UrlLoadingService instances.
@property(nonatomic, assign) AppUrlLoadingService* appURLLoadingService;
// The tab switcher command and the voice search commands can be sent by views
// that reside in a different UIWindow leading to the fact that the exclusive
// touch property will be ineffective and a command for processing both
// commands may be sent in the same run of the runloop leading to
// inconsistencies. Those two boolean indicate if one of those commands have
// been processed in the last 200ms in order to only allow processing one at
// a time.
// TODO(crbug.com/560296): Provide a general solution for handling mutually
// exclusive chrome commands sent at nearly the same time.
@property(nonatomic, assign) BOOL isProcessingTabSwitcherCommand;
@property(nonatomic, assign) BOOL isProcessingVoiceSearchCommand;
// If YES, the tab switcher is currently active.
@property(nonatomic, assign, getter=isTabSwitcherActive)
BOOL tabSwitcherIsActive;
......@@ -60,24 +37,10 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
// YES while animating the dismissal of tab switcher.
@property(nonatomic, assign) BOOL dismissingTabSwitcher;
// If not NONE, the current BVC should be switched to this BVC on completion
// of tab switcher dismissal.
@property(nonatomic, assign)
TabSwitcherDismissalMode modeToDisplayOnTabSwitcherDismissal;
// A property to track whether the QR Scanner should be started upon tab
// switcher dismissal. It can only be YES if the QR Scanner experiment is
// enabled.
@property(nonatomic, readwrite)
NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal;
// Parameters received at startup time when the app is launched from another
// app.
@property(nonatomic, strong) AppStartupParameters* startupParameters;
- (ProceduralBlock)completionBlockForTriggeringAction:
(NTPTabOpeningPostOpeningAction)action;
// Keeps track of the restore state during startup.
@property(nonatomic, strong) CrashRestoreHelper* restoreHelper;
......@@ -91,10 +54,6 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
- (BrowserViewController*)otrBVC;
- (TabGridCoordinator*)mainCoordinator;
- (id<BrowserInterfaceProvider>)interfaceProvider;
- (void)startVoiceSearchInCurrentBVC;
// Sets |currentBVC| as the root view controller for the window.
- (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox;
- (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState
timePeriod:(browsing_data::TimePeriod)timePeriod
......
......@@ -59,6 +59,7 @@ source_set("scene") {
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/signin_interaction",
"//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
......
......@@ -50,6 +50,7 @@
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/signin_interaction/signin_interaction_coordinator.h"
#include "ios/chrome/browser/ui/tab_grid/tab_grid_coordinator.h"
#import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#import "ios/chrome/browser/ui/util/top_view_controller.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
......@@ -97,6 +98,11 @@ enum class EnterTabSwitcherSnapshotResult {
kMaxValue = kPageNotLoadingAndSnapshotSucceeded,
};
// Used to update the current BVC mode if a new tab is added while the tab
// switcher view is being dismissed. This is different than ApplicationMode in
// that it can be set to |NONE| when not in use.
enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
} // namespace
@interface SceneController () <UserFeedbackDataSource,
......@@ -117,6 +123,32 @@ enum class EnterTabSwitcherSnapshotResult {
@property(nonatomic, assign, readonly, getter=isSettingsViewPresented)
BOOL settingsViewPresented;
// Coordinator for displaying history.
@property(nonatomic, strong) HistoryCoordinator* historyCoordinator;
// The tab switcher command and the voice search commands can be sent by views
// that reside in a different UIWindow leading to the fact that the exclusive
// touch property will be ineffective and a command for processing both
// commands may be sent in the same run of the runloop leading to
// inconsistencies. Those two boolean indicate if one of those commands have
// been processed in the last 200ms in order to only allow processing one at
// a time.
// TODO(crbug.com/560296): Provide a general solution for handling mutually
// exclusive chrome commands sent at nearly the same time.
@property(nonatomic, assign) BOOL isProcessingTabSwitcherCommand;
@property(nonatomic, assign) BOOL isProcessingVoiceSearchCommand;
// If not NONE, the current BVC should be switched to this BVC on completion
// of tab switcher dismissal.
@property(nonatomic, assign)
TabSwitcherDismissalMode modeToDisplayOnTabSwitcherDismissal;
// A property to track whether the QR Scanner should be started upon tab
// switcher dismissal. It can only be YES if the QR Scanner experiment is
// enabled.
@property(nonatomic, readwrite)
NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal;
@end
@implementation SceneController
......@@ -188,6 +220,9 @@ enum class EnterTabSwitcherSnapshotResult {
[self.signinInteractionCoordinator cancel];
self.signinInteractionCoordinator = nil;
[self.historyCoordinator stop];
self.historyCoordinator = nil;
self.hasInitializedUI = NO;
}
......@@ -198,15 +233,14 @@ enum class EnterTabSwitcherSnapshotResult {
}
- (void)showHistory {
self.mainController.historyCoordinator = [[HistoryCoordinator alloc]
self.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.mainController.currentBVC
browserState:self.mainController.mainBrowserState];
self.mainController.historyCoordinator.loadStrategy =
self.historyCoordinator.loadStrategy =
[self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL;
self.mainController.historyCoordinator.dispatcher =
self.mainController.mainBVC.dispatcher;
[self.mainController.historyCoordinator start];
self.historyCoordinator.dispatcher = self.mainController.mainBVC.dispatcher;
[self.historyCoordinator start];
}
// Opens an url from a link in the settings UI.
......@@ -250,14 +284,14 @@ enum class EnterTabSwitcherSnapshotResult {
- (void)displayTabSwitcher {
DCHECK(!self.mainController.isTabSwitcherActive);
if (!self.mainController.isProcessingVoiceSearchCommand) {
if (!self.isProcessingVoiceSearchCommand) {
[self.mainController.currentBVC userEnteredTabSwitcher];
[self showTabSwitcher];
self.mainController.isProcessingTabSwitcherCommand = YES;
self.isProcessingTabSwitcherCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.mainController.isProcessingTabSwitcherCommand = NO;
self.isProcessingTabSwitcherCommand = NO;
});
}
}
......@@ -375,13 +409,13 @@ enum class EnterTabSwitcherSnapshotResult {
}
- (void)startVoiceSearch {
if (!self.mainController.isProcessingTabSwitcherCommand) {
[self.mainController startVoiceSearchInCurrentBVC];
self.mainController.isProcessingVoiceSearchCommand = YES;
if (!self.isProcessingTabSwitcherCommand) {
[self startVoiceSearchInCurrentBVC];
self.isProcessingVoiceSearchCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.mainController.isProcessingVoiceSearchCommand = NO;
self.isProcessingVoiceSearchCommand = NO;
});
}
}
......@@ -642,7 +676,7 @@ enum class EnterTabSwitcherSnapshotResult {
// The call to set currentBVC above does not actually display the BVC, because
// _dismissingTabSwitcher is YES. So: Force the BVC transition to start.
[self.mainController displayCurrentBVCAndFocusOmnibox:focusOmnibox];
[self displayCurrentBVCAndFocusOmnibox:focusOmnibox];
}
- (void)finishDismissingTabSwitcher {
......@@ -659,9 +693,8 @@ enum class EnterTabSwitcherSnapshotResult {
self.currentInterface.browser->GetWebStateList()->count() == 0U) {
self.mainController.tabSwitcherIsActive = NO;
self.mainController.dismissingTabSwitcher = NO;
self.mainController.modeToDisplayOnTabSwitcherDismissal =
TabSwitcherDismissalMode::NONE;
self.mainController.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
self.modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
self.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
[self showTabSwitcher];
return;
}
......@@ -672,21 +705,19 @@ enum class EnterTabSwitcherSnapshotResult {
DCHECK_EQ(self.mainController.mainCoordinator.activeViewController,
self.mainController.currentBVC);
if (self.mainController.modeToDisplayOnTabSwitcherDismissal ==
if (self.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::NORMAL) {
[self setCurrentInterfaceForMode:ApplicationMode::NORMAL];
} else if (self.mainController.modeToDisplayOnTabSwitcherDismissal ==
} else if (self.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::INCOGNITO) {
[self setCurrentInterfaceForMode:ApplicationMode::INCOGNITO];
}
self.mainController.modeToDisplayOnTabSwitcherDismissal =
TabSwitcherDismissalMode::NONE;
self.modeToDisplayOnTabSwitcherDismissal = TabSwitcherDismissalMode::NONE;
ProceduralBlock action = [self.mainController
completionBlockForTriggeringAction:
self.mainController.NTPActionAfterTabSwitcherDismissal];
self.mainController.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
ProceduralBlock action = [self completionBlockForTriggeringAction:
self.NTPActionAfterTabSwitcherDismissal];
self.NTPActionAfterTabSwitcherDismissal = NO_ACTION;
if (action) {
action();
}
......@@ -695,6 +726,41 @@ enum class EnterTabSwitcherSnapshotResult {
self.mainController.dismissingTabSwitcher = NO;
}
#pragma mark Tab opening utility methods.
- (ProceduralBlock)completionBlockForTriggeringAction:
(NTPTabOpeningPostOpeningAction)action {
switch (action) {
case START_VOICE_SEARCH:
return ^{
[self startVoiceSearchInCurrentBVC];
};
case START_QR_CODE_SCANNER:
return ^{
[self.mainController.currentBVC.dispatcher showQRScanner];
};
case FOCUS_OMNIBOX:
return ^{
[self.mainController.currentBVC.dispatcher focusOmnibox];
};
default:
return nil;
}
}
// Starts a voice search on the current BVC.
- (void)startVoiceSearchInCurrentBVC {
// If the background (non-current) BVC is playing TTS audio, call
// -startVoiceSearch on it to stop the TTS.
BrowserViewController* backgroundBVC =
self.mainInterface == self.currentInterface ? self.incognitoInterface.bvc
: self.mainInterface.bvc;
if (backgroundBVC.playingTTS)
[backgroundBVC startVoiceSearch];
else
[self.mainController.currentBVC startVoiceSearch];
}
#pragma mark - TabSwitching
- (BOOL)openNewTabFromTabSwitcher {
......@@ -789,11 +855,6 @@ enum class EnterTabSwitcherSnapshotResult {
WebStateList::kInvalidIndex;
}
- (ProceduralBlock)completionBlockForTriggeringAction:
(NTPTabOpeningPostOpeningAction)action {
return [self.mainController completionBlockForTriggeringAction:action];
}
- (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel {
if (self.mainController.tabSwitcherIsActive) {
TabModel* mainTabModel =
......@@ -851,7 +912,7 @@ enum class EnterTabSwitcherSnapshotResult {
self.interfaceProvider.currentInterface = newInterface;
if (!self.mainController.dismissingTabSwitcher)
[self.mainController displayCurrentBVCAndFocusOmnibox:NO];
[self displayCurrentBVCAndFocusOmnibox:NO];
// Tell the BVC that was made current that it can use the web.
[self activateBVCAndMakeCurrentBVCPrimary];
......@@ -959,7 +1020,7 @@ enum class EnterTabSwitcherSnapshotResult {
? self.interfaceProvider.mainInterface
: self.interfaceProvider.incognitoInterface;
NSUInteger tabIndex = NSNotFound;
ProceduralBlock startupCompletion = [self.mainController
ProceduralBlock startupCompletion = [self
completionBlockForTriggeringAction:[self.mainController.startupParameters
postOpeningAction]];
......@@ -985,7 +1046,7 @@ enum class EnterTabSwitcherSnapshotResult {
// note that when the tab switcher finishes dismissing, the current BVC
// should be switched to be the main BVC if necessary.
if (self.mainController.dismissingTabSwitcher) {
self.mainController.modeToDisplayOnTabSwitcherDismissal =
self.modeToDisplayOnTabSwitcherDismissal =
targetMode == ApplicationMode::NORMAL
? TabSwitcherDismissalMode::NORMAL
: TabSwitcherDismissalMode::INCOGNITO;
......@@ -998,7 +1059,7 @@ enum class EnterTabSwitcherSnapshotResult {
} else {
// Voice search, QRScanner and the omnibox are presented by the BVC.
// They must be started after the BVC view is added in the hierarchy.
self.mainController.NTPActionAfterTabSwitcherDismissal =
self.NTPActionAfterTabSwitcherDismissal =
[self.mainController.startupParameters postOpeningAction];
[self.mainController setStartupParameters:nil];
[self.mainController.tabSwitcher
......@@ -1126,6 +1187,24 @@ enum class EnterTabSwitcherSnapshotResult {
}
}
// Displays current (incognito/normal) BVC and optionally focuses the omnibox.
- (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox {
ProceduralBlock completion = nil;
if (focusOmnibox) {
__weak BrowserViewController* weakCurrentBVC =
self.mainController.currentBVC;
completion = ^{
[weakCurrentBVC.dispatcher focusOmnibox];
};
}
[self.mainController.mainCoordinator
showTabViewController:self.currentInterface.bvc
completion:completion];
[self.currentInterface.bvc.dispatcher
setIncognitoContentVisible:(self.currentInterface ==
self.incognitoInterface)];
}
#pragma mark - AppNavigation
- (void)presentSignedInAccountsViewControllerForBrowserState:
......
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