Changeset 234045 in webkit


Ignore:
Timestamp:
Jul 20, 2018 9:58:54 AM (6 years ago)
Author:
youenn@apple.com
Message:

FetchResponse should close its stream when loading finishes
https://bugs.webkit.org/show_bug.cgi?id=187790

Reviewed by Chris Dumez.

It simplifies for a FetchResponse to push all its data into its stream if already created at end of load time.
Did some refactoring in FetchBodyOwner to have a cleaner relationship with the stream source.
Did a minor refactoring to expose the error description when loading fails as part of the rejected promise.
This is consistent to errors sent back through callbacks.

Covered by existing tests.

  • Modules/fetch/FetchBodyOwner.cpp:

(WebCore::FetchBodyOwner::~FetchBodyOwner):

  • Modules/fetch/FetchBodyOwner.h:
  • Modules/fetch/FetchBodySource.cpp:

(WebCore::FetchBodySource::FetchBodySource):
(WebCore::FetchBodySource::setActive):
(WebCore::FetchBodySource::setInactive):
(WebCore::FetchBodySource::doStart):
(WebCore::FetchBodySource::doPull):
(WebCore::FetchBodySource::doCancel):
(WebCore::FetchBodySource::cleanBodyOwner):

  • Modules/fetch/FetchBodySource.h:
  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::BodyLoader::didSucceed):
(WebCore::FetchResponse::BodyLoader::didFail):

Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r234044 r234045  
     12018-07-20  Youenn Fablet  <youenn@apple.com>
     2
     3        FetchResponse should close its stream when loading finishes
     4        https://bugs.webkit.org/show_bug.cgi?id=187790
     5
     6        Reviewed by Chris Dumez.
     7
     8        It simplifies for a FetchResponse to push all its data into its stream if already created at end of load time.
     9        Did some refactoring in FetchBodyOwner to have a cleaner relationship with the stream source.
     10        Did a minor refactoring to expose the error description when loading fails as part of the rejected promise.
     11        This is consistent to errors sent back through callbacks.
     12
     13        Covered by existing tests.
     14
     15        * Modules/fetch/FetchBodyOwner.cpp:
     16        (WebCore::FetchBodyOwner::~FetchBodyOwner):
     17        * Modules/fetch/FetchBodyOwner.h:
     18        * Modules/fetch/FetchBodySource.cpp:
     19        (WebCore::FetchBodySource::FetchBodySource):
     20        (WebCore::FetchBodySource::setActive):
     21        (WebCore::FetchBodySource::setInactive):
     22        (WebCore::FetchBodySource::doStart):
     23        (WebCore::FetchBodySource::doPull):
     24        (WebCore::FetchBodySource::doCancel):
     25        (WebCore::FetchBodySource::cleanBodyOwner):
     26        * Modules/fetch/FetchBodySource.h:
     27        * Modules/fetch/FetchResponse.cpp:
     28        (WebCore::FetchResponse::BodyLoader::didSucceed):
     29        (WebCore::FetchResponse::BodyLoader::didFail):
     30
    1312018-07-20  Jer Noble  <jer.noble@apple.com>
    232
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp

    r234003 r234045  
    4646}
    4747
     48FetchBodyOwner::~FetchBodyOwner()
     49{
     50    if (m_readableStreamSource)
     51        m_readableStreamSource->detach();
     52}
     53
    4854void FetchBodyOwner::stop()
    4955{
  • trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h

    r234003 r234045  
    4242public:
    4343    FetchBodyOwner(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);
     44    ~FetchBodyOwner();
    4445
    4546    bool bodyUsed() const { return isDisturbed(); }
  • trunk/Source/WebCore/Modules/fetch/FetchBodySource.cpp

    r234003 r234045  
    3535
    3636FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner)
    37     : m_bodyOwner(bodyOwner)
     37    : m_bodyOwner(&bodyOwner)
    3838{
    3939}
     
    4141void FetchBodySource::setActive()
    4242{
    43     m_bodyOwner.setPendingActivity(&m_bodyOwner);
     43    ASSERT(m_bodyOwner);
     44    if (m_bodyOwner)
     45        m_bodyOwner->setPendingActivity(m_bodyOwner);
    4446}
    4547
    4648void FetchBodySource::setInactive()
    4749{
    48     m_bodyOwner.unsetPendingActivity(&m_bodyOwner);
     50    ASSERT(m_bodyOwner);
     51    if (m_bodyOwner)
     52        m_bodyOwner->unsetPendingActivity(m_bodyOwner);
    4953}
    5054
    5155void FetchBodySource::doStart()
    5256{
    53     m_bodyOwner.consumeBodyAsStream();
     57    ASSERT(m_bodyOwner);
     58    if (m_bodyOwner)
     59        m_bodyOwner->consumeBodyAsStream();
    5460}
    5561
    5662void FetchBodySource::doPull()
    5763{
    58     m_bodyOwner.feedStream();
     64    ASSERT(m_bodyOwner);
     65    if (m_bodyOwner)
     66        m_bodyOwner->feedStream();
    5967}
    6068
     
    6270{
    6371    m_isCancelling = true;
    64     m_bodyOwner.cancel();
     72    ASSERT(m_bodyOwner || m_isClosed);
     73    if (!m_bodyOwner)
     74        return;
     75
     76    m_bodyOwner->cancel();
     77    m_bodyOwner = nullptr;
    6578}
    6679
    6780void FetchBodySource::close()
    6881{
     82#ifndef NDEBUG
     83    m_isClosed = true;
     84#endif
     85
    6986    controller().close();
    7087    clean();
     88    m_bodyOwner = nullptr;
    7189}
    7290
     
    7593    controller().error(value);
    7694    clean();
     95    m_bodyOwner = nullptr;
    7796}
    7897
  • trunk/Source/WebCore/Modules/fetch/FetchBodySource.h

    r234003 r234045  
    5050
    5151    void resolvePullPromise() { pullFinished(); }
     52    void detach() { m_bodyOwner = nullptr; }
    5253
    5354private:
     
    5859    void setInactive() final;
    5960
    60     FetchBodyOwner& m_bodyOwner;
     61    FetchBodyOwner* m_bodyOwner;
    6162    bool m_isCancelling { false };
     63#ifndef NDEBUG
     64    bool m_isClosed { false };
     65#endif
    6266};
    6367
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r234003 r234045  
    226226
    227227#if ENABLE(STREAMS_API)
    228     if (m_response.m_readableStreamSource && !m_response.body().consumer().hasData())
     228    if (m_response.m_readableStreamSource) {
     229        if (m_response.body().consumer().hasData())
     230            m_response.m_readableStreamSource->enqueue(m_response.body().consumer().takeAsArrayBuffer());
     231
    229232        m_response.closeStream();
     233    }
    230234#endif
    231235    if (auto consumeDataCallback = WTFMove(m_consumeDataCallback))
     
    253257    if (m_response.m_readableStreamSource) {
    254258        if (!m_response.m_readableStreamSource->isCancelling())
    255             m_response.m_readableStreamSource->error("Loading failed"_s);
     259            m_response.m_readableStreamSource->error(makeString("Loading failed: "_s, error.localizedDescription()));
    256260        m_response.m_readableStreamSource = nullptr;
    257261    }
Note: See TracChangeset for help on using the changeset viewer.