Commit 131342bd authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[multiball] Opening new window should not restore last session.

Assigns IDs semi-randomly to created scenes and restores the session
from a given session ID into a scene.
This fixes a bug where opening a new window would restore the previous
session from the first window.
However, a permanent solution here would be to actually implement
session restoration that is not based on non-persistent integer
window IDs.

Bug: 1069747
Change-Id: I4a5352d56f4a7d506ff618944b9868c688a5b612
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144274
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758205}
parent 410a8857
......@@ -129,6 +129,7 @@ source_set("main") {
"//ios/chrome/browser/ui/recent_tabs",
"//ios/chrome/browser/ui/snackbar",
"//ios/chrome/browser/ui/translate:legacy_translate",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/web",
"//ios/chrome/browser/web:tab_helper_delegates",
......
......@@ -43,6 +43,11 @@ NSString* kIncognitoCurrentKey = @"IncognitoActive";
- (instancetype)init NS_UNAVAILABLE;
// Window ID. Only used in multiwindow. Temporary solution for session
// restoration in multiwindow.
// TODO(crbug.com/1069762): remove this.
@property(nonatomic, assign) NSUInteger windowID;
// Creates the main Browser used by the receiver, using the browser state
// and tab model observer it was configured with. The main interface is then
// created; until this method is called, the main and incognito interfaces will
......
......@@ -25,6 +25,7 @@
#import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browsing_data_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -408,10 +409,18 @@
browser->GetBrowserState()->GetStatePath().AsUTF8Unsafe());
SessionIOS* session =
[[SessionServiceIOS sharedService] loadSessionFromDirectory:statePath];
if (session) {
DCHECK_EQ(session.sessionWindows.count, 1u);
sessionWindow = session.sessionWindows[0];
if (IsMultiwindowSupported()) {
if (session && session.sessionWindows.count > self.windowID) {
sessionWindow = session.sessionWindows[self.windowID];
}
} else {
if (session) {
DCHECK_EQ(session.sessionWindows.count, 1u);
sessionWindow = session.sessionWindows[0];
}
}
SessionRestorationBrowserAgent::FromBrowser(browser)->RestoreSessionWindow(
sessionWindow);
}
......
......@@ -306,6 +306,8 @@ const NSTimeInterval kDisplayPromoDelay = 0.1;
applicationCommandEndpoint:self
browsingDataCommandEndpoint:self.mainController];
self.browserViewWrangler.windowID = self.sceneState.windowID;
// Ensure the main browser is created. This also creates the BVC.
[self.browserViewWrangler createMainBrowser];
......
......@@ -45,6 +45,10 @@ typedef NS_ENUM(NSUInteger, SceneActivationLevel) {
// The current activation level.
@property(nonatomic, assign) SceneActivationLevel activationLevel;
// Window ID, used for restoration.
// TODO(crbug.com/1069762): remove this.
@property(nonatomic, assign, readonly) NSUInteger windowID;
// Window for the associated scene, if any.
@property(nonatomic, strong) UIWindow* window;
......
......@@ -30,12 +30,16 @@
@implementation SceneState
@synthesize window = _window;
@synthesize windowID = _windowID;
- (instancetype)init {
self = [super init];
if (self) {
_observers = [SceneStateObserverList
observersWithProtocol:@protocol(SceneStateObserver)];
if (@available(iOS 13, *)) {
_windowID = UIApplication.sharedApplication.connectedScenes.count - 1;
}
}
return self;
}
......@@ -52,6 +56,14 @@
#pragma mark - Setters & Getters.
- (NSUInteger)windowID {
if (IsMultiwindowSupported()) {
return _windowID;
} else {
return 0;
}
}
- (void)setWindow:(UIWindow*)window {
if (IsMultiwindowSupported()) {
// No need to set anything, instead the getter is backed by scene.windows
......
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