Commit 62b6f297 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Fix new session with open incogito without multiwindow.

Fix this scenario by:
- Checking startupParameters on top of connectionOption for when
  multiwindow is disabled
- Checking startup actions first as this is also needed if tab grid
  is displayed
- Check if there are pending actions in the "other" mode as this seems
  to be the expected behavior.

Bug: 1110836
Change-Id: I22fb44ebe9537fd99893289031974cfb5d15795f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332616Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794213}
parent 24080f7d
...@@ -1422,6 +1422,20 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1422,6 +1422,20 @@ 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.
// In that case, it is not useful to open another tab.
if (@available(iOS 13, *)) {
for (NSUserActivity* activity in self.sceneState.connectionOptions
.userActivities) {
if (ActivityIsURLLoad(activity)) {
return NO;
}
}
}
if (self.startupParameters) {
return NO;
}
if (self.tabSwitcherIsActive) { if (self.tabSwitcherIsActive) {
Browser* mainBrowser = self.mainInterface.browser; Browser* mainBrowser = self.mainInterface.browser;
Browser* otrBrowser = self.incognitoInterface.browser; Browser* otrBrowser = self.incognitoInterface.browser;
...@@ -1447,24 +1461,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1447,24 +1461,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
return YES; return YES;
} }
BOOL hasPendingURL = NO;
if (@available(iOS 13, *)) {
// Only consider normal mode load as this function always returns NO for
// incognito browser.
for (NSUserActivity* activity in self.sceneState.connectionOptions
.userActivities) {
if (ActivityIsURLLoadInNormalMode(activity)) {
hasPendingURL = YES;
break;
}
}
}
// If there is a URLLoading activity, avoid opening a new tab as the NTP would // If there is a URLLoading activity, avoid opening a new tab as the NTP would
// flash before the target URL is loaded. // flash before the target URL is loaded.
return browser->GetWebStateList()->empty() && return browser->GetWebStateList()->empty() &&
!(browser->GetBrowserState()->IsOffTheRecord()) && !hasPendingURL; !(browser->GetBrowserState()->IsOffTheRecord());
} }
#pragma mark - SceneURLLoadingServiceDelegate #pragma mark - SceneURLLoadingServiceDelegate
......
...@@ -60,10 +60,6 @@ NSUserActivity* ActivityToMoveTab(NSString* tab_id); ...@@ -60,10 +60,6 @@ NSUserActivity* ActivityToMoveTab(NSString* tab_id);
// new tab page in a new tab). // new tab page in a new tab).
bool ActivityIsURLLoad(NSUserActivity* activity); bool ActivityIsURLLoad(NSUserActivity* activity);
// true if |activity| is one that indicates a URL load (including loading the
// new tab page in a new tab) in normal mode.
bool ActivityIsURLLoadInNormalMode(NSUserActivity* activity);
// true if |activity| is one that indicates a tab move. // true if |activity| is one that indicates a tab move.
bool ActivityIsTabMove(NSUserActivity* activity); bool ActivityIsTabMove(NSUserActivity* activity);
......
...@@ -80,10 +80,6 @@ bool ActivityIsURLLoad(NSUserActivity* activity) { ...@@ -80,10 +80,6 @@ bool ActivityIsURLLoad(NSUserActivity* activity) {
[activity.activityType isEqualToString:kLoadIncognitoURLActivityType]; [activity.activityType isEqualToString:kLoadIncognitoURLActivityType];
} }
bool ActivityIsURLLoadInNormalMode(NSUserActivity* activity) {
return [activity.activityType isEqualToString:kLoadURLActivityType];
}
bool ActivityIsTabMove(NSUserActivity* activity) { bool ActivityIsTabMove(NSUserActivity* activity) {
return [activity.activityType isEqualToString:kMoveTabActivityType]; return [activity.activityType isEqualToString:kMoveTabActivityType];
} }
......
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