Commit 60dc7fa7 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Move ApplicationCommands to SceneController.

Introduces a temporary interface connecting the Scene and the Main
controllers, and exposes a bunch of internals of MainController through
a MainControllerGuts protocol (obviously temporary).

Uses this interface to implement ApplicationCommands in SceneController
and updates the use of the commands endpoint to be SceneController.

Note also:
- Updates a bunch of ivar use in MainController to properties.
- Moves a Deferred Initialization constant to a shared file as it's
used in both SceneCtrl and MainCtrl. It seems like this is semantically
correct for it to be used in both places, so it probably is a permanent
change.
- Removes a DCHECK(_localStatePrefObserverBridge) in
showSettingsFromViewController, as keeping it would mean exposing MainController->_localStatePrefObserverBridge to SceneController.

Bug: None
Change-Id: Idd45bc0850eaabca068e59e3843d901c9a0c780b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845976
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709497}
parent f81687c7
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "base/ios/block_types.h" #include "base/ios/block_types.h"
// Constants for deferred initialization of preferences observer.
extern NSString* const kPrefObserverInit;
// A singleton object to run initialization code asynchronously. Blocks are // A singleton object to run initialization code asynchronously. Blocks are
// scheduled to be run after a delay. The block is named when added to the // scheduled to be run after a delay. The block is named when added to the
// singleton so that other code can force a deferred block to be run // singleton so that other code can force a deferred block to be run
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kPrefObserverInit = @"PrefObserverInit";
// An object encapsulating the deferred execution of a block of initialization // An object encapsulating the deferred execution of a block of initialization
// code. // code.
@interface DeferredInitializationBlock : NSObject @interface DeferredInitializationBlock : NSObject
......
...@@ -86,6 +86,10 @@ ...@@ -86,6 +86,10 @@
_sceneState = [[SceneState alloc] init]; _sceneState = [[SceneState alloc] init];
_sceneController = _sceneController =
[[SceneController alloc] initWithSceneState:_sceneState]; [[SceneController alloc] initWithSceneState:_sceneState];
// This is temporary plumbing that's not supposed to be here.
_sceneController.mainController = (id<MainControllerGuts>)_mainController;
_mainController.sceneController = _sceneController;
} }
} }
return self; return self;
...@@ -117,8 +121,14 @@ ...@@ -117,8 +121,14 @@
BOOL inBackground = BOOL inBackground =
[application applicationState] == UIApplicationStateBackground; [application applicationState] == UIApplicationStateBackground;
return [_appState requiresHandlingAfterLaunchWithOptions:launchOptions BOOL requiresHandling =
[_appState requiresHandlingAfterLaunchWithOptions:launchOptions
stateBackground:inBackground]; stateBackground:inBackground];
if (!IsMultiwindowSupported()) {
self.sceneState.activationLevel = SceneActivationLevelForegroundInactive;
}
return requiresHandling;
} }
- (void)applicationDidBecomeActive:(UIApplication*)application { - (void)applicationDidBecomeActive:(UIApplication*)application {
...@@ -152,10 +162,10 @@ ...@@ -152,10 +162,10 @@
self.sceneState.activationLevel = SceneActivationLevelBackground; self.sceneState.activationLevel = SceneActivationLevelBackground;
} }
[_appState [_appState applicationDidEnterBackground:application
applicationDidEnterBackground:application
memoryHelper:_memoryHelper memoryHelper:_memoryHelper
incognitoContentVisible:_mainController.incognitoContentVisible]; incognitoContentVisible:self.sceneController
.incognitoContentVisible];
} }
// Called when returning to the foreground. // Called when returning to the foreground.
......
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
// //
// By design, it has no public API of its own. Anything interacting with // By design, it has no public API of its own. Anything interacting with
// MainController should be doing so through a specific protocol. // MainController should be doing so through a specific protocol.
@interface MainController : NSObject <ApplicationCommands, @interface MainController : NSObject <AppNavigation,
AppNavigation,
BrowserLauncher, BrowserLauncher,
MainControllerGuts, MainControllerGuts,
StartupInformation, StartupInformation,
...@@ -43,9 +42,8 @@ ...@@ -43,9 +42,8 @@
// to the user preferences. // to the user preferences.
@property(nonatomic, weak) MetricsMediator* metricsMediator; @property(nonatomic, weak) MetricsMediator* metricsMediator;
// Returns whether the app is showing or partially showing the // For temporary plumbing only.
// incognito panel. @property(nonatomic, weak) id<ApplicationCommands> sceneController;
@property(nonatomic, assign, readonly) BOOL incognitoContentVisible;
@end @end
......
...@@ -177,9 +177,6 @@ namespace { ...@@ -177,9 +177,6 @@ namespace {
// Preference key used to store which profile is current. // Preference key used to store which profile is current.
NSString* kIncognitoCurrentKey = @"IncognitoActive"; NSString* kIncognitoCurrentKey = @"IncognitoActive";
// Constants for deferred initialization of preferences observer.
NSString* const kPrefObserverInit = @"PrefObserverInit";
// Constants for deferring notifying the AuthenticationService of a new cold // Constants for deferring notifying the AuthenticationService of a new cold
// start. // start.
NSString* const kAuthenticationServiceNotification = NSString* const kAuthenticationServiceNotification =
...@@ -227,11 +224,6 @@ NSString* const kEnterpriseManagedDeviceCheck = @"EnterpriseManagedDeviceCheck"; ...@@ -227,11 +224,6 @@ NSString* const kEnterpriseManagedDeviceCheck = @"EnterpriseManagedDeviceCheck";
// Constants for deferred promo display. // Constants for deferred promo display.
const NSTimeInterval kDisplayPromoDelay = 0.1; const NSTimeInterval kDisplayPromoDelay = 0.1;
// A rough estimate of the expected duration of a view controller transition
// animation. It's used to temporarily disable mutally exclusive chrome
// commands that trigger a view controller presentation.
const int64_t kExpectedTransitionDurationInNanoSeconds = 0.2 * NSEC_PER_SEC;
// Adapted from chrome/browser/ui/browser_init.cc. // Adapted from chrome/browser/ui/browser_init.cc.
void RegisterComponentsForUpdate() { void RegisterComponentsForUpdate() {
component_updater::ComponentUpdateService* cus = component_updater::ComponentUpdateService* cus =
...@@ -293,26 +285,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -293,26 +285,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
completionBlock:completion]; completionBlock:completion];
} }
// Possible results of snapshotting at the moment the user enters the tab
// switcher. These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
enum class EnterTabSwitcherSnapshotResult {
// Page was loading at the time of the snapshot request, and the snapshot
// failed.
kPageLoadingAndSnapshotFailed = 0,
// Page was loading at the time of the snapshot request, and the snapshot
// succeeded.
kPageLoadingAndSnapshotSucceeded = 1,
// Page was not loading at the time of the snapshot request, and the snapshot
// failed.
kPageNotLoadingAndSnapshotFailed = 2,
// Page was not loading at the time of the snapshot request, and the snapshot
// succeeded.
kPageNotLoadingAndSnapshotSucceeded = 3,
// kMaxValue should share the value of the highest enumerator.
kMaxValue = kPageNotLoadingAndSnapshotSucceeded,
};
} // namespace } // namespace
@interface MainController () <AppURLLoadingServiceDelegate, @interface MainController () <AppURLLoadingServiceDelegate,
...@@ -339,9 +311,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -339,9 +311,6 @@ enum class EnterTabSwitcherSnapshotResult {
// app. // app.
AppStartupParameters* _startupParameters; AppStartupParameters* _startupParameters;
// Navigation View controller for the settings.
SettingsNavigationController* _settingsNavigationController;
// TabSwitcher object -- the tab grid. // TabSwitcher object -- the tab grid.
id<TabSwitcher> _tabSwitcher; id<TabSwitcher> _tabSwitcher;
...@@ -417,7 +386,7 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -417,7 +386,7 @@ enum class EnterTabSwitcherSnapshotResult {
NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal; NTPTabOpeningPostOpeningAction NTPActionAfterTabSwitcherDismissal;
// Returns YES if the settings are presented, either from // Returns YES if the settings are presented, either from
// _settingsNavigationController or from SigninInteractionCoordinator. // self.settingsNavigationController or from SigninInteractionCoordinator.
@property(nonatomic, assign, readonly, getter=isSettingsViewPresented) @property(nonatomic, assign, readonly, getter=isSettingsViewPresented)
BOOL settingsViewPresented; BOOL settingsViewPresented;
...@@ -465,8 +434,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -465,8 +434,6 @@ enum class EnterTabSwitcherSnapshotResult {
// Completes the process of dismissing the tab switcher, removing it from the // Completes the process of dismissing the tab switcher, removing it from the
// screen and showing the appropriate BVC. // screen and showing the appropriate BVC.
- (void)finishDismissingTabSwitcher; - (void)finishDismissingTabSwitcher;
// Opens an url from a link in the settings UI.
- (void)openUrlFromSettings:(OpenNewTabCommand*)command;
// Switch all global states for the given mode (normal or incognito). // Switch all global states for the given mode (normal or incognito).
- (void)switchGlobalStateToMode:(ApplicationMode)mode; - (void)switchGlobalStateToMode:(ApplicationMode)mode;
// Updates the local storage, cookie store, and sets the global state. // Updates the local storage, cookie store, and sets the global state.
...@@ -711,7 +678,7 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -711,7 +678,7 @@ enum class EnterTabSwitcherSnapshotResult {
_browserViewWrangler = [[BrowserViewWrangler alloc] _browserViewWrangler = [[BrowserViewWrangler alloc]
initWithBrowserState:self.mainBrowserState initWithBrowserState:self.mainBrowserState
webStateListObserver:self webStateListObserver:self
applicationCommandEndpoint:self applicationCommandEndpoint:self.sceneController
appURLLoadingService:self.appURLLoadingService appURLLoadingService:self.appURLLoadingService
storageSwitcher:self]; storageSwitcher:self];
...@@ -723,7 +690,7 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -723,7 +690,7 @@ enum class EnterTabSwitcherSnapshotResult {
AuthenticationServiceFactory::CreateAndInitializeForBrowserState( AuthenticationServiceFactory::CreateAndInitializeForBrowserState(
self.mainBrowserState, self.mainBrowserState,
std::make_unique<MainControllerAuthenticationServiceDelegate>( std::make_unique<MainControllerAuthenticationServiceDelegate>(
self.mainBrowserState, self)); self.mainBrowserState, self.sceneController));
// Send "Chrome Opened" event to the feature_engagement::Tracker on cold // Send "Chrome Opened" event to the feature_engagement::Tracker on cold
// start. // start.
...@@ -851,7 +818,8 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -851,7 +818,8 @@ enum class EnterTabSwitcherSnapshotResult {
DCHECK(self.mainBrowserState->HasOffTheRecordChromeBrowserState()); DCHECK(self.mainBrowserState->HasOffTheRecordChromeBrowserState());
ios::ChromeBrowserState* otrBrowserState = ios::ChromeBrowserState* otrBrowserState =
self.mainBrowserState->GetOffTheRecordChromeBrowserState(); self.mainBrowserState->GetOffTheRecordChromeBrowserState();
[self removeBrowsingDataForBrowserState:otrBrowserState [self.sceneController
removeBrowsingDataForBrowserState:otrBrowserState
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
removeMask:BrowsingDataRemoveMask::REMOVE_ALL removeMask:BrowsingDataRemoveMask::REMOVE_ALL
completionBlock:^{ completionBlock:^{
...@@ -911,7 +879,7 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -911,7 +879,7 @@ enum class EnterTabSwitcherSnapshotResult {
// Lazily create the main coordinator. // Lazily create the main coordinator.
TabGridCoordinator* tabGridCoordinator = TabGridCoordinator* tabGridCoordinator =
[[TabGridCoordinator alloc] initWithWindow:self.window [[TabGridCoordinator alloc] initWithWindow:self.window
applicationCommandEndpoint:self]; applicationCommandEndpoint:self.sceneController];
tabGridCoordinator.regularTabModel = self.mainTabModel; tabGridCoordinator.regularTabModel = self.mainTabModel;
tabGridCoordinator.incognitoTabModel = self.otrTabModel; tabGridCoordinator.incognitoTabModel = self.otrTabModel;
_mainCoordinator = tabGridCoordinator; _mainCoordinator = tabGridCoordinator;
...@@ -924,7 +892,7 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -924,7 +892,7 @@ enum class EnterTabSwitcherSnapshotResult {
} }
- (BOOL)isSettingsViewPresented { - (BOOL)isSettingsViewPresented {
return _settingsNavigationController || return self.settingsNavigationController ||
self.signinInteractionCoordinator.isSettingsViewPresented; self.signinInteractionCoordinator.isSettingsViewPresented;
} }
...@@ -1507,310 +1475,8 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1507,310 +1475,8 @@ enum class EnterTabSwitcherSnapshotResult {
completion:nil]; completion:nil];
} }
#pragma mark - ApplicationCommands
- (void)dismissModalDialogs {
[self dismissModalDialogsWithCompletion:nil dismissOmnibox:YES];
}
- (void)showHistory {
self.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.currentBVC
browserState:self.mainBrowserState];
self.historyCoordinator.loadStrategy =
[self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL;
self.historyCoordinator.dispatcher = self.mainBVC.dispatcher;
[self.historyCoordinator start];
}
- (void)closeSettingsUIAndOpenURL:(OpenNewTabCommand*)command {
[self openUrlFromSettings:command];
}
- (void)closeSettingsUI {
[self closeSettingsAnimated:YES completion:NULL];
}
- (void)prepareTabSwitcher {
web::WebState* currentWebState =
self.currentBVC.tabModel.webStateList->GetActiveWebState();
if (currentWebState) {
BOOL loading = currentWebState->IsLoading();
SnapshotTabHelper::FromWebState(currentWebState)
->UpdateSnapshotWithCallback(^(UIImage* snapshot) {
EnterTabSwitcherSnapshotResult snapshotResult;
if (loading && !snapshot) {
snapshotResult =
EnterTabSwitcherSnapshotResult::kPageLoadingAndSnapshotFailed;
} else if (loading && snapshot) {
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageLoadingAndSnapshotSucceeded;
} else if (!loading && !snapshot) {
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageNotLoadingAndSnapshotFailed;
} else {
DCHECK(!loading && snapshot);
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageNotLoadingAndSnapshotSucceeded;
}
UMA_HISTOGRAM_ENUMERATION("IOS.EnterTabSwitcherSnapshotResult",
snapshotResult);
});
}
[self.mainCoordinator prepareToShowTabSwitcher:_tabSwitcher];
}
- (void)displayTabSwitcher {
DCHECK(!_tabSwitcherIsActive);
if (!self.isProcessingVoiceSearchCommand) {
[self.currentBVC userEnteredTabSwitcher];
[self showTabSwitcher];
self.isProcessingTabSwitcherCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.isProcessingTabSwitcherCommand = NO;
});
}
}
// TODO(crbug.com/779791) : Remove showing settings from MainController.
- (void)showAutofillSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController)
return;
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController autofillProfileControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
- (void)showReportAnIssueFromViewController:
(UIViewController*)baseViewController {
DCHECK(baseViewController);
DCHECK(![baseViewController presentedViewController]);
// This dispatch is necessary to give enough time for the tools menu to
// disappear before taking a screenshot.
dispatch_async(dispatch_get_main_queue(), ^{
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController)
return;
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController userFeedbackControllerForBrowser:browser
delegate:self
feedbackDataSource:self
dispatcher:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
});
}
- (void)openURLInNewTab:(OpenNewTabCommand*)command {
UrlLoadParams params =
UrlLoadParams::InNewTab(command.URL, command.virtualURL);
params.SetInBackground(command.inBackground);
params.web_params.referrer = command.referrer;
params.in_incognito = command.inIncognito;
params.append_to = command.appendTo;
params.origin_point = command.originPoint;
params.from_chrome = command.fromChrome;
params.user_initiated = command.userInitiated;
params.should_focus_omnibox = command.shouldFocusOmnibox;
self.appURLLoadingService->LoadUrlInNewTab(params);
}
// TODO(crbug.com/779791) : Do not pass |baseViewController| through dispatcher.
- (void)showSignin:(ShowSigninCommand*)command
baseViewController:(UIViewController*)baseViewController {
if (!self.signinInteractionCoordinator) {
self.signinInteractionCoordinator = [[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainBrowserState
dispatcher:self.mainBVC.dispatcher];
}
switch (command.operation) {
case AUTHENTICATION_OPERATION_REAUTHENTICATE:
[self.signinInteractionCoordinator
reAuthenticateWithAccessPoint:command.accessPoint
promoAction:command.promoAction
presentingViewController:baseViewController
completion:command.callback];
break;
case AUTHENTICATION_OPERATION_SIGNIN:
[self.signinInteractionCoordinator signInWithIdentity:command.identity
accessPoint:command.accessPoint
promoAction:command.promoAction
presentingViewController:baseViewController
completion:command.callback];
break;
}
}
- (void)showAdvancedSigninSettingsFromViewController:
(UIViewController*)baseViewController {
self.signinInteractionCoordinator = [[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainBrowserState
dispatcher:self.mainBVC.dispatcher];
[self.signinInteractionCoordinator
showAdvancedSigninSettingsWithPresentingViewController:
baseViewController];
}
// TODO(crbug.com/779791) : Remove settings commands from MainController.
- (void)showAddAccountFromViewController:(UIViewController*)baseViewController {
if (!self.signinInteractionCoordinator) {
self.signinInteractionCoordinator = [[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainBrowserState
dispatcher:self.mainBVC.dispatcher];
}
[self.signinInteractionCoordinator
addAccountWithAccessPoint:signin_metrics::AccessPoint::
ACCESS_POINT_UNKNOWN
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO
presentingViewController:baseViewController
completion:nil];
}
- (void)setIncognitoContentVisible:(BOOL)incognitoContentVisible {
_incognitoContentVisible = incognitoContentVisible;
}
#pragma mark - ApplicationSettingsCommands
// TODO(crbug.com/779791) : Remove show settings from MainController.
- (void)showAccountsSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.currentBVC, self.mainCoordinator.activeViewController);
baseViewController = self.currentBVC;
}
if ([self currentBrowserState]->IsOffTheRecord()) {
NOTREACHED();
return;
}
if (_settingsNavigationController) {
[_settingsNavigationController
showAccountsSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController accountsControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove Google services settings from MainController.
- (void)showGoogleServicesSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.currentBVC, self.mainCoordinator.activeViewController);
baseViewController = self.currentBVC;
}
if (_settingsNavigationController) {
// Navigate to the Google services settings if the settings dialog is
// already opened.
[_settingsNavigationController
showGoogleServicesSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController googleServicesControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showSyncPassphraseSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) {
[_settingsNavigationController
showSyncPassphraseSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController syncPassphraseControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showSavedPasswordsSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) {
[_settingsNavigationController
showSavedPasswordsSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController savePasswordsControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showProfileSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) {
[_settingsNavigationController
showProfileSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController autofillProfileControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showCreditCardSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController) {
[_settingsNavigationController
showCreditCardSettingsFromViewController:baseViewController];
return;
}
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController = [SettingsNavigationController
autofillCreditCardControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
#pragma mark - AppURLLoadingServiceDelegate #pragma mark - AppURLLoadingServiceDelegate
...@@ -1833,33 +1499,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1833,33 +1499,6 @@ enum class EnterTabSwitcherSnapshotResult {
focusOmnibox:focusOmnibox]; focusOmnibox:focusOmnibox];
} }
#pragma mark - ApplicationCommands helpers
- (void)openUrlFromSettings:(OpenNewTabCommand*)command {
DCHECK([command fromChrome]);
UrlLoadParams params = UrlLoadParams::InNewTab([command URL]);
params.web_params.transition_type = ui::PAGE_TRANSITION_TYPED;
ProceduralBlock completion = ^{
[self dismissModalsAndOpenSelectedTabInMode:ApplicationModeForTabOpening::
NORMAL
withUrlLoadParams:params
dismissOmnibox:YES
completion:nil];
};
[self closeSettingsAnimated:YES completion:completion];
}
- (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 - Preferences Management #pragma mark - Preferences Management
- (void)onPreferenceChanged:(const std::string&)preferenceName { - (void)onPreferenceChanged:(const std::string&)preferenceName {
...@@ -1984,18 +1623,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -1984,18 +1623,6 @@ enum class EnterTabSwitcherSnapshotResult {
#pragma mark - Mode Switching #pragma mark - Mode Switching
- (void)startVoiceSearch {
if (!self.isProcessingTabSwitcherCommand) {
[self startVoiceSearchInCurrentBVC];
self.isProcessingVoiceSearchCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.isProcessingVoiceSearchCommand = NO;
});
}
}
- (void)switchGlobalStateToMode:(ApplicationMode)mode { - (void)switchGlobalStateToMode:(ApplicationMode)mode {
const BOOL incognito = (mode == ApplicationMode::INCOGNITO); const BOOL incognito = (mode == ApplicationMode::INCOGNITO);
// Write the state to disk of what is "active". // Write the state to disk of what is "active".
...@@ -2165,66 +1792,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2165,66 +1792,6 @@ enum class EnterTabSwitcherSnapshotResult {
_dismissingTabSwitcher = NO; _dismissingTabSwitcher = NO;
} }
#pragma mark - BrowsingDataCommands
- (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState
timePeriod:(browsing_data::TimePeriod)timePeriod
removeMask:(BrowsingDataRemoveMask)removeMask
completionBlock:(ProceduralBlock)completionBlock {
// TODO(crbug.com/632772): https://bugs.webkit.org/show_bug.cgi?id=149079
// makes it necessary to disable web usage while clearing browsing data.
// It is however unnecessary for off-the-record BrowserState (as the code
// is not invoked) and has undesired side-effect (cause all regular tabs
// to reload, see http://crbug.com/821753 for details).
BOOL disableWebUsageDuringRemoval =
!browserState->IsOffTheRecord() &&
IsRemoveDataMaskSet(removeMask, BrowsingDataRemoveMask::REMOVE_SITE_DATA);
BOOL showActivityIndicator = NO;
if (@available(iOS 13, *)) {
// TODO(crbug.com/632772): Visited links clearing doesn't require disabling
// web usage with iOS 13. Stop disabling web usage once iOS 12 is not
// supported.
showActivityIndicator = disableWebUsageDuringRemoval;
disableWebUsageDuringRemoval = NO;
}
if (disableWebUsageDuringRemoval) {
// Disables browsing and purges web views.
// Must be called only on the main thread.
DCHECK([NSThread isMainThread]);
self.interfaceProvider.mainInterface.userInteractionEnabled = NO;
self.interfaceProvider.incognitoInterface.userInteractionEnabled = NO;
} else if (showActivityIndicator) {
// Show activity overlay so users know that clear browsing data is in
// progress.
[self.mainBVC.dispatcher showActivityOverlay:YES];
}
BrowsingDataRemoverFactory::GetForBrowserState(browserState)
->Remove(
timePeriod, removeMask, base::BindOnce(^{
// Activates browsing and enables web views.
// Must be called only on the main thread.
DCHECK([NSThread isMainThread]);
if (showActivityIndicator) {
// User interaction still needs to be disabled as a way to
// force reload all the web states and to reset NTPs.
self.interfaceProvider.mainInterface.userInteractionEnabled = NO;
self.interfaceProvider.incognitoInterface.userInteractionEnabled =
NO;
[self.mainBVC.dispatcher showActivityOverlay:NO];
}
self.interfaceProvider.mainInterface.userInteractionEnabled = YES;
self.interfaceProvider.incognitoInterface.userInteractionEnabled =
YES;
[self.currentBVC setPrimary:YES];
if (completionBlock)
completionBlock();
}));
}
#pragma mark - Navigation Controllers #pragma mark - Navigation Controllers
...@@ -2240,34 +1807,18 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2240,34 +1807,18 @@ enum class EnterTabSwitcherSnapshotResult {
completion:nil]; completion:nil];
} }
- (void)showSettingsFromViewController:(UIViewController*)baseViewController {
DCHECK(!self.signinInteractionCoordinator.isSettingsViewPresented);
if (_settingsNavigationController)
return;
[[DeferredInitializationRunner sharedInstance]
runBlockIfNecessary:kPrefObserverInit];
DCHECK(_localStatePrefObserverBridge);
Browser* browser = self.interfaceProvider.mainInterface.browser;
_settingsNavigationController =
[SettingsNavigationController mainSettingsControllerForBrowser:browser
delegate:self];
[baseViewController presentViewController:_settingsNavigationController
animated:YES
completion:nil];
}
- (void)closeSettingsAnimated:(BOOL)animated - (void)closeSettingsAnimated:(BOOL)animated
completion:(ProceduralBlock)completion { completion:(ProceduralBlock)completion {
if (_settingsNavigationController) { if (self.settingsNavigationController) {
[_settingsNavigationController cleanUpSettings]; [self.settingsNavigationController cleanUpSettings];
UIViewController* presentingViewController = UIViewController* presentingViewController =
[_settingsNavigationController presentingViewController]; [self.settingsNavigationController presentingViewController];
// If presentingViewController is nil it means the VC was already dismissed // If presentingViewController is nil it means the VC was already dismissed
// by some other action like swiping down. // by some other action like swiping down.
DCHECK(presentingViewController); DCHECK(presentingViewController);
[presentingViewController dismissViewControllerAnimated:animated [presentingViewController dismissViewControllerAnimated:animated
completion:completion]; completion:completion];
_settingsNavigationController = nil; self.settingsNavigationController = nil;
return; return;
} }
// |self.signinInteractionCoordinator| can also present settings, like // |self.signinInteractionCoordinator| can also present settings, like
...@@ -2642,8 +2193,8 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2642,8 +2193,8 @@ enum class EnterTabSwitcherSnapshotResult {
} }
- (void)settingsWasDismissed { - (void)settingsWasDismissed {
[_settingsNavigationController cleanUpSettings]; [self.settingsNavigationController cleanUpSettings];
_settingsNavigationController = nil; self.settingsNavigationController = nil;
} }
- (id<ApplicationCommands, BrowserCommands>)dispatcherForSettings { - (id<ApplicationCommands, BrowserCommands>)dispatcherForSettings {
...@@ -2677,10 +2228,6 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2677,10 +2228,6 @@ enum class EnterTabSwitcherSnapshotResult {
return CaptureView(lastView, scale); return CaptureView(lastView, scale);
} }
- (BOOL)currentPageIsIncognito {
return [self currentBrowserState]->IsOffTheRecord();
}
- (NSString*)currentPageSyncedUserName { - (NSString*)currentPageSyncedUserName {
ios::ChromeBrowserState* browserState = [self currentBrowserState]; ios::ChromeBrowserState* browserState = [self currentBrowserState];
if (browserState->IsOffTheRecord()) if (browserState->IsOffTheRecord())
...@@ -2691,6 +2238,45 @@ enum class EnterTabSwitcherSnapshotResult { ...@@ -2691,6 +2238,45 @@ enum class EnterTabSwitcherSnapshotResult {
return username.empty() ? nil : base::SysUTF8ToNSString(username); return username.empty() ? nil : base::SysUTF8ToNSString(username);
} }
- (BOOL)currentPageIsIncognito {
return [self currentBrowserState] -> IsOffTheRecord();
}
#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
// This method is temporarily both required in the scene controller and here.
- (void)closeSettingsUI {
[self closeSettingsAnimated:YES completion:nullptr];
}
// This method is temporarily both required in the scene controller and here.
- (void)openURLInNewTab:(OpenNewTabCommand*)command {
UrlLoadParams params =
UrlLoadParams::InNewTab(command.URL, command.virtualURL);
params.SetInBackground(command.inBackground);
params.web_params.referrer = command.referrer;
params.in_incognito = command.inIncognito;
params.append_to = command.appendTo;
params.origin_point = command.originPoint;
params.from_chrome = command.fromChrome;
params.user_initiated = command.userInitiated;
params.should_focus_omnibox = command.shouldFocusOmnibox;
self.appURLLoadingService->LoadUrlInNewTab(params);
}
#pragma mark - MainControllerGuts #pragma mark - MainControllerGuts
- (id<TabSwitcher>)tabSwitcher { - (id<TabSwitcher>)tabSwitcher {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h" #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
@class BrowserViewController;
@class HistoryCoordinator; @class HistoryCoordinator;
@class SigninInteractionCoordinator; @class SigninInteractionCoordinator;
@class TabGridCoordinator; @class TabGridCoordinator;
......
...@@ -80,7 +80,7 @@ bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() { ...@@ -80,7 +80,7 @@ bool OpenNewIncognitoTabUsingUIAndEvictMainTabs() {
bool RemoveBrowsingCacheForMainTabs() { bool RemoveBrowsingCacheForMainTabs() {
__block BOOL caches_cleared = NO; __block BOOL caches_cleared = NO;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:chrome_test_util:: removeBrowsingDataForBrowserState:chrome_test_util::
GetOriginalBrowserState() GetOriginalBrowserState()
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
......
...@@ -18,10 +18,22 @@ source_set("scene") { ...@@ -18,10 +18,22 @@ source_set("scene") {
deps = [ deps = [
":main", ":main",
"//base", "//base",
"//ios/chrome/app:app",
"//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/snapshots",
"//ios/chrome/browser/tabs:tabs", "//ios/chrome/browser/tabs:tabs",
"//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/commands:commands", "//ios/chrome/browser/ui/commands:commands",
"//ios/chrome/browser/ui/history",
"//ios/chrome/browser/ui/settings:settings_root",
"//ios/chrome/browser/ui/signin_interaction",
"//ios/chrome/browser/ui/tab_grid", "//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/util:multiwindow_util", "//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
......
...@@ -7,10 +7,13 @@ ...@@ -7,10 +7,13 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/main/scene_state.h" #import "ios/chrome/browser/ui/main/scene_state.h"
@protocol MainControllerGuts;
// The controller object for a scene. Reacts to scene state changes. // The controller object for a scene. Reacts to scene state changes.
@interface SceneController : NSObject <SceneStateObserver> @interface SceneController : NSObject <SceneStateObserver, ApplicationCommands>
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithSceneState:(SceneState*)sceneState - (instancetype)initWithSceneState:(SceneState*)sceneState
...@@ -19,6 +22,13 @@ ...@@ -19,6 +22,13 @@
// The state of the scene controlled by this object. // The state of the scene controlled by this object.
@property(nonatomic, weak, readonly) SceneState* sceneState; @property(nonatomic, weak, readonly) SceneState* sceneState;
// Returns whether the scene is showing or partially showing the
// incognito panel.
@property(nonatomic, assign, readonly) BOOL incognitoContentVisible;
// A temporary pointer to MainController.
@property(nonatomic, weak) id<MainControllerGuts> mainController;
@end @end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_
...@@ -5,13 +5,74 @@ ...@@ -5,13 +5,74 @@
#import "ios/chrome/browser/ui/main/scene_controller.h" #import "ios/chrome/browser/ui/main/scene_controller.h"
#import "base/logging.h" #import "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/app/chrome_overlay_window.h" #import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/app/deferred_initialization_runner.h"
#import "ios/chrome/app/main_controller_guts.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"
#include "ios/chrome/browser/browsing_data/browsing_data_remover_factory.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/commands/show_signin_command.h"
#include "ios/chrome/browser/ui/history/history_coordinator.h"
#import "ios/chrome/browser/ui/main/browser_interface_provider.h"
#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/util/multi_window_support.h" #import "ios/chrome/browser/ui/util/multi_window_support.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.h"
#import "ios/web/public/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
// A rough estimate of the expected duration of a view controller transition
// animation. It's used to temporarily disable mutally exclusive chrome
// commands that trigger a view controller presentation.
const int64_t kExpectedTransitionDurationInNanoSeconds = 0.2 * NSEC_PER_SEC;
// Possible results of snapshotting at the moment the user enters the tab
// switcher. These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
enum class EnterTabSwitcherSnapshotResult {
// Page was loading at the time of the snapshot request, and the snapshot
// failed.
kPageLoadingAndSnapshotFailed = 0,
// Page was loading at the time of the snapshot request, and the snapshot
// succeeded.
kPageLoadingAndSnapshotSucceeded = 1,
// Page was not loading at the time of the snapshot request, and the snapshot
// failed.
kPageNotLoadingAndSnapshotFailed = 2,
// Page was not loading at the time of the snapshot request, and the snapshot
// succeeded.
kPageNotLoadingAndSnapshotSucceeded = 3,
// kMaxValue should share the value of the highest enumerator.
kMaxValue = kPageNotLoadingAndSnapshotSucceeded,
};
} // namespace
@interface SceneController ()
// A flag that keeps track of the UI initialization for the controlled scene.
@property(nonatomic, assign) BOOL hasInitializedUI;
@end
@implementation SceneController @implementation SceneController
- (instancetype)initWithSceneState:(SceneState*)sceneState { - (instancetype)initWithSceneState:(SceneState*)sceneState {
...@@ -35,6 +96,485 @@ ...@@ -35,6 +96,485 @@
- (void)sceneState:(SceneState*)sceneState - (void)sceneState:(SceneState*)sceneState
transitionedToActivationLevel:(SceneActivationLevel)level { transitionedToActivationLevel:(SceneActivationLevel)level {
if (level > SceneActivationLevelBackground && !self.hasInitializedUI) {
[self initializeUI];
}
}
#pragma mark - private
- (void)initializeUI {
self.hasInitializedUI = YES;
}
#pragma mark - ApplicationCommands
- (void)dismissModalDialogs {
[self.mainController dismissModalDialogsWithCompletion:nil
dismissOmnibox:YES];
}
- (void)showHistory {
self.mainController.historyCoordinator = [[HistoryCoordinator alloc]
initWithBaseViewController:self.mainController.currentBVC
browserState:self.mainController.mainBrowserState];
self.mainController.historyCoordinator.loadStrategy =
[self currentPageIsIncognito] ? UrlLoadStrategy::ALWAYS_IN_INCOGNITO
: UrlLoadStrategy::NORMAL;
self.mainController.historyCoordinator.dispatcher =
self.mainController.mainBVC.dispatcher;
[self.mainController.historyCoordinator start];
}
// Opens an url from a link in the settings UI.
- (void)closeSettingsUIAndOpenURL:(OpenNewTabCommand*)command {
[self openUrlFromSettings:command];
}
- (void)closeSettingsUI {
[self.mainController closeSettingsAnimated:YES completion:nullptr];
}
- (void)prepareTabSwitcher {
web::WebState* currentWebState =
self.mainController.currentBVC.tabModel.webStateList->GetActiveWebState();
if (currentWebState) {
BOOL loading = currentWebState->IsLoading();
SnapshotTabHelper::FromWebState(currentWebState)
->UpdateSnapshotWithCallback(^(UIImage* snapshot) {
EnterTabSwitcherSnapshotResult snapshotResult;
if (loading && !snapshot) {
snapshotResult =
EnterTabSwitcherSnapshotResult::kPageLoadingAndSnapshotFailed;
} else if (loading && snapshot) {
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageLoadingAndSnapshotSucceeded;
} else if (!loading && !snapshot) {
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageNotLoadingAndSnapshotFailed;
} else {
DCHECK(!loading && snapshot);
snapshotResult = EnterTabSwitcherSnapshotResult::
kPageNotLoadingAndSnapshotSucceeded;
}
UMA_HISTOGRAM_ENUMERATION("IOS.EnterTabSwitcherSnapshotResult",
snapshotResult);
});
}
[self.mainController.mainCoordinator
prepareToShowTabSwitcher:self.mainController.tabSwitcher];
}
- (void)displayTabSwitcher {
DCHECK(!self.mainController.isTabSwitcherActive);
if (!self.mainController.isProcessingVoiceSearchCommand) {
[self.mainController.currentBVC userEnteredTabSwitcher];
[self.mainController showTabSwitcher];
self.mainController.isProcessingTabSwitcherCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.mainController.isProcessingTabSwitcherCommand = NO;
});
}
}
// TODO(crbug.com/779791) : Remove showing settings from MainController.
- (void)showAutofillSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController)
return;
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
autofillProfileControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
- (void)showReportAnIssueFromViewController:
(UIViewController*)baseViewController {
DCHECK(baseViewController);
DCHECK(![baseViewController presentedViewController]);
// This dispatch is necessary to give enough time for the tools menu to
// disappear before taking a screenshot.
dispatch_async(dispatch_get_main_queue(), ^{
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController)
return;
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
userFeedbackControllerForBrowser:browser
delegate:self.mainController
feedbackDataSource:self.mainController
dispatcher:self];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
});
}
- (void)openURLInNewTab:(OpenNewTabCommand*)command {
UrlLoadParams params =
UrlLoadParams::InNewTab(command.URL, command.virtualURL);
params.SetInBackground(command.inBackground);
params.web_params.referrer = command.referrer;
params.in_incognito = command.inIncognito;
params.append_to = command.appendTo;
params.origin_point = command.originPoint;
params.from_chrome = command.fromChrome;
params.user_initiated = command.userInitiated;
params.should_focus_omnibox = command.shouldFocusOmnibox;
self.mainController.appURLLoadingService->LoadUrlInNewTab(params);
}
// TODO(crbug.com/779791) : Do not pass |baseViewController| through dispatcher.
- (void)showSignin:(ShowSigninCommand*)command
baseViewController:(UIViewController*)baseViewController {
if (!self.mainController.signinInteractionCoordinator) {
self.mainController.signinInteractionCoordinator =
[[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainController.mainBrowserState
dispatcher:self.mainController.mainBVC.dispatcher];
}
switch (command.operation) {
case AUTHENTICATION_OPERATION_REAUTHENTICATE:
[self.mainController.signinInteractionCoordinator
reAuthenticateWithAccessPoint:command.accessPoint
promoAction:command.promoAction
presentingViewController:baseViewController
completion:command.callback];
break;
case AUTHENTICATION_OPERATION_SIGNIN:
[self.mainController.signinInteractionCoordinator
signInWithIdentity:command.identity
accessPoint:command.accessPoint
promoAction:command.promoAction
presentingViewController:baseViewController
completion:command.callback];
break;
}
}
- (void)showAdvancedSigninSettingsFromViewController:
(UIViewController*)baseViewController {
self.mainController.signinInteractionCoordinator =
[[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainController.mainBrowserState
dispatcher:self.mainController.mainBVC.dispatcher];
[self.mainController.signinInteractionCoordinator
showAdvancedSigninSettingsWithPresentingViewController:
baseViewController];
}
// TODO(crbug.com/779791) : Remove settings commands from MainController.
- (void)showAddAccountFromViewController:(UIViewController*)baseViewController {
if (!self.mainController.signinInteractionCoordinator) {
self.mainController.signinInteractionCoordinator =
[[SigninInteractionCoordinator alloc]
initWithBrowserState:self.mainController.mainBrowserState
dispatcher:self.mainController.mainBVC.dispatcher];
}
[self.mainController.signinInteractionCoordinator
addAccountWithAccessPoint:signin_metrics::AccessPoint::
ACCESS_POINT_UNKNOWN
promoAction:signin_metrics::PromoAction::
PROMO_ACTION_NO_SIGNIN_PROMO
presentingViewController:baseViewController
completion:nil];
}
- (void)setIncognitoContentVisible:(BOOL)incognitoContentVisible {
_incognitoContentVisible = incognitoContentVisible;
}
- (void)startVoiceSearch {
if (!self.mainController.isProcessingTabSwitcherCommand) {
[self.mainController startVoiceSearchInCurrentBVC];
self.mainController.isProcessingVoiceSearchCommand = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,
kExpectedTransitionDurationInNanoSeconds),
dispatch_get_main_queue(), ^{
self.mainController.isProcessingVoiceSearchCommand = NO;
});
}
}
- (void)showSettingsFromViewController:(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController)
return;
[[DeferredInitializationRunner sharedInstance]
runBlockIfNecessary:kPrefObserverInit];
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
mainSettingsControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
#pragma mark - ApplicationSettingsCommands
// TODO(crbug.com/779791) : Remove show settings from MainController.
- (void)showAccountsSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.mainController.currentBVC,
self.mainController.mainCoordinator.activeViewController);
baseViewController = self.mainController.currentBVC;
}
if ([self.mainController currentBrowserState] -> IsOffTheRecord()) {
NOTREACHED();
return;
}
if (self.mainController.settingsNavigationController) {
[self.mainController.settingsNavigationController
showAccountsSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
accountsControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove Google services settings from MainController.
- (void)showGoogleServicesSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (!baseViewController) {
DCHECK_EQ(self.mainController.currentBVC,
self.mainController.mainCoordinator.activeViewController);
baseViewController = self.mainController.currentBVC;
}
if (self.mainController.settingsNavigationController) {
// Navigate to the Google services settings if the settings dialog is
// already opened.
[self.mainController.settingsNavigationController
showGoogleServicesSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
googleServicesControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showSyncPassphraseSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController) {
[self.mainController.settingsNavigationController
showSyncPassphraseSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
syncPassphraseControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showSavedPasswordsSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController) {
[self.mainController.settingsNavigationController
showSavedPasswordsSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
savePasswordsControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showProfileSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController) {
[self.mainController.settingsNavigationController
showProfileSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
autofillProfileControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
// TODO(crbug.com/779791) : Remove show settings commands from MainController.
- (void)showCreditCardSettingsFromViewController:
(UIViewController*)baseViewController {
DCHECK(!self.mainController.signinInteractionCoordinator
.isSettingsViewPresented);
if (self.mainController.settingsNavigationController) {
[self.mainController.settingsNavigationController
showCreditCardSettingsFromViewController:baseViewController];
return;
}
Browser* browser =
self.mainController.interfaceProvider.mainInterface.browser;
self.mainController.settingsNavigationController =
[SettingsNavigationController
autofillCreditCardControllerForBrowser:browser
delegate:self.mainController];
[baseViewController
presentViewController:self.mainController.settingsNavigationController
animated:YES
completion:nil];
}
#pragma mark - BrowsingDataCommands
- (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState
timePeriod:(browsing_data::TimePeriod)timePeriod
removeMask:(BrowsingDataRemoveMask)removeMask
completionBlock:(ProceduralBlock)completionBlock {
// TODO(crbug.com/632772): https://bugs.webkit.org/show_bug.cgi?id=149079
// makes it necessary to disable web usage while clearing browsing data.
// It is however unnecessary for off-the-record BrowserState (as the code
// is not invoked) and has undesired side-effect (cause all regular tabs
// to reload, see http://crbug.com/821753 for details).
BOOL disableWebUsageDuringRemoval =
!browserState->IsOffTheRecord() &&
IsRemoveDataMaskSet(removeMask, BrowsingDataRemoveMask::REMOVE_SITE_DATA);
BOOL showActivityIndicator = NO;
if (@available(iOS 13, *)) {
// TODO(crbug.com/632772): Visited links clearing doesn't require disabling
// web usage with iOS 13. Stop disabling web usage once iOS 12 is not
// supported.
showActivityIndicator = disableWebUsageDuringRemoval;
disableWebUsageDuringRemoval = NO;
}
if (disableWebUsageDuringRemoval) {
// Disables browsing and purges web views.
// Must be called only on the main thread.
DCHECK([NSThread isMainThread]);
self.mainController.interfaceProvider.mainInterface.userInteractionEnabled =
NO;
self.mainController.interfaceProvider.incognitoInterface
.userInteractionEnabled = NO;
} else if (showActivityIndicator) {
// Show activity overlay so users know that clear browsing data is in
// progress.
[self.mainController.mainBVC.dispatcher showActivityOverlay:YES];
}
BrowsingDataRemoverFactory::GetForBrowserState(browserState)
->Remove(timePeriod, removeMask, base::BindOnce(^{
// Activates browsing and enables web views.
// Must be called only on the main thread.
DCHECK([NSThread isMainThread]);
if (showActivityIndicator) {
// User interaction still needs to be disabled as a way to
// force reload all the web states and to reset NTPs.
self.mainController.interfaceProvider.mainInterface
.userInteractionEnabled = NO;
self.mainController.interfaceProvider.incognitoInterface
.userInteractionEnabled = NO;
[self.mainController.mainBVC.dispatcher
showActivityOverlay:NO];
}
self.mainController.interfaceProvider.mainInterface
.userInteractionEnabled = YES;
self.mainController.interfaceProvider.incognitoInterface
.userInteractionEnabled = YES;
[self.mainController.currentBVC setPrimary:YES];
if (completionBlock)
completionBlock();
}));
}
#pragma mark - ApplicationCommandsHelpers
- (BOOL)currentPageIsIncognito {
return self.mainController.currentBrowserState->IsOffTheRecord();
}
- (void)openUrlFromSettings:(OpenNewTabCommand*)command {
DCHECK([command fromChrome]);
UrlLoadParams params = UrlLoadParams::InNewTab([command URL]);
params.web_params.transition_type = ui::PAGE_TRANSITION_TYPED;
ProceduralBlock completion = ^{
[self.mainController dismissModalsAndOpenSelectedTabInMode:
ApplicationModeForTabOpening::NORMAL
withUrlLoadParams:params
dismissOmnibox:YES
completion:nil];
};
[self.mainController closeSettingsAnimated:YES completion:completion];
} }
@end @end
...@@ -79,7 +79,7 @@ void TapOnPrimarySignInButtonInRecentTabs() { ...@@ -79,7 +79,7 @@ void TapOnPrimarySignInButtonInRecentTabs() {
// Removes all browsing data. // Removes all browsing data.
void RemoveBrowsingData() { void RemoveBrowsingData() {
__block BOOL browsing_data_removed = NO; __block BOOL browsing_data_removed = NO;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:chrome_test_util:: removeBrowsingDataForBrowserState:chrome_test_util::
GetOriginalBrowserState() GetOriginalBrowserState()
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
......
...@@ -32,7 +32,7 @@ bool ClearBrowsingData(bool off_the_record, BrowsingDataRemoveMask mask) { ...@@ -32,7 +32,7 @@ bool ClearBrowsingData(bool off_the_record, BrowsingDataRemoveMask mask) {
: chrome_test_util::GetOriginalBrowserState(); : chrome_test_util::GetOriginalBrowserState();
__block bool did_complete = false; __block bool did_complete = false;
[chrome_test_util::GetMainController() [chrome_test_util::GetMainController().sceneController
removeBrowsingDataForBrowserState:browser_state removeBrowsingDataForBrowserState:browser_state
timePeriod:browsing_data::TimePeriod::ALL_TIME timePeriod:browsing_data::TimePeriod::ALL_TIME
removeMask:mask removeMask:mask
......
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