Commit 70f823e5 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Execute external intents after scene is unblocked

If an external intent comes when Chrome shows a blocking UI, it should
be delayed until it is possible to execute it.

This CL considers the scene as not active if it is blocked.
The activities are stored in startupParameters when they are
received.
When the scene is unblocked, call handleExternalIntents to
execute it.

Bug: 1101786
Change-Id: I8117b0cd328847e03283f0d11fea825708594af5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2292475Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788654}
parent 55ae16c8
......@@ -51,10 +51,7 @@ const char* const kUMAMobileSessionStartFromAppsHistogram =
if (startupInformation.isPresentingFirstRunUI) {
UMA_HISTOGRAM_ENUMERATION("FirstRun.LaunchSource", [params launchSource],
first_run::LAUNCH_SIZE);
return NO;
}
if (applicationActive) {
} else if (applicationActive) {
// The app is already active so the applicationDidBecomeActive: method will
// never be called. Open the requested URL immediately and return YES if
// the parsed URL was valid.
......@@ -105,10 +102,10 @@ const char* const kUMAMobileSessionStartFromAppsHistogram =
return YES;
}
return NO;
}
// Don't record the first user action.
} else {
// Don't record the first user action if application is not active.
[startupInformation resetFirstUserActionRecorder];
}
connectionInformation.startupParameters = params;
return connectionInformation.startupParameters != nil;
......
......@@ -396,6 +396,16 @@ TEST_F(URLOpenerTest, PresentingFirstRunUI) {
isPresentingFirstRunUI];
id connectionInformationMock =
[OCMockObject mockForProtocol:@protocol(ConnectionInformation)];
__block ChromeAppStartupParameters* params = nil;
[[connectionInformationMock expect]
setStartupParameters:[OCMArg checkWithBlock:^(
ChromeAppStartupParameters* p) {
params = p;
EXPECT_NSEQ(net::NSURLWithGURL(p.completeURL), url);
EXPECT_EQ(p.callerApp, CALLER_APP_APPLE_MOBILESAFARI);
return YES;
}]];
[[[connectionInformationMock expect] andReturn:params] startupParameters];
id appStateMock = [OCMockObject mockForClass:[AppState class]];
[[appStateMock expect] launchFromURLHandled:NO];
......
......@@ -297,6 +297,46 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[ContentSuggestionsSchedulerNotifications
notifyForeground:self.mainInterface.browserState];
}
[self handleExternalIntents];
if (!initializingUIInColdStart && self.tabSwitcherIsActive &&
[self shouldOpenNTPTabOnActivationOfBrowser:self.currentInterface
.browser]) {
DCHECK(!self.dismissingTabSwitcher);
[self beginDismissingTabSwitcherWithCurrentBrowser:self.mainInterface
.browser
focusOmnibox:NO];
OpenNewTabCommand* command = [OpenNewTabCommand commandWithIncognito:NO];
command.userInitiated = NO;
Browser* browser = self.currentInterface.browser;
id<ApplicationCommands> applicationHandler = HandlerForProtocol(
browser->GetCommandDispatcher(), ApplicationCommands);
[applicationHandler openURLInNewTab:command];
[self finishDismissingTabSwitcher];
}
}
if (sceneState.currentOrigin != WindowActivityRestoredOrigin) {
if (IsMultiwindowSupported()) {
if (@available(iOS 13, *)) {
base::UmaHistogramEnumeration(kMultiWindowOpenInNewWindowHistogram,
sceneState.currentOrigin);
}
}
}
if (self.hasInitializedUI && level == SceneActivationLevelUnattached) {
[self teardownUI];
}
}
- (void)handleExternalIntents {
if (self.mainController.isPresentingFirstRunUI ||
self.blockingOverlayViewController) {
return;
}
if (IsSceneStartupSupported()) {
if (@available(iOS 13, *)) {
// Handle URL opening from
......@@ -369,37 +409,6 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
startupInformation:self.mainController
appState:self.sceneState.appState];
}
if (!initializingUIInColdStart && self.tabSwitcherIsActive &&
[self shouldOpenNTPTabOnActivationOfBrowser:self.currentInterface
.browser]) {
DCHECK(!self.dismissingTabSwitcher);
[self beginDismissingTabSwitcherWithCurrentBrowser:self.mainInterface
.browser
focusOmnibox:NO];
OpenNewTabCommand* command = [OpenNewTabCommand commandWithIncognito:NO];
command.userInitiated = NO;
Browser* browser = self.currentInterface.browser;
id<ApplicationCommands> applicationHandler = HandlerForProtocol(
browser->GetCommandDispatcher(), ApplicationCommands);
[applicationHandler openURLInNewTab:command];
[self finishDismissingTabSwitcher];
}
}
if (sceneState.currentOrigin != WindowActivityRestoredOrigin) {
if (IsMultiwindowSupported()) {
if (@available(iOS 13, *)) {
base::UmaHistogramEnumeration(kMultiWindowOpenInNewWindowHistogram,
sceneState.currentOrigin);
}
}
}
if (self.hasInitializedUI && level == SceneActivationLevelUnattached) {
[self teardownUI];
}
}
- (void)sceneStateWillShowModalOverlay:(SceneState*)sceneState {
......@@ -426,6 +435,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
}
}
}
if (sceneState.activationLevel >= SceneActivationLevelForegroundActive) {
[self handleExternalIntents];
}
}
// TODO(crbug.com/1072408): factor out into a new class.
......@@ -491,6 +504,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
}
BOOL sceneIsActive =
self.sceneState.activationLevel >= SceneActivationLevelForegroundActive;
if (self.mainController.isPresentingFirstRunUI ||
self.blockingOverlayViewController) {
sceneIsActive = NO;
}
[UserActivityHandler continueUserActivity:userActivity
applicationIsActive:sceneIsActive
tabOpener:self
......@@ -736,16 +753,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
removeObserver:self
name:kChromeFirstRunUIWillFinishNotification
object:nil];
if (self.startupParameters) {
UrlLoadParams params =
UrlLoadParams::InNewTab(self.startupParameters.externalURL);
[self dismissModalsAndOpenSelectedTabInMode:ApplicationModeForTabOpening::
NORMAL
withUrlLoadParams:params
dismissOmnibox:YES
completion:^{
[self setStartupParameters:nil];
}];
if (self.sceneState.activationLevel >= SceneActivationLevelForegroundActive) {
[self handleExternalIntents];
}
}
......@@ -1977,6 +1986,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
DCHECK(URLsToOpen.count == URLContexts.count || URLContexts.count == 1);
BOOL active =
_sceneState.activationLevel >= SceneActivationLevelForegroundActive;
if (self.mainController.isPresentingFirstRunUI ||
self.blockingOverlayViewController) {
active = NO;
}
for (URLOpenerParams* options : URLsToOpen) {
[URLOpener openURL:options
applicationActive:active
......
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