Commit 7194d494 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Do not create a second NTP on opening a window

New windows are created with an NSUserActivity to load
a URL (that can be chrome://newtabpage) in a new tab.

1. Use openOrReuseTab function to open such activities
to reuse the current tab if it is an NTP
2. avoid opening the default NTP if such an activity
exists as the NTP would flash before the target URL is
loaded.

Bug: 1106738
Change-Id: Ib034d54dc596b9ca5a69046fd71234831f35bd31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302616
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789473}
parent 3cd7ca07
...@@ -368,8 +368,12 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -368,8 +368,12 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
.userActivities) { .userActivities) {
if (ActivityIsURLLoad(activity)) { if (ActivityIsURLLoad(activity)) {
UrlLoadParams params = LoadParamsFromActivity(activity); UrlLoadParams params = LoadParamsFromActivity(activity);
UrlLoadingBrowserAgent::FromBrowser(self.mainInterface.browser) ApplicationMode mode = params.in_incognito
->Load(params); ? ApplicationMode::INCOGNITO
: ApplicationMode::NORMAL;
[self openOrReuseTabInMode:mode
withUrlLoadParams:params
tabOpenedCompletion:nil];
} else if (!activityWithCompletion) { } else if (!activityWithCompletion) {
// Completion involves user interaction. // Completion involves user interaction.
// Only one can be triggered. // Only one can be triggered.
...@@ -1453,8 +1457,24 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1453,8 +1457,24 @@ 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
// flash before the target URL is loaded.
return browser->GetWebStateList()->empty() && return browser->GetWebStateList()->empty() &&
!(browser->GetBrowserState()->IsOffTheRecord()); !(browser->GetBrowserState()->IsOffTheRecord()) && !hasPendingURL;
} }
#pragma mark - SceneURLLoadingServiceDelegate #pragma mark - SceneURLLoadingServiceDelegate
...@@ -1686,7 +1706,6 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1686,7 +1706,6 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
} }
// Checks the target BVC's current tab's URL. If this URL is chrome://newtab, // Checks the target BVC's current tab's URL. If this URL is chrome://newtab,
// loads |urlLoadParams| in this tab. Otherwise, open |urlLoadParams| in a new // loads |urlLoadParams| in this tab. Otherwise, open |urlLoadParams| in a new
// tab in the target BVC. |tabDisplayedCompletion| will be called on the new tab // tab in the target BVC. |tabDisplayedCompletion| will be called on the new tab
......
...@@ -125,7 +125,7 @@ using base::UserMetricsAction; ...@@ -125,7 +125,7 @@ using base::UserMetricsAction;
break; break;
#endif // !defined(NDEBUG) #endif // !defined(NDEBUG)
case PopupMenuActionOpenNewWindow: case PopupMenuActionOpenNewWindow:
[self.dispatcher openNewWindowWithActivity:ActivityToOpenNewTab(false)]; [self.dispatcher openNewWindowWithActivity:nil];
break; break;
case PopupMenuActionBookmarks: case PopupMenuActionBookmarks:
RecordAction(UserMetricsAction("MobileMenuAllBookmarks")); RecordAction(UserMetricsAction("MobileMenuAllBookmarks"));
......
...@@ -41,10 +41,6 @@ typedef NS_ENUM(NSInteger, WindowActivityOrigin) { ...@@ -41,10 +41,6 @@ typedef NS_ENUM(NSInteger, WindowActivityOrigin) {
// Helper functions to create NSUserActivity instances that encode specific // Helper functions to create NSUserActivity instances that encode specific
// actions in the browser, and to decode those actions from those activities. // actions in the browser, and to decode those actions from those activities.
// Create a new activity that opens a new, empty tab. |in_incognito| indicates
// if the new tab should be incognito.
NSUserActivity* ActivityToOpenNewTab(bool in_incognito);
// Create a new activity that opens a new tab, loading |url| with the referrer // Create a new activity that opens a new tab, loading |url| with the referrer
// |referrer|. |in_incognito| indicates if the new tab should be incognito. // |referrer|. |in_incognito| indicates if the new tab should be incognito.
NSUserActivity* ActivityToLoadURL(WindowActivityOrigin origin, NSUserActivity* ActivityToLoadURL(WindowActivityOrigin origin,
...@@ -64,6 +60,10 @@ NSUserActivity* ActivityToMoveTab(NSString* tab_id); ...@@ -64,6 +60,10 @@ 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);
......
...@@ -38,14 +38,6 @@ NSUserActivity* BaseActivityForURLOpening(bool in_incognito) { ...@@ -38,14 +38,6 @@ NSUserActivity* BaseActivityForURLOpening(bool in_incognito) {
} // namespace } // namespace
NSUserActivity* ActivityToOpenNewTab(bool in_incognito) {
NSUserActivity* activity = BaseActivityForURLOpening(in_incognito);
[activity addUserInfoEntriesFromDictionary:@{
kURLKey : net::NSURLWithGURL(GURL(kChromeUINewTabURL))
}];
return activity;
}
NSUserActivity* ActivityToLoadURL(WindowActivityOrigin origin, NSUserActivity* ActivityToLoadURL(WindowActivityOrigin origin,
const GURL& url, const GURL& url,
const web::Referrer& referrer, const web::Referrer& referrer,
...@@ -88,6 +80,10 @@ bool ActivityIsURLLoad(NSUserActivity* activity) { ...@@ -88,6 +80,10 @@ 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