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 = ...@@ -51,10 +51,7 @@ const char* const kUMAMobileSessionStartFromAppsHistogram =
if (startupInformation.isPresentingFirstRunUI) { if (startupInformation.isPresentingFirstRunUI) {
UMA_HISTOGRAM_ENUMERATION("FirstRun.LaunchSource", [params launchSource], UMA_HISTOGRAM_ENUMERATION("FirstRun.LaunchSource", [params launchSource],
first_run::LAUNCH_SIZE); first_run::LAUNCH_SIZE);
return NO; } else if (applicationActive) {
}
if (applicationActive) {
// The app is already active so the applicationDidBecomeActive: method will // The app is already active so the applicationDidBecomeActive: method will
// never be called. Open the requested URL immediately and return YES if // never be called. Open the requested URL immediately and return YES if
// the parsed URL was valid. // the parsed URL was valid.
...@@ -105,10 +102,10 @@ const char* const kUMAMobileSessionStartFromAppsHistogram = ...@@ -105,10 +102,10 @@ const char* const kUMAMobileSessionStartFromAppsHistogram =
return YES; return YES;
} }
return NO; return NO;
} } else {
// Don't record the first user action if application is not active.
// Don't record the first user action.
[startupInformation resetFirstUserActionRecorder]; [startupInformation resetFirstUserActionRecorder];
}
connectionInformation.startupParameters = params; connectionInformation.startupParameters = params;
return connectionInformation.startupParameters != nil; return connectionInformation.startupParameters != nil;
......
...@@ -396,6 +396,16 @@ TEST_F(URLOpenerTest, PresentingFirstRunUI) { ...@@ -396,6 +396,16 @@ TEST_F(URLOpenerTest, PresentingFirstRunUI) {
isPresentingFirstRunUI]; isPresentingFirstRunUI];
id connectionInformationMock = id connectionInformationMock =
[OCMockObject mockForProtocol:@protocol(ConnectionInformation)]; [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]]; id appStateMock = [OCMockObject mockForClass:[AppState class]];
[[appStateMock expect] launchFromURLHandled:NO]; [[appStateMock expect] launchFromURLHandled:NO];
......
...@@ -297,6 +297,46 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -297,6 +297,46 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
[ContentSuggestionsSchedulerNotifications [ContentSuggestionsSchedulerNotifications
notifyForeground:self.mainInterface.browserState]; 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 (IsSceneStartupSupported()) {
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
// Handle URL opening from // Handle URL opening from
...@@ -369,37 +409,6 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -369,37 +409,6 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
startupInformation:self.mainController startupInformation:self.mainController
appState:self.sceneState.appState]; 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 { - (void)sceneStateWillShowModalOverlay:(SceneState*)sceneState {
...@@ -426,6 +435,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -426,6 +435,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
} }
} }
if (sceneState.activationLevel >= SceneActivationLevelForegroundActive) {
[self handleExternalIntents];
}
} }
// TODO(crbug.com/1072408): factor out into a new class. // TODO(crbug.com/1072408): factor out into a new class.
...@@ -491,6 +504,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -491,6 +504,10 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
} }
BOOL sceneIsActive = BOOL sceneIsActive =
self.sceneState.activationLevel >= SceneActivationLevelForegroundActive; self.sceneState.activationLevel >= SceneActivationLevelForegroundActive;
if (self.mainController.isPresentingFirstRunUI ||
self.blockingOverlayViewController) {
sceneIsActive = NO;
}
[UserActivityHandler continueUserActivity:userActivity [UserActivityHandler continueUserActivity:userActivity
applicationIsActive:sceneIsActive applicationIsActive:sceneIsActive
tabOpener:self tabOpener:self
...@@ -736,16 +753,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -736,16 +753,8 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
removeObserver:self removeObserver:self
name:kChromeFirstRunUIWillFinishNotification name:kChromeFirstRunUIWillFinishNotification
object:nil]; object:nil];
if (self.startupParameters) { if (self.sceneState.activationLevel >= SceneActivationLevelForegroundActive) {
UrlLoadParams params = [self handleExternalIntents];
UrlLoadParams::InNewTab(self.startupParameters.externalURL);
[self dismissModalsAndOpenSelectedTabInMode:ApplicationModeForTabOpening::
NORMAL
withUrlLoadParams:params
dismissOmnibox:YES
completion:^{
[self setStartupParameters:nil];
}];
} }
} }
...@@ -1977,6 +1986,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] = ...@@ -1977,6 +1986,11 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
DCHECK(URLsToOpen.count == URLContexts.count || URLContexts.count == 1); DCHECK(URLsToOpen.count == URLContexts.count || URLContexts.count == 1);
BOOL active = BOOL active =
_sceneState.activationLevel >= SceneActivationLevelForegroundActive; _sceneState.activationLevel >= SceneActivationLevelForegroundActive;
if (self.mainController.isPresentingFirstRunUI ||
self.blockingOverlayViewController) {
active = NO;
}
for (URLOpenerParams* options : URLsToOpen) { for (URLOpenerParams* options : URLsToOpen) {
[URLOpener openURL:options [URLOpener openURL:options
applicationActive:active 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