Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(924)

Unified Diff: third_party/WebKit/Source/modules/fetch/RequestInit.cpp

Issue 2679563002: [WIP] Expose Request.body property
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/fetch/RequestInit.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/RequestInit.cpp b/third_party/WebKit/Source/modules/fetch/RequestInit.cpp
index 54a76a215bdb1497bd74102830eef4e701a0dc90..6ec59d189a7b689bcc49c232dc3368dd88ba4ec8 100644
--- a/third_party/WebKit/Source/modules/fetch/RequestInit.cpp
+++ b/third_party/WebKit/Source/modules/fetch/RequestInit.cpp
@@ -5,6 +5,7 @@
#include "modules/fetch/RequestInit.h"
#include "bindings/core/v8/Dictionary.h"
+#include "bindings/core/v8/ScriptState.h"
#include "bindings/core/v8/V8ArrayBuffer.h"
#include "bindings/core/v8/V8ArrayBufferView.h"
#include "bindings/core/v8/V8Binding.h"
@@ -15,7 +16,9 @@
#include "core/dom/URLSearchParams.h"
#include "core/fileapi/Blob.h"
#include "core/html/FormData.h"
+#include "core/streams/ReadableStreamOperations.h"
#include "modules/fetch/BlobBytesConsumer.h"
+#include "modules/fetch/BodyStreamBuffer.h"
#include "modules/fetch/FormDataBytesConsumer.h"
#include "modules/fetch/Headers.h"
#include "platform/RuntimeEnabledFeatures.h"
@@ -25,7 +28,7 @@
namespace blink {
-RequestInit::RequestInit(ExecutionContext* context,
+RequestInit::RequestInit(ScriptState* scriptState,
const Dictionary& options,
ExceptionState& exceptionState)
: areAnyMembersSet(false) {
@@ -98,7 +101,7 @@ RequestInit::RequestInit(ExecutionContext* context,
}
}
- v8::Isolate* isolate = toIsolate(context);
+ v8::Isolate* isolate = scriptState->isolate();
if (isCredentialSet) {
if (V8PasswordCredential::hasInstance(v8Credential, isolate)) {
// TODO(mkwst): According to the spec, we'd serialize this once we touch
@@ -123,16 +126,20 @@ RequestInit::RequestInit(ExecutionContext* context,
return;
if (v8Body->IsArrayBuffer()) {
- body = new FormDataBytesConsumer(
- V8ArrayBuffer::toImpl(v8Body.As<v8::Object>()));
+ body = new BodyStreamBuffer(
+ scriptState, new FormDataBytesConsumer(
+ V8ArrayBuffer::toImpl(v8Body.As<v8::Object>())));
} else if (v8Body->IsArrayBufferView()) {
- body = new FormDataBytesConsumer(
- V8ArrayBufferView::toImpl(v8Body.As<v8::Object>()));
+ body = new BodyStreamBuffer(
+ scriptState, new FormDataBytesConsumer(
+ V8ArrayBufferView::toImpl(v8Body.As<v8::Object>())));
} else if (V8Blob::hasInstance(v8Body, isolate)) {
RefPtr<BlobDataHandle> blobDataHandle =
V8Blob::toImpl(v8Body.As<v8::Object>())->blobDataHandle();
contentType = blobDataHandle->type();
- body = new BlobBytesConsumer(context, blobDataHandle.release());
+ body = new BodyStreamBuffer(
+ scriptState, new BlobBytesConsumer(scriptState->getExecutionContext(),
+ blobDataHandle.release()));
} else if (V8FormData::hasInstance(v8Body, isolate)) {
RefPtr<EncodedFormData> formData =
V8FormData::toImpl(v8Body.As<v8::Object>())->encodeMultiPartFormData();
@@ -140,17 +147,28 @@ RequestInit::RequestInit(ExecutionContext* context,
// FormDataEncoder::generateUniqueBoundaryString.
contentType = AtomicString("multipart/form-data; boundary=") +
formData->boundary().data();
- body = new FormDataBytesConsumer(context, formData.release());
+ body = new BodyStreamBuffer(
+ scriptState,
+ new FormDataBytesConsumer(scriptState->getExecutionContext(),
+ formData.release()));
} else if (V8URLSearchParams::hasInstance(v8Body, isolate)) {
RefPtr<EncodedFormData> formData =
V8URLSearchParams::toImpl(v8Body.As<v8::Object>())->toEncodedFormData();
contentType =
AtomicString("application/x-www-form-urlencoded;charset=UTF-8");
- body = new FormDataBytesConsumer(context, formData.release());
+ body = new BodyStreamBuffer(
+ scriptState,
+ new FormDataBytesConsumer(scriptState->getExecutionContext(),
+ formData.release()));
} else if (v8Body->IsString()) {
contentType = "text/plain;charset=UTF-8";
- body =
- new FormDataBytesConsumer(toUSVString(isolate, v8Body, exceptionState));
+ body = new BodyStreamBuffer(
+ scriptState, new FormDataBytesConsumer(
+ toUSVString(isolate, v8Body, exceptionState)));
+ } else {
+ ScriptValue value(scriptState, v8Body);
+ if (ReadableStreamOperations::isReadableStream(scriptState, value))
+ body = new BodyStreamBuffer(scriptState, value);
}
}
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/RequestInit.h ('k') | third_party/WebKit/Source/platform/RuntimeEnabledFeatures.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698