Commit 2d06237e authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Fix multiwindow-disabled app.

Fixes some scene-specific API usage on iOS 13 that's not gated with
multiwindow checks.

Bug: 1133356
Change-Id: I6ead2767526b111d3ad292ac638509428ff3f88f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437399
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812224}
parent 594ff1fb
...@@ -171,13 +171,18 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -171,13 +171,18 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
_mainApplicationDelegate = applicationDelegate; _mainApplicationDelegate = applicationDelegate;
_appCommandDispatcher = [[CommandDispatcher alloc] init]; _appCommandDispatcher = [[CommandDispatcher alloc] init];
if (@available(iOS 13, *)) { // Subscribe to scene-related notifications when using scenes.
// Subscribe to scene connection notifications. // Note these are also sent when not using scenes, so avoid subscribing to
[[NSNotificationCenter defaultCenter] // them unless necessary.
addObserver:self if (IsSceneStartupSupported()) {
selector:@selector(sceneWillConnect:) if (@available(iOS 13, *)) {
name:UISceneWillConnectNotification // Subscribe to scene connection notifications.
object:nil]; [[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sceneWillConnect:)
name:UISceneWillConnectNotification
object:nil];
}
} }
} }
return self; return self;
...@@ -696,6 +701,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -696,6 +701,7 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
} }
- (void)sceneWillConnect:(NSNotification*)notification { - (void)sceneWillConnect:(NSNotification*)notification {
DCHECK(IsSceneStartupSupported());
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
UIWindowScene* scene = UIWindowScene* scene =
base::mac::ObjCCastStrict<UIWindowScene>(notification.object); base::mac::ObjCCastStrict<UIWindowScene>(notification.object);
......
...@@ -76,8 +76,10 @@ ...@@ -76,8 +76,10 @@
- (void)showOverlay { - (void)showOverlay {
NSArray<UIWindow*>* windows = nil; NSArray<UIWindow*>* windows = nil;
if (@available(iOS 13, *)) { if (IsMultiwindowSupported()) {
windows = self.sceneState.scene.windows; if (@available(iOS 13, *)) {
windows = self.sceneState.scene.windows;
}
} else { } else {
windows = UIApplication.sharedApplication.windows; windows = UIApplication.sharedApplication.windows;
} }
......
...@@ -308,11 +308,13 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -308,11 +308,13 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
level > SceneActivationLevelBackground && !self.hasInitializedUI; level > SceneActivationLevelBackground && !self.hasInitializedUI;
if (initializingUIInColdStart) { if (initializingUIInColdStart) {
[self initializeUI]; [self initializeUI];
if (@available(iOS 13, *)) { if (IsMultiwindowSupported()) {
// Add the scene to the list of connected scene, to restore in case of if (@available(iOS 13, *)) {
// crashes. // Add the scene to the list of connected scene, to restore in case of
[[PreviousSessionInfo sharedInstance] // crashes.
addSceneSessionID:sceneState.scene.session.persistentIdentifier]; [[PreviousSessionInfo sharedInstance]
addSceneSessionID:sceneState.scene.session.persistentIdentifier];
}
} }
} }
...@@ -359,9 +361,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -359,9 +361,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
if (self.hasInitializedUI && level == SceneActivationLevelUnattached) { if (self.hasInitializedUI && level == SceneActivationLevelUnattached) {
if (@available(iOS 13, *)) { if (IsMultiwindowSupported()) {
[[PreviousSessionInfo sharedInstance] if (@available(iOS 13, *)) {
removeSceneSessionID:sceneState.scene.session.persistentIdentifier]; [[PreviousSessionInfo sharedInstance]
removeSceneSessionID:sceneState.scene.session.persistentIdentifier];
}
} }
[self teardownUI]; [self teardownUI];
} }
...@@ -1585,14 +1589,17 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1585,14 +1589,17 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
- (BOOL)shouldOpenNTPTabOnActivationOfBrowser:(Browser*)browser { - (BOOL)shouldOpenNTPTabOnActivationOfBrowser:(Browser*)browser {
// Check if there are pending actions that would result in opening a new tab. // Check if there are pending actions that would result in opening a new tab.
// In that case, it is not useful to open another tab. // In that case, it is not useful to open another tab.
if (@available(iOS 13, *)) { if (IsSceneStartupSupported()) {
for (NSUserActivity* activity in self.sceneState.connectionOptions if (@available(iOS 13, *)) {
.userActivities) { for (NSUserActivity* activity in self.sceneState.connectionOptions
if (ActivityIsURLLoad(activity)) { .userActivities) {
return NO; if (ActivityIsURLLoad(activity)) {
return NO;
}
} }
} }
} }
if (self.startupParameters) { if (self.startupParameters) {
return NO; return NO;
} }
......
...@@ -154,6 +154,7 @@ source_set("app_support+eg2") { ...@@ -154,6 +154,7 @@ source_set("app_support+eg2") {
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/list_model", "//ios/chrome/browser/ui/list_model",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
] ]
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_app_interface.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_app_interface.h"
#import "ios/chrome/browser/ui/list_model/list_model.h" #import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -14,15 +15,17 @@ ...@@ -14,15 +15,17 @@
@implementation RecentTabsAppInterface @implementation RecentTabsAppInterface
+ (void)clearCollapsedListViewSectionStates { + (void)clearCollapsedListViewSectionStates {
if (@available(iOS 13, *)) { if (IsSceneStartupSupported()) {
NSArray<UIWindow*>* windows = [UIApplication sharedApplication].windows; if (@available(iOS 13, *)) {
for (UIWindow* window in windows) { NSArray<UIWindow*>* windows = [UIApplication sharedApplication].windows;
UISceneSession* session = window.windowScene.session; for (UIWindow* window in windows) {
UISceneSession* session = window.windowScene.session;
NSMutableDictionary* newUserInfo = NSMutableDictionary* newUserInfo =
[NSMutableDictionary dictionaryWithDictionary:session.userInfo]; [NSMutableDictionary dictionaryWithDictionary:session.userInfo];
[newUserInfo removeObjectForKey:kListModelCollapsedKey]; [newUserInfo removeObjectForKey:kListModelCollapsedKey];
session.userInfo = newUserInfo; session.userInfo = newUserInfo;
}
} }
} else { } else {
[NSUserDefaults.standardUserDefaults setObject:@{} [NSUserDefaults.standardUserDefaults setObject:@{}
......
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