Title: [250782] trunk
Revision
250782
Author
cdu...@apple.com
Date
2019-10-07 11:58:23 -0700 (Mon, 07 Oct 2019)

Log Message

PendingImageBitmap should not prevent entering the back/forward cache
https://bugs.webkit.org/show_bug.cgi?id=202585

Reviewed by Tim Horton.

Source/WebCore:

Add PageCache support to PendingImageBitmap by doing the promise resolution on a
SuspendableTimer (which properly gets paused while in PageCache).

Test: fast/history/page-cache-createImageBitmap.html

* html/ImageBitmap.cpp:

LayoutTests:

Add layout test coverage.

* TestExpectations:
* fast/history/page-cache-createImageBitmap-expected.txt: Added.
* fast/history/page-cache-createImageBitmap.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (250781 => 250782)


--- trunk/LayoutTests/ChangeLog	2019-10-07 18:57:27 UTC (rev 250781)
+++ trunk/LayoutTests/ChangeLog	2019-10-07 18:58:23 UTC (rev 250782)
@@ -1,3 +1,16 @@
+2019-10-07  Chris Dumez  <cdu...@apple.com>
+
+        PendingImageBitmap should not prevent entering the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=202585
+
+        Reviewed by Tim Horton.
+
+        Add layout test coverage.
+
+        * TestExpectations:
+        * fast/history/page-cache-createImageBitmap-expected.txt: Added.
+        * fast/history/page-cache-createImageBitmap.html: Added.
+
 2019-10-07  Antoine Quint  <grao...@apple.com>
 
         [macOS WK2 Debug ] Flaky Test: animations/play-state-in-shorthand.html

Modified: trunk/LayoutTests/TestExpectations (250781 => 250782)


--- trunk/LayoutTests/TestExpectations	2019-10-07 18:57:27 UTC (rev 250781)
+++ trunk/LayoutTests/TestExpectations	2019-10-07 18:58:23 UTC (rev 250782)
@@ -262,6 +262,7 @@
 imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html [ DumpJSConsoleLogInStdErr Failure Pass ]
 imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-weird.html [ DumpJSConsoleLogInStdErr ]
 imported/w3c/web-platform-tests/service-workers/service-worker/fetch-cors-xhr.https.html [ DumpJSConsoleLogInStdErr ]
+fast/history/page-cache-createImageBitmap.html [ DumpJSConsoleLogInStdErr ]
 
 webkit.org/b/202495 imported/w3c/web-platform-tests/shadow-dom/directionality-002.tentative.html [ ImageOnlyFailure ]
 

Added: trunk/LayoutTests/fast/history/page-cache-createImageBitmap-expected.txt (0 => 250782)


--- trunk/LayoutTests/fast/history/page-cache-createImageBitmap-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-createImageBitmap-expected.txt	2019-10-07 18:58:23 UTC (rev 250782)
@@ -0,0 +1,15 @@
+Tests that a page with a pending createImageBitmap promise is able to enter the page cache.
+
+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 !!imageBitmap is true
+PASS restoredFromPageCache is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/history/page-cache-createImageBitmap.html (0 => 250782)


--- trunk/LayoutTests/fast/history/page-cache-createImageBitmap.html	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-createImageBitmap.html	2019-10-07 18:58:23 UTC (rev 250782)
@@ -0,0 +1,62 @@
+<!-- webkit-test-runner [ enablePageCache=true ] -->
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<img src=""
+<a id="testLink" style="display: none" href=""
+<script>
+description('Tests that a page with a pending createImageBitmap promise is able to enter the page cache.');
+jsTestIsAsync = true;
+let restoredFromPageCache = false;
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+    if (event.persisted) {
+        debug("PASS - Page did enter and was restored from the page cache");
+        restoredFromPageCache = true;
+    }
+});
+
+function createImage()
+{
+    createImageBitmap(blob).then((result) => {
+        imageBitmap = result;
+        shouldBeTrue("!!imageBitmap");
+        shouldBeTrue("restoredFromPageCache");
+        finishJSTest();
+    }, () => {
+        createImage();
+    });
+}
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        debug("FAIL - Page did not enter the page cache.");
+        finishJSTest();
+    }
+
+    createImage();
+});
+
+window.addEventListener('load', function() {
+    setTimeout(() => {
+        let img = document.querySelector('img');
+        let canvas = document.createElement('canvas');
+        canvas.width = img.clientWidth;
+        canvas.height = img.clientHeight;
+
+        let context = canvas.getContext('2d');
+        context.drawImage(img, 0, 0);
+        canvas.toBlob((_blob) => {
+            blob = _blob;
+            testLink.click();
+        }, 'image/png');
+    }, 0);
+});
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (250781 => 250782)


--- trunk/Source/WebCore/ChangeLog	2019-10-07 18:57:27 UTC (rev 250781)
+++ trunk/Source/WebCore/ChangeLog	2019-10-07 18:58:23 UTC (rev 250782)
@@ -1,3 +1,17 @@
+2019-10-07  Chris Dumez  <cdu...@apple.com>
+
+        PendingImageBitmap should not prevent entering the back/forward cache
+        https://bugs.webkit.org/show_bug.cgi?id=202585
+
+        Reviewed by Tim Horton.
+
+        Add PageCache support to PendingImageBitmap by doing the promise resolution on a
+        SuspendableTimer (which properly gets paused while in PageCache).
+
+        Test: fast/history/page-cache-createImageBitmap.html
+
+        * html/ImageBitmap.cpp:
+
 2019-10-07  Dirk Schulze  <k...@webkit.org>
 
         clip-path: <geometry-box> mapping incorrect

Modified: trunk/Source/WebCore/html/ImageBitmap.cpp (250781 => 250782)


--- trunk/Source/WebCore/html/ImageBitmap.cpp	2019-10-07 18:57:27 UTC (rev 250781)
+++ trunk/Source/WebCore/html/ImageBitmap.cpp	2019-10-07 18:58:23 UTC (rev 250782)
@@ -45,9 +45,11 @@
 #include "LayoutSize.h"
 #include "RenderElement.h"
 #include "SharedBuffer.h"
+#include "SuspendableTimer.h"
 #include "TypedOMCSSImageValue.h"
 #include <wtf/IsoMallocInlines.h>
 #include <wtf/Optional.h>
+#include <wtf/Scope.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Variant.h>
 
@@ -525,6 +527,7 @@
 };
 
 class PendingImageBitmap final : public ActiveDOMObject, public FileReaderLoaderClient {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     static void fetch(ScriptExecutionContext& scriptExecutionContext, RefPtr<Blob>&& blob, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
     {
@@ -540,8 +543,10 @@
         , m_options(WTFMove(options))
         , m_rect(WTFMove(rect))
         , m_promise(WTFMove(promise))
+        , m_createImageBitmapTimer(&scriptExecutionContext, *this, &PendingImageBitmap::createImageBitmapAndResolvePromise)
     {
         suspendIfNeeded();
+        m_createImageBitmapTimer.suspendIfNeeded();
     }
 
     void start(ScriptExecutionContext& scriptExecutionContext)
@@ -551,17 +556,21 @@
 
     // ActiveDOMObject
 
-    const char* activeDOMObjectName() const override
+    const char* activeDOMObjectName() const final
     {
         return "PendingImageBitmap";
     }
 
-    bool canSuspendForDocumentSuspension() const override
+    bool canSuspendForDocumentSuspension() const final
     {
-        // FIXME: Deal with suspension.
-        return false;
+        return true;
     }
 
+    void stop() final
+    {
+        delete this;
+    }
+
     // FileReaderLoaderClient
 
     void didStartLoading() override
@@ -574,24 +583,33 @@
 
     void didFinishLoading() override
     {
-        createImageBitmap(m_blobLoader.arrayBufferResult());
-        delete this;
+        createImageBitmapAndResolvePromiseSoon(m_blobLoader.arrayBufferResult());
     }
 
     void didFail(int) override
     {
-        createImageBitmap(nullptr);
-        delete this;
+        createImageBitmapAndResolvePromiseSoon(nullptr);
     }
 
-    void createImageBitmap(RefPtr<ArrayBuffer>&& arrayBuffer)
+    void createImageBitmapAndResolvePromiseSoon(RefPtr<ArrayBuffer>&& arrayBuffer)
     {
-        if (!arrayBuffer) {
+        ASSERT(!m_createImageBitmapTimer.isActive());
+        m_arrayBufferToProcess = WTFMove(arrayBuffer);
+        m_createImageBitmapTimer.startOneShot(0_s);
+    }
+
+    void createImageBitmapAndResolvePromise()
+    {
+        auto destroyOnExit = makeScopeExit([this] {
+            delete this;
+        });
+
+        if (!m_arrayBufferToProcess) {
             m_promise.reject(InvalidStateError, "An error occured reading the Blob argument to createImageBitmap");
             return;
         }
 
-        ImageBitmap::createFromBuffer(arrayBuffer.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
+        ImageBitmap::createFromBuffer(m_arrayBufferToProcess.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
     }
 
     FileReaderLoader m_blobLoader;
@@ -599,6 +617,8 @@
     ImageBitmapOptions m_options;
     Optional<IntRect> m_rect;
     ImageBitmap::Promise m_promise;
+    SuspendableTimer m_createImageBitmapTimer;
+    RefPtr<ArrayBuffer> m_arrayBufferToProcess;
 };
 
 void ImageBitmap::createFromBuffer(
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to