Commit 4e26f273 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Move -createInitialUI to SceneController.

* Moves -createInitialUI method to SceneController
* Reparents TabSwitcher
* Moves the call to CustomizeUIAppearance() outside of per-window
code section
* Removes a   DCHECK(!_mainCoordinator) that relies on an ivar in
MainController (vs a lazy getter). This can be re-added when we move
mainCoordinator.

Bug: 1045657, 1045658
Change-Id: Ia8b91bdb9c0116b71b253b88c89d948aefe3a1d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2084674
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746778}
parent 1c0d373b
......@@ -127,7 +127,6 @@
#import "ios/chrome/browser/ui/promos/signin_promo_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#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/ui_feature_flags.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
......@@ -282,8 +281,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// The object that drives the Chrome startup/shutdown logic.
std::unique_ptr<IOSChromeMain> _chromeMain;
// TabSwitcher object -- the tab grid.
id<TabSwitcher> _tabSwitcher;
// True if the current session began from a cold start. False if the app has
// entered the background at least once since start up.
......@@ -381,8 +378,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
- (void)scheduleDeleteTempPasswordsDirectory;
// Returns whether or not the app can launch in incognito mode.
- (BOOL)canLaunchInIncognito;
// Determines which UI should be shown on startup, and shows it.
- (void)createInitialUI:(ApplicationMode)launchMode;
// Initializes the first run UI and presents it to the user.
- (void)showFirstRunUI;
// Schedules presentation of the first eligible promo found, if any.
......@@ -642,8 +637,9 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
if (switchFromIncognito)
startInIncognito = NO;
[self createInitialUI:(startInIncognito ? ApplicationMode::INCOGNITO
: ApplicationMode::NORMAL)];
[self.sceneController
createInitialUI:(startInIncognito ? ApplicationMode::INCOGNITO
: ApplicationMode::NORMAL)];
[self.sceneController.browserViewWrangler updateDeviceSharingManager];
......@@ -657,6 +653,8 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
// End of per-window code.
CustomizeUIAppearance();
[self scheduleStartupCleanupTasks];
[MetricsMediator
logLaunchMetricsWithStartupInformation:self
......@@ -1173,71 +1171,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
return ![self.otrTabModel isEmpty];
}
- (void)createInitialUI:(ApplicationMode)launchMode {
DCHECK(self.mainBrowserState);
// In order to correctly set the mode switch icon, we need to know how many
// tabs are in the other tab model. That means loading both models. They
// may already be loaded.
// TODO(crbug.com/546203): Find a way to handle this that's closer to the
// point where it is necessary.
TabModel* mainTabModel = self.mainTabModel;
TabModel* otrTabModel = self.otrTabModel;
// MainCoordinator shouldn't have been initialized yet.
DCHECK(!_mainCoordinator);
// Enables UI initializations to query the keyWindow's size.
[self.window makeKeyAndVisible];
CustomizeUIAppearance();
// Lazy init of mainCoordinator.
[self.mainCoordinator start];
_tabSwitcher = self.mainCoordinator.tabSwitcher;
// Call -restoreInternalState so that the grid shows the correct panel.
[_tabSwitcher restoreInternalStateWithMainBrowser:self.mainBrowser
otrBrowser:self.otrBrowser
activeBrowser:self.currentBrowser];
// Decide if the First Run UI needs to run.
BOOL firstRun = (FirstRun::IsChromeFirstRun() ||
experimental_flags::AlwaysDisplayFirstRun()) &&
!tests_hook::DisableFirstRun();
[self.sceneController.browserViewWrangler switchGlobalStateToMode:launchMode];
TabModel* tabModel;
if (launchMode == ApplicationMode::INCOGNITO) {
tabModel = otrTabModel;
[self.sceneController
setCurrentInterfaceForMode:ApplicationMode::INCOGNITO];
} else {
tabModel = mainTabModel;
[self.sceneController setCurrentInterfaceForMode:ApplicationMode::NORMAL];
}
if (self.tabSwitcherIsActive) {
DCHECK(!self.dismissingTabSwitcher);
[self.sceneController
beginDismissingTabSwitcherWithCurrentModel:self.mainTabModel
focusOmnibox:NO];
[self.sceneController finishDismissingTabSwitcher];
}
if (firstRun ||
[self.sceneController shouldOpenNTPTabOnActivationOfTabModel:tabModel]) {
OpenNewTabCommand* command = [OpenNewTabCommand
commandWithIncognito:(self.currentBVC == self.otrBVC)];
command.userInitiated = NO;
[self.currentBVC.dispatcher openURLInNewTab:command];
}
if (firstRun) {
[self showFirstRunUI];
// Do not ever show the 'restore' infobar during first run.
self.restoreHelper = nil;
}
}
- (void)showFirstRunUI {
// Register for notification when First Run is completed.
......@@ -1512,11 +1445,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}));
}
#pragma mark - MainControllerGuts
- (id<TabSwitcher>)tabSwitcher {
return _tabSwitcher;
}
@end
......@@ -1535,7 +1463,11 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
}
- (void)setTabSwitcher:(id<TabSwitcher>)switcher {
_tabSwitcher = switcher;
[self.sceneController setTabSwitcher:switcher];
}
- (id<TabSwitcher>)tabSwitcher {
return self.sceneController.tabSwitcher;
}
- (void)setTabSwitcherActive:(BOOL)active {
......
......@@ -17,7 +17,6 @@
class ChromeBrowserState;
@class TabGridCoordinator;
@protocol BrowserInterfaceProvider;
@protocol TabSwitcher;
// TODO(crbug.com/1012697): Remove this protocol when SceneController is
// operational. Move the private internals back into MainController, and pass
......@@ -38,7 +37,6 @@ class ChromeBrowserState;
// Keeps track of the restore state during startup.
@property(nonatomic, strong) CrashRestoreHelper* restoreHelper;
- (id<TabSwitcher>)tabSwitcher;
- (TabModel*)currentTabModel;
- (ChromeBrowserState*)mainBrowserState;
- (ChromeBrowserState*)currentBrowserState;
......@@ -47,12 +45,15 @@ class ChromeBrowserState;
- (BrowserViewController*)otrBVC;
- (TabGridCoordinator*)mainCoordinator;
- (id<BrowserInterfaceProvider>)interfaceProvider;
- (UIWindow*)window;
- (void)removeBrowsingDataForBrowserState:(ChromeBrowserState*)browserState
timePeriod:(browsing_data::TimePeriod)timePeriod
removeMask:(BrowsingDataRemoveMask)removeMask
completionBlock:(ProceduralBlock)completionBlock;
- (void)showFirstRunUI;
@end
#endif // IOS_CHROME_APP_MAIN_CONTROLLER_GUTS_H_
......@@ -30,11 +30,12 @@ class GURL;
@interface MainController (TestingOnly)
@property(nonatomic, readonly) DeviceSharingManager* deviceSharingManager;
@property(nonatomic, retain) id<TabSwitcher> tabSwitcher;
// Tab switcher state.
@property(nonatomic, getter=isTabSwitcherActive) BOOL tabSwitcherActive;
@property(nonatomic, strong) id<TabSwitcher> tabSwitcher;
// Sets the internal startup state to indicate that the launch was triggered
// by an external app opening the given URL.
- (void)setStartupParametersWithURL:(const GURL&)launchURL;
......
......@@ -7,8 +7,10 @@ import("//ios/build/chrome_build.gni")
source_set("scene_guts") {
sources = [ "scene_controller_guts.h" ]
deps = [
"//ios/chrome/app:mode",
"//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/browser:utils",
"//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list",
]
......@@ -34,6 +36,7 @@ source_set("scene") {
"//components/signin/public/identity_manager",
"//components/url_formatter",
"//ios/chrome/app:app",
"//ios/chrome/app:tests_hook",
"//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/browser",
"//ios/chrome/browser:chrome_url_constants",
......@@ -43,11 +46,13 @@ source_set("scene") {
"//ios/chrome/browser/crash_report:crash_report_internal",
"//ios/chrome/browser/crash_report/breadcrumbs",
"//ios/chrome/browser/crash_report/breadcrumbs:feature_flags",
"//ios/chrome/browser/first_run",
"//ios/chrome/browser/main",
"//ios/chrome/browser/ntp:features",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/snapshots",
"//ios/chrome/browser/tabs:tabs",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/authentication",
"//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/commands:commands",
......
......@@ -17,6 +17,7 @@
#import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/app/deferred_initialization_runner.h"
#import "ios/chrome/app/main_controller_guts.h"
#import "ios/chrome/app/tests_hook.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remove_mask.h"
#include "ios/chrome/browser/browsing_data/browsing_data_remover.h"
......@@ -29,10 +30,12 @@
#include "ios/chrome/browser/crash_report/breadcrumbs/features.h"
#include "ios/chrome/browser/crash_report/breakpad_helper.h"
#include "ios/chrome/browser/crash_report/crash_report_helper.h"
#import "ios/chrome/browser/first_run/first_run.h"
#include "ios/chrome/browser/main/browser.h"
#include "ios/chrome/browser/ntp/features.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/authentication/signed_in_accounts_view_controller.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
......@@ -47,6 +50,7 @@
#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/ui_feature_flags.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"
......@@ -145,6 +149,9 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
@property(nonatomic, readwrite)
NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal;
// TabSwitcher object -- the tab grid.
@property(nonatomic, strong) id<TabSwitcher> tabSwitcher;
@end
@implementation SceneController
......@@ -206,12 +213,78 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
}
}
#pragma mark - private
#pragma mark - SceneControllerGuts
- (void)initializeUI {
if (self.hasInitializedUI) {
return;
}
self.hasInitializedUI = YES;
}
#pragma mark - private
// Determines which UI should be shown on startup, and shows it.
- (void)createInitialUI:(ApplicationMode)launchMode {
DCHECK(self.mainController.mainBrowserState);
// In order to correctly set the mode switch icon, we need to know how many
// tabs are in the other tab model. That means loading both models. They
// may already be loaded.
// TODO(crbug.com/546203): Find a way to handle this that's closer to the
// point where it is necessary.
TabModel* mainTabModel = self.mainInterface.tabModel;
TabModel* otrTabModel = self.incognitoInterface.tabModel;
// Enables UI initializations to query the keyWindow's size.
[self.mainController.window makeKeyAndVisible];
// Lazy init of mainCoordinator.
[self.mainController.mainCoordinator start];
_tabSwitcher = self.mainController.mainCoordinator.tabSwitcher;
// Call -restoreInternalState so that the grid shows the correct panel.
[_tabSwitcher
restoreInternalStateWithMainBrowser:self.mainInterface.browser
otrBrowser:self.incognitoInterface.browser
activeBrowser:self.currentInterface.browser];
// Decide if the First Run UI needs to run.
BOOL firstRun = (FirstRun::IsChromeFirstRun() ||
experimental_flags::AlwaysDisplayFirstRun()) &&
!tests_hook::DisableFirstRun();
[self.browserViewWrangler switchGlobalStateToMode:launchMode];
TabModel* tabModel;
if (launchMode == ApplicationMode::INCOGNITO) {
tabModel = otrTabModel;
[self setCurrentInterfaceForMode:ApplicationMode::INCOGNITO];
} else {
tabModel = mainTabModel;
[self setCurrentInterfaceForMode:ApplicationMode::NORMAL];
}
if (self.mainController.tabSwitcherIsActive) {
DCHECK(!self.mainController.dismissingTabSwitcher);
[self beginDismissingTabSwitcherWithCurrentModel:self.mainInterface.tabModel
focusOmnibox:NO];
[self finishDismissingTabSwitcher];
}
if (firstRun || [self shouldOpenNTPTabOnActivationOfTabModel:tabModel]) {
OpenNewTabCommand* command =
[OpenNewTabCommand commandWithIncognito:(self.currentInterface.bvc ==
self.incognitoInterface.bvc)];
command.userInitiated = NO;
[self.currentInterface.bvc.dispatcher openURLInNewTab:command];
}
if (firstRun) {
[self.mainController showFirstRunUI];
// Do not ever show the 'restore' infobar during first run.
self.mainController.restoreHelper = nil;
}
}
// This method completely destroys all of the UI. It should be called when the
// scene is disconnected.
- (void)teardownUI {
......@@ -281,7 +354,7 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
});
}
[self.mainController.mainCoordinator
prepareToShowTabSwitcher:self.mainController.tabSwitcher];
prepareToShowTabSwitcher:self.tabSwitcher];
}
- (void)displayTabSwitcher {
......@@ -762,7 +835,7 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
#pragma mark - TabSwitching
- (BOOL)openNewTabFromTabSwitcher {
if (!self.mainController.tabSwitcher)
if (!self.tabSwitcher)
return NO;
UrlLoadParams urlLoadParams =
......@@ -771,10 +844,9 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
Browser* mainBrowser = self.mainInterface.browser;
WebStateList* webStateList = mainBrowser->GetWebStateList();
[self.mainController.tabSwitcher
dismissWithNewTabAnimationToBrowser:mainBrowser
withUrlLoadParams:urlLoadParams
atIndex:webStateList->count()];
[self.tabSwitcher dismissWithNewTabAnimationToBrowser:mainBrowser
withUrlLoadParams:urlLoadParams
atIndex:webStateList->count()];
return YES;
}
......@@ -834,14 +906,13 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
// If the tabSwitcher is contained, check if the parent container is
// presenting another view controller.
if ([[self.mainController.tabSwitcher viewController]
if ([[self.tabSwitcher viewController]
.parentViewController presentedViewController]) {
return NO;
}
// Check if the tabSwitcher is directly presenting another view controller.
if ([self.mainController.tabSwitcher viewController]
.presentedViewController) {
if ([self.tabSwitcher viewController].presentedViewController) {
return NO;
}
......@@ -1026,7 +1097,7 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
self.NTPActionAfterTabSwitcherDismissal =
[self.mainController.startupParameters postOpeningAction];
[self.mainController setStartupParameters:nil];
[self.mainController.tabSwitcher
[self.tabSwitcher
dismissWithNewTabAnimationToBrowser:targetInterface.browser
withUrlLoadParams:urlLoadParams
atIndex:tabIndex];
......@@ -1317,18 +1388,17 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
}
- (void)showTabSwitcher {
DCHECK(self.mainController.tabSwitcher);
DCHECK(self.tabSwitcher);
// Tab switcher implementations may need to rebuild state before being
// displayed.
[self.mainController.tabSwitcher
[self.tabSwitcher
restoreInternalStateWithMainBrowser:self.mainInterface.browser
otrBrowser:self.incognitoInterface.browser
activeBrowser:self.currentInterface.browser];
self.mainController.tabSwitcherIsActive = YES;
[self.mainController.tabSwitcher setDelegate:self];
[self.tabSwitcher setDelegate:self];
[self.mainController.mainCoordinator
showTabSwitcher:self.mainController.tabSwitcher];
[self.mainController.mainCoordinator showTabSwitcher:self.tabSwitcher];
}
// Destroys and rebuilds the incognito browser state.
......@@ -1338,7 +1408,7 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
// Clear the Incognito Browser and notify the _tabSwitcher that its otrBrowser
// will be destroyed.
[self.mainController.tabSwitcher setOtrBrowser:nil];
[self.tabSwitcher setOtrBrowser:nil];
if (base::FeatureList::IsEnabled(kLogBreadcrumbs)) {
BreadcrumbManagerBrowserAgent::FromBrowser(self.incognitoInterface.browser)
......@@ -1363,8 +1433,7 @@ enum class TabSwitcherDismissalMode { NONE, NORMAL, INCOGNITO };
// Always set the new otr Browser for the tablet or grid switcher.
// Notify the _tabSwitcher with the new Incognito Browser.
[self.mainController.tabSwitcher
setOtrBrowser:self.incognitoInterface.browser];
[self.tabSwitcher setOtrBrowser:self.incognitoInterface.browser];
// This seems the best place to deem the destroying and rebuilding the
// incognito browser state to be completed.
......
......@@ -9,7 +9,9 @@
#include "ios/chrome/app/application_delegate/startup_information.h"
#import "ios/chrome/app/application_delegate/tab_opening.h"
#include "ios/chrome/app/application_mode.h"
#import "ios/chrome/browser/procedural_block_types.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
#import "ios/chrome/browser/url_loading/app_url_loading_service.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
......@@ -29,6 +31,8 @@ class ChromeBrowserState;
// browser state level UrlLoadingService instances.
@property(nonatomic, assign) AppUrlLoadingService* appURLLoadingService;
- (void)createInitialUI:(ApplicationMode)launchMode;
- (void)dismissModalDialogsWithCompletion:(ProceduralBlock)completion
dismissOmnibox:(BOOL)dismissOmnibox;
......@@ -61,6 +65,10 @@ class ChromeBrowserState;
// screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher;
// Testing only.
- (void)setTabSwitcher:(id<TabSwitcher>)switcher;
- (id<TabSwitcher>)tabSwitcher;
#pragma mark - AppNavigation helpers
// Presents a SignedInAccountsViewController for |browserState| on the top view
......
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