Title: [242135] branches/safari-607-branch/Source
Revision
242135
Author
bshaf...@apple.com
Date
2019-02-27 10:49:24 -0800 (Wed, 27 Feb 2019)

Log Message

Cherry-pick r242099. rdar://problem/48429675

    [iOS] Regression(PSON) Scroll position is no longer restored when navigating back to reddit.com
    https://bugs.webkit.org/show_bug.cgi?id=195054
    <rdar://problem/48330549>

    Reviewed by Geoff Garen.

    Source/WebCore:

    Add MaintainMemoryCache flag to indicate that the memory cache should not get purged.

    * page/MemoryRelease.cpp:
    (WebCore::releaseNoncriticalMemory):
    (WebCore::releaseCriticalMemory):
    (WebCore::releaseMemory):
    * page/MemoryRelease.h:

    Source/WebKit:

    We attempt to restore the scroll position twice, on first layout and then on load completion.
    Before PSON, the scroll position would fail to get restored on first layout but would succeed
    on load completion because the view is tall enough by then. With PSON however, we would
    fail to restore the scroll position on load completion because the view would not be tall
    enough yet by this point. The reason is that the dynamic resources would not be in the memory cache
    and would then get reloaded abd finish loading *after* the load event.

    To address the issue, we now make sure to not purge the memory cache on process suspension on
    iOS if there is currently a SuspendedPageProxy in the UIProcess for this process.

    * UIProcess/SuspendedPageProxy.cpp:
    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
    (WebKit::SuspendedPageProxy::~SuspendedPageProxy):
    * UIProcess/WebProcessProxy.cpp:
    (WebKit::WebProcessProxy::incrementSuspendedPageCount):
    (WebKit::WebProcessProxy::decrementSuspendedPageCount):
    * UIProcess/WebProcessProxy.h:
    * WebProcess/WebProcess.cpp:
    (WebKit::WebProcess::initializeWebProcess):
    (WebKit::WebProcess::setHasSuspendedPageProxy):
    * WebProcess/WebProcess.h:
    * WebProcess/WebProcess.messages.in:

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

Modified Paths

Diff

Modified: branches/safari-607-branch/Source/WebCore/ChangeLog (242134 => 242135)


--- branches/safari-607-branch/Source/WebCore/ChangeLog	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebCore/ChangeLog	2019-02-27 18:49:24 UTC (rev 242135)
@@ -1,3 +1,67 @@
+2019-02-27  Babak Shafiei  <bshaf...@apple.com>
+
+        Cherry-pick r242099. rdar://problem/48429675
+
+    [iOS] Regression(PSON) Scroll position is no longer restored when navigating back to reddit.com
+    https://bugs.webkit.org/show_bug.cgi?id=195054
+    <rdar://problem/48330549>
+    
+    Reviewed by Geoff Garen.
+    
+    Source/WebCore:
+    
+    Add MaintainMemoryCache flag to indicate that the memory cache should not get purged.
+    
+    * page/MemoryRelease.cpp:
+    (WebCore::releaseNoncriticalMemory):
+    (WebCore::releaseCriticalMemory):
+    (WebCore::releaseMemory):
+    * page/MemoryRelease.h:
+    
+    Source/WebKit:
+    
+    We attempt to restore the scroll position twice, on first layout and then on load completion.
+    Before PSON, the scroll position would fail to get restored on first layout but would succeed
+    on load completion because the view is tall enough by then. With PSON however, we would
+    fail to restore the scroll position on load completion because the view would not be tall
+    enough yet by this point. The reason is that the dynamic resources would not be in the memory cache
+    and would then get reloaded abd finish loading *after* the load event.
+    
+    To address the issue, we now make sure to not purge the memory cache on process suspension on
+    iOS if there is currently a SuspendedPageProxy in the UIProcess for this process.
+    
+    * UIProcess/SuspendedPageProxy.cpp:
+    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+    (WebKit::SuspendedPageProxy::~SuspendedPageProxy):
+    * UIProcess/WebProcessProxy.cpp:
+    (WebKit::WebProcessProxy::incrementSuspendedPageCount):
+    (WebKit::WebProcessProxy::decrementSuspendedPageCount):
+    * UIProcess/WebProcessProxy.h:
+    * WebProcess/WebProcess.cpp:
+    (WebKit::WebProcess::initializeWebProcess):
+    (WebKit::WebProcess::setHasSuspendedPageProxy):
+    * WebProcess/WebProcess.h:
+    * WebProcess/WebProcess.messages.in:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-02-26  Chris Dumez  <cdu...@apple.com>
+
+            [iOS] Regression(PSON) Scroll position is no longer restored when navigating back to reddit.com
+            https://bugs.webkit.org/show_bug.cgi?id=195054
+            <rdar://problem/48330549>
+
+            Reviewed by Geoff Garen.
+
+            Add MaintainMemoryCache flag to indicate that the memory cache should not get purged.
+
+            * page/MemoryRelease.cpp:
+            (WebCore::releaseNoncriticalMemory):
+            (WebCore::releaseCriticalMemory):
+            (WebCore::releaseMemory):
+            * page/MemoryRelease.h:
+
 2019-02-24  Babak Shafiei  <bshaf...@apple.com>
 
         Cherry-pick r241986. rdar://problem/48350373

Modified: branches/safari-607-branch/Source/WebCore/page/MemoryRelease.cpp (242134 => 242135)


--- branches/safari-607-branch/Source/WebCore/page/MemoryRelease.cpp	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebCore/page/MemoryRelease.cpp	2019-02-27 18:49:24 UTC (rev 242135)
@@ -58,7 +58,7 @@
 
 namespace WebCore {
 
-static void releaseNoncriticalMemory()
+static void releaseNoncriticalMemory(MaintainMemoryCache maintainMemoryCache)
 {
     RenderTheme::singleton().purgeCaches();
 
@@ -70,12 +70,13 @@
     for (auto* document : Document::allDocuments())
         document->clearSelectorQueryCache();
 
-    MemoryCache::singleton().pruneDeadResourcesToSize(0);
+    if (maintainMemoryCache == MaintainMemoryCache::No)
+        MemoryCache::singleton().pruneDeadResourcesToSize(0);
 
     InlineStyleSheetOwner::clearCache();
 }
 
-static void releaseCriticalMemory(Synchronous synchronous, MaintainPageCache maintainPageCache)
+static void releaseCriticalMemory(Synchronous synchronous, MaintainPageCache maintainPageCache, MaintainMemoryCache maintainMemoryCache)
 {
     // Right now, the only reason we call release critical memory while not under memory pressure is if the process is about to be suspended.
     if (maintainPageCache == MaintainPageCache::No) {
@@ -83,7 +84,10 @@
         PageCache::singleton().pruneToSizeNow(0, pruningReason);
     }
 
-    MemoryCache::singleton().pruneLiveResourcesToSize(0, /*shouldDestroyDecodedDataForAllLiveResources*/ true);
+    if (maintainMemoryCache == MaintainMemoryCache::No) {
+        auto shouldDestroyDecodedDataForAllLiveResources = true;
+        MemoryCache::singleton().pruneLiveResourcesToSize(0, shouldDestroyDecodedDataForAllLiveResources);
+    }
 
     CSSValuePool::singleton().drain();
 
@@ -113,7 +117,7 @@
     }
 }
 
-void releaseMemory(Critical critical, Synchronous synchronous, MaintainPageCache maintainPageCache)
+void releaseMemory(Critical critical, Synchronous synchronous, MaintainPageCache maintainPageCache, MaintainMemoryCache maintainMemoryCache)
 {
     TraceScope scope(MemoryPressureHandlerStart, MemoryPressureHandlerEnd, static_cast<uint64_t>(critical), static_cast<uint64_t>(synchronous));
 
@@ -120,10 +124,10 @@
     if (critical == Critical::Yes) {
         // Return unused pages back to the OS now as this will likely give us a little memory to work with.
         WTF::releaseFastMallocFreeMemory();
-        releaseCriticalMemory(synchronous, maintainPageCache);
+        releaseCriticalMemory(synchronous, maintainPageCache, maintainMemoryCache);
     }
 
-    releaseNoncriticalMemory();
+    releaseNoncriticalMemory(maintainMemoryCache);
 
     platformReleaseMemory(critical);
 

Modified: branches/safari-607-branch/Source/WebCore/page/MemoryRelease.h (242134 => 242135)


--- branches/safari-607-branch/Source/WebCore/page/MemoryRelease.h	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebCore/page/MemoryRelease.h	2019-02-27 18:49:24 UTC (rev 242135)
@@ -30,8 +30,9 @@
 namespace WebCore {
 
 enum class MaintainPageCache : bool { No, Yes };
+enum class MaintainMemoryCache : bool { No, Yes };
 
-WEBCORE_EXPORT void releaseMemory(Critical, Synchronous, MaintainPageCache = MaintainPageCache::No);
+WEBCORE_EXPORT void releaseMemory(Critical, Synchronous, MaintainPageCache = MaintainPageCache::No, MaintainMemoryCache = MaintainMemoryCache::No);
 void platformReleaseMemory(Critical);
 void jettisonExpensiveObjectsOnTopLevelNavigation();
 WEBCORE_EXPORT void registerMemoryReleaseNotifyCallbacks();

Modified: branches/safari-607-branch/Source/WebKit/ChangeLog (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/ChangeLog	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/ChangeLog	2019-02-27 18:49:24 UTC (rev 242135)
@@ -1,5 +1,84 @@
 2019-02-27  Babak Shafiei  <bshaf...@apple.com>
 
+        Cherry-pick r242099. rdar://problem/48429675
+
+    [iOS] Regression(PSON) Scroll position is no longer restored when navigating back to reddit.com
+    https://bugs.webkit.org/show_bug.cgi?id=195054
+    <rdar://problem/48330549>
+    
+    Reviewed by Geoff Garen.
+    
+    Source/WebCore:
+    
+    Add MaintainMemoryCache flag to indicate that the memory cache should not get purged.
+    
+    * page/MemoryRelease.cpp:
+    (WebCore::releaseNoncriticalMemory):
+    (WebCore::releaseCriticalMemory):
+    (WebCore::releaseMemory):
+    * page/MemoryRelease.h:
+    
+    Source/WebKit:
+    
+    We attempt to restore the scroll position twice, on first layout and then on load completion.
+    Before PSON, the scroll position would fail to get restored on first layout but would succeed
+    on load completion because the view is tall enough by then. With PSON however, we would
+    fail to restore the scroll position on load completion because the view would not be tall
+    enough yet by this point. The reason is that the dynamic resources would not be in the memory cache
+    and would then get reloaded abd finish loading *after* the load event.
+    
+    To address the issue, we now make sure to not purge the memory cache on process suspension on
+    iOS if there is currently a SuspendedPageProxy in the UIProcess for this process.
+    
+    * UIProcess/SuspendedPageProxy.cpp:
+    (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+    (WebKit::SuspendedPageProxy::~SuspendedPageProxy):
+    * UIProcess/WebProcessProxy.cpp:
+    (WebKit::WebProcessProxy::incrementSuspendedPageCount):
+    (WebKit::WebProcessProxy::decrementSuspendedPageCount):
+    * UIProcess/WebProcessProxy.h:
+    * WebProcess/WebProcess.cpp:
+    (WebKit::WebProcess::initializeWebProcess):
+    (WebKit::WebProcess::setHasSuspendedPageProxy):
+    * WebProcess/WebProcess.h:
+    * WebProcess/WebProcess.messages.in:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-02-26  Chris Dumez  <cdu...@apple.com>
+
+            [iOS] Regression(PSON) Scroll position is no longer restored when navigating back to reddit.com
+            https://bugs.webkit.org/show_bug.cgi?id=195054
+            <rdar://problem/48330549>
+
+            Reviewed by Geoff Garen.
+
+            We attempt to restore the scroll position twice, on first layout and then on load completion.
+            Before PSON, the scroll position would fail to get restored on first layout but would succeed
+            on load completion because the view is tall enough by then. With PSON however, we would
+            fail to restore the scroll position on load completion because the view would not be tall
+            enough yet by this point. The reason is that the dynamic resources would not be in the memory cache
+            and would then get reloaded abd finish loading *after* the load event.
+
+            To address the issue, we now make sure to not purge the memory cache on process suspension on
+            iOS if there is currently a SuspendedPageProxy in the UIProcess for this process.
+
+            * UIProcess/SuspendedPageProxy.cpp:
+            (WebKit::SuspendedPageProxy::SuspendedPageProxy):
+            (WebKit::SuspendedPageProxy::~SuspendedPageProxy):
+            * UIProcess/WebProcessProxy.cpp:
+            (WebKit::WebProcessProxy::incrementSuspendedPageCount):
+            (WebKit::WebProcessProxy::decrementSuspendedPageCount):
+            * UIProcess/WebProcessProxy.h:
+            * WebProcess/WebProcess.cpp:
+            (WebKit::WebProcess::initializeWebProcess):
+            (WebKit::WebProcess::setHasSuspendedPageProxy):
+            * WebProcess/WebProcess.h:
+            * WebProcess/WebProcess.messages.in:
+
+2019-02-27  Babak Shafiei  <bshaf...@apple.com>
+
         Cherry-pick r242089. rdar://problem/48429668
 
     WebPageProxy should nullify m_userMediaPermissionRequestManager after resetting the media state

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/SuspendedPageProxy.cpp (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/SuspendedPageProxy.cpp	2019-02-27 18:49:24 UTC (rev 242135)
@@ -88,6 +88,7 @@
 #endif
 {
     item.setSuspendedPage(this);
+    m_process->incrementSuspendedPageCount();
     m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_page.pageID(), *this);
 
     m_suspensionTimeoutTimer.startOneShot(suspensionTimeout);
@@ -96,6 +97,8 @@
 
 SuspendedPageProxy::~SuspendedPageProxy()
 {
+    m_process->decrementSuspendedPageCount();
+
     if (m_readyToUnsuspendHandler) {
         RunLoop::main().dispatch([readyToUnsuspendHandler = WTFMove(m_readyToUnsuspendHandler)]() mutable {
             readyToUnsuspendHandler(nullptr);

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-02-27 18:49:24 UTC (rev 242135)
@@ -1540,6 +1540,21 @@
     m_registrableDomain = WTFMove(registrableDomain);
 }
 
+void WebProcessProxy::incrementSuspendedPageCount()
+{
+    ++m_suspendedPageCount;
+    if (m_suspendedPageCount == 1)
+        send(Messages::WebProcess::SetHasSuspendedPageProxy(true), 0);
+}
+
+void WebProcessProxy::decrementSuspendedPageCount()
+{
+    ASSERT(m_suspendedPageCount);
+    --m_suspendedPageCount;
+    if (!m_suspendedPageCount)
+        send(Messages::WebProcess::SetHasSuspendedPageProxy(false), 0);
+}
+
 #if PLATFORM(WATCHOS)
 
 void WebProcessProxy::takeBackgroundActivityTokenForFullscreenInput()

Modified: branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.h (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.h	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/UIProcess/WebProcessProxy.h	2019-02-27 18:49:24 UTC (rev 242135)
@@ -110,6 +110,9 @@
 
     WebConnection* webConnection() const { return m_webConnection.get(); }
 
+    void incrementSuspendedPageCount();
+    void decrementSuspendedPageCount();
+
     WebProcessPool& processPool() const { ASSERT(m_processPool); return *m_processPool.get(); }
 
     String registrableDomain() const { return m_registrableDomain.valueOr(String()); }
@@ -427,6 +430,7 @@
     HashMap<uint64_t, Function<void()>> m_messageBatchDeliveryCompletionHandlers;
     HashMap<uint64_t, CompletionHandler<void(WebCore::MessagePortChannelProvider::HasActivity)>> m_localPortActivityCompletionHandlers;
 
+    unsigned m_suspendedPageCount { 0 };
     bool m_hasCommittedAnyProvisionalLoads { false };
     bool m_isPrewarmed;
 

Modified: branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.cpp (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.cpp	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.cpp	2019-02-27 18:49:24 UTC (rev 242135)
@@ -297,7 +297,8 @@
 #endif
 
             auto maintainPageCache = m_isSuspending && hasPageRequiringPageCacheWhileSuspended() ? WebCore::MaintainPageCache::Yes : WebCore::MaintainPageCache::No;
-            WebCore::releaseMemory(critical, synchronous, maintainPageCache);
+            auto maintainMemoryCache = m_isSuspending && m_hasSuspendedPageProxy ? WebCore::MaintainMemoryCache::Yes : WebCore::MaintainMemoryCache::No;
+            WebCore::releaseMemory(critical, synchronous, maintainPageCache, maintainMemoryCache);
         });
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101200) || PLATFORM(GTK) || PLATFORM(WPE)
         memoryPressureHandler.setShouldUsePeriodicMemoryMonitor(true);
@@ -463,6 +464,12 @@
     return true;
 }
 
+void WebProcess::setHasSuspendedPageProxy(bool hasSuspendedPageProxy)
+{
+    ASSERT(m_hasSuspendedPageProxy != hasSuspendedPageProxy);
+    m_hasSuspendedPageProxy = hasSuspendedPageProxy;
+}
+
 void WebProcess::setIsInProcessCache(bool isInProcessCache)
 {
 #if PLATFORM(MAC)

Modified: branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.h (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.h	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.h	2019-02-27 18:49:24 UTC (rev 242135)
@@ -270,6 +270,7 @@
 
     void platformTerminate();
 
+    void setHasSuspendedPageProxy(bool);
     void setIsInProcessCache(bool);
     void markIsNoLongerPrewarmed();
 
@@ -482,6 +483,7 @@
 #if PLATFORM(WAYLAND)
     std::unique_ptr<WaylandCompositorDisplay> m_waylandCompositorDisplay;
 #endif
+    bool m_hasSuspendedPageProxy { false };
     bool m_isSuspending { false };
 };
 

Modified: branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.messages.in (242134 => 242135)


--- branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.messages.in	2019-02-27 18:49:19 UTC (rev 242134)
+++ branches/safari-607-branch/Source/WebKit/WebProcess/WebProcess.messages.in	2019-02-27 18:49:24 UTC (rev 242135)
@@ -128,6 +128,7 @@
     CheckProcessLocalPortForActivity(struct WebCore::MessagePortIdentifier port, uint64_t callbackIdentifier)
     MessagesAvailableForPort(struct WebCore::MessagePortIdentifier port)
 
+    SetHasSuspendedPageProxy(bool hasSuspendedPageProxy);
     SetIsInProcessCache(bool isInProcessCache)
     MarkIsNoLongerPrewarmed()
     UpdateActivePages()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to