0

[iOS] Skip intents when they are handled in odd sequences

It seems that in some rare cases, the order of the lifecycle events
break our assumptions. We had similar odd issues in the past, e.g.
crbug.com/658420.

For example, -[SceneDelegate scene:continueUserActivity:] might be
unexpectedly called during startup before sceneWillEnterForeground:. In
which case the intent is handled before the browser UI objects being
initialized which might lead to memory crashes
(e.g., crbug.com/1211006).

Bug: 1211006, 1220836
Change-Id: I60f4b23f45bd8d97f2fad367f0a9eeca792b01f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2967219
Commit-Queue: Vincent Boisselle <vincb@google.com>
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#894003}
This commit is contained in:
Vincent Boisselle
2021-06-18 22:29:43 +00:00
committed by Chromium LUCI CQ
parent 8a9411999d
commit 6a12403329

@ -581,6 +581,15 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
- (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
completionHandler:(void (^)(BOOL succeeded))completionHandler
API_AVAILABLE(ios(13)) {
if (self.sceneState.appState.initStage <= InitStageNormalUI ||
!self.currentInterface.browserState) {
// Don't handle the intent if the browser UI objects aren't yet initialized.
// This is the case when the app is in safe mode or may be the case when the
// app is going through an odd sequence of lifecyle events (shouldn't happen
// but happens somehow), see crbug.com/1211006 for more details.
return;
}
self.sceneState.startupHadExternalIntent = YES;
// Perform the action in incognito when only incognito mode is available.
@ -598,10 +607,19 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
- (void)sceneState:(SceneState*)sceneState
receivedUserActivity:(NSUserActivity*)userActivity {
if (self.sceneState.appState.initStage <= InitStageSafeMode ||
!userActivity) {
if (!userActivity) {
return;
}
if (self.sceneState.appState.initStage <= InitStageNormalUI ||
!self.currentInterface.browserState) {
// Don't handle the intent if the browser UI objects aren't yet initialized.
// This is the case when the app is in safe mode or may be the case when the
// app is going through an odd sequence of lifecyle events (shouldn't happen
// but happens somehow), see crbug.com/1211006 for more details.
return;
}
BOOL sceneIsActive =
self.sceneState.activationLevel >= SceneActivationLevelForegroundActive;
// TODO(crbug.com/1210542): Review this stage threshold; works for now.
@ -2746,7 +2764,12 @@ const char kMultiWindowOpenInNewWindowHistogram[] =
- (void)openURLContexts:(NSSet<UIOpenURLContext*>*)URLContexts
API_AVAILABLE(ios(13)) {
if (self.sceneState.appState.initStage <= InitStageSafeMode) {
if (self.sceneState.appState.initStage <= InitStageNormalUI ||
!self.currentInterface.browserState) {
// Don't handle the intent if the browser UI objects aren't yet initialized.
// This is the case when the app is in safe mode or may be the case when the
// app is going through an odd sequence of lifecyle events (shouldn't happen
// but happens somehow), see crbug.com/1211006 for more details.
return;
}