Diff
Modified: trunk/Source/WebCore/ChangeLog (206736 => 206737)
--- trunk/Source/WebCore/ChangeLog 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/ChangeLog 2016-10-03 17:57:27 UTC (rev 206737)
@@ -1,3 +1,64 @@
+2016-10-03 Youenn Fablet <[email protected]>
+
+ Remove FetchBody::m_isEmpty
+ https://bugs.webkit.org/show_bug.cgi?id=162857
+
+ Reviewed by Alex Christensen.
+
+ No change of behavior.
+
+ Moving handling of null bodies in FetchBodyOwner, by having an Optional<FetchBody> in FetchBodyOwner.
+ Moving storage of m_contentType in FetchBodyOwner.
+
+ Moving header storage from FetchResponse/FetchRequest to FetchBodyOwner, as it helps updating m_contentType.
+
+ * Modules/fetch/FetchBody.cpp: removing m_isEmpty and m_contentType.
+ (WebCore::FetchBody::extract): Computes the default content-type which is stored in FetchBodyOwner.
+ (WebCore::FetchBody::blob):
+ (WebCore::FetchBody::consume):
+ (WebCore::FetchBody::consumeAsStream):
+ (WebCore::FetchBody::loadingSucceeded):
+ (WebCore::FetchBody::bodyForInternalRequest):
+ (WebCore::FetchBody::clone):
+ * Modules/fetch/FetchBody.h:
+ (WebCore::FetchBody::loadingBody):
+ (WebCore::FetchBody::FetchBody):
+ * Modules/fetch/FetchBodyOwner.cpp:
+ (WebCore::FetchBodyOwner::FetchBodyOwner):
+ (WebCore::FetchBodyOwner::stop):
+ (WebCore::FetchBodyOwner::arrayBuffer):
+ (WebCore::FetchBodyOwner::blob):
+ (WebCore::FetchBodyOwner::cloneBody): Needs to clone m_contentType as well.
+ (WebCore::FetchBodyOwner::extractBody):
+ (WebCore::FetchBodyOwner::updateContentType):
+ (WebCore::FetchBodyOwner::consumeOnceLoadingFinished):
+ (WebCore::FetchBodyOwner::formData):
+ (WebCore::FetchBodyOwner::json):
+ (WebCore::FetchBodyOwner::text):
+ (WebCore::FetchBodyOwner::loadBlob):
+ (WebCore::FetchBodyOwner::blobLoadingSucceeded):
+ (WebCore::FetchBodyOwner::blobLoadingFailed):
+ (WebCore::FetchBodyOwner::finishBlobLoading):
+ * Modules/fetch/FetchBodyOwner.h:
+ (WebCore::FetchBodyOwner::body):
+ (WebCore::FetchBodyOwner::isBodyNull):
+ * Modules/fetch/FetchRequest.cpp:
+ (WebCore::FetchRequest::setBody):
+ (WebCore::FetchRequest::internalRequest):
+ (WebCore::FetchRequest::clone):
+ * Modules/fetch/FetchRequest.h:
+ (WebCore::FetchRequest::FetchRequest):
+ * Modules/fetch/FetchResponse.cpp:
+ (WebCore::FetchResponse::initializeWith):
+ (WebCore::FetchResponse::FetchResponse):
+ (WebCore::FetchResponse::cloneForJS):
+ (WebCore::FetchResponse::fetch):
+ (WebCore::FetchResponse::BodyLoader::didSucceed):
+ (WebCore::FetchResponse::BodyLoader::didReceiveResponse):
+ (WebCore::FetchResponse::BodyLoader::start):
+ (WebCore::FetchResponse::createReadableStreamSource):
+ * Modules/fetch/FetchResponse.h:
+
2016-10-03 Andy Estes <[email protected]>
ASSERTION FAILED: result in WebCore::CSSParser::parseURI
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp 2016-10-03 17:57:27 UTC (rev 206737)
@@ -47,92 +47,41 @@
namespace WebCore {
-FetchBody::FetchBody(Ref<const Blob>&& blob)
- : m_data(WTFMove(blob))
- , m_contentType(this->blobBody().type())
+Optional<FetchBody> FetchBody::extract(ScriptExecutionContext& context, JSC::ExecState& state, JSC::JSValue value, String& contentType)
{
-}
-
-FetchBody::FetchBody(DOMFormData& formData, Document& document)
- : m_data(FormData::createMultiPart(formData, formData.encoding(), &document))
- , m_contentType(makeString("multipart/form-data;boundary=", this->formDataBody().boundary().data()))
-{
-}
-
-FetchBody::FetchBody(String&& text)
- : m_data(WTFMove(text))
- , m_contentType(ASCIILiteral("text/plain;charset=UTF-8"))
-{
-}
-
-FetchBody::FetchBody(Ref<const ArrayBuffer>&& data)
- : m_data(WTFMove(data))
-{
-}
-
-FetchBody::FetchBody(Ref<const ArrayBufferView>&& dataView)
- : m_data(WTFMove(dataView))
-{
-}
-
-FetchBody::FetchBody(Ref<const URLSearchParams>&& url)
- : m_data(WTFMove(url))
- , m_contentType(ASCIILiteral("application/x-www-form-urlencoded;charset=UTF-8"))
-{
-}
-
-FetchBody::FetchBody(const String& contentType, const FetchBodyConsumer& consumer)
- : m_contentType(contentType)
- , m_consumer(consumer)
-{
-}
-
-FetchBody FetchBody::extract(ScriptExecutionContext& context, JSC::ExecState& state, JSC::JSValue value)
-{
- if (value.inherits(JSBlob::info()))
- return FetchBody(*JSBlob::toWrapped(value));
+ if (value.inherits(JSBlob::info())) {
+ auto& blob = *JSBlob::toWrapped(value);
+ contentType = blob.type();
+ return FetchBody(blob);
+ }
if (value.inherits(JSDOMFormData::info())) {
ASSERT(!context.isWorkerGlobalScope());
- return FetchBody(*JSDOMFormData::toWrapped(value), static_cast<Document&>(context));
+ auto& domFormData = *JSDOMFormData::toWrapped(value);
+ auto formData = FormData::createMultiPart(domFormData, domFormData.encoding(), &static_cast<Document&>(context));
+ contentType = makeString("multipart/form-data;boundary=", formData->boundary().data());
+ return FetchBody(WTFMove(formData));
}
- if (value.isString())
+ if (value.isString()) {
+ contentType = ASCIILiteral("text/plain;charset=UTF-8");
return FetchBody(value.toWTFString(&state));
- if (value.inherits(JSURLSearchParams::info()))
+ }
+ if (value.inherits(JSURLSearchParams::info())) {
+ contentType = ASCIILiteral("application/x-www-form-urlencoded;charset=UTF-8");
return FetchBody(*JSURLSearchParams::toWrapped(value));
- if (value.inherits(JSReadableStream::info())) {
- FetchBody body;
- body.m_isEmpty = false;
- return body;
- } if (value.inherits(JSC::JSArrayBuffer::info())) {
+ }
+ if (value.inherits(JSReadableStream::info()))
+ return FetchBody();
+ if (value.inherits(JSC::JSArrayBuffer::info())) {
ArrayBuffer* data = ""
ASSERT(data);
- return { *data };
+ return FetchBody(*data);
}
if (value.inherits(JSC::JSArrayBufferView::info()))
- return { toArrayBufferView(value).releaseConstNonNull() };
+ return FetchBody(toArrayBufferView(value).releaseConstNonNull());
- return { };
+ return Nullopt;
}
-FetchBody FetchBody::extractFromBody(FetchBody* body)
-{
- if (!body)
- return { };
-
- return FetchBody(WTFMove(*body));
-}
-
-void FetchBody::updateContentType(FetchHeaders& headers)
-{
- String contentType = headers.fastGet(HTTPHeaderName::ContentType);
- if (!contentType.isNull()) {
- m_contentType = contentType;
- return;
- }
- if (!m_contentType.isNull())
- headers.fastSet(HTTPHeaderName::ContentType, m_contentType);
-}
-
void FetchBody::arrayBuffer(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
{
m_consumer.setType(FetchBodyConsumer::Type::ArrayBuffer);
@@ -139,10 +88,10 @@
consume(owner, WTFMove(promise));
}
-void FetchBody::blob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise)
+void FetchBody::blob(FetchBodyOwner& owner, Ref<DeferredPromise>&& promise, const String& contentType)
{
m_consumer.setType(FetchBodyConsumer::Type::Blob);
- m_consumer.setContentType(Blob::normalizedContentType(extractMIMETypeFromMediaType(m_contentType)));
+ m_consumer.setContentType(Blob::normalizedContentType(extractMIMETypeFromMediaType(contentType)));
consume(owner, WTFMove(promise));
}
@@ -194,16 +143,12 @@
consumeBlob(owner, WTFMove(promise));
return;
}
- if (m_consumer.hasData()) {
- m_consumer.resolve(WTFMove(promise));
- return;
- }
if (isFormData()) {
// FIXME: Support consuming FormData.
promise->reject(0);
return;
}
- ASSERT_NOT_REACHED();
+ m_consumer.resolve(WTFMove(promise));
}
#if ENABLE(READABLE_STREAM_API)
@@ -227,12 +172,12 @@
} else if (isBlob()) {
owner.loadBlob(blobBody(), nullptr);
m_data = nullptr;
- } else if (m_consumer.hasData())
+ } else if (isFormData())
+ source.error(ASCIILiteral("not implemented"));
+ else if (m_consumer.hasData())
closeStream = source.enqueue(m_consumer.takeAsArrayBuffer());
- else if (isEmpty())
+ else
closeStream = true;
- else
- source.error(ASCIILiteral("not implemented"));
if (closeStream)
source.close();
@@ -275,7 +220,6 @@
void FetchBody::loadingSucceeded()
{
- m_isEmpty = !m_consumer.hasData();
if (m_consumePromise)
m_consumer.resolve(m_consumePromise.releaseNonNull());
}
@@ -282,8 +226,6 @@
RefPtr<FormData> FetchBody::bodyForInternalRequest(ScriptExecutionContext& context) const
{
- if (isEmpty())
- return nullptr;
if (isText())
return FormData::create(UTF8Encoding().encode(textBody(), EntitiesForUnencodables));
if (isURLSearchParams())
@@ -310,8 +252,7 @@
FetchBody FetchBody::clone() const
{
ASSERT(!m_consumePromise);
- FetchBody clone(m_contentType, m_consumer);
- clone.m_isEmpty = m_isEmpty;
+ FetchBody clone(m_consumer);
if (isArrayBuffer())
clone.m_data = arrayBufferBody();
Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchBody.h 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h 2016-10-03 17:57:27 UTC (rev 206737)
@@ -37,6 +37,7 @@
#include "FormData.h"
#include "JSDOMPromise.h"
#include "URLSearchParams.h"
+#include <wtf/Optional.h>
#include <wtf/Variant.h>
namespace JSC {
@@ -55,7 +56,7 @@
class FetchBody {
public:
void arrayBuffer(FetchBodyOwner&, Ref<DeferredPromise>&&);
- void blob(FetchBodyOwner&, Ref<DeferredPromise>&&);
+ void blob(FetchBodyOwner&, Ref<DeferredPromise>&&, const String&);
void json(FetchBodyOwner&, Ref<DeferredPromise>&&);
void text(FetchBodyOwner&, Ref<DeferredPromise>&&);
void formData(FetchBodyOwner&, Ref<DeferredPromise>&& promise) { promise.get().reject(0); }
@@ -64,7 +65,6 @@
void consumeAsStream(FetchBodyOwner&, FetchResponseSource&);
#endif
- bool isEmpty() const { return m_isEmpty; }
bool isBlob() const { return std::experimental::holds_alternative<Ref<const Blob>>(m_data); }
bool isFormData() const { return std::experimental::holds_alternative<Ref<FormData>>(m_data); }
bool isArrayBuffer() const { return std::experimental::holds_alternative<Ref<const ArrayBuffer>>(m_data); }
@@ -72,14 +72,9 @@
bool isURLSearchParams() const { return std::experimental::holds_alternative<Ref<const URLSearchParams>>(m_data); }
bool isText() const { return std::experimental::holds_alternative<String>(m_data); }
- void updateContentType(FetchHeaders&);
- void setContentType(const String& contentType) { m_contentType = contentType; }
- String contentType() const { return m_contentType; }
+ static Optional<FetchBody> extract(ScriptExecutionContext&, JSC::ExecState&, JSC::JSValue, String&);
+ static FetchBody loadingBody() { return { }; }
- static FetchBody extract(ScriptExecutionContext&, JSC::ExecState&, JSC::JSValue);
- static FetchBody extractFromBody(FetchBody*);
- FetchBody() : m_isEmpty(true) { }
-
void loadingFailed();
void loadingSucceeded();
@@ -93,13 +88,14 @@
FetchBody clone() const;
private:
- FetchBody(Ref<const Blob>&&);
- FetchBody(Ref<const ArrayBuffer>&&);
- FetchBody(Ref<const ArrayBufferView>&&);
- FetchBody(DOMFormData&, Document&);
- FetchBody(String&&);
- FetchBody(Ref<const URLSearchParams>&&);
- FetchBody(const String&, const FetchBodyConsumer&);
+ explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(Ref<const ArrayBuffer>&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(Ref<const ArrayBufferView>&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(Ref<FormData>&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(String&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(Ref<const URLSearchParams>&& data) : m_data(WTFMove(data)) { }
+ explicit FetchBody(const FetchBodyConsumer& consumer) : m_consumer(consumer) { }
+ FetchBody() = default;
void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
@@ -118,10 +114,7 @@
const URLSearchParams& urlSearchParamsBody() const { return std::experimental::get<Ref<const URLSearchParams>>(m_data).get(); }
std::experimental::variant<std::nullptr_t, Ref<const Blob>, Ref<FormData>, Ref<const ArrayBuffer>, Ref<const ArrayBufferView>, Ref<const URLSearchParams>, String> m_data { nullptr };
- String m_contentType;
- bool m_isEmpty { false };
-
FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
RefPtr<DeferredPromise> m_consumePromise;
};
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-10-03 17:57:27 UTC (rev 206737)
@@ -40,9 +40,10 @@
namespace WebCore {
-FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, FetchBody&& body)
+FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, Optional<FetchBody>&& body, Ref<FetchHeaders>&& headers)
: ActiveDOMObject(&context)
, m_body(WTFMove(body))
+ , m_headers(WTFMove(headers))
{
suspendIfNeeded();
}
@@ -49,7 +50,8 @@
void FetchBodyOwner::stop()
{
- m_body.cleanConsumePromise();
+ if (m_body)
+ m_body->cleanConsumePromise();
if (m_blobLoader) {
bool isUniqueReference = hasOneRef();
@@ -75,7 +77,7 @@
void FetchBodyOwner::arrayBuffer(Ref<DeferredPromise>&& promise)
{
- if (m_body.isEmpty()) {
+ if (isBodyNull()) {
fulfillPromiseWithArrayBuffer(WTFMove(promise), nullptr, 0);
return;
}
@@ -84,13 +86,13 @@
return;
}
m_isDisturbed = true;
- m_body.arrayBuffer(*this, WTFMove(promise));
+ m_body->arrayBuffer(*this, WTFMove(promise));
}
void FetchBodyOwner::blob(Ref<DeferredPromise>&& promise)
{
- if (m_body.isEmpty()) {
- promise->resolve(Blob::create(Vector<uint8_t>(), Blob::normalizedContentType(extractMIMETypeFromMediaType(m_body.contentType()))));
+ if (isBodyNull()) {
+ promise->resolve(Blob::create(Vector<uint8_t>(), Blob::normalizedContentType(extractMIMETypeFromMediaType(m_contentType))));
return;
}
if (isDisturbedOrLocked()) {
@@ -98,9 +100,33 @@
return;
}
m_isDisturbed = true;
- m_body.blob(*this, WTFMove(promise));
+ m_body->blob(*this, WTFMove(promise), m_contentType);
}
+void FetchBodyOwner::cloneBody(const FetchBodyOwner& owner)
+{
+ m_contentType = owner.m_contentType;
+ if (owner.isBodyNull())
+ return;
+ m_body = owner.m_body->clone();
+}
+
+void FetchBodyOwner::extractBody(ScriptExecutionContext& context, JSC::ExecState& state, JSC::JSValue value)
+{
+ m_body = FetchBody::extract(context, state, value, m_contentType);
+}
+
+void FetchBodyOwner::updateContentType()
+{
+ String contentType = m_headers->fastGet(HTTPHeaderName::ContentType);
+ if (!contentType.isNull()) {
+ m_contentType = WTFMove(contentType);
+ return;
+ }
+ if (!m_contentType.isNull())
+ m_headers->fastSet(HTTPHeaderName::ContentType, m_contentType);
+}
+
void FetchBodyOwner::consumeOnceLoadingFinished(FetchBodyConsumer::Type type, Ref<DeferredPromise>&& promise)
{
if (isDisturbedOrLocked()) {
@@ -108,12 +134,12 @@
return;
}
m_isDisturbed = true;
- m_body.consumeOnceLoadingFinished(type, WTFMove(promise));
+ m_body->consumeOnceLoadingFinished(type, WTFMove(promise));
}
void FetchBodyOwner::formData(Ref<DeferredPromise>&& promise)
{
- if (m_body.isEmpty()) {
+ if (isBodyNull()) {
promise->reject(0);
return;
}
@@ -122,12 +148,12 @@
return;
}
m_isDisturbed = true;
- m_body.formData(*this, WTFMove(promise));
+ m_body->formData(*this, WTFMove(promise));
}
void FetchBodyOwner::json(Ref<DeferredPromise>&& promise)
{
- if (m_body.isEmpty()) {
+ if (isBodyNull()) {
promise->reject(SYNTAX_ERR);
return;
}
@@ -136,12 +162,12 @@
return;
}
m_isDisturbed = true;
- m_body.json(*this, WTFMove(promise));
+ m_body->json(*this, WTFMove(promise));
}
void FetchBodyOwner::text(Ref<DeferredPromise>&& promise)
{
- if (m_body.isEmpty()) {
+ if (isBodyNull()) {
promise->resolve(String());
return;
}
@@ -150,7 +176,7 @@
return;
}
m_isDisturbed = true;
- m_body.text(*this, WTFMove(promise));
+ m_body->text(*this, WTFMove(promise));
}
void FetchBodyOwner::loadBlob(const Blob& blob, FetchBodyConsumer* consumer)
@@ -158,9 +184,10 @@
// Can only be called once for a body instance.
ASSERT(isDisturbed());
ASSERT(!m_blobLoader);
+ ASSERT(!isBodyNull());
if (!scriptExecutionContext()) {
- m_body.loadingFailed();
+ m_body->loadingFailed();
return;
}
@@ -169,7 +196,7 @@
m_blobLoader->loader->start(*scriptExecutionContext(), blob);
if (!m_blobLoader->loader->isStarted()) {
- m_body.loadingFailed();
+ m_body->loadingFailed();
m_blobLoader = Nullopt;
return;
}
@@ -186,6 +213,7 @@
void FetchBodyOwner::blobLoadingSucceeded()
{
+ ASSERT(!isBodyNull());
#if ENABLE(READABLE_STREAM_API)
if (m_readableStreamSource) {
m_readableStreamSource->close();
@@ -192,12 +220,13 @@
m_readableStreamSource = nullptr;
}
#endif
- m_body.loadingSucceeded();
+ m_body->loadingSucceeded();
finishBlobLoading();
}
void FetchBodyOwner::blobLoadingFailed()
{
+ ASSERT(!isBodyNull());
#if ENABLE(READABLE_STREAM_API)
if (m_readableStreamSource) {
if (!m_readableStreamSource->isCancelling())
@@ -205,7 +234,7 @@
m_readableStreamSource = nullptr;
} else
#endif
- m_body.loadingFailed();
+ m_body->loadingFailed();
finishBlobLoading();
}
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-10-03 17:57:27 UTC (rev 206737)
@@ -33,6 +33,7 @@
#include "ActiveDOMObject.h"
#include "FetchBody.h"
+#include "FetchHeaders.h"
#include "FetchLoader.h"
#include "FetchLoaderClient.h"
#include "FetchResponseSource.h"
@@ -41,7 +42,7 @@
class FetchBodyOwner : public RefCounted<FetchBodyOwner>, public ActiveDOMObject {
public:
- FetchBodyOwner(ScriptExecutionContext&, FetchBody&&);
+ FetchBodyOwner(ScriptExecutionContext&, Optional<FetchBody>&&, Ref<FetchHeaders>&&);
// Exposed Body API
bool isDisturbed() const { return m_isDisturbed; };
@@ -59,8 +60,13 @@
bool isActive() const { return !!m_blobLoader; }
protected:
- const FetchBody& body() const { return m_body; }
- FetchBody& body() { return m_body; }
+ const FetchBody& body() const { return *m_body; }
+ FetchBody& body() { return *m_body; }
+ bool isBodyNull() const { return !m_body; }
+ void cloneBody(const FetchBodyOwner&);
+
+ void extractBody(ScriptExecutionContext&, JSC::ExecState&, JSC::JSValue);
+ void updateContentType();
void consumeOnceLoadingFinished(FetchBodyConsumer::Type, Ref<DeferredPromise>&&);
// ActiveDOMObject API
@@ -89,11 +95,13 @@
};
protected:
- FetchBody m_body;
+ Optional<FetchBody> m_body;
+ String m_contentType;
bool m_isDisturbed { false };
#if ENABLE(READABLE_STREAM_API)
RefPtr<FetchResponseSource> m_readableStreamSource;
#endif
+ Ref<FetchHeaders> m_headers;
private:
Optional<BlobLoader> m_blobLoader;
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-10-03 17:57:27 UTC (rev 206737)
@@ -261,23 +261,21 @@
}
ASSERT(scriptExecutionContext());
- m_body = FetchBody::extract(*scriptExecutionContext(), execState, body);
- if (m_body.isEmpty()) {
+ extractBody(*scriptExecutionContext(), execState, body);
+ if (isBodyNull()) {
ec = TypeError;
return;
}
- }
- else if (request && !request->m_body.isEmpty()) {
+ } else if (request && !request->isBodyNull()) {
if (!methodCanHaveBody(m_internalRequest)) {
ec = TypeError;
return;
}
- m_body = FetchBody::extractFromBody(&request->m_body);
+ m_body = WTFMove(request->m_body);
request->setDisturbed();
}
-
- m_body.updateContentType(m_headers);
+ updateContentType();
}
String FetchRequest::referrer() const
@@ -302,8 +300,10 @@
ResourceRequest request = m_internalRequest.request;
request.setHTTPHeaderFields(m_headers->internalHeaders());
- request.setHTTPBody(body().bodyForInternalRequest(*scriptExecutionContext()));
+ if (!isBodyNull())
+ request.setHTTPBody(body().bodyForInternalRequest(*scriptExecutionContext()));
+
return request;
}
@@ -314,7 +314,9 @@
return nullptr;
}
- return adoptRef(*new FetchRequest(context, m_body.clone(), FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
+ auto clone = adoptRef(*new FetchRequest(context, Nullopt, FetchHeaders::create(m_headers.get()), FetchRequest::InternalRequest(m_internalRequest)));
+ clone->cloneBody(*this);
+ return WTFMove(clone);
}
const char* FetchRequest::activeDOMObjectName() const
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h 2016-10-03 17:57:27 UTC (rev 206737)
@@ -32,7 +32,6 @@
#if ENABLE(FETCH_API)
#include "FetchBodyOwner.h"
-#include "FetchHeaders.h"
#include "FetchOptions.h"
#include "ResourceRequest.h"
@@ -45,7 +44,7 @@
class FetchRequest final : public FetchBodyOwner {
public:
- static Ref<FetchRequest> create(ScriptExecutionContext& context) { return adoptRef(*new FetchRequest(context, { }, FetchHeaders::create(FetchHeaders::Guard::Request), { })); }
+ static Ref<FetchRequest> create(ScriptExecutionContext& context) { return adoptRef(*new FetchRequest(context, Nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { })); }
FetchHeaders* initializeWith(FetchRequest&, const Dictionary&, ExceptionCode&);
FetchHeaders* initializeWith(const String&, const Dictionary&, ExceptionCode&);
@@ -95,7 +94,7 @@
const String& internalRequestReferrer() const { return m_internalRequest.referrer; }
private:
- FetchRequest(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, InternalRequest&&);
+ FetchRequest(ScriptExecutionContext&, Optional<FetchBody>&&, Ref<FetchHeaders>&&, InternalRequest&&);
void initializeOptions(const Dictionary&, ExceptionCode&);
@@ -103,14 +102,12 @@
const char* activeDOMObjectName() const final;
bool canSuspendForDocumentSuspension() const final;
- Ref<FetchHeaders> m_headers;
InternalRequest m_internalRequest;
mutable String m_requestURL;
};
-inline FetchRequest::FetchRequest(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
- : FetchBodyOwner(context, WTFMove(body))
- , m_headers(WTFMove(headers))
+inline FetchRequest::FetchRequest(ScriptExecutionContext& context, Optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, InternalRequest&& internalRequest)
+ : FetchBodyOwner(context, WTFMove(body), WTFMove(headers))
, m_internalRequest(WTFMove(internalRequest))
{
}
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-10-03 17:57:27 UTC (rev 206737)
@@ -83,14 +83,13 @@
void FetchResponse::initializeWith(JSC::ExecState& execState, JSC::JSValue body)
{
ASSERT(scriptExecutionContext());
- m_body = FetchBody::extract(*scriptExecutionContext(), execState, body);
- m_body.updateContentType(m_headers);
+ extractBody(*scriptExecutionContext(), execState, body);
+ updateContentType();
}
-FetchResponse::FetchResponse(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
- : FetchBodyOwner(context, WTFMove(body))
+FetchResponse::FetchResponse(ScriptExecutionContext& context, Optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
+ : FetchBodyOwner(context, WTFMove(body), WTFMove(headers))
, m_response(WTFMove(response))
- , m_headers(WTFMove(headers))
{
}
@@ -98,12 +97,15 @@
{
ASSERT(scriptExecutionContext());
ASSERT(!isDisturbedOrLocked());
- return adoptRef(*new FetchResponse(*scriptExecutionContext(), m_body.clone(), FetchHeaders::create(headers()), ResourceResponse(m_response)));
+
+ auto clone = adoptRef(*new FetchResponse(*scriptExecutionContext(), Nullopt, FetchHeaders::create(headers()), ResourceResponse(m_response)));
+ clone->cloneBody(*this);
+ return clone;
}
void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, FetchPromise&& promise)
{
- auto response = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
+ auto response = adoptRef(*new FetchResponse(context, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
// Setting pending activity until BodyLoader didFail or didSucceed callback is called.
response->setPendingActivity(response.ptr());
@@ -123,10 +125,10 @@
void FetchResponse::BodyLoader::didSucceed()
{
ASSERT(m_response.hasPendingActivity());
- m_response.m_body.loadingSucceeded();
+ m_response.m_body->loadingSucceeded();
#if ENABLE(READABLE_STREAM_API)
- if (m_response.m_readableStreamSource && m_response.body().isEmpty()) {
+ if (m_response.m_readableStreamSource && !m_response.body().consumer().hasData()) {
// We only close the stream if FetchBody already enqueued all data.
// Otherwise, FetchBody will close the stream after enqueuing the data.
m_response.m_readableStreamSource->close();
@@ -174,7 +176,6 @@
m_response.m_response = resourceResponse;
m_response.m_headers->filterAndFill(resourceResponse.httpHeaderFields(), FetchHeaders::Guard::Response);
- m_response.m_body.setContentType(m_response.m_headers->fastGet(HTTPHeaderName::ContentType));
std::exchange(m_promise, Nullopt)->resolve(m_response);
}
@@ -194,7 +195,7 @@
bool FetchResponse::BodyLoader::start(ScriptExecutionContext& context, const FetchRequest& request)
{
- m_loader = std::make_unique<FetchLoader>(*this, &m_response.m_body.consumer());
+ m_loader = std::make_unique<FetchLoader>(*this, &m_response.m_body->consumer());
m_loader->start(context, request);
return m_loader->isStarted();
}
@@ -278,7 +279,7 @@
ASSERT(!m_readableStreamSource);
ASSERT(!m_isDisturbed);
- if (body().isEmpty() && !isLoading())
+ if (isBodyNull())
return nullptr;
m_readableStreamSource = adoptRef(*new FetchResponseSource(*this));
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (206736 => 206737)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-10-03 17:44:29 UTC (rev 206736)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h 2016-10-03 17:57:27 UTC (rev 206737)
@@ -31,7 +31,6 @@
#if ENABLE(FETCH_API)
#include "FetchBodyOwner.h"
-#include "FetchHeaders.h"
#include "ResourceResponse.h"
#include <runtime/TypedArrays.h>
@@ -53,7 +52,7 @@
public:
using Type = ResourceResponse::Type;
- static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
+ static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, Nullopt, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
static Ref<FetchResponse> error(ScriptExecutionContext&);
static RefPtr<FetchResponse> redirect(ScriptExecutionContext&, const String&, int, ExceptionCode&);
@@ -88,7 +87,7 @@
bool isLoading() const { return !!m_bodyLoader; }
private:
- FetchResponse(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+ FetchResponse(ScriptExecutionContext&, Optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
static void startFetching(ScriptExecutionContext&, const FetchRequest&, FetchPromise&&);
@@ -121,7 +120,6 @@
};
ResourceResponse m_response;
- Ref<FetchHeaders> m_headers;
Optional<BodyLoader> m_bodyLoader;
mutable String m_responseURL;