Commit 8b66b989 authored by Andy Lu's avatar Andy Lu Committed by Commit Bot

address cold start issue with opening multiple tabs in IOS14

With Xcode 12.3 beta and iOS14, there was an issue with Open URLs
in Chrome In Incognito Siri shortcut during cold start. For example,
open a few NTP tabs in Incognito and then kill the application.
Then when triggering the shortcut, the URLs are not loaded.
It seems like the order of the restoration functions during cold start
changed, so that what worked before no longer works. To solve this
issue, a function similar to how Open URL in Chrome is handled in
ContinueUserActivity is written and is modified to handle multiple
URLs. This way, the tabs are opened directly after ContinueUserActivity
is invoked and no longer depend on the restoration functions during
cold start.

Bug:1113529

Change-Id: Ie6a8c91cad307bb5e510d300695a4490116a7491
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2336185Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795985}
parent fe83694a
......@@ -208,7 +208,12 @@ NSString* const kSiriShortcutOpenInIncognito = @"OpenInChromeIncognitoIntent";
[[AppStartupParameters alloc] initWithURLs:URLs];
startupParams.launchInIncognito = YES;
[connectionInformation setStartupParameters:startupParams];
return YES;
return [self continueUserActivityURLs:URLs
applicationIsActive:applicationIsActive
tabOpener:tabOpener
connectionInformation:connectionInformation
startupInformation:startupInformation
Incognito:YES];
} else {
// Do nothing for unknown activity type.
......@@ -267,6 +272,65 @@ NSString* const kSiriShortcutOpenInIncognito = @"OpenInChromeIncognitoIntent";
return YES;
}
+ (void)openMultipleTabsWithConnectionInformation:
(id<ConnectionInformation>)connectionInformation
tabOpener:(id<TabOpening>)tabOpener {
ApplicationModeForTabOpening mode =
connectionInformation.startupParameters.launchInIncognito
? ApplicationModeForTabOpening::INCOGNITO
: ApplicationModeForTabOpening::NORMAL;
BOOL dismissOmnibox = [[connectionInformation startupParameters]
postOpeningAction] != FOCUS_OMNIBOX;
// Using a weak reference to |connectionInformation| to solve a memory leak
// issue. |tabOpener| and |connectionInformation| are the same object in
// some cases (SceneController). This retains the object while the block
// exists. Then this block is passed around and in some cases it ends up
// stored in BrowserViewController. This results in a memory leak that looks
// like this: SceneController -> BrowserViewWrangler -> BrowserCoordinator
// -> BrowserViewController -> SceneController
__weak id<ConnectionInformation> weakConnectionInfo = connectionInformation;
[tabOpener
dismissModalsAndOpenMultipleTabsInMode:mode
URLs:weakConnectionInfo
.startupParameters.URLs
dismissOmnibox:dismissOmnibox
completion:^{
weakConnectionInfo.startupParameters = nil;
}];
}
+ (BOOL)continueUserActivityURLs:(const std::vector<GURL>&)webpageURLs
applicationIsActive:(BOOL)applicationIsActive
tabOpener:(id<TabOpening>)tabOpener
connectionInformation:
(id<ConnectionInformation>)connectionInformation
startupInformation:(id<StartupInformation>)startupInformation
Incognito:(BOOL)Incognito {
if (applicationIsActive && ![startupInformation isPresentingFirstRunUI]) {
// The app is already active so the applicationDidBecomeActive: method will
// never be called. Open the requested URLs immediately.
[self openMultipleTabsWithConnectionInformation:connectionInformation
tabOpener:tabOpener];
return YES;
}
// Don't record the first action as a user action, since it will not be
// initiated by the user.
[startupInformation resetFirstUserActionRecorder];
if (![connectionInformation startupParameters]) {
AppStartupParameters* startupParams =
[[AppStartupParameters alloc] initWithURLs:webpageURLs];
startupParams.launchInIncognito = Incognito;
[connectionInformation setStartupParameters:startupParams];
}
return YES;
}
+ (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler
tabOpener:(id<TabOpening>)tabOpener
......@@ -315,32 +379,8 @@ NSString* const kSiriShortcutOpenInIncognito = @"OpenInChromeIncognitoIntent";
}
if (!connectionInformation.startupParameters.URLs.empty()) {
ApplicationModeForTabOpening mode =
connectionInformation.startupParameters.launchInIncognito
? ApplicationModeForTabOpening::INCOGNITO
: ApplicationModeForTabOpening::NORMAL;
BOOL dismissOmnibox = [[connectionInformation startupParameters]
postOpeningAction] != FOCUS_OMNIBOX;
// Using a weak reference to |connectionInformation| to solve a memory leak
// issue. |tabOpener| and |connectionInformation| are the same object in
// some cases (SceneController). This retains the object while the block
// exists. Then this block is passed around and in some cases it ends up
// stored in BrowserViewController. This results in a memory leak that looks
// like this: SceneController -> BrowserViewWrangler -> BrowserCoordinator
// -> BrowserViewController -> SceneController
__weak id<ConnectionInformation> weakConnectionInfo = connectionInformation;
[tabOpener
dismissModalsAndOpenMultipleTabsInMode:mode
URLs:weakConnectionInfo
.startupParameters.URLs
dismissOmnibox:dismissOmnibox
completion:^{
weakConnectionInfo.startupParameters =
nil;
}];
[self openMultipleTabsWithConnectionInformation:connectionInformation
tabOpener:tabOpener];
return;
}
......
......@@ -594,6 +594,16 @@ TEST_F(UserActivityHandlerTest, ContinueUserActivityIntentIncognitoForeground) {
[[[startupInformationMock stub] andReturnValue:@NO] isPresentingFirstRunUI];
std::vector<GURL> URLs;
for (NSURL* URL in urls) {
URLs.push_back(net::GURLWithNSURL(URL));
}
AppStartupParameters* startupParams =
[[AppStartupParameters alloc] initWithURLs:URLs];
[[[connectionInformationMock stub] andReturn:startupParams]
startupParameters];
MockTabOpener* tabOpener = [[MockTabOpener alloc] init];
// Action.
......
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