summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Smith <brian@dbsoft.org>2023-09-27 23:22:06 -0500
committerBrian Smith <brian@dbsoft.org>2023-09-27 23:22:06 -0500
commit03ec9c095b8adc0d1fc2c528112e5eb0f6dad6a3 (patch)
treec9de145426f43aa97a61803ef9a63799d23bd7f3
parent24edfc1652a6be18d053976b26a26ac331ab6661 (diff)
downloaduxp-03ec9c095b8adc0d1fc2c528112e5eb0f6dad6a3.tar.gz
Issue #1442 - Part 10b - Use nsIXHRSendable instead Blob/FormData/URLSearchParams.
https://bugzilla.mozilla.org/show_bug.cgi?id=1329298 Pre-requisite for Part 11.
-rw-r--r--dom/base/Navigator.cpp7
-rw-r--r--dom/fetch/BodyExtractor.cpp30
-rw-r--r--dom/fetch/BodyExtractor.h4
-rw-r--r--dom/fetch/Fetch.cpp15
-rw-r--r--dom/xhr/XMLHttpRequestMainThread.h12
5 files changed, 18 insertions, 50 deletions
diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp
index 93b3b71a50..7499b697d8 100644
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -40,6 +40,7 @@
#include "mozilla/dom/ServiceWorkerContainer.h"
#include "mozilla/dom/StorageManager.h"
#include "mozilla/dom/TCPSocket.h"
+#include "mozilla/dom/URLSearchParams.h"
#include "mozilla/dom/workers/RuntimeService.h"
#include "mozilla/Hal.h"
#include "nsISiteSpecificUserAgent.h"
@@ -865,12 +866,12 @@ Navigator::SendBeacon(const nsAString& aUrl,
}
if (aData.Value().IsBlob()) {
- BodyExtractor<Blob> body(&aData.Value().GetAsBlob());
+ BodyExtractor<nsIXHRSendable> body(&aData.Value().GetAsBlob());
return SendBeaconInternal(aUrl, &body, /* isBlob */ true, aRv);
}
if (aData.Value().IsFormData()) {
- BodyExtractor<FormData> body(&aData.Value().GetAsFormData());
+ BodyExtractor<nsIXHRSendable> body(&aData.Value().GetAsFormData());
return SendBeaconInternal(aUrl, &body, /* isBlob */ false, aRv);
}
@@ -880,7 +881,7 @@ Navigator::SendBeacon(const nsAString& aUrl,
}
if (aData.Value().IsURLSearchParams()) {
- BodyExtractor<URLSearchParams> body(&aData.Value().GetAsURLSearchParams());
+ BodyExtractor<nsIXHRSendable> body(&aData.Value().GetAsURLSearchParams());
return SendBeaconInternal(aUrl, &body, /* isBlob */ false, aRv);
}
diff --git a/dom/fetch/BodyExtractor.cpp b/dom/fetch/BodyExtractor.cpp
index 889526314e..89c9c20ddf 100644
--- a/dom/fetch/BodyExtractor.cpp
+++ b/dom/fetch/BodyExtractor.cpp
@@ -193,36 +193,6 @@ BodyExtractor<nsIInputStream>::GetAsStream(nsIInputStream** aResult,
}
template<> nsresult
-BodyExtractor<Blob>::GetAsStream(nsIInputStream** aResult,
- uint64_t* aContentLength,
- nsACString& aContentTypeWithCharset,
- nsACString& aCharset) const
-{
- return mBody->GetSendInfo(aResult, aContentLength, aContentTypeWithCharset,
- aCharset);
-}
-
-template<> nsresult
-BodyExtractor<FormData>::GetAsStream(nsIInputStream** aResult,
- uint64_t* aContentLength,
- nsACString& aContentTypeWithCharset,
- nsACString& aCharset) const
-{
- return mBody->GetSendInfo(aResult, aContentLength, aContentTypeWithCharset,
- aCharset);
-}
-
-template<> nsresult
-BodyExtractor<URLSearchParams>::GetAsStream(nsIInputStream** aResult,
- uint64_t* aContentLength,
- nsACString& aContentTypeWithCharset,
- nsACString& aCharset) const
-{
- return mBody->GetSendInfo(aResult, aContentLength, aContentTypeWithCharset,
- aCharset);
-}
-
-template<> nsresult
BodyExtractor<nsIXHRSendable>::GetAsStream(nsIInputStream** aResult,
uint64_t* aContentLength,
nsACString& aContentTypeWithCharset,
diff --git a/dom/fetch/BodyExtractor.h b/dom/fetch/BodyExtractor.h
index 7d4bfd068e..d6b79b0349 100644
--- a/dom/fetch/BodyExtractor.h
+++ b/dom/fetch/BodyExtractor.h
@@ -24,8 +24,8 @@ public:
};
// The implementation versions of this template are:
-// ArrayBuffer, ArrayBufferView, Blob, FormData, nsAString, nsIDocument,
-// nsIInputStream, nsIXHRSendable, URLSearchParams
+// ArrayBuffer, ArrayBufferView, nsIXHRSendable (Blob, FormData,
+// URLSearchParams), nsAString, nsIDocument, nsIInputStream
template<typename Type>
class BodyExtractor final : public BodyExtractorBase
{
diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp
index de54b6094e..a831843a96 100644
--- a/dom/fetch/Fetch.cpp
+++ b/dom/fetch/Fetch.cpp
@@ -746,13 +746,13 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
}
if (aBodyInit.IsBlob()) {
Blob& blob = aBodyInit.GetAsBlob();
- BodyExtractor<Blob> body(&blob);
+ BodyExtractor<nsIXHRSendable> body(&blob);
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
if (aBodyInit.IsFormData()) {
FormData& formData = aBodyInit.GetAsFormData();
- BodyExtractor<FormData> body(&formData);
+ BodyExtractor<nsIXHRSendable> body(&formData);
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
@@ -763,7 +763,7 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
}
if (aBodyInit.IsURLSearchParams()) {
URLSearchParams& usp = aBodyInit.GetAsURLSearchParams();
- BodyExtractor<URLSearchParams> body(&usp);
+ BodyExtractor<nsIXHRSendable> body(&usp);
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
@@ -795,14 +795,12 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
charset);
}
if (aBodyInit.IsBlob()) {
- Blob& blob = aBodyInit.GetAsBlob();
- BodyExtractor<Blob> body(&blob);
+ BodyExtractor<nsIXHRSendable> body(&aBodyInit.GetAsBlob());
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
if (aBodyInit.IsFormData()) {
- FormData& formData = aBodyInit.GetAsFormData();
- BodyExtractor<FormData> body(&formData);
+ BodyExtractor<nsIXHRSendable> body(&aBodyInit.GetAsFormData());
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
@@ -812,8 +810,7 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
charset);
}
if (aBodyInit.IsURLSearchParams()) {
- URLSearchParams& usp = aBodyInit.GetAsURLSearchParams();
- BodyExtractor<URLSearchParams> body(&usp);
+ BodyExtractor<nsIXHRSendable> body(&aBodyInit.GetAsURLSearchParams());
return body.GetAsStream(aStream, &aContentLength, aContentTypeWithCharset,
charset);
}
diff --git a/dom/xhr/XMLHttpRequestMainThread.h b/dom/xhr/XMLHttpRequestMainThread.h
index ed02fd1da4..f2145605ef 100644
--- a/dom/xhr/XMLHttpRequestMainThread.h
+++ b/dom/xhr/XMLHttpRequestMainThread.h
@@ -36,6 +36,9 @@
#include "mozilla/dom/MutableBlobStorage.h"
#include "mozilla/dom/BodyExtractor.h"
#include "mozilla/dom/TypedArray.h"
+#include "mozilla/dom/File.h"
+#include "mozilla/dom/FormData.h"
+#include "mozilla/dom/URLSearchParams.h"
#include "mozilla/dom/XMLHttpRequest.h"
#include "mozilla/dom/XMLHttpRequestBinding.h"
#include "mozilla/dom/XMLHttpRequestEventTarget.h"
@@ -55,11 +58,8 @@ class nsIJSID;
namespace mozilla {
namespace dom {
-class Blob;
class BlobSet;
class DOMString;
-class FormData;
-class URLSearchParams;
class XMLHttpRequestUpload;
struct OriginAttributesDictionary;
@@ -325,14 +325,14 @@ public:
virtual void
Send(JSContext* /*aCx*/, Blob& aBlob, ErrorResult& aRv) override
{
- BodyExtractor<Blob> body(&aBlob);
+ BodyExtractor<nsIXHRSendable> body(&aBlob);
aRv = SendInternal(&body);
}
virtual void Send(JSContext* /*aCx*/, URLSearchParams& aURLSearchParams,
ErrorResult& aRv) override
{
- BodyExtractor<URLSearchParams> body(&aURLSearchParams);
+ BodyExtractor<nsIXHRSendable> body(&aURLSearchParams);
aRv = SendInternal(&body);
}
@@ -357,7 +357,7 @@ public:
virtual void
Send(JSContext* /*aCx*/, FormData& aFormData, ErrorResult& aRv) override
{
- BodyExtractor<FormData> body(&aFormData);
+ BodyExtractor<nsIXHRSendable> body(&aFormData);
aRv = SendInternal(&body);
}