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

Changeset 231663 in webkit


Ignore:
Timestamp:
May 10, 2018, 3:02:31 PM (8 years ago)
Author:
Chris Dumez
Message:

[iOS] Apps that are not visible may not get suspended if they trigger page loads while in the background
https://bugs.webkit.org/show_bug.cgi?id=185318

Reviewed by Geoffrey Garen.

Whenever there is a page load going on, we take a background process assertion to delay process
suspension until this load completes. However, there is also a 3 seconds grace period after
a load is complete to allow the app to trigger a new load shortly after. This grace period was
introduced to support use cases where a visible app does loads in an offscreen view. However,
it can be abused by apps running in the background as they could trigger new page loads while
in the background to delay process suspension. This patch tightens the policy so that only
apps that are currently visible get to use this grace period. Apps that are in the background
get to finish their current load and will then get suspended.

  • UIProcess/Cocoa/NavigationState.mm:

(WebKit::NavigationState::didChangeIsLoading):

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r231654 r231663  
     12018-05-10  Chris Dumez  <cdumez@apple.com>
     2
     3        [iOS] Apps that are not visible may not get suspended if they trigger page loads while in the background
     4        https://bugs.webkit.org/show_bug.cgi?id=185318
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Whenever there is a page load going on, we take a background process assertion to delay process
     9        suspension until this load completes. However, there is also a 3 seconds grace period after
     10        a load is complete to allow the app to trigger a new load shortly after. This grace period was
     11        introduced to support use cases where a visible app does loads in an offscreen view. However,
     12        it can be abused by apps running in the background as they could trigger new page loads while
     13        in the background to delay process suspension. This patch tightens the policy so that only
     14        apps that are currently visible get to use this grace period. Apps that are in the background
     15        get to finish their current load and will then get suspended.
     16
     17        * UIProcess/Cocoa/NavigationState.mm:
     18        (WebKit::NavigationState::didChangeIsLoading):
     19
    1202018-05-10  Chris Dumez  <cdumez@apple.com>
    221
  • trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm

    r231498 r231663  
    11581158#if PLATFORM(IOS)
    11591159    if (m_webView->_page->pageLoadState().isLoading()) {
    1160         if (m_releaseActivityTimer.isActive())
     1160        if (m_releaseActivityTimer.isActive()) {
     1161            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - A new page load started while the UIProcess was still holding a page load background assertion", this);
    11611162            m_releaseActivityTimer.stop();
    1162         else {
     1163        } else {
    11631164            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because a page load started", this);
    11641165            ASSERT(!m_activityToken);
    11651166            m_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
    11661167        }
    1167     } else {
    1168         // Delay releasing the background activity for 3 seconds to give the application a chance to start another navigation
    1169         // before suspending the WebContent process <rdar://problem/27910964>.
    1170         m_releaseActivityTimer.startOneShot(3_s);
     1168    } else if (m_activityToken) {
     1169        if (m_webView._isBackground)
     1170            releaseNetworkActivityToken();
     1171        else {
     1172            // The application is visible so we delay releasing the background activity for 3 seconds to give it a chance to start another navigation
     1173            // before suspending the WebContent process <rdar://problem/27910964>.
     1174            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - Page load completed and UIProcess will be releasing background assertion soon unless a new load starts", this);
     1175            m_releaseActivityTimer.startOneShot(3_s);
     1176        }
    11711177    }
    11721178#endif
  • trunk/Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

    r229542 r231663  
    5050SOFT_LINK_FRAMEWORK(UIKit)
    5151SOFT_LINK_CLASS(UIKit, UIWindow)
     52
     53@implementation WKWebView (WKWebViewTestingQuicks)
     54
     55// TestWebKitAPI is currently not a UIApplication so we are unable to track if it is in
     56// the background or not (https://bugs.webkit.org/show_bug.cgi?id=175204). This can
     57// cause our processes to get suspended on iOS. We work around this by having
     58// WKWebView._isBackground always return NO in the context of API tests.
     59- (BOOL)_isBackground
     60{
     61    return NO;
     62}
     63@end
    5264#endif
    5365
Note: See TracChangeset for help on using the changeset viewer.