Title: [231376] trunk/Source/WebKit
Revision
231376
Author
cdu...@apple.com
Date
2018-05-04 13:48:23 -0700 (Fri, 04 May 2018)

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

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (231375 => 231376)


--- trunk/Source/WebKit/ChangeLog	2018-05-04 20:47:57 UTC (rev 231375)
+++ trunk/Source/WebKit/ChangeLog	2018-05-04 20:48:23 UTC (rev 231376)
@@ -1,3 +1,22 @@
+2018-05-04  Chris Dumez  <cdu...@apple.com>
+
+        [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):
+
 2018-05-04  Per Arne Vollan  <pvol...@apple.com>
 
         Adjust sandbox profile for simulator.

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (231375 => 231376)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-04 20:47:57 UTC (rev 231375)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-04 20:48:23 UTC (rev 231376)
@@ -1157,17 +1157,23 @@
 {
 #if PLATFORM(IOS)
     if (m_webView->_page->pageLoadState().isLoading()) {
-        if (m_releaseActivityTimer.isActive())
+        if (m_releaseActivityTimer.isActive()) {
+            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);
             m_releaseActivityTimer.stop();
-        else {
+        } else {
             RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - UIProcess is taking a background assertion because a page load started", this);
             ASSERT(!m_activityToken);
             m_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
         }
-    } else {
-        // Delay releasing the background activity for 3 seconds to give the application a chance to start another navigation
-        // before suspending the WebContent process <rdar://problem/27910964>.
-        m_releaseActivityTimer.startOneShot(3_s);
+    } else if (m_activityToken) {
+        if (m_webView._isBackground)
+            releaseNetworkActivityToken();
+        else {
+            // The application is visible so we delay releasing the background activity for 3 seconds to give it a chance to start another navigation
+            // before suspending the WebContent process <rdar://problem/27910964>.
+            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);
+            m_releaseActivityTimer.startOneShot(3_s);
+        }
     }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to