Commit 84d1f087 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Cleanup Scene/Main Controller Guts.

Cleans up the Guts protocols from things that are no longer used.
Uses interfaceProvider everywhere instead of alternative accessors.

Bug: 1045659, 1045660
Change-Id: Ib3355505686c6b034e98373d380330dff256d8af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087675
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748190}
parent db0eaaec
......@@ -1164,7 +1164,10 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}
- (ChromeBrowserState*)currentBrowserState {
return self.currentBVC.browserState;
if (!self.interfaceProvider.currentInterface.browser) {
return nullptr;
}
return self.interfaceProvider.currentInterface.browser->GetBrowserState();
}
- (bool)mustShowRestoreInfobar {
......@@ -1206,12 +1209,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
#pragma mark - SceneController plumbing
- (BOOL)currentPageIsIncognito {
return [self currentBrowserState] -> IsOffTheRecord();
}
#pragma mark - BrowsingDataCommands
- (void)removeBrowsingDataForBrowserState:(ChromeBrowserState*)browserState
......
......@@ -16,10 +16,7 @@
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
@class AppState;
@class BrowserViewController;
class ChromeBrowserState;
@class TabGridCoordinator;
@protocol BrowserInterfaceProvider;
// TODO(crbug.com/1012697): Remove this protocol when SceneController is
// operational. Move the private internals back into MainController, and pass
......@@ -40,13 +37,7 @@ class ChromeBrowserState;
// Keeps track of the restore state during startup.
@property(nonatomic, strong) CrashRestoreHelper* restoreHelper;
- (TabModel*)currentTabModel;
- (ChromeBrowserState*)mainBrowserState;
- (ChromeBrowserState*)currentBrowserState;
- (BrowserViewController*)currentBVC;
- (BrowserViewController*)mainBVC;
- (BrowserViewController*)otrBVC;
- (id<BrowserInterfaceProvider>)interfaceProvider;
- (UIWindow*)window;
- (NSDictionary*)launchOptions;
- (AppState*)appState;
......
......@@ -118,6 +118,10 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
SettingsNavigationControllerDelegate,
WebStateListObserving>
// The scene level component for url loading. Is passed down to
// browser state level UrlLoadingService instances.
@property(nonatomic, assign) AppUrlLoadingService* appURLLoadingService;
// A flag that keeps track of the UI initialization for the controlled scene.
@property(nonatomic, assign) BOOL hasInitializedUI;
......@@ -216,19 +220,19 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
}
- (id<BrowserInterface>)mainInterface {
return self.mainController.interfaceProvider.mainInterface;
return self.browserViewWrangler.mainInterface;
}
- (id<BrowserInterface>)currentInterface {
return self.mainController.interfaceProvider.currentInterface;
return self.browserViewWrangler.currentInterface;
}
- (id<BrowserInterface>)incognitoInterface {
return self.mainController.interfaceProvider.incognitoInterface;
return self.browserViewWrangler.incognitoInterface;
}
- (id<BrowserInterfaceProvider>)interfaceProvider {
return self.mainController.interfaceProvider;
return self.browserViewWrangler;
}
- (BOOL)isSettingsViewPresented {
......@@ -507,10 +511,10 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (void)showHistory {
self.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.mainController.currentBVC
initWithBaseViewController:self.currentInterface.bvc
browser:self.mainInterface.browser];
self.historyCoordinator.loadStrategy =
[self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
self.currentInterface.incognito ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL;
[self.historyCoordinator start];
}
......@@ -526,7 +530,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (void)prepareTabSwitcher {
web::WebState* currentWebState =
self.mainController.currentBVC.tabModel.webStateList->GetActiveWebState();
self.currentInterface.browser->GetWebStateList()->GetActiveWebState();
if (currentWebState) {
BOOL loading = currentWebState->IsLoading();
SnapshotTabHelper::FromWebState(currentWebState)
......@@ -556,7 +560,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (void)displayTabSwitcher {
DCHECK(!self.mainController.isTabSwitcherActive);
if (!self.isProcessingVoiceSearchCommand) {
[self.mainController.currentBVC userEnteredTabSwitcher];
[self.currentInterface.bvc userEnteredTabSwitcher];
[self showTabSwitcher];
self.isProcessingTabSwitcherCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
......@@ -712,12 +716,12 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.mainController.currentBVC,
DCHECK_EQ(self.currentInterface.bvc,
self.mainCoordinator.activeViewController);
baseViewController = self.mainController.currentBVC;
baseViewController = self.currentInterface.bvc;
}
if ([self.mainController currentBrowserState] -> IsOffTheRecord()) {
if (self.currentInterface.incognito) {
NOTREACHED();
return;
}
......@@ -741,9 +745,9 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.mainController.currentBVC,
DCHECK_EQ(self.currentInterface.bvc,
self.mainCoordinator.activeViewController);
baseViewController = self.mainController.currentBVC;
baseViewController = self.currentInterface.bvc;
}
if (self.settingsNavigationController) {
......@@ -789,7 +793,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
if (!baseViewController) {
// TODO(crbug.com/779791): Don't pass base view controller through
// dispatched command.
baseViewController = [self.mainController currentBVC];
baseViewController = self.currentInterface.bvc;
}
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (self.settingsNavigationController) {
......@@ -862,11 +866,15 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
#pragma mark - UserFeedbackDataSource
- (BOOL)currentPageIsIncognito {
return self.currentInterface.incognito;
}
- (NSString*)currentPageDisplayURL {
if (self.mainController.tabSwitcherIsActive)
return nil;
web::WebState* webState =
self.mainController.currentTabModel.webStateList->GetActiveWebState();
self.currentInterface.browser->GetWebStateList()->GetActiveWebState();
if (!webState)
return nil;
// Returns URL of browser tab that is currently showing.
......@@ -887,7 +895,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
}
- (NSString*)currentPageSyncedUserName {
ChromeBrowserState* browserState = self.mainController.currentBrowserState;
ChromeBrowserState* browserState = self.currentBrowserState;
if (browserState->IsOffTheRecord())
return nil;
signin::IdentityManager* identity_manager =
......@@ -896,10 +904,6 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
return username.empty() ? nil : base::SysUTF8ToNSString(username);
}
- (BOOL)currentPageIsIncognito {
return self.mainController.currentBrowserState->IsOffTheRecord();
}
#pragma mark - SettingsNavigationControllerDelegate
- (void)closeSettings {
......@@ -913,7 +917,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (id<ApplicationCommands, BrowserCommands>)dispatcherForSettings {
// Assume that settings always wants the dispatcher from the main BVC.
return self.mainController.mainBVC.dispatcher;
return self.mainInterface.bvc.dispatcher;
}
#pragma mark - TabSwitcherDelegate
......@@ -929,6 +933,10 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
[self finishDismissingTabSwitcher];
}
// Begins the process of dismissing the tab switcher with the given current
// model, switching which BVC is suspended if necessary, but not updating the
// UI. The omnibox will be focused after the tab switcher dismissal is
// completed if |focusOmnibox| is YES.
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox {
DCHECK(tabModel == self.mainInterface.tabModel ||
......@@ -945,6 +953,8 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
[self displayCurrentBVCAndFocusOmnibox:focusOmnibox];
}
// Completes the process of dismissing the tab switcher, removing it from the
// screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher {
// In real world devices, it is possible to have an empty tab model at the
// finishing block of a BVC presentation animation. This can happen when the
......@@ -969,7 +979,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
// as part of the BVC presentation process. The BVC is presented before the
// animations begin, so it should be the current active VC at this point.
DCHECK_EQ(self.mainCoordinator.activeViewController,
self.mainController.currentBVC);
self.currentInterface.bvc);
if (self.modeToDisplayOnTabSwitcherDismissal ==
TabSwitcherDismissalMode::NORMAL) {
......@@ -1003,11 +1013,17 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
};
case START_QR_CODE_SCANNER:
return ^{
[self.mainController.currentBVC.dispatcher showQRScanner];
id<QRScannerCommands> QRHandler = HandlerForProtocol(
self.currentInterface.browser->GetCommandDispatcher(),
QRScannerCommands);
[QRHandler showQRScanner];
};
case FOCUS_OMNIBOX:
return ^{
[self.mainController.currentBVC.dispatcher focusOmnibox];
id<OmniboxFocuser> focusHandler = HandlerForProtocol(
self.currentInterface.browser->GetCommandDispatcher(),
OmniboxFocuser);
[focusHandler focusOmnibox];
};
default:
return nil;
......@@ -1024,7 +1040,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
if (backgroundBVC.playingTTS)
[backgroundBVC startVoiceSearch];
else
[self.mainController.currentBVC startVoiceSearch];
[self.currentInterface.bvc startVoiceSearch];
}
#pragma mark - TabSwitching
......@@ -1080,18 +1096,16 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
}
- (BOOL)URLIsOpenedInRegularMode:(const GURL&)URL {
WebStateList* webStateList =
self.mainController.interfaceProvider.mainInterface.tabModel.webStateList;
WebStateList* webStateList = self.mainInterface.browser->GetWebStateList();
return webStateList && webStateList->GetIndexOfWebStateWithURL(URL) !=
WebStateList::kInvalidIndex;
}
- (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel {
if (self.mainController.tabSwitcherIsActive) {
TabModel* mainTabModel =
self.mainController.interfaceProvider.mainInterface.tabModel;
TabModel* mainTabModel = self.browserViewWrangler.mainInterface.tabModel;
TabModel* otrTabModel =
self.mainController.interfaceProvider.incognitoInterface.tabModel;
self.browserViewWrangler.incognitoInterface.tabModel;
// Only attempt to dismiss the tab switcher and open a new tab if:
// - there are no tabs open in either tab model, and
// - the tab switcher controller is not directly or indirectly presenting
......@@ -1168,7 +1182,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
// Then, depending on what the SSO view controller is presented on, dismiss
// it.
ProceduralBlock completionWithBVC = ^{
DCHECK(self.mainController.currentBVC);
DCHECK(self.currentInterface.bvc);
DCHECK(!self.mainController.tabSwitcherIsActive);
DCHECK(!self.signinInteractionCoordinator.isActive);
// This will dismiss the SSO view controller.
......@@ -1177,7 +1191,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
dismissOmnibox:dismissOmnibox];
};
ProceduralBlock completionWithoutBVC = ^{
// |self.mainController.currentBVC| may exist but tab switcher should be
// |self.currentInterface.bvc| may exist but tab switcher should be
// active.
DCHECK(self.mainController.tabSwitcherIsActive);
// This will dismiss the SSO view controller.
......@@ -1297,7 +1311,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
atIndex:tabIndex];
}
} else {
if (!self.mainController.currentBVC.presentedViewController) {
if (!self.currentInterface.bvc.presentedViewController) {
[targetInterface.bvc expectNewForegroundTab];
}
[self setCurrentInterfaceForMode:targetMode];
......@@ -1331,23 +1345,22 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (void)openNewTabFromOriginPoint:(CGPoint)originPoint
focusOmnibox:(BOOL)focusOmnibox {
[self.mainController.currentBVC openNewTabFromOriginPoint:originPoint
[self.currentInterface.bvc openNewTabFromOriginPoint:originPoint
focusOmnibox:focusOmnibox];
}
- (ChromeBrowserState*)currentBrowserState {
return self.mainController.interfaceProvider.currentInterface.browserState;
return self.browserViewWrangler.currentInterface.browserState;
}
- (TabModel*)currentTabModel {
return self.mainController.interfaceProvider.currentInterface.bvc.tabModel;
return self.browserViewWrangler.currentInterface.bvc.tabModel;
}
// Asks the respective Snapshot helper to update the snapshot for the active
// WebState.
- (void)updateActiveWebStateSnapshot {
WebStateList* webStateList =
self.mainController.currentBVC.tabModel.webStateList;
WebStateList* webStateList = self.currentInterface.bvc.tabModel.webStateList;
if (webStateList) {
web::WebState* webState = webStateList->GetActiveWebState();
if (webState) {
......@@ -1367,8 +1380,8 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
tabOpenedCompletion:(ProceduralBlock)tabOpenedCompletion {
BrowserViewController* targetBVC =
targetMode == ApplicationMode::NORMAL
? self.mainController.interfaceProvider.mainInterface.bvc
: self.mainController.interfaceProvider.incognitoInterface.bvc;
? self.browserViewWrangler.mainInterface.bvc
: self.browserViewWrangler.incognitoInterface.bvc;
web::WebState* currentWebState =
targetBVC.tabModel.webStateList->GetActiveWebState();
......@@ -1416,8 +1429,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
- (void)displayCurrentBVCAndFocusOmnibox:(BOOL)focusOmnibox {
ProceduralBlock completion = nil;
if (focusOmnibox) {
__weak BrowserViewController* weakCurrentBVC =
self.mainController.currentBVC;
__weak BrowserViewController* weakCurrentBVC = self.currentInterface.bvc;
completion = ^{
[weakCurrentBVC.dispatcher focusOmnibox];
};
......@@ -1436,7 +1448,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
UIViewController* accountsViewController =
[[SignedInAccountsViewController alloc]
initWithBrowserState:browserState
dispatcher:self.mainController.mainBVC.dispatcher];
dispatcher:self.mainInterface.bvc.dispatcher];
[[self topPresentedViewController]
presentViewController:accountsViewController
animated:YES
......@@ -1525,11 +1537,11 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
// regular tab or creating a new incognito tab from the settings menu) will
// take care of the logic to mode switch.
if (self.mainController.tabSwitcherIsActive ||
![self.mainController.currentTabModel isOffTheRecord]) {
![self.currentTabModel isOffTheRecord]) {
return;
}
if ([self.mainController.currentTabModel count] == 0U) {
if ([self.currentTabModel count] == 0U) {
[self showTabSwitcher];
} else {
[self setCurrentInterfaceForMode:ApplicationMode::NORMAL];
......@@ -1545,13 +1557,15 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
// current.
// Nothing to do here.
if (self.mainController.tabSwitcherIsActive ||
[self.mainController.currentTabModel isOffTheRecord]) {
[self.currentTabModel isOffTheRecord]) {
return;
}
[self showTabSwitcher];
}
// Clears incognito data that is specific to iOS and won't be cleared by
// deleting the browser state.
- (void)clearIOSSpecificIncognitoData {
DCHECK(self.mainController.mainBrowserState
->HasOffTheRecordChromeBrowserState());
......@@ -1577,7 +1591,7 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
self.interfaceProvider.mainInterface.userInteractionEnabled = YES;
self.interfaceProvider.incognitoInterface.userInteractionEnabled = YES;
[self.mainController.currentBVC setPrimary:YES];
[self.currentInterface.bvc setPrimary:YES];
}
- (void)showTabSwitcher {
......
......@@ -17,7 +17,6 @@
class ChromeBrowserState;
@class BrowserViewWrangler;
@class TabModel;
@protocol SceneControllerGuts <WebStateListObserving>
......@@ -26,24 +25,9 @@ class ChromeBrowserState;
// BrowserViewInformation protocol.
@property(nonatomic, strong) BrowserViewWrangler* browserViewWrangler;
// The scene level component for url loading. Is passed down to
// browser state level UrlLoadingService instances.
@property(nonatomic, assign) AppUrlLoadingService* appURLLoadingService;
- (void)startUpChromeUIPostCrash:(BOOL)isPostCrashLaunch
needRestoration:(BOOL)needsRestoration;
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
- (void)openSelectedTabInMode:(ApplicationModeForTabOpening)tabOpeningTargetMode
withUrlLoadParams:(const UrlLoadParams&)urlLoadParams
completion:(ProceduralBlock)completion;
- (void)openTabFromLaunchOptions:(NSDictionary*)launchOptions
startupInformation:(id<StartupInformation>)startupInformation
appState:(AppState*)appState;
- (void)dismissModalsAndOpenSelectedTabInMode:
(ApplicationModeForTabOpening)targetMode
withUrlLoadParams:
......@@ -51,27 +35,15 @@ class ChromeBrowserState;
dismissOmnibox:(BOOL)dismissOmnibox
completion:(ProceduralBlock)completion;
- (BOOL)shouldOpenNTPTabOnActivationOfTabModel:(TabModel*)tabModel;
// TabSwitcherDelegate helpers
// Begins the process of dismissing the tab switcher with the given current
// model, switching which BVC is suspended if necessary, but not updating the
// UI. The omnibox will be focused after the tab switcher dismissal is
// completed if |focusOmnibox| is YES.
- (void)beginDismissingTabSwitcherWithCurrentModel:(TabModel*)tabModel
focusOmnibox:(BOOL)focusOmnibox;
// Completes the process of dismissing the tab switcher, removing it from the
// screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher;
- (BOOL)presentingFirstRunUI;
// Testing only.
- (BOOL)presentingFirstRunUI;
- (void)showFirstRunUI;
- (void)setTabSwitcher:(id<TabSwitcher>)switcher;
- (id<TabSwitcher>)tabSwitcher;
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
#pragma mark - AppNavigation helpers
// Presents a SignedInAccountsViewController for |browserState| on the top view
......@@ -79,12 +51,6 @@ class ChromeBrowserState;
- (void)presentSignedInAccountsViewControllerForBrowserState:
(ChromeBrowserState*)browserState;
// Clears incognito data that is specific to iOS and won't be cleared by
// deleting the browser state.
- (void)clearIOSSpecificIncognitoData;
- (void)activateBVCAndMakeCurrentBVCPrimary;
#pragma mark - iOS 12 compat
// Method called on SceneController when the scene disconnects. Exposed here for
......
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