WebKit Bugzilla
Attachment 371163 Details for
Bug 198380
: [iOS] UIProcess' background task expiration handler may get called after the app is foreground again
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-198380-20190602145540.patch (text/plain), 4.44 KB, created by
Chris Dumez
on 2019-06-02 14:55:42 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2019-06-02 14:55:42 PDT
Size:
4.44 KB
patch
obsolete
>Subversion Revision: 246023 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 0ae2a31e86e4d05aafbe15edb3e6a522e0ed3b6c..bddb63d9468f03572a179ddc4ca7a2118c789397 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,23 @@ >+2019-06-02 Chris Dumez <cdumez@apple.com> >+ >+ [iOS] UIProcess' background task expiration handler may get called after the app is foreground again >+ https://bugs.webkit.org/show_bug.cgi?id=198380 >+ <rdar://problem/49762471> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ UIProcess' background task expiration handler may get called after the app is foreground again. When >+ this happens, we already have a foreground assertion on behalf of the WebContent process, and the view >+ is visible. We would send the WillSuspendImminently IPC to the WebContent process, which would freeze >+ its layers, even though it is visible on screen. >+ >+ To address the issue, we now check if the app is visible in the expiration handler. If it is visible, >+ we do not notify clients of imminent suspension. Instead, we end the background task right away and >+ call _updateBackgroundTask asynchronously to start a new background task if necessary. >+ >+ * UIProcess/ios/ProcessAssertionIOS.mm: >+ (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]): >+ > 2019-06-01 Dean Jackson <dino@apple.com> > > Provide an action to save an image on a link sheet >diff --git a/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm b/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >index 2aca868bb8b5713159c91d2abe5feca9461cc72f..9b05709278cb9a510c6bfa9bcf01366444282031 100644 >--- a/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >+++ b/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm >@@ -65,6 +65,11 @@ + (WKProcessAssertionBackgroundTaskManager *)shared > return shared; > } > >+static bool isBackgroundState(BKSApplicationState state) >+{ >+ return state == BKSApplicationStateBackgroundRunning || state == BKSApplicationStateBackgroundTaskSuspended; >+} >+ > - (instancetype)init > { > self = [super init]; >@@ -73,6 +78,9 @@ - (instancetype)init > > _backgroundTask = UIBackgroundTaskInvalid; > >+ auto applicationStateMonitor = adoptNS([[BKSApplicationStateMonitor alloc] init]); >+ _applicationIsBackgrounded = isBackgroundState([applicationStateMonitor mostElevatedApplicationStateForPID:getpid()]); >+ > [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:[UIApplication sharedApplication] queue:nil usingBlock:^(NSNotification *) { > _applicationIsBackgrounded = NO; > [self _cancelPendingReleaseTask]; >@@ -150,7 +158,23 @@ - (void)_updateBackgroundTask > } > RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager - beginBackgroundTaskWithName", self); > _backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.ProcessAssertion" expirationHandler:^{ >- RELEASE_LOG_ERROR(ProcessSuspension, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d).", RunLoop::isMain()); >+ RELEASE_LOG_ERROR(ProcessSuspension, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d, applicationIsBackgrounded? %d).", RunLoop::isMain(), _applicationIsBackgrounded); >+ >+ // FIXME: Background tasks can currently expire while the application is in the foreground with UIKit for macOS. >+ // See <rdar://problem/51313780>. >+#if !PLATFORM(IOSMAC) >+ if (!_applicationIsBackgrounded) { >+ // We've received the invalidation warning after the app has become foreground again. In this case, we should not warn clients of imminent suspension. >+ // To be safe (avoid potential killing), we end the task right away and call _updateBackgroundTask asynchronously to start a new task if necessary. >+ [self _cancelPendingReleaseTask]; >+ [self _releaseBackgroundTask]; >+ dispatch_async(dispatch_get_main_queue(), ^{ >+ [self _updateBackgroundTask]; >+ }); >+ return; >+ } >+#endif >+ > // The expiration handler gets called on a non-main thread when the underlying assertion could not be taken (rdar://problem/27278419). > if (RunLoop::isMain()) > [self _notifyAssertionsOfImminentSuspension];
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 198380
:
370951
|
371163
|
371284