summaryrefslogtreecommitdiff
path: root/dom/fetch/Fetch.h
diff options
context:
space:
mode:
Diffstat (limited to 'dom/fetch/Fetch.h')
-rw-r--r--dom/fetch/Fetch.h57
1 files changed, 51 insertions, 6 deletions
diff --git a/dom/fetch/Fetch.h b/dom/fetch/Fetch.h
index c605e45bc5..cac72ede81 100644
--- a/dom/fetch/Fetch.h
+++ b/dom/fetch/Fetch.h
@@ -25,9 +25,11 @@ namespace mozilla {
namespace dom {
class ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
+class BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString;
class BlobImpl;
class InternalRequest;
class OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams;
+struct ReadableStream;
class RequestOrUSVString;
namespace workers {
@@ -41,13 +43,20 @@ FetchRequest(nsIGlobalObject* aGlobal, const RequestOrUSVString& aInput,
nsresult
UpdateRequestReferrer(nsIGlobalObject* aGlobal, InternalRequest* aRequest);
+/* Deal with unwieldy long webIDL-generated type names */
+namespace fetch {
+ typedef ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams BodyInit;
+ typedef BlobOrArrayBufferViewOrArrayBufferOrFormDataOrURLSearchParamsOrReadableStreamOrUSVString ResponseBodyInit;
+ typedef OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams OwningBodyInit;
+};
+
/*
* Creates an nsIInputStream based on the fetch specifications 'extract a byte
* stream algorithm' - http://fetch.spec.whatwg.org/#concept-bodyinit-extract.
* Stores content type in out param aContentType.
*/
nsresult
-ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
+ExtractByteStreamFromBody(const fetch::OwningBodyInit& aBodyInit,
nsIInputStream** aStream,
nsCString& aContentType,
uint64_t& aContentLength);
@@ -56,7 +65,17 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
* Non-owning version.
*/
nsresult
-ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUSVStringOrURLSearchParams& aBodyInit,
+ExtractByteStreamFromBody(const fetch::BodyInit& aBodyInit,
+ nsIInputStream** aStream,
+ nsCString& aContentType,
+ uint64_t& aContentLength);
+
+/*
+ * Non-owning version. This method should go away when BodyInit will contain
+ * ReadableStream.
+ */
+nsresult
+ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit,
nsIInputStream** aStream,
nsCString& aContentType,
uint64_t& aContentLength);
@@ -72,6 +91,15 @@ enum FetchConsumeType
CONSUME_TEXT,
};
+class FetchStreamHolder
+{
+public:
+ NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
+ NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
+
+ virtual void NullifyStream() = 0;
+};
+
/*
* FetchBody's body consumption uses nsIInputStreamPump to read from the
* underlying stream to a block of memory, which is then adopted by
@@ -106,14 +134,11 @@ enum FetchConsumeType
* The pump is always released on the main thread.
*/
template <class Derived>
-class FetchBody
+class FetchBody : public FetchStreamHolder
{
public:
friend class FetchBodyConsumer<Derived>;
- NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
- NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
-
bool
BodyUsed() const;
@@ -152,6 +177,13 @@ public:
JS::MutableHandle<JSObject*> aBodyOut,
ErrorResult& aRv);
+ // If the body contains a ReadableStream body object, this method produces a
+ // tee() of it.
+ void
+ MaybeTeeReadableStreamBody(JSContext* aCx,
+ JS::MutableHandle<JSObject*> aBodyOut,
+ ErrorResult& aRv);
+
// Utility public methods accessed by various runnables.
void
@@ -166,6 +198,12 @@ public:
return mMimeType;
}
+ void
+ NullifyStream() override
+ {
+ mReadableStreamBody = nullptr;
+ }
+
virtual AbortSignal*
GetSignal() const = 0;
@@ -182,6 +220,10 @@ protected:
void
SetMimeType();
+
+ void
+ SetReadableStreamBody(JSObject* aBody);
+
private:
Derived*
DerivedClass() const
@@ -192,6 +234,9 @@ private:
already_AddRefed<Promise>
ConsumeBody(JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
+ void
+ LockStream(JSContext* aCx, JS::HandleObject aStream, ErrorResult& aRv);
+
bool
IsOnTargetThread()
{