⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 245899 in webkit


Ignore:
Timestamp:
May 30, 2019, 12:34:19 PM (7 years ago)
Author:
Chris Dumez
Message:

[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 Geoffrey Garen.

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]):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245896 r245899  
     12019-05-30  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] UIProcess' background task expiration handler may get called after the app is foreground again
     4        https://bugs.webkit.org/show_bug.cgi?id=198380
     5        <rdar://problem/49762471>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        UIProcess' background task expiration handler may get called after the app is foreground again. When
     10        this happens, we already have a foreground assertion on behalf of the WebContent process, and the view
     11        is visible. We would send the WillSuspendImminently IPC to the WebContent process, which would freeze
     12        its layers, even though it is visible on screen.
     13
     14        To address the issue, we now check if the app is visible in the expiration handler. If it is visible,
     15        we do not notify clients of imminent suspension. Instead, we end the background task right away and
     16        call _updateBackgroundTask asynchronously to start a new background task if necessary.
     17
     18        * UIProcess/ios/ProcessAssertionIOS.mm:
     19        (-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]):
     20
    1212019-05-30  Chris Dumez  <cdumez@apple.com>
    222
  • trunk/Source/WebKit/UIProcess/ios/ProcessAssertionIOS.mm

    r245334 r245899  
    151151        RELEASE_LOG(ProcessSuspension, "%p - WKProcessAssertionBackgroundTaskManager - beginBackgroundTaskWithName", self);
    152152        _backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"com.apple.WebKit.ProcessAssertion" expirationHandler:^{
    153             RELEASE_LOG_ERROR(ProcessSuspension, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d).", RunLoop::isMain());
     153            RELEASE_LOG_ERROR(ProcessSuspension, "Background task expired while holding WebKit ProcessAssertion (isMainThread? %d, applicationIsBackgrounded? %d).", RunLoop::isMain(), _applicationIsBackgrounded);
     154            if (!_applicationIsBackgrounded) {
     155                // We've received the invalidation warning after the app has become foreground again. In this case, we should not warn clients of imminent suspension.
     156                // To be safe (avoid potential killing), we end the task right away and call _updateBackgroundTask asynchronously to start a new task if necessary.
     157                [self _cancelPendingReleaseTask];
     158                [self _releaseBackgroundTask];
     159                dispatch_async(dispatch_get_main_queue(), ^{
     160                    [self _updateBackgroundTask];
     161                });
     162                return;
     163            }
    154164            // The expiration handler gets called on a non-main thread when the underlying assertion could not be taken (rdar://problem/27278419).
    155165            if (RunLoop::isMain())
Note: See TracChangeset for help on using the changeset viewer.