Title: [233994] trunk/Source/WebCore
- Revision
- 233994
- Author
- [email protected]
- Date
- 2018-07-19 11:32:53 -0700 (Thu, 19 Jul 2018)
Log 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (233993 => 233994)
--- trunk/Source/WebCore/ChangeLog 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/ChangeLog 2018-07-19 18:32:53 UTC (rev 233994)
@@ -1,3 +1,33 @@
+2018-07-19 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-19 Jon Lee <[email protected]>
Update iOS fullscreen alert text again
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (233993 => 233994)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2018-07-19 18:32:53 UTC (rev 233994)
@@ -45,6 +45,12 @@
suspendIfNeeded();
}
+FetchBodyOwner::~FetchBodyOwner()
+{
+ if (m_readableStreamSource)
+ m_readableStreamSource->detach();
+}
+
void FetchBodyOwner::stop()
{
if (m_body)
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (233993 => 233994)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2018-07-19 18:32:53 UTC (rev 233994)
@@ -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: trunk/Source/WebCore/Modules/fetch/FetchBodySource.cpp (233993 => 233994)
--- trunk/Source/WebCore/Modules/fetch/FetchBodySource.cpp 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodySource.cpp 2018-07-19 18:32:53 UTC (rev 233994)
@@ -34,38 +34,52 @@
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);
+ if (!m_bodyOwner)
+ return;
+
+ m_bodyOwner->cancel();
+ m_bodyOwner = nullptr;
}
void FetchBodySource::close()
{
+ m_bodyOwner = nullptr;
controller().close();
clean();
}
@@ -72,6 +86,7 @@
void FetchBodySource::error(const String& value)
{
+ m_bodyOwner = nullptr;
controller().error(value);
clean();
}
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodySource.h (233993 => 233994)
--- trunk/Source/WebCore/Modules/fetch/FetchBodySource.h 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodySource.h 2018-07-19 18:32:53 UTC (rev 233994)
@@ -49,6 +49,7 @@
bool isCancelling() const { return m_isCancelling; }
void resolvePullPromise() { pullFinished(); }
+ void detach() { m_bodyOwner = nullptr; }
private:
void doStart() final;
@@ -57,7 +58,7 @@
void setActive() final;
void setInactive() final;
- FetchBodyOwner& m_bodyOwner;
+ FetchBodyOwner* m_bodyOwner;
bool m_isCancelling { false };
};
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (233993 => 233994)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2018-07-19 18:07:47 UTC (rev 233993)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2018-07-19 18:32:53 UTC (rev 233994)
@@ -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