Title: [248358] branches/safari-608.1-branch
Revision
248358
Author
[email protected]
Date
2019-08-06 23:53:01 -0700 (Tue, 06 Aug 2019)

Log Message

Cherry-pick r248148. rdar://problem/54017841

    Pages using MessagePorts should be PageCacheable
    https://bugs.webkit.org/show_bug.cgi?id=200366
    <rdar://problem/53837882>

    Reviewed by Geoffrey Garen.

    Source/WebCore:

    Allow a page to enter PageCache, even if it has MessagePorts (potentially with
    pending messages). If there are pending messages on the MessagePorts when
    entering PageCache, those will get dispatched upon restoring from PageCache.

    Test: fast/history/page-cache-MessagePort-pending-message.html

    * dom/MessagePort.cpp:
    (WebCore::MessagePort::messageAvailable):
    (WebCore::MessagePort::dispatchMessages):
    Do not dispatch messages while in PageCache.

    (WebCore::MessagePort::canSuspendForDocumentSuspension const):
    Allow pages with MessagePort objects to enter PageCache.

    * dom/ScriptExecutionContext.cpp:
    (WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
    Make sure pending messages on MessagePorts get dispatched asynchronously after restoring
    from PageCache.

    * loader/DocumentLoader.cpp:
    (WebCore::areAllLoadersPageCacheAcceptable):
    Make sure only CachedResources that are still loading upon load cancelation prevent
    entering PageCache.

    LayoutTests:

    Add layout test coverage.

    * fast/history/page-cache-MessagePort-pending-message-expected.txt: Added.
    * fast/history/page-cache-MessagePort-pending-message.html: Added.

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

Modified Paths

Added Paths

Diff

Modified: branches/safari-608.1-branch/LayoutTests/ChangeLog (248357 => 248358)


--- branches/safari-608.1-branch/LayoutTests/ChangeLog	2019-08-07 06:52:57 UTC (rev 248357)
+++ branches/safari-608.1-branch/LayoutTests/ChangeLog	2019-08-07 06:53:01 UTC (rev 248358)
@@ -1,5 +1,64 @@
 2019-08-06  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r248148. rdar://problem/54017841
+
+    Pages using MessagePorts should be PageCacheable
+    https://bugs.webkit.org/show_bug.cgi?id=200366
+    <rdar://problem/53837882>
+    
+    Reviewed by Geoffrey Garen.
+    
+    Source/WebCore:
+    
+    Allow a page to enter PageCache, even if it has MessagePorts (potentially with
+    pending messages). If there are pending messages on the MessagePorts when
+    entering PageCache, those will get dispatched upon restoring from PageCache.
+    
+    Test: fast/history/page-cache-MessagePort-pending-message.html
+    
+    * dom/MessagePort.cpp:
+    (WebCore::MessagePort::messageAvailable):
+    (WebCore::MessagePort::dispatchMessages):
+    Do not dispatch messages while in PageCache.
+    
+    (WebCore::MessagePort::canSuspendForDocumentSuspension const):
+    Allow pages with MessagePort objects to enter PageCache.
+    
+    * dom/ScriptExecutionContext.cpp:
+    (WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
+    Make sure pending messages on MessagePorts get dispatched asynchronously after restoring
+    from PageCache.
+    
+    * loader/DocumentLoader.cpp:
+    (WebCore::areAllLoadersPageCacheAcceptable):
+    Make sure only CachedResources that are still loading upon load cancelation prevent
+    entering PageCache.
+    
+    LayoutTests:
+    
+    Add layout test coverage.
+    
+    * fast/history/page-cache-MessagePort-pending-message-expected.txt: Added.
+    * fast/history/page-cache-MessagePort-pending-message.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-08-01  Chris Dumez  <[email protected]>
+
+            Pages using MessagePorts should be PageCacheable
+            https://bugs.webkit.org/show_bug.cgi?id=200366
+            <rdar://problem/53837882>
+
+            Reviewed by Geoffrey Garen.
+
+            Add layout test coverage.
+
+            * fast/history/page-cache-MessagePort-pending-message-expected.txt: Added.
+            * fast/history/page-cache-MessagePort-pending-message.html: Added.
+
+2019-08-06  Kocsen Chung  <[email protected]>
+
         Cherry-pick r248015. rdar://problem/54017889
 
     Can't scroll on yummly.co.uk recipe (scale(0) div covers the content and hit-tests)

Added: branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt (0 => 248358)


--- branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt	                        (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt	2019-08-07 06:53:01 UTC (rev 248358)
@@ -0,0 +1,15 @@
+Tests that a page that has a MessagePort with a pending message can enter PageCache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the page cache
+PASS e.data is "foo"
+PASS afterPageCacheRestore is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html (0 => 248358)


--- branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html	                        (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html	2019-08-07 06:53:01 UTC (rev 248358)
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description('Tests that a page that has a MessagePort with a pending message can enter PageCache.');
+window.jsTestIsAsync = true;
+
+if (window.testRunner)
+    testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+
+let afterPageCacheRestore = false;
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+
+    if (event.persisted) {
+        testPassed("Page did enter and was restored from the page cache");
+        afterPageCacheRestore = true;
+    }
+}, false);
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        testFailed("Page did not enter the page cache.");
+        finishJSTest();
+    }
+    port2.postMessage("foo");
+}, false);
+
+window.addEventListener('load', function() {
+    channel = new MessageChannel();
+    port1 = channel.port1;
+    port1._onmessage_ = (_e) => {
+        e = _e;
+        shouldBeEqualToString("e.data", "foo");
+        shouldBeTrue("afterPageCacheRestore");
+        finishJSTest();
+    };
+    port2 = channel.port2;
+
+    // This needs to happen outside the onload handler so that a history
+    // item is created.
+    setTimeout(function() {
+        // Force a back navigation back to this page.
+        window.location = "resources/page-cache-helper.html";
+    }, 0);
+}, false);
+
+</script>
+<script src=""
+</body>
+</html>

Modified: branches/safari-608.1-branch/Source/WebCore/ChangeLog (248357 => 248358)


--- branches/safari-608.1-branch/Source/WebCore/ChangeLog	2019-08-07 06:52:57 UTC (rev 248357)
+++ branches/safari-608.1-branch/Source/WebCore/ChangeLog	2019-08-07 06:53:01 UTC (rev 248358)
@@ -1,5 +1,83 @@
 2019-08-06  Kocsen Chung  <[email protected]>
 
+        Cherry-pick r248148. rdar://problem/54017841
+
+    Pages using MessagePorts should be PageCacheable
+    https://bugs.webkit.org/show_bug.cgi?id=200366
+    <rdar://problem/53837882>
+    
+    Reviewed by Geoffrey Garen.
+    
+    Source/WebCore:
+    
+    Allow a page to enter PageCache, even if it has MessagePorts (potentially with
+    pending messages). If there are pending messages on the MessagePorts when
+    entering PageCache, those will get dispatched upon restoring from PageCache.
+    
+    Test: fast/history/page-cache-MessagePort-pending-message.html
+    
+    * dom/MessagePort.cpp:
+    (WebCore::MessagePort::messageAvailable):
+    (WebCore::MessagePort::dispatchMessages):
+    Do not dispatch messages while in PageCache.
+    
+    (WebCore::MessagePort::canSuspendForDocumentSuspension const):
+    Allow pages with MessagePort objects to enter PageCache.
+    
+    * dom/ScriptExecutionContext.cpp:
+    (WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
+    Make sure pending messages on MessagePorts get dispatched asynchronously after restoring
+    from PageCache.
+    
+    * loader/DocumentLoader.cpp:
+    (WebCore::areAllLoadersPageCacheAcceptable):
+    Make sure only CachedResources that are still loading upon load cancelation prevent
+    entering PageCache.
+    
+    LayoutTests:
+    
+    Add layout test coverage.
+    
+    * fast/history/page-cache-MessagePort-pending-message-expected.txt: Added.
+    * fast/history/page-cache-MessagePort-pending-message.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248148 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-08-01  Chris Dumez  <[email protected]>
+
+            Pages using MessagePorts should be PageCacheable
+            https://bugs.webkit.org/show_bug.cgi?id=200366
+            <rdar://problem/53837882>
+
+            Reviewed by Geoffrey Garen.
+
+            Allow a page to enter PageCache, even if it has MessagePorts (potentially with
+            pending messages). If there are pending messages on the MessagePorts when
+            entering PageCache, those will get dispatched upon restoring from PageCache.
+
+            Test: fast/history/page-cache-MessagePort-pending-message.html
+
+            * dom/MessagePort.cpp:
+            (WebCore::MessagePort::messageAvailable):
+            (WebCore::MessagePort::dispatchMessages):
+            Do not dispatch messages while in PageCache.
+
+            (WebCore::MessagePort::canSuspendForDocumentSuspension const):
+            Allow pages with MessagePort objects to enter PageCache.
+
+            * dom/ScriptExecutionContext.cpp:
+            (WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
+            Make sure pending messages on MessagePorts get dispatched asynchronously after restoring
+            from PageCache.
+
+            * loader/DocumentLoader.cpp:
+            (WebCore::areAllLoadersPageCacheAcceptable):
+            Make sure only CachedResources that are still loading upon load cancelation prevent
+            entering PageCache.
+
+2019-08-06  Kocsen Chung  <[email protected]>
+
         Cherry-pick r248028. rdar://problem/54017896
 
     ASSERTion failure under takeSnapshot after r247846

Modified: branches/safari-608.1-branch/Source/WebCore/dom/MessagePort.cpp (248357 => 248358)


--- branches/safari-608.1-branch/Source/WebCore/dom/MessagePort.cpp	2019-08-07 06:52:57 UTC (rev 248357)
+++ branches/safari-608.1-branch/Source/WebCore/dom/MessagePort.cpp	2019-08-07 06:53:01 UTC (rev 248358)
@@ -195,7 +195,7 @@
 {
     // This MessagePort object might be disentangled because the port is being transferred,
     // in which case we'll notify it that messages are available once a new end point is created.
-    if (!m_scriptExecutionContext)
+    if (!m_scriptExecutionContext || m_scriptExecutionContext->activeDOMObjectsAreSuspended())
         return;
 
     m_scriptExecutionContext->processMessageWithMessagePortsSoon();
@@ -243,7 +243,7 @@
     // The HTML5 spec specifies that any messages sent to a document that is not fully active should be dropped, so this behavior is OK.
     ASSERT(started());
 
-    if (!isEntangled())
+    if (!m_scriptExecutionContext || m_scriptExecutionContext->activeDOMObjectsAreSuspended() || !isEntangled())
         return;
 
     RefPtr<WorkerThread> workerThread;
@@ -430,7 +430,7 @@
 
 bool MessagePort::canSuspendForDocumentSuspension() const
 {
-    return !hasPendingActivity() || (!m_started || m_closed);
+    return true;
 }
 
 } // namespace WebCore

Modified: branches/safari-608.1-branch/Source/WebCore/dom/ScriptExecutionContext.cpp (248357 => 248358)


--- branches/safari-608.1-branch/Source/WebCore/dom/ScriptExecutionContext.cpp	2019-08-07 06:52:57 UTC (rev 248357)
+++ branches/safari-608.1-branch/Source/WebCore/dom/ScriptExecutionContext.cpp	2019-08-07 06:53:01 UTC (rev 248358)
@@ -307,6 +307,10 @@
         activeDOMObject.resume();
         return ShouldContinue::Yes;
     });
+
+    // In case there were pending messages at the time the script execution context entered PageCache,
+    // make sure those get dispatched shortly after restoring from PageCache.
+    processMessageWithMessagePortsSoon();
 }
 
 void ScriptExecutionContext::stopActiveDOMObjects()

Modified: branches/safari-608.1-branch/Source/WebCore/loader/DocumentLoader.cpp (248357 => 248358)


--- branches/safari-608.1-branch/Source/WebCore/loader/DocumentLoader.cpp	2019-08-07 06:52:57 UTC (rev 248357)
+++ branches/safari-608.1-branch/Source/WebCore/loader/DocumentLoader.cpp	2019-08-07 06:53:01 UTC (rev 248358)
@@ -135,9 +135,9 @@
         if (!cachedResource)
             return false;
 
-        // Only image and XHR loads do prevent the page from entering the PageCache.
+        // Only image and XHR loads do not prevent the page from entering the PageCache.
         // All non-image loads will prevent the page from entering the PageCache.
-        if (!cachedResource->isImage() && !cachedResource->areAllClientsXMLHttpRequests())
+        if (cachedResource->isLoading() && !cachedResource->isImage() && !cachedResource->areAllClientsXMLHttpRequests())
             return false;
     }
     return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to