Commit 5b991853 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Don't expose BrowserInterfaceProvider in SceneControllerGuts

Removes the BVWrangler from the temporary interface, and instead sets
up a more permanent scheme:
1. SceneState exposes an interface provider
2. AppState allows access to SceneStates
3. MainController uses AppState's scenes to find an interface provider.

Note that a lot of code in MainController still assumes a single window
and this is not fixed in this CL.

Also breaks down application_delegate_internal target by splitting
out tab_opening. This allows to avoid a deps cycle.

Bug: 1045660
Change-Id: Iabd71bc18c901d6990dfdec77190605c4f51cb0a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120404Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753966}
parent 087f0fcc
...@@ -48,6 +48,7 @@ source_set("unit_tests") { ...@@ -48,6 +48,7 @@ source_set("unit_tests") {
"//components/metrics", "//components/metrics",
"//components/prefs", "//components/prefs",
"//ios/chrome/app/application_delegate:application_delegate_internal", "//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state:test_support", "//ios/chrome/browser/browser_state:test_support",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
...@@ -158,6 +159,7 @@ source_set("app_internal") { ...@@ -158,6 +159,7 @@ source_set("app_internal") {
"//components/web_resource", "//components/web_resource",
"//ios/chrome/app/application_delegate", "//ios/chrome/app/application_delegate",
"//ios/chrome/app/application_delegate:application_delegate_internal", "//ios/chrome/app/application_delegate:application_delegate_internal",
"//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/app/intents", "//ios/chrome/app/intents",
"//ios/chrome/app/spotlight", "//ios/chrome/app/spotlight",
"//ios/chrome/app/startup", "//ios/chrome/app/startup",
......
...@@ -30,6 +30,7 @@ source_set("unit_tests") { ...@@ -30,6 +30,7 @@ source_set("unit_tests") {
deps = [ deps = [
":application_delegate", ":application_delegate",
":application_delegate_internal", ":application_delegate_internal",
":tab_opening",
":test_support", ":test_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
...@@ -83,6 +84,24 @@ source_set("unit_tests") { ...@@ -83,6 +84,24 @@ source_set("unit_tests") {
libs = [ "CoreSpotlight.framework" ] libs = [ "CoreSpotlight.framework" ]
} }
source_set("tab_opening") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"tab_opening.h",
"tab_switching.h",
]
deps = [
"//base",
"//ios/chrome/app",
"//ios/chrome/app:mode",
"//ui/base",
]
libs = [
"CoreSpotlight.framework",
"UIKit.framework",
]
}
source_set("application_delegate_internal") { source_set("application_delegate_internal") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
...@@ -92,7 +111,6 @@ source_set("application_delegate_internal") { ...@@ -92,7 +111,6 @@ source_set("application_delegate_internal") {
"metrics_mediator.h", "metrics_mediator.h",
"metrics_mediator.mm", "metrics_mediator.mm",
"startup_information.h", "startup_information.h",
"tab_opening.h",
"tab_switching.h", "tab_switching.h",
"url_opener.h", "url_opener.h",
"url_opener.mm", "url_opener.mm",
...@@ -101,6 +119,7 @@ source_set("application_delegate_internal") { ...@@ -101,6 +119,7 @@ source_set("application_delegate_internal") {
] ]
deps = [ deps = [
":application_delegate", ":application_delegate",
":tab_opening",
"//base", "//base",
"//build:branding_buildflags", "//build:branding_buildflags",
"//components/crash/core/common", "//components/crash/core/common",
...@@ -132,8 +151,10 @@ source_set("application_delegate_internal") { ...@@ -132,8 +151,10 @@ source_set("application_delegate_internal") {
"//ios/chrome/browser/ui/browser_view", "//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/main", "//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/main:scene",
"//ios/chrome/browser/ui/safe_mode", "//ios/chrome/browser/ui/safe_mode",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading", "//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web:tab_id_tab_helper", "//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
...@@ -151,7 +172,10 @@ source_set("application_delegate_internal") { ...@@ -151,7 +172,10 @@ source_set("application_delegate_internal") {
"CoreSpotlight.framework", "CoreSpotlight.framework",
"UIKit.framework", "UIKit.framework",
] ]
allow_circular_includes_from = [ "//ios/chrome/browser/url_loading" ] allow_circular_includes_from = [
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/ui/main:scene",
]
} }
source_set("test_support") { source_set("test_support") {
...@@ -167,6 +191,7 @@ source_set("test_support") { ...@@ -167,6 +191,7 @@ source_set("test_support") {
] ]
deps = [ deps = [
":application_delegate_internal", ":application_delegate_internal",
":tab_opening",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/app", "//ios/chrome/app",
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@protocol BrowserLauncher; @protocol BrowserLauncher;
@class SceneState;
@class MainApplicationDelegate; @class MainApplicationDelegate;
@class MemoryWarningHelper; @class MemoryWarningHelper;
@class MetricsMediator; @class MetricsMediator;
...@@ -35,6 +36,10 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -35,6 +36,10 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// Set the property before calling methods related to it. // Set the property before calling methods related to it.
@property(nonatomic, weak) UIWindow* window; @property(nonatomic, weak) UIWindow* window;
// When multiwindow is unavailable, this is the only scene state. It is created
// by the app delegate.
@property(nonatomic, strong) SceneState* mainSceneState;
// Saves the launchOptions to be used from -newTabFromLaunchOptions. If the // Saves the launchOptions to be used from -newTabFromLaunchOptions. If the
// application is in background, initialize the browser to basic. If not, launch // application is in background, initialize the browser to basic. If not, launch
// the browser. // the browser.
...@@ -80,6 +85,9 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -80,6 +85,9 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
// -performActionForShortcutItem or -openURL. // -performActionForShortcutItem or -openURL.
- (void)launchFromURLHandled:(BOOL)URLHandled; - (void)launchFromURLHandled:(BOOL)URLHandled;
// Returns a list of all connected scenes.
- (NSArray<SceneState*>*)connectedScenes;
@end @end
#endif // IOS_CHROME_APP_APPLICATION_DELEGATE_APP_STATE_H_ #endif // IOS_CHROME_APP_APPLICATION_DELEGATE_APP_STATE_H_
...@@ -46,7 +46,10 @@ ...@@ -46,7 +46,10 @@
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h" #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/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/safe_mode/safe_mode_coordinator.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/net/cookies/cookie_store_ios.h" #include "ios/net/cookies/cookie_store_ios.h"
#include "ios/net/cookies/system_cookie_util.h" #include "ios/net/cookies/system_cookie_util.h"
...@@ -458,6 +461,26 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -458,6 +461,26 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
self.shouldPerformAdditionalDelegateHandling = !URLHandled; self.shouldPerformAdditionalDelegateHandling = !URLHandled;
} }
#pragma mark - Multiwindow-related
- (NSArray<SceneState*>*)connectedScenes {
if (IsMultiwindowSupported()) {
NSMutableArray* sceneStates = [[NSMutableArray alloc] init];
if (@available(iOS 13, *)) {
NSSet* connectedScenes =
[UIApplication sharedApplication].connectedScenes;
for (UIWindowScene* scene in connectedScenes) {
SceneDelegate* sceneDelegate =
base::mac::ObjCCastStrict<SceneDelegate>(scene.delegate);
[sceneStates addObject:sceneDelegate.sceneState];
}
}
return sceneStates;
} else {
return @[ self.mainSceneState ];
}
}
#pragma mark - SafeModeCoordinatorDelegate Implementation #pragma mark - SafeModeCoordinatorDelegate Implementation
- (void)coordinatorDidExitSafeMode:(nonnull SafeModeCoordinator*)coordinator { - (void)coordinatorDidExitSafeMode:(nonnull SafeModeCoordinator*)coordinator {
......
...@@ -79,8 +79,10 @@ ...@@ -79,8 +79,10 @@
// and a "scene" controller. This allows the rest of the app to be mostly // and a "scene" controller. This allows the rest of the app to be mostly
// multiwindow-agnostic. // multiwindow-agnostic.
_sceneState = [[SceneState alloc] init]; _sceneState = [[SceneState alloc] init];
_appState.mainSceneState = _sceneState;
_sceneController = _sceneController =
[[SceneController alloc] initWithSceneState:_sceneState]; [[SceneController alloc] initWithSceneState:_sceneState];
_sceneState.controller = _sceneController;
// TODO(crbug.com/1040501): remove this. // TODO(crbug.com/1040501): remove this.
// This is temporary plumbing that's not supposed to be here. // This is temporary plumbing that's not supposed to be here.
......
...@@ -645,7 +645,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData( ...@@ -645,7 +645,7 @@ void MainControllerAuthenticationServiceDelegate::ClearBrowsingData(
#pragma mark - Property implementation. #pragma mark - Property implementation.
- (id<BrowserInterfaceProvider>)interfaceProvider { - (id<BrowserInterfaceProvider>)interfaceProvider {
return self.sceneController.browserViewWrangler; return self.appState.connectedScenes[0].interfaceProvider;
} }
- (BOOL)isFirstLaunchAfterUpgrade { - (BOOL)isFirstLaunchAfterUpgrade {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/threading/thread.h" #include "base/threading/thread.h"
#import "ios/chrome/app/application_delegate/app_state.h" #import "ios/chrome/app/application_delegate/app_state.h"
#include "ios/chrome/app/application_delegate/startup_information.h"
#import "ios/chrome/app/application_delegate/tab_opening.h" #import "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/app/application_delegate/url_opener.h" #import "ios/chrome/app/application_delegate/url_opener.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
......
...@@ -7,7 +7,7 @@ import("//ios/build/chrome_build.gni") ...@@ -7,7 +7,7 @@ import("//ios/build/chrome_build.gni")
source_set("scene_guts") { source_set("scene_guts") {
sources = [ "scene_controller_guts.h" ] sources = [ "scene_controller_guts.h" ]
deps = [ deps = [
"//ios/chrome/app/application_delegate:application_delegate_internal", "//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/browser:utils", "//ios/chrome/browser:utils",
"//ios/chrome/browser/ui/tab_grid", "//ios/chrome/browser/ui/tab_grid",
"//ios/chrome/browser/url_loading", "//ios/chrome/browser/url_loading",
...@@ -37,7 +37,7 @@ source_set("scene") { ...@@ -37,7 +37,7 @@ source_set("scene") {
"//ios/chrome/app:app", "//ios/chrome/app:app",
"//ios/chrome/app:mode", "//ios/chrome/app:mode",
"//ios/chrome/app:tests_hook", "//ios/chrome/app:tests_hook",
"//ios/chrome/app/application_delegate:application_delegate_internal", "//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser:chrome_url_constants", "//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
......
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
// A temporary pointer to MainController. // A temporary pointer to MainController.
@property(nonatomic, weak) id<MainControllerGuts> mainController; @property(nonatomic, weak) id<MainControllerGuts> mainController;
// The interface provider for this scene.
@property(nonatomic, strong, readonly) id<BrowserInterfaceProvider>
interfaceProvider;
@end @end
#endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_MAIN_SCENE_CONTROLLER_H_
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/signin/public/identity_manager/identity_manager.h" #include "components/signin/public/identity_manager/identity_manager.h"
#include "components/url_formatter/url_formatter.h" #include "components/url_formatter/url_formatter.h"
#import "ios/chrome/app/application_delegate/app_state.h"
#include "ios/chrome/app/application_delegate/tab_opening.h" #include "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/app/application_delegate/url_opener.h" #import "ios/chrome/app/application_delegate/url_opener.h"
#include "ios/chrome/app/application_mode.h" #include "ios/chrome/app/application_mode.h"
...@@ -184,6 +183,10 @@ const NSTimeInterval kDisplayPromoDelay = 0.1; ...@@ -184,6 +183,10 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
// YES while animating the dismissal of tab switcher. // YES while animating the dismissal of tab switcher.
@property(nonatomic, assign) BOOL dismissingTabSwitcher; @property(nonatomic, assign) BOOL dismissingTabSwitcher;
// Wrangler to handle BVC and tab model creation, access, and related logic.
// Implements faetures exposed from this object through the
// BrowserViewInformation protocol.
@property(nonatomic, strong) BrowserViewWrangler* browserViewWrangler;
// The coordinator used to control sign-in UI flows. Lazily created the first // The coordinator used to control sign-in UI flows. Lazily created the first
// time it is accessed. // time it is accessed.
@property(nonatomic, strong) SigninCoordinator* signinCoordinator; @property(nonatomic, strong) SigninCoordinator* signinCoordinator;
...@@ -193,8 +196,6 @@ const NSTimeInterval kDisplayPromoDelay = 0.1; ...@@ -193,8 +196,6 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
@implementation SceneController @implementation SceneController
@synthesize appURLLoadingService = @synthesize appURLLoadingService =
_appURLLoadingService; //< From SceneControllerGuts _appURLLoadingService; //< From SceneControllerGuts
@synthesize browserViewWrangler =
_browserViewWrangler; //< From SceneControllerGuts
- (instancetype)initWithSceneState:(SceneState*)sceneState { - (instancetype)initWithSceneState:(SceneState*)sceneState {
self = [super init]; self = [super init];
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "ios/chrome/app/application_delegate/startup_information.h"
#import "ios/chrome/app/application_delegate/tab_opening.h" #import "ios/chrome/app/application_delegate/tab_opening.h"
#import "ios/chrome/browser/procedural_block_types.h" #import "ios/chrome/browser/procedural_block_types.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h" #import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
...@@ -19,11 +18,6 @@ ...@@ -19,11 +18,6 @@
@protocol SceneControllerGuts <WebStateListObserving> @protocol SceneControllerGuts <WebStateListObserving>
// Wrangler to handle BVC and tab model creation, access, and related logic.
// Implements faetures exposed from this object through the
// BrowserViewInformation protocol.
@property(nonatomic, strong) BrowserViewWrangler* browserViewWrangler;
- (void)startUpChromeUIPostCrash:(BOOL)isPostCrashLaunch - (void)startUpChromeUIPostCrash:(BOOL)isPostCrashLaunch
needRestoration:(BOOL)needsRestoration; needRestoration:(BOOL)needsRestoration;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
if (!_sceneState) { if (!_sceneState) {
_sceneState = [[SceneState alloc] init]; _sceneState = [[SceneState alloc] init];
_sceneController = [[SceneController alloc] initWithSceneState:_sceneState]; _sceneController = [[SceneController alloc] initWithSceneState:_sceneState];
_sceneState.controller = _sceneController;
} }
return _sceneState; return _sceneState;
} }
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@class SceneController;
@class SceneState; @class SceneState;
@protocol BrowserInterfaceProvider;
// Describes the possible scene states. // Describes the possible scene states.
// This is an iOS 12 compatible version of UISceneActivationState enum. // This is an iOS 12 compatible version of UISceneActivationState enum.
...@@ -48,6 +50,13 @@ typedef NS_ENUM(NSUInteger, SceneActivationLevel) { ...@@ -48,6 +50,13 @@ typedef NS_ENUM(NSUInteger, SceneActivationLevel) {
@property(nonatomic, strong) UIWindowScene* scene API_AVAILABLE(ios(13)); @property(nonatomic, strong) UIWindowScene* scene API_AVAILABLE(ios(13));
// The interface provider associated with this scene.
@property(nonatomic, strong, readonly) id<BrowserInterfaceProvider>
interfaceProvider;
// The controller for this scene.
@property(nonatomic, weak) SceneController* controller;
// Adds an observer to this scene state. The observers will be notified about // Adds an observer to this scene state. The observers will be notified about
// scene state changes per SceneStateObserver protocol. // scene state changes per SceneStateObserver protocol.
- (void)addObserver:(id<SceneStateObserver>)observer; - (void)addObserver:(id<SceneStateObserver>)observer;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "base/ios/crb_protocol_observers.h" #import "base/ios/crb_protocol_observers.h"
#import "ios/chrome/app/chrome_overlay_window.h" #import "ios/chrome/app/chrome_overlay_window.h"
#import "ios/chrome/browser/ui/main/scene_controller.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h" #import "ios/chrome/browser/ui/util/multi_window_support.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -84,6 +85,10 @@ ...@@ -84,6 +85,10 @@
[self.observers sceneState:self transitionedToActivationLevel:newLevel]; [self.observers sceneState:self transitionedToActivationLevel:newLevel];
} }
- (id<BrowserInterfaceProvider>)interfaceProvider {
return self.controller.interfaceProvider;
}
#pragma mark - debug #pragma mark - debug
- (NSString*)description { - (NSString*)description {
......
...@@ -28,6 +28,7 @@ source_set("url_loading") { ...@@ -28,6 +28,7 @@ source_set("url_loading") {
"//components/search_engines", "//components/search_engines",
"//components/sessions", "//components/sessions",
"//ios/chrome/app:mode", "//ios/chrome/app:mode",
"//ios/chrome/app/application_delegate:tab_opening",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/feature_engagement", "//ios/chrome/browser/feature_engagement",
......
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