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

[multiball] Remove differences on iOS 12 and 13 wrt startupChromeUI.

Before this CL, MainController calls startUpChromeUI on the scene on iOS
12.

With this CL, this exceptional call is removed. Instead, the call now
always happens in SceneController. The follow-up call to
startUpAfterFirstWindowCreated in MainController is now triggered
through the appState:firstSceneActivated: observer callback in both old
and new startup sequences.

This requires a few minor changes:
* AppState now observes SceneWillConnect and immediately adds itself
as a SceneState observer. The UISceneDidActivateNotification observation
is now replaced with sceneState:transitionedToActivationLevel:, which
is available on both iOS 12 and 13.
* SceneController now becomes an AppStateObserver immediately on init,
instead of waiting to initializeUI.

Minor win: SceneControllerGuts are no longer necessary.

Bug: 1012697
Change-Id: Id82e6a10c5825e34f53f076fef19a1e6bf9e7908
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398505
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807938}
parent fe575b2a
......@@ -221,7 +221,6 @@ source_set("app_internal") {
"//ios/chrome/browser/ui/first_run",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/main:scene_guts",
"//ios/chrome/browser/ui/scoped_ui_blocker",
"//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/ui/tab_grid:tab_grid_ui",
......
......@@ -138,7 +138,10 @@ source_set("metric_kit_subscriber") {
source_set("app_state_header") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "app_state.h" ]
public_deps = [ "//ios/chrome/browser/ui/scoped_ui_blocker" ]
public_deps = [
"//ios/chrome/browser/ui/main:scene_state_observer",
"//ios/chrome/browser/ui/scoped_ui_blocker",
]
}
source_set("application_delegate_internal") {
......
......@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/main/scene_state_observer.h"
#import "ios/chrome/browser/ui/scoped_ui_blocker/ui_blocker_manager.h"
@class AppState;
......@@ -39,7 +40,7 @@
// Represents the application state and responds to application state changes
// and system events.
@interface AppState : NSObject <UIBlockerManager>
@interface AppState : NSObject <UIBlockerManager, SceneStateObserver>
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -51,7 +51,6 @@
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/main/browser_interface_provider.h"
#import "ios/chrome/browser/ui/main/scene_delegate.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/ui/safe_mode/safe_mode_coordinator.h"
#import "ios/chrome/browser/ui/scoped_ui_blocker/scoped_ui_blocker.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
......@@ -88,7 +87,7 @@ NSString* const kStartupAttemptReset = @"StartupAttempReset";
#pragma mark - AppState
@interface AppState ()<SafeModeCoordinatorDelegate> {
@interface AppState () <SafeModeCoordinatorDelegate> {
// Container for startup information.
__weak id<StartupInformation> _startupInformation;
// Browser launcher to launch browser in different states.
......@@ -170,17 +169,6 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
_browserLauncher = browserLauncher;
_mainApplicationDelegate = applicationDelegate;
_appCommandDispatcher = [[CommandDispatcher alloc] init];
if (@available(iOS 13, *)) {
if (IsSceneStartupSupported()) {
// Subscribe for scene activation notifications.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sceneDidActivate:)
name:UISceneDidActivateNotification
object:nil];
}
}
}
return self;
}
......@@ -206,6 +194,11 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
}
}
- (void)setMainSceneState:(SceneState*)mainSceneState {
DCHECK(!_mainSceneState);
_mainSceneState = mainSceneState;
}
#pragma mark - Public methods.
- (void)applicationDidEnterBackground:(UIApplication*)application
......@@ -664,22 +657,13 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
return self.uiBlockerTarget;
}
#pragma mark - Scene notifications
// Handler for UISceneDidActivateNotification.
- (void)sceneDidActivate:(NSNotification*)notification {
DCHECK(IsSceneStartupSupported());
if (@available(iOS 13, *)) {
UIWindowScene* scene =
base::mac::ObjCCastStrict<UIWindowScene>(notification.object);
SceneDelegate* sceneDelegate =
base::mac::ObjCCastStrict<SceneDelegate>(scene.delegate);
- (void)sceneState:(SceneState*)sceneState
transitionedToActivationLevel:(SceneActivationLevel)level {
if (level >= SceneActivationLevelForegroundActive) {
if (!self.firstSceneHasActivated) {
self.firstSceneHasActivated = YES;
[self.observers appState:self
firstSceneActivated:sceneDelegate.sceneState];
[self.observers appState:self firstSceneActivated:sceneState];
if (self.isInSafeMode) {
// Safe mode can only be started when there's a window, so the actual
......@@ -687,9 +671,8 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
[self startSafeMode];
}
}
sceneDelegate.sceneState.presentingModalOverlay =
(self.uiBlockerTarget != nil) &&
(self.uiBlockerTarget != sceneDelegate.sceneState);
sceneState.presentingModalOverlay =
(self.uiBlockerTarget != nil) && (self.uiBlockerTarget != sceneState);
}
}
......
......@@ -130,7 +130,9 @@
[_appState requiresHandlingAfterLaunchWithOptions:launchOptions
stateBackground:inBackground];
if (!IsSceneStartupSupported()) {
self.sceneState.activationLevel = SceneActivationLevelForegroundInactive;
self.sceneState.activationLevel =
inBackground ? SceneActivationLevelBackground
: SceneActivationLevelForegroundInactive;
}
if (@available(iOS 13, *)) {
......@@ -169,9 +171,11 @@
if ([_appState isInSafeMode])
return;
[_appState resumeSessionWithTabOpener:_tabOpener
tabSwitcher:_tabSwitcherProtocol
connectionInformation:self.sceneController];
if (!IsSceneStartupSupported()) {
[_appState resumeSessionWithTabOpener:_tabOpener
tabSwitcher:_tabSwitcherProtocol
connectionInformation:self.sceneController];
}
}
- (void)applicationWillResignActive:(UIApplication*)application {
......
......@@ -89,7 +89,6 @@
#import "ios/chrome/browser/ui/first_run/first_run_util.h"
#import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
#import "ios/chrome/browser/ui/main/browser_view_wrangler.h"
#import "ios/chrome/browser/ui/main/scene_controller_guts.h"
#import "ios/chrome/browser/ui/main/scene_delegate.h"
#import "ios/chrome/browser/ui/scoped_ui_blocker/scoped_ui_blocker.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h"
......@@ -571,18 +570,6 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
self.appState.sessionRestorationRequired =
[self startUpBeforeFirstWindowCreatedAndPrepareForRestorationPostCrash:
self.appState.postCrashLaunch];
if (@available(iOS 13, *)) {
if (IsSceneStartupSupported()) {
// The rest of the startup sequence is handled by the Scenes and in
// response to notifications.
return;
}
}
SceneState* sceneState = self.appState.connectedScenes.firstObject;
[sceneState.controller startUpChromeUI];
[self startUpAfterFirstWindowCreated];
}
- (void)initializeBrowserState:(ChromeBrowserState*)browserState {
......
......@@ -10,15 +10,9 @@ source_set("scene_testing") {
frameworks = [ "UIKit.framework" ]
}
source_set("scene_guts") {
sources = [ "scene_controller_guts.h" ]
deps = [
"//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/browser:utils",
"//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web_state_list",
]
source_set("scene_state_observer") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [ "scene_state_observer.h" ]
frameworks = [ "UIKit.framework" ]
}
......@@ -30,6 +24,7 @@ source_set("scene_state_header") {
"scene_state_browser_agent.h",
]
public_deps = [
":scene_state_observer",
"//ios/chrome/browser/main:public",
"//ios/chrome/browser/ui/scoped_ui_blocker",
"//ios/chrome/browser/window_activities",
......@@ -68,7 +63,6 @@ source_set("scene") {
deps = [
":incognito_blocker_scene_agent",
":main",
":scene_guts",
":scene_testing",
"//base",
"//components/signin/public/identity_manager",
......@@ -122,7 +116,10 @@ source_set("scene") {
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/user_feedback",
]
public_deps = [ ":scene_state_header" ]
public_deps = [
":scene_state_header",
":scene_state_observer",
]
allow_circular_includes_from = [
":main",
......
......@@ -11,7 +11,6 @@
#import "ios/chrome/app/application_delegate/tab_switching.h"
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/main/connection_information.h"
#import "ios/chrome/browser/ui/main/scene_controller_guts.h"
#import "ios/chrome/browser/ui/main/scene_state.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
......@@ -21,7 +20,6 @@
@interface SceneController : NSObject <SceneStateObserver,
ApplicationCommands,
TabSwitching,
SceneControllerGuts,
ConnectionInformation,
TabOpening,
WebStateListObserving>
......
......@@ -220,6 +220,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
if (self) {
_sceneState = sceneState;
[_sceneState addObserver:self];
[_sceneState.appState addObserver:self];
// The window is necessary very early in the app/scene lifecycle, so it
// should be created right away.
// When multiwindow is supported, the window is created by SceneDelegate,
......@@ -518,26 +520,18 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
transitionedToActivationLevel:self.sceneState.activationLevel];
}
#pragma mark - SceneControllerGuts
#pragma mark - private
- (void)initializeUI {
if (self.hasInitializedUI) {
return;
}
DCHECK(self.mainController);
if (IsSceneStartupSupported()) {
// TODO(crbug.com/1012697): This should probably be the only code path for
// UIScene and non-UIScene cases.
[self startUpChromeUI];
}
[self.sceneState.appState addObserver:self];
[self startUpChromeUI];
self.hasInitializedUI = YES;
}
#pragma mark - private
// Starts up a single chrome window and its UI.
- (void)startUpChromeUI {
DCHECK(!self.browserViewWrangler);
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_GUTS_H_
#define IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_GUTS_H_
#import <UIKit/UIKit.h>
@protocol SceneControllerGuts
#pragma mark - iOS 12 compat
- (void)startUpChromeUI;
@end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_GUTS_H_
......@@ -7,6 +7,7 @@
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/main/scene_state_observer.h"
#import "ios/chrome/browser/ui/scoped_ui_blocker/ui_blocker_target.h"
#import "ios/chrome/browser/window_activities/window_activity_helpers.h"
......@@ -42,31 +43,6 @@ typedef NS_ENUM(NSUInteger, SceneActivationLevel) {
@end
@protocol SceneStateObserver <NSObject>
@optional
// Called whenever the scene state transitions between different activity
// states.
- (void)sceneState:(SceneState*)sceneState
transitionedToActivationLevel:(SceneActivationLevel)level;
// Notifies when presentingModalOverlay is being set to true.
- (void)sceneStateWillShowModalOverlay:(SceneState*)sceneState;
// Notifies when presentingModalOverlay is being set to false.
- (void)sceneStateWillHideModalOverlay:(SceneState*)sceneState;
// Notifies when presentingModalOverlay has been set to false.
- (void)sceneStateDidHideModalOverlay:(SceneState*)sceneState;
// Notifies when URLContexts have been added to |URLContextsToOpen|.
- (void)sceneState:(SceneState*)sceneState
hasPendingURLs:(NSSet<UIOpenURLContext*>*)URLContexts
API_AVAILABLE(ios(13));
// Notifies that a new activity request has been received.
- (void)sceneState:(SceneState*)sceneState
receivedUserActivity:(NSUserActivity*)userActivity;
@end
// An object containing the state of a UIWindowScene. One state object
// corresponds to one scene.
@interface SceneState : NSObject <UIBlockerTarget>
......
......@@ -45,6 +45,11 @@
_observers = [SceneStateObserverList
observersWithProtocol:@protocol(SceneStateObserver)];
_agents = [[NSMutableArray alloc] init];
// AppState might be nil in tests.
if (appState) {
[self addObserver:appState];
}
}
return self;
}
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_MAIN_SCENE_STATE_OBSERVER_H_
#define IOS_CHROME_BROWSER_UI_MAIN_SCENE_STATE_OBSERVER_H_
#import <UIKit/UIKit.h>
@class SceneState;
enum SceneActivationLevel : NSUInteger;
// Observer for a SceneState.
@protocol SceneStateObserver <NSObject>
@optional
// Called whenever the scene state transitions between different activity
// states.
- (void)sceneState:(SceneState*)sceneState
transitionedToActivationLevel:(SceneActivationLevel)level;
// Notifies when presentingModalOverlay is being set to true.
- (void)sceneStateWillShowModalOverlay:(SceneState*)sceneState;
// Notifies when presentingModalOverlay is being set to false.
- (void)sceneStateWillHideModalOverlay:(SceneState*)sceneState;
// Notifies when presentingModalOverlay has been set to false.
- (void)sceneStateDidHideModalOverlay:(SceneState*)sceneState;
// Notifies when URLContexts have been added to |URLContextsToOpen|.
- (void)sceneState:(SceneState*)sceneState
hasPendingURLs:(NSSet<UIOpenURLContext*>*)URLContexts
API_AVAILABLE(ios(13));
// Notifies that a new activity request has been received.
- (void)sceneState:(SceneState*)sceneState
receivedUserActivity:(NSUserActivity*)userActivity;
@end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_STATE_OBSERVER_H_
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