Title: [231792] branches/safari-606.1.17-branch/Source/WebKit
Revision
231792
Author
[email protected]
Date
2018-05-15 01:07:00 -0700 (Tue, 15 May 2018)

Log Message

Cherry-pick r231676. rdar://problem/40038038

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

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231676 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-606.1.17-branch/Source/WebKit/ChangeLog (231791 => 231792)


--- branches/safari-606.1.17-branch/Source/WebKit/ChangeLog	2018-05-15 08:06:57 UTC (rev 231791)
+++ branches/safari-606.1.17-branch/Source/WebKit/ChangeLog	2018-05-15 08:07:00 UTC (rev 231792)
@@ -1,5 +1,50 @@
 2018-05-15  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r231676. rdar://problem/40038038
+
+    [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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231676 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-05-10  Chris Dumez  <[email protected]>
+
+            [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-15  Babak Shafiei  <[email protected]>
+
         Cherry-pick r231663. rdar://problem/39987839
 
     [iOS] Apps that are not visible may not get suspended if they trigger page loads while in the background

Modified: branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h (231791 => 231792)


--- branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-15 08:06:57 UTC (rev 231791)
+++ branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.h	2018-05-15 08:07:00 UTC (rev 231792)
@@ -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: branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm (231791 => 231792)


--- branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-15 08:06:57 UTC (rev 231791)
+++ branches/safari-606.1.17-branch/Source/WebKit/UIProcess/Cocoa/NavigationState.mm	2018-05-15 08:07:00 UTC (rev 231792)
@@ -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: branches/safari-606.1.17-branch/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (231791 => 231792)


--- branches/safari-606.1.17-branch/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2018-05-15 08:06:57 UTC (rev 231791)
+++ branches/safari-606.1.17-branch/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2018-05-15 08:07:00 UTC (rev 231792)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to