Changeset 250782 in webkit


Ignore:
Timestamp:
Oct 7, 2019 11:58:23 AM (5 years ago)
Author:
Chris Dumez
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.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r250781 r250782  
     12019-10-07  Chris Dumez  <cdumez@apple.com>
     2
     3        PendingImageBitmap should not prevent entering the back/forward cache
     4        https://bugs.webkit.org/show_bug.cgi?id=202585
     5
     6        Reviewed by Tim Horton.
     7
     8        Add layout test coverage.
     9
     10        * TestExpectations:
     11        * fast/history/page-cache-createImageBitmap-expected.txt: Added.
     12        * fast/history/page-cache-createImageBitmap.html: Added.
     13
    1142019-10-07  Antoine Quint  <graouts@apple.com>
    215
  • trunk/LayoutTests/TestExpectations

    r250772 r250782  
    263263imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location-protocol-setter-non-broken-weird.html [ DumpJSConsoleLogInStdErr ]
    264264imported/w3c/web-platform-tests/service-workers/service-worker/fetch-cors-xhr.https.html [ DumpJSConsoleLogInStdErr ]
     265fast/history/page-cache-createImageBitmap.html [ DumpJSConsoleLogInStdErr ]
    265266
    266267webkit.org/b/202495 imported/w3c/web-platform-tests/shadow-dom/directionality-002.tentative.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r250778 r250782  
     12019-10-07  Chris Dumez  <cdumez@apple.com>
     2
     3        PendingImageBitmap should not prevent entering the back/forward cache
     4        https://bugs.webkit.org/show_bug.cgi?id=202585
     5
     6        Reviewed by Tim Horton.
     7
     8        Add PageCache support to PendingImageBitmap by doing the promise resolution on a
     9        SuspendableTimer (which properly gets paused while in PageCache).
     10
     11        Test: fast/history/page-cache-createImageBitmap.html
     12
     13        * html/ImageBitmap.cpp:
     14
    1152019-10-07  Dirk Schulze  <krit@webkit.org>
    216
  • trunk/Source/WebCore/html/ImageBitmap.cpp

    r250735 r250782  
    4646#include "RenderElement.h"
    4747#include "SharedBuffer.h"
     48#include "SuspendableTimer.h"
    4849#include "TypedOMCSSImageValue.h"
    4950#include <wtf/IsoMallocInlines.h>
    5051#include <wtf/Optional.h>
     52#include <wtf/Scope.h>
    5153#include <wtf/StdLibExtras.h>
    5254#include <wtf/Variant.h>
     
    526528
    527529class PendingImageBitmap final : public ActiveDOMObject, public FileReaderLoaderClient {
     530    WTF_MAKE_FAST_ALLOCATED;
    528531public:
    529532    static void fetch(ScriptExecutionContext& scriptExecutionContext, RefPtr<Blob>&& blob, ImageBitmapOptions&& options, Optional<IntRect> rect, ImageBitmap::Promise&& promise)
     
    541544        , m_rect(WTFMove(rect))
    542545        , m_promise(WTFMove(promise))
     546        , m_createImageBitmapTimer(&scriptExecutionContext, *this, &PendingImageBitmap::createImageBitmapAndResolvePromise)
    543547    {
    544548        suspendIfNeeded();
     549        m_createImageBitmapTimer.suspendIfNeeded();
    545550    }
    546551
     
    552557    // ActiveDOMObject
    553558
    554     const char* activeDOMObjectName() const override
     559    const char* activeDOMObjectName() const final
    555560    {
    556561        return "PendingImageBitmap";
    557562    }
    558563
    559     bool canSuspendForDocumentSuspension() const override
    560     {
    561         // FIXME: Deal with suspension.
    562         return false;
     564    bool canSuspendForDocumentSuspension() const final
     565    {
     566        return true;
     567    }
     568
     569    void stop() final
     570    {
     571        delete this;
    563572    }
    564573
     
    575584    void didFinishLoading() override
    576585    {
    577         createImageBitmap(m_blobLoader.arrayBufferResult());
    578         delete this;
     586        createImageBitmapAndResolvePromiseSoon(m_blobLoader.arrayBufferResult());
    579587    }
    580588
    581589    void didFail(int) override
    582590    {
    583         createImageBitmap(nullptr);
    584         delete this;
    585     }
    586 
    587     void createImageBitmap(RefPtr<ArrayBuffer>&& arrayBuffer)
    588     {
    589         if (!arrayBuffer) {
     591        createImageBitmapAndResolvePromiseSoon(nullptr);
     592    }
     593
     594    void createImageBitmapAndResolvePromiseSoon(RefPtr<ArrayBuffer>&& arrayBuffer)
     595    {
     596        ASSERT(!m_createImageBitmapTimer.isActive());
     597        m_arrayBufferToProcess = WTFMove(arrayBuffer);
     598        m_createImageBitmapTimer.startOneShot(0_s);
     599    }
     600
     601    void createImageBitmapAndResolvePromise()
     602    {
     603        auto destroyOnExit = makeScopeExit([this] {
     604            delete this;
     605        });
     606
     607        if (!m_arrayBufferToProcess) {
    590608            m_promise.reject(InvalidStateError, "An error occured reading the Blob argument to createImageBitmap");
    591609            return;
    592610        }
    593611
    594         ImageBitmap::createFromBuffer(arrayBuffer.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
     612        ImageBitmap::createFromBuffer(m_arrayBufferToProcess.releaseNonNull(), m_blob->type(), m_blob->size(), m_blobLoader.url(), WTFMove(m_options), WTFMove(m_rect), WTFMove(m_promise));
    595613    }
    596614
     
    600618    Optional<IntRect> m_rect;
    601619    ImageBitmap::Promise m_promise;
     620    SuspendableTimer m_createImageBitmapTimer;
     621    RefPtr<ArrayBuffer> m_arrayBufferToProcess;
    602622};
    603623
Note: See TracChangeset for help on using the changeset viewer.