Title: [248148] trunk
Revision
248148
Author
[email protected]
Date
2019-08-01 22:46:32 -0700 (Thu, 01 Aug 2019)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (248147 => 248148)


--- trunk/LayoutTests/ChangeLog	2019-08-02 04:30:38 UTC (rev 248147)
+++ trunk/LayoutTests/ChangeLog	2019-08-02 05:46:32 UTC (rev 248148)
@@ -1,5 +1,18 @@
 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-01  Chris Dumez  <[email protected]>
+
         fast/forms/ios/file-upload-panel.html is flaky on iOS 13
         https://bugs.webkit.org/show_bug.cgi?id=200357
         <rdar://problem/53028551>

Added: trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt (0 => 248148)


--- trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message-expected.txt	2019-08-02 05:46:32 UTC (rev 248148)
@@ -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: trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html (0 => 248148)


--- trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-MessagePort-pending-message.html	2019-08-02 05:46:32 UTC (rev 248148)
@@ -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: trunk/Source/WebCore/ChangeLog (248147 => 248148)


--- trunk/Source/WebCore/ChangeLog	2019-08-02 04:30:38 UTC (rev 248147)
+++ trunk/Source/WebCore/ChangeLog	2019-08-02 05:46:32 UTC (rev 248148)
@@ -1,3 +1,35 @@
+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-01  Konstantin Tokarev  <[email protected]>
 
         Fix compilation of PageConsoleClient with !ENABLE(VIDEO)

Modified: trunk/Source/WebCore/dom/MessagePort.cpp (248147 => 248148)


--- trunk/Source/WebCore/dom/MessagePort.cpp	2019-08-02 04:30:38 UTC (rev 248147)
+++ trunk/Source/WebCore/dom/MessagePort.cpp	2019-08-02 05:46:32 UTC (rev 248148)
@@ -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: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (248147 => 248148)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2019-08-02 04:30:38 UTC (rev 248147)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2019-08-02 05:46:32 UTC (rev 248148)
@@ -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: trunk/Source/WebCore/loader/DocumentLoader.cpp (248147 => 248148)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-08-02 04:30:38 UTC (rev 248147)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-08-02 05:46:32 UTC (rev 248148)
@@ -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