Title: [234050] branches/safari-606-branch/Source/WebCore
Revision
234050
Author
[email protected]
Date
2018-07-20 10:17:13 -0700 (Fri, 20 Jul 2018)

Log Message

Cherry-pick r234045. rdar://problem/42434024

    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):

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

Modified Paths

Diff

Modified: branches/safari-606-branch/Source/WebCore/ChangeLog (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/ChangeLog	2018-07-20 17:17:13 UTC (rev 234050)
@@ -1,5 +1,70 @@
 2018-07-20  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r234045. rdar://problem/42434024
+
+    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):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234045 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2018-07-20  Youenn Fablet  <[email protected]>
+
+            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):
+
+2018-07-20  Babak Shafiei  <[email protected]>
+
         Cherry-pick r234044. rdar://problem/42433225
 
     REGRESSION(r233969): ASSERT in -[WebAVPlayerLayer setVideoGravity:]

Modified: branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2018-07-20 17:17:13 UTC (rev 234050)
@@ -45,6 +45,12 @@
     suspendIfNeeded();
 }
 
+FetchBodyOwner::~FetchBodyOwner()
+{
+    if (m_readableStreamSource)
+        m_readableStreamSource->detach();
+}
+
 void FetchBodyOwner::stop()
 {
     if (m_body)

Modified: branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.h (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2018-07-20 17:17:13 UTC (rev 234050)
@@ -41,6 +41,7 @@
 class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject {
 public:
     FetchBodyOwner(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);
+    ~FetchBodyOwner();
 
     bool bodyUsed() const { return isDisturbed(); }
     void arrayBuffer(Ref<DeferredPromise>&&);

Modified: branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.cpp (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.cpp	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.cpp	2018-07-20 17:17:13 UTC (rev 234050)
@@ -34,40 +34,58 @@
 namespace WebCore {
 
 FetchBodySource::FetchBodySource(FetchBodyOwner& bodyOwner)
-    : m_bodyOwner(bodyOwner)
+    : m_bodyOwner(&bodyOwner)
 {
 }
 
 void FetchBodySource::setActive()
 {
-    m_bodyOwner.setPendingActivity(&m_bodyOwner);
+    ASSERT(m_bodyOwner);
+    if (m_bodyOwner)
+        m_bodyOwner->setPendingActivity(m_bodyOwner);
 }
 
 void FetchBodySource::setInactive()
 {
-    m_bodyOwner.unsetPendingActivity(&m_bodyOwner);
+    ASSERT(m_bodyOwner);
+    if (m_bodyOwner)
+        m_bodyOwner->unsetPendingActivity(m_bodyOwner);
 }
 
 void FetchBodySource::doStart()
 {
-    m_bodyOwner.consumeBodyAsStream();
+    ASSERT(m_bodyOwner);
+    if (m_bodyOwner)
+        m_bodyOwner->consumeBodyAsStream();
 }
 
 void FetchBodySource::doPull()
 {
-    m_bodyOwner.feedStream();
+    ASSERT(m_bodyOwner);
+    if (m_bodyOwner)
+        m_bodyOwner->feedStream();
 }
 
 void FetchBodySource::doCancel()
 {
     m_isCancelling = true;
-    m_bodyOwner.cancel();
+    ASSERT(m_bodyOwner || m_isClosed);
+    if (!m_bodyOwner)
+        return;
+
+    m_bodyOwner->cancel();
+    m_bodyOwner = nullptr;
 }
 
 void FetchBodySource::close()
 {
+#ifndef NDEBUG
+    m_isClosed = true;
+#endif
+
     controller().close();
     clean();
+    m_bodyOwner = nullptr;
 }
 
 void FetchBodySource::error(const String& value)
@@ -74,6 +92,7 @@
 {
     controller().error(value);
     clean();
+    m_bodyOwner = nullptr;
 }
 
 } // namespace WebCore

Modified: branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.h (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.h	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchBodySource.h	2018-07-20 17:17:13 UTC (rev 234050)
@@ -49,6 +49,7 @@
     bool isCancelling() const { return m_isCancelling; }
 
     void resolvePullPromise() { pullFinished(); }
+    void detach() { m_bodyOwner = nullptr; }
 
 private:
     void doStart() final;
@@ -57,8 +58,11 @@
     void setActive() final;
     void setInactive() final;
 
-    FetchBodyOwner& m_bodyOwner;
+    FetchBodyOwner* m_bodyOwner;
     bool m_isCancelling { false };
+#ifndef NDEBUG
+    bool m_isClosed { false };
+#endif
 };
 
 } // namespace WebCore

Modified: branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchResponse.cpp (234049 => 234050)


--- branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchResponse.cpp	2018-07-20 17:08:44 UTC (rev 234049)
+++ branches/safari-606-branch/Source/WebCore/Modules/fetch/FetchResponse.cpp	2018-07-20 17:17:13 UTC (rev 234050)
@@ -225,8 +225,12 @@
     m_response.m_body->loadingSucceeded();
 
 #if ENABLE(STREAMS_API)
-    if (m_response.m_readableStreamSource && !m_response.body().consumer().hasData())
+    if (m_response.m_readableStreamSource) {
+        if (m_response.body().consumer().hasData())
+            m_response.m_readableStreamSource->enqueue(m_response.body().consumer().takeAsArrayBuffer());
+
         m_response.closeStream();
+    }
 #endif
     if (auto consumeDataCallback = WTFMove(m_consumeDataCallback))
         consumeDataCallback(nullptr);
@@ -252,7 +256,7 @@
 #if ENABLE(STREAMS_API)
     if (m_response.m_readableStreamSource) {
         if (!m_response.m_readableStreamSource->isCancelling())
-            m_response.m_readableStreamSource->error("Loading failed"_s);
+            m_response.m_readableStreamSource->error(makeString("Loading failed: "_s, error.localizedDescription()));
         m_response.m_readableStreamSource = nullptr;
     }
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to