Title: [231676] trunk/Source/WebKit
Revision
231676
Author
cdu...@apple.com
Date
2018-05-10 16:35:32 -0700 (Thu, 10 May 2018)

Log Message

[iOS] Release page load process assertion if the screen is locked
https://bugs.webkit.org/show_bug.cgi?id=185333

Reviewed by Geoff Garen.

We normally take a background process assertion during page loads to allow them to complete
even if the tab / app is backgrounded. We should however avoid doing so when the backgrounding
is caused by the screen locking. Keeping the process assertion in this case would prevent the
whole device from sleeping longer than it should, thus negatively impacting power.

* UIProcess/Cocoa/NavigationState.h:
* UIProcess/Cocoa/NavigationState.mm:
(WebKit::NavigationState::NavigationState):
(WebKit::NavigationState::releaseNetworkActivityToken):
(WebKit::NavigationState::didChangeIsLoading):
* UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::applicationDidEnterBackground):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (231675 => 231676)


--- trunk/Source/WebKit/ChangeLog	2018-05-10 23:18:49 UTC (rev 231675)
+++ trunk/Source/WebKit/ChangeLog	2018-05-10 23:35:32 UTC (rev 231676)
@@ -1,3 +1,23 @@
+2018-05-10  Chris Dumez  <cdu...@apple.com>
+
+        [iOS] Release page load process assertion if the screen is locked
+        https://bugs.webkit.org/show_bug.cgi?id=185333
+
+        Reviewed by Geoff Garen.
+
+        We normally take a background process assertion during page loads to allow them to complete
+        even if the tab / app is backgrounded. We should however avoid doing so when the backgrounding
+        is caused by the screen locking. Keeping the process assertion in this case would prevent the
+        whole device from sleeping longer than it should, thus negatively impacting power.
+
+        * UIProcess/Cocoa/NavigationState.h:
+        * UIProcess/Cocoa/NavigationState.mm:
+        (WebKit::NavigationState::NavigationState):
+        (WebKit::NavigationState::releaseNetworkActivityToken):
+        (WebKit::NavigationState::didChangeIsLoading):
+        * UIProcess/ios/WebPageProxyIOS.mm:
+        (WebKit::WebPageProxy::applicationDidEnterBackground):
+
 2018-05-10  Megan Gardner  <megan_gard...@apple.com>
 
         Remove Unused Chinese/Japanese Reanalyze code

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h (231675 => 231676)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-10 23:18:49 UTC (rev 231675)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-10 23:35:32 UTC (rev 231676)
@@ -82,6 +82,11 @@
 
     void didFirstPaint();
 
+#if PLATFORM(IOS)
+    enum class NetworkActivityTokenReleaseReason { LoadCompleted, ScreenLocked };
+    void releaseNetworkActivityToken(NetworkActivityTokenReleaseReason);
+#endif
+
 private:
     class NavigationClient final : public API::NavigationClient {
     public:
@@ -172,7 +177,7 @@
     void didChangeWebProcessIsResponsive() override;
 
 #if PLATFORM(IOS)
-    void releaseNetworkActivityToken();
+    void releaseNetworkActivityTokenAfterLoadCompletion() { releaseNetworkActivityToken(NetworkActivityTokenReleaseReason::LoadCompleted); }
 #endif
 
     WKWebView *m_webView;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (231675 => 231676)


--- trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-10 23:18:49 UTC (rev 231675)
+++ trunk/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-10 23:35:32 UTC (rev 231676)
@@ -97,7 +97,7 @@
     , m_navigationDelegateMethods()
     , m_historyDelegateMethods()
 #if PLATFORM(IOS)
-    , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityToken)
+    , m_releaseActivityTimer(RunLoop::current(), this, &NavigationState::releaseNetworkActivityTokenAfterLoadCompletion)
 #endif
 {
     ASSERT(m_webView->_page);
@@ -1145,11 +1145,21 @@
 }
 
 #if PLATFORM(IOS)
-void NavigationState::releaseNetworkActivityToken()
+void NavigationState::releaseNetworkActivityToken(NetworkActivityTokenReleaseReason reason)
 {
-    RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p UIProcess is releasing a background assertion because a page load completed", this);
-    ASSERT(m_activityToken);
+    if (!m_activityToken)
+        return;
+
+    switch (reason) {
+    case NetworkActivityTokenReleaseReason::LoadCompleted:
+        RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because a page load completed", this);
+        break;
+    case NetworkActivityTokenReleaseReason::ScreenLocked:
+        RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p NavigationState is releasing background process assertion because the screen was locked", this);
+        break;
+    }
     m_activityToken = nullptr;
+    m_releaseActivityTimer.stop();
 }
 #endif
 
@@ -1157,21 +1167,25 @@
 {
 #if PLATFORM(IOS)
     if (m_webView->_page->pageLoadState().isLoading()) {
+        // We do not take a network activity token if a load starts after the screen has been locked.
+        if ([UIApp isSuspendedUnderLock])
+            return;
+
         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);
+            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState keeps its process network assertion because a new page load started", this);
             m_releaseActivityTimer.stop();
-        } 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);
+        }
+        if (!m_activityToken) {
+            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState is taking a process network assertion because a page load started", this);
             m_activityToken = m_webView->_page->process().throttler().backgroundActivityToken();
         }
     } else if (m_activityToken) {
         if (m_webView._isBackground)
-            releaseNetworkActivityToken();
+            releaseNetworkActivityTokenAfterLoadCompletion();
         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);
+            RELEASE_LOG_IF(m_webView->_page->isAlwaysOnLoggingAllowed(), ProcessSuspension, "%p - NavigationState will release its process network assertion soon because the page load completed", this);
             m_releaseActivityTimer.startOneShot(3_s);
         }
     }

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (231675 => 231676)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2018-05-10 23:18:49 UTC (rev 231675)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2018-05-10 23:35:32 UTC (rev 231676)
@@ -34,6 +34,7 @@
 #import "InteractionInformationAtPosition.h"
 #import "Logging.h"
 #import "NativeWebKeyboardEvent.h"
+#import "NavigationState.h"
 #import "PageClient.h"
 #import "PrintInfo.h"
 #import "RemoteLayerTreeDrawingAreaProxy.h"
@@ -677,6 +678,11 @@
 void WebPageProxy::applicationDidEnterBackground()
 {
     bool isSuspendedUnderLock = [UIApp isSuspendedUnderLock];
+
+    // We normally delay process suspension when the app is backgrounded until the current page load completes. However,
+    // we do not want to do so when the screen is locked for power reasons.
+    if (isSuspendedUnderLock)
+        NavigationState::fromWebPage(*this).releaseNetworkActivityToken(NavigationState::NetworkActivityTokenReleaseReason::ScreenLocked);
     m_process->send(Messages::WebPage::ApplicationDidEnterBackground(isSuspendedUnderLock), m_pageID);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to