mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-05 23:38:38 +09:00
Issue #1442 - Part 10a - Unify body extraction in Fetch/Beacon/XHR. https://bugzilla.mozilla.org/show_bug.cgi?id=1329298 Pre-requisite for Part 11.
This commit is contained in:
parent
3979e4847c
commit
a4146b60a4
15 changed files with 439 additions and 447 deletions
|
|
@ -34,6 +34,7 @@
|
|||
#include "mozilla/MemoryReporting.h"
|
||||
#include "mozilla/NotNull.h"
|
||||
#include "mozilla/dom/MutableBlobStorage.h"
|
||||
#include "mozilla/dom/BodyExtractor.h"
|
||||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/dom/XMLHttpRequest.h"
|
||||
#include "mozilla/dom/XMLHttpRequestBinding.h"
|
||||
|
|
@ -288,34 +289,7 @@ public:
|
|||
private:
|
||||
virtual ~XMLHttpRequestMainThread();
|
||||
|
||||
class RequestBodyBase
|
||||
{
|
||||
public:
|
||||
virtual nsresult GetAsStream(nsIInputStream** aResult,
|
||||
uint64_t* aContentLength,
|
||||
nsACString& aContentType,
|
||||
nsACString& aCharset) const
|
||||
{
|
||||
NS_ASSERTION(false, "RequestBodyBase should not be used directly.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Type>
|
||||
class RequestBody final : public RequestBodyBase
|
||||
{
|
||||
Type* mBody;
|
||||
public:
|
||||
explicit RequestBody(Type* aBody) : mBody(aBody)
|
||||
{
|
||||
}
|
||||
nsresult GetAsStream(nsIInputStream** aResult,
|
||||
uint64_t* aContentLength,
|
||||
nsACString& aContentType,
|
||||
nsACString& aCharset) const override;
|
||||
};
|
||||
|
||||
nsresult SendInternal(const RequestBodyBase* aBody);
|
||||
nsresult SendInternal(const BodyExtractorBase* aBody);
|
||||
|
||||
bool IsCrossSiteCORSRequest() const;
|
||||
bool IsDeniedCrossSiteCORSRequest();
|
||||
|
|
@ -336,7 +310,7 @@ public:
|
|||
Send(JSContext* /*aCx*/, const ArrayBuffer& aArrayBuffer,
|
||||
ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<const ArrayBuffer> body(&aArrayBuffer);
|
||||
BodyExtractor<const ArrayBuffer> body(&aArrayBuffer);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
|
|
@ -344,28 +318,28 @@ public:
|
|||
Send(JSContext* /*aCx*/, const ArrayBufferView& aArrayBufferView,
|
||||
ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<const ArrayBufferView> body(&aArrayBufferView);
|
||||
BodyExtractor<const ArrayBufferView> body(&aArrayBufferView);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
virtual void
|
||||
Send(JSContext* /*aCx*/, Blob& aBlob, ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<Blob> body(&aBlob);
|
||||
BodyExtractor<Blob> body(&aBlob);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
virtual void Send(JSContext* /*aCx*/, URLSearchParams& aURLSearchParams,
|
||||
ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<URLSearchParams> body(&aURLSearchParams);
|
||||
BodyExtractor<URLSearchParams> body(&aURLSearchParams);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
virtual void
|
||||
Send(JSContext* /*aCx*/, nsIDocument& aDoc, ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<nsIDocument> body(&aDoc);
|
||||
BodyExtractor<nsIDocument> body(&aDoc);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
|
|
@ -375,7 +349,7 @@ public:
|
|||
if (DOMStringIsNull(aString)) {
|
||||
Send(aCx, aRv);
|
||||
} else {
|
||||
RequestBody<const nsAString> body(&aString);
|
||||
BodyExtractor<const nsAString> body(&aString);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
}
|
||||
|
|
@ -383,7 +357,7 @@ public:
|
|||
virtual void
|
||||
Send(JSContext* /*aCx*/, FormData& aFormData, ErrorResult& aRv) override
|
||||
{
|
||||
RequestBody<FormData> body(&aFormData);
|
||||
BodyExtractor<FormData> body(&aFormData);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +365,7 @@ public:
|
|||
Send(JSContext* aCx, nsIInputStream* aStream, ErrorResult& aRv) override
|
||||
{
|
||||
NS_ASSERTION(aStream, "Null should go to string version");
|
||||
RequestBody<nsIInputStream> body(aStream);
|
||||
BodyExtractor<nsIInputStream> body(aStream);
|
||||
aRv = SendInternal(&body);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue