mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1557121 - Implement Blob.text()/Blob.arrayBuffer()/Blob.stream() - part 3 - Rename FetchBodyConsumer to BodyConsumer, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D33828 --HG-- rename : dom/fetch/FetchConsumer.cpp => dom/base/BodyConsumer.cpp rename : dom/fetch/FetchConsumer.h => dom/base/BodyConsumer.h extra : moz-landing-system : lando
This commit is contained in:
parent
a96bc57140
commit
30d3748577
@ -4,14 +4,16 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Fetch.h"
|
||||
#include "FetchConsumer.h"
|
||||
#include "BodyConsumer.h"
|
||||
|
||||
#include "mozilla/dom/BlobBinding.h"
|
||||
#include "mozilla/dom/BlobURLProtocolHandler.h"
|
||||
#include "mozilla/dom/BodyUtil.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/FileBinding.h"
|
||||
#include "mozilla/dom/FileCreatorHelper.h"
|
||||
#include "mozilla/dom/MutableBlobStreamListener.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/WorkerCommon.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
@ -19,8 +21,8 @@
|
||||
#include "mozilla/dom/WorkerRunnable.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "nsIInputStreamPump.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
||||
// Undefine the macro of CreateFile to avoid FileCreatorHelper#CreateFile being
|
||||
@ -36,20 +38,20 @@ namespace {
|
||||
|
||||
class BeginConsumeBodyRunnable final : public Runnable {
|
||||
public:
|
||||
BeginConsumeBodyRunnable(FetchBodyConsumer* aConsumer,
|
||||
BeginConsumeBodyRunnable(BodyConsumer* aConsumer,
|
||||
ThreadSafeWorkerRef* aWorkerRef)
|
||||
: Runnable("BeginConsumeBodyRunnable"),
|
||||
mFetchBodyConsumer(aConsumer),
|
||||
mBodyConsumer(aConsumer),
|
||||
mWorkerRef(aWorkerRef) {}
|
||||
|
||||
NS_IMETHOD
|
||||
Run() override {
|
||||
mFetchBodyConsumer->BeginConsumeBodyMainThread(mWorkerRef);
|
||||
mBodyConsumer->BeginConsumeBodyMainThread(mWorkerRef);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||
};
|
||||
|
||||
@ -57,17 +59,17 @@ class BeginConsumeBodyRunnable final : public Runnable {
|
||||
* Called on successfully reading the complete stream.
|
||||
*/
|
||||
class ContinueConsumeBodyRunnable final : public MainThreadWorkerRunnable {
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
nsresult mStatus;
|
||||
uint32_t mLength;
|
||||
uint8_t* mResult;
|
||||
|
||||
public:
|
||||
ContinueConsumeBodyRunnable(FetchBodyConsumer* aFetchBodyConsumer,
|
||||
ContinueConsumeBodyRunnable(BodyConsumer* aBodyConsumer,
|
||||
WorkerPrivate* aWorkerPrivate, nsresult aStatus,
|
||||
uint32_t aLength, uint8_t* aResult)
|
||||
: MainThreadWorkerRunnable(aWorkerPrivate),
|
||||
mFetchBodyConsumer(aFetchBodyConsumer),
|
||||
mBodyConsumer(aBodyConsumer),
|
||||
mStatus(aStatus),
|
||||
mLength(aLength),
|
||||
mResult(aResult) {
|
||||
@ -75,7 +77,7 @@ class ContinueConsumeBodyRunnable final : public MainThreadWorkerRunnable {
|
||||
}
|
||||
|
||||
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override {
|
||||
mFetchBodyConsumer->ContinueConsumeBody(mStatus, mLength, mResult);
|
||||
mBodyConsumer->ContinueConsumeBody(mStatus, mLength, mResult);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -84,19 +86,19 @@ class ContinueConsumeBodyRunnable final : public MainThreadWorkerRunnable {
|
||||
// thread when already shutting down.
|
||||
class AbortConsumeBodyControlRunnable final
|
||||
: public MainThreadWorkerControlRunnable {
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
|
||||
public:
|
||||
AbortConsumeBodyControlRunnable(FetchBodyConsumer* aFetchBodyConsumer,
|
||||
AbortConsumeBodyControlRunnable(BodyConsumer* aBodyConsumer,
|
||||
WorkerPrivate* aWorkerPrivate)
|
||||
: MainThreadWorkerControlRunnable(aWorkerPrivate),
|
||||
mFetchBodyConsumer(aFetchBodyConsumer) {
|
||||
mBodyConsumer(aBodyConsumer) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override {
|
||||
mFetchBodyConsumer->ContinueConsumeBody(NS_BINDING_ABORTED, 0, nullptr,
|
||||
true /* shutting down */);
|
||||
mBodyConsumer->ContinueConsumeBody(NS_BINDING_ABORTED, 0, nullptr,
|
||||
true /* shutting down */);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -107,7 +109,7 @@ class AbortConsumeBodyControlRunnable final
|
||||
*/
|
||||
class MOZ_STACK_CLASS AutoFailConsumeBody final {
|
||||
public:
|
||||
AutoFailConsumeBody(FetchBodyConsumer* aBodyConsumer,
|
||||
AutoFailConsumeBody(BodyConsumer* aBodyConsumer,
|
||||
ThreadSafeWorkerRef* aWorkerRef)
|
||||
: mBodyConsumer(aBodyConsumer), mWorkerRef(aWorkerRef) {}
|
||||
|
||||
@ -136,7 +138,7 @@ class MOZ_STACK_CLASS AutoFailConsumeBody final {
|
||||
void DontFail() { mBodyConsumer = nullptr; }
|
||||
|
||||
private:
|
||||
RefPtr<FetchBodyConsumer> mBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||
};
|
||||
|
||||
@ -144,22 +146,22 @@ class MOZ_STACK_CLASS AutoFailConsumeBody final {
|
||||
* Called on successfully reading the complete stream for Blob.
|
||||
*/
|
||||
class ContinueConsumeBlobBodyRunnable final : public MainThreadWorkerRunnable {
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
RefPtr<BlobImpl> mBlobImpl;
|
||||
|
||||
public:
|
||||
ContinueConsumeBlobBodyRunnable(FetchBodyConsumer* aFetchBodyConsumer,
|
||||
ContinueConsumeBlobBodyRunnable(BodyConsumer* aBodyConsumer,
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
BlobImpl* aBlobImpl)
|
||||
: MainThreadWorkerRunnable(aWorkerPrivate),
|
||||
mFetchBodyConsumer(aFetchBodyConsumer),
|
||||
mBodyConsumer(aBodyConsumer),
|
||||
mBlobImpl(aBlobImpl) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mBlobImpl);
|
||||
}
|
||||
|
||||
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override {
|
||||
mFetchBodyConsumer->ContinueConsumeBlobBody(mBlobImpl);
|
||||
mBodyConsumer->ContinueConsumeBlobBody(mBlobImpl);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -168,19 +170,18 @@ class ContinueConsumeBlobBodyRunnable final : public MainThreadWorkerRunnable {
|
||||
// thread when already shutting down.
|
||||
class AbortConsumeBlobBodyControlRunnable final
|
||||
: public MainThreadWorkerControlRunnable {
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
|
||||
public:
|
||||
AbortConsumeBlobBodyControlRunnable(FetchBodyConsumer* aFetchBodyConsumer,
|
||||
AbortConsumeBlobBodyControlRunnable(BodyConsumer* aBodyConsumer,
|
||||
WorkerPrivate* aWorkerPrivate)
|
||||
: MainThreadWorkerControlRunnable(aWorkerPrivate),
|
||||
mFetchBodyConsumer(aFetchBodyConsumer) {
|
||||
mBodyConsumer(aBodyConsumer) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
}
|
||||
|
||||
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override {
|
||||
mFetchBodyConsumer->ContinueConsumeBlobBody(nullptr,
|
||||
true /* shutting down */);
|
||||
mBodyConsumer->ContinueConsumeBlobBody(nullptr, true /* shutting down */);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -190,9 +191,9 @@ class ConsumeBodyDoneObserver final : public nsIStreamLoaderObserver,
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
ConsumeBodyDoneObserver(FetchBodyConsumer* aFetchBodyConsumer,
|
||||
ConsumeBodyDoneObserver(BodyConsumer* aBodyConsumer,
|
||||
ThreadSafeWorkerRef* aWorkerRef)
|
||||
: mFetchBodyConsumer(aFetchBodyConsumer), mWorkerRef(aWorkerRef) {}
|
||||
: mBodyConsumer(aBodyConsumer), mWorkerRef(aWorkerRef) {}
|
||||
|
||||
NS_IMETHOD
|
||||
OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aCtxt,
|
||||
@ -202,25 +203,25 @@ class ConsumeBodyDoneObserver final : public nsIStreamLoaderObserver,
|
||||
|
||||
// The loading is completed. Let's nullify the pump before continuing the
|
||||
// consuming of the body.
|
||||
mFetchBodyConsumer->NullifyConsumeBodyPump();
|
||||
mBodyConsumer->NullifyConsumeBodyPump();
|
||||
|
||||
uint8_t* nonconstResult = const_cast<uint8_t*>(aResult);
|
||||
|
||||
// Main-thread.
|
||||
if (!mWorkerRef) {
|
||||
mFetchBodyConsumer->ContinueConsumeBody(aStatus, aResultLength,
|
||||
nonconstResult);
|
||||
// FetchBody is responsible for data.
|
||||
mBodyConsumer->ContinueConsumeBody(aStatus, aResultLength,
|
||||
nonconstResult);
|
||||
// The caller is responsible for data.
|
||||
return NS_SUCCESS_ADOPTED_DATA;
|
||||
}
|
||||
|
||||
// Web Worker.
|
||||
{
|
||||
RefPtr<ContinueConsumeBodyRunnable> r = new ContinueConsumeBodyRunnable(
|
||||
mFetchBodyConsumer, mWorkerRef->Private(), aStatus, aResultLength,
|
||||
mBodyConsumer, mWorkerRef->Private(), aStatus, aResultLength,
|
||||
nonconstResult);
|
||||
if (r->Dispatch()) {
|
||||
// FetchBody is responsible for data.
|
||||
// The caller is responsible for data.
|
||||
return NS_SUCCESS_ADOPTED_DATA;
|
||||
}
|
||||
}
|
||||
@ -229,7 +230,7 @@ class ConsumeBodyDoneObserver final : public nsIStreamLoaderObserver,
|
||||
// shutting down procedure.
|
||||
|
||||
RefPtr<AbortConsumeBodyControlRunnable> r =
|
||||
new AbortConsumeBodyControlRunnable(mFetchBodyConsumer,
|
||||
new AbortConsumeBodyControlRunnable(mBodyConsumer,
|
||||
mWorkerRef->Private());
|
||||
if (NS_WARN_IF(!r->Dispatch())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@ -249,15 +250,15 @@ class ConsumeBodyDoneObserver final : public nsIStreamLoaderObserver,
|
||||
|
||||
// The loading is completed. Let's nullify the pump before continuing the
|
||||
// consuming of the body.
|
||||
mFetchBodyConsumer->NullifyConsumeBodyPump();
|
||||
mBodyConsumer->NullifyConsumeBodyPump();
|
||||
|
||||
mFetchBodyConsumer->OnBlobResult(aBlob, mWorkerRef);
|
||||
mBodyConsumer->OnBlobResult(aBlob, mWorkerRef);
|
||||
}
|
||||
|
||||
private:
|
||||
~ConsumeBodyDoneObserver() = default;
|
||||
|
||||
RefPtr<FetchBodyConsumer> mFetchBodyConsumer;
|
||||
RefPtr<BodyConsumer> mBodyConsumer;
|
||||
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||
};
|
||||
|
||||
@ -265,10 +266,10 @@ NS_IMPL_ISUPPORTS(ConsumeBodyDoneObserver, nsIStreamLoaderObserver)
|
||||
|
||||
} // namespace
|
||||
|
||||
/* static */ already_AddRefed<Promise> FetchBodyConsumer::Create(
|
||||
/* static */ already_AddRefed<Promise> BodyConsumer::Create(
|
||||
nsIGlobalObject* aGlobal, nsIEventTarget* aMainThreadEventTarget,
|
||||
nsIInputStream* aBodyStream, AbortSignalImpl* aSignalImpl,
|
||||
FetchConsumeType aType, const nsACString& aBodyBlobURISpec,
|
||||
ConsumeType aType, const nsACString& aBodyBlobURISpec,
|
||||
const nsAString& aBodyLocalPath, const nsACString& aBodyMimeType,
|
||||
MutableBlobStorage::MutableBlobStorageType aBlobStorageType,
|
||||
ErrorResult& aRv) {
|
||||
@ -280,7 +281,7 @@ NS_IMPL_ISUPPORTS(ConsumeBodyDoneObserver, nsIStreamLoaderObserver)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<FetchBodyConsumer> consumer = new FetchBodyConsumer(
|
||||
RefPtr<BodyConsumer> consumer = new BodyConsumer(
|
||||
aMainThreadEventTarget, aGlobal, aBodyStream, promise, aType,
|
||||
aBodyBlobURISpec, aBodyLocalPath, aBodyMimeType, aBlobStorageType);
|
||||
|
||||
@ -291,7 +292,7 @@ NS_IMPL_ISUPPORTS(ConsumeBodyDoneObserver, nsIStreamLoaderObserver)
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
||||
RefPtr<StrongWorkerRef> strongWorkerRef = StrongWorkerRef::Create(
|
||||
workerPrivate, "FetchBodyConsumer",
|
||||
workerPrivate, "BodyConsumer",
|
||||
[consumer]() { consumer->ShutDownMainThreadConsuming(); });
|
||||
if (NS_WARN_IF(!strongWorkerRef)) {
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
@ -330,7 +331,7 @@ NS_IMPL_ISUPPORTS(ConsumeBodyDoneObserver, nsIStreamLoaderObserver)
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
void FetchBodyConsumer::ReleaseObject() {
|
||||
void BodyConsumer::ReleaseObject() {
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
@ -346,9 +347,9 @@ void FetchBodyConsumer::ReleaseObject() {
|
||||
Unfollow();
|
||||
}
|
||||
|
||||
FetchBodyConsumer::FetchBodyConsumer(
|
||||
BodyConsumer::BodyConsumer(
|
||||
nsIEventTarget* aMainThreadEventTarget, nsIGlobalObject* aGlobalObject,
|
||||
nsIInputStream* aBodyStream, Promise* aPromise, FetchConsumeType aType,
|
||||
nsIInputStream* aBodyStream, Promise* aPromise, ConsumeType aType,
|
||||
const nsACString& aBodyBlobURISpec, const nsAString& aBodyLocalPath,
|
||||
const nsACString& aBodyMimeType,
|
||||
MutableBlobStorage::MutableBlobStorageType aBlobStorageType)
|
||||
@ -369,9 +370,9 @@ FetchBodyConsumer::FetchBodyConsumer(
|
||||
MOZ_ASSERT(aPromise);
|
||||
}
|
||||
|
||||
FetchBodyConsumer::~FetchBodyConsumer() = default;
|
||||
BodyConsumer::~BodyConsumer() = default;
|
||||
|
||||
void FetchBodyConsumer::AssertIsOnTargetThread() const {
|
||||
void BodyConsumer::AssertIsOnTargetThread() const {
|
||||
MOZ_ASSERT(NS_GetCurrentThread() == mTargetThread);
|
||||
}
|
||||
|
||||
@ -381,7 +382,7 @@ class FileCreationHandler final : public PromiseNativeHandler {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
static void Create(Promise* aPromise, FetchBodyConsumer* aConsumer,
|
||||
static void Create(Promise* aPromise, BodyConsumer* aConsumer,
|
||||
ThreadSafeWorkerRef* aWorkerRef) {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(aPromise);
|
||||
@ -415,8 +416,7 @@ class FileCreationHandler final : public PromiseNativeHandler {
|
||||
}
|
||||
|
||||
private:
|
||||
FileCreationHandler(FetchBodyConsumer* aConsumer,
|
||||
ThreadSafeWorkerRef* aWorkerRef)
|
||||
FileCreationHandler(BodyConsumer* aConsumer, ThreadSafeWorkerRef* aWorkerRef)
|
||||
: mConsumer(aConsumer), mWorkerRef(aWorkerRef) {
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(aConsumer);
|
||||
@ -424,7 +424,7 @@ class FileCreationHandler final : public PromiseNativeHandler {
|
||||
|
||||
~FileCreationHandler() = default;
|
||||
|
||||
RefPtr<FetchBodyConsumer> mConsumer;
|
||||
RefPtr<BodyConsumer> mConsumer;
|
||||
RefPtr<ThreadSafeWorkerRef> mWorkerRef;
|
||||
};
|
||||
|
||||
@ -432,7 +432,7 @@ NS_IMPL_ISUPPORTS0(FileCreationHandler)
|
||||
|
||||
} // namespace
|
||||
|
||||
nsresult FetchBodyConsumer::GetBodyLocalFile(nsIFile** aFile) const {
|
||||
nsresult BodyConsumer::GetBodyLocalFile(nsIFile** aFile) const {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
if (!mBodyLocalPath.Length()) {
|
||||
@ -471,8 +471,7 @@ nsresult FetchBodyConsumer::GetBodyLocalFile(nsIFile** aFile) const {
|
||||
* and clean up on any failures, so there is no need for callers to do so,
|
||||
* reflected in a lack of error return code.
|
||||
*/
|
||||
void FetchBodyConsumer::BeginConsumeBodyMainThread(
|
||||
ThreadSafeWorkerRef* aWorkerRef) {
|
||||
void BodyConsumer::BeginConsumeBodyMainThread(ThreadSafeWorkerRef* aWorkerRef) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
AutoFailConsumeBody autoReject(this, aWorkerRef);
|
||||
@ -551,7 +550,7 @@ void FetchBodyConsumer::BeginConsumeBodyMainThread(
|
||||
}
|
||||
|
||||
// Now that everything succeeded, we can assign the pump to a pointer that
|
||||
// stays alive for the lifetime of the FetchConsumer.
|
||||
// stays alive for the lifetime of the BodyConsumer.
|
||||
mConsumeBodyPump = pump;
|
||||
|
||||
// It is ok for retargeting to fail and reads to happen on the main thread.
|
||||
@ -575,14 +574,13 @@ void FetchBodyConsumer::BeginConsumeBodyMainThread(
|
||||
* been wrapped by FileCreationHandler). The blob is sent to the target thread
|
||||
* and ContinueConsumeBody is called.
|
||||
*/
|
||||
void FetchBodyConsumer::OnBlobResult(Blob* aBlob,
|
||||
ThreadSafeWorkerRef* aWorkerRef) {
|
||||
void BodyConsumer::OnBlobResult(Blob* aBlob, ThreadSafeWorkerRef* aWorkerRef) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
DispatchContinueConsumeBlobBody(aBlob ? aBlob->Impl() : nullptr, aWorkerRef);
|
||||
}
|
||||
|
||||
void FetchBodyConsumer::DispatchContinueConsumeBlobBody(
|
||||
void BodyConsumer::DispatchContinueConsumeBlobBody(
|
||||
BlobImpl* aBlobImpl, ThreadSafeWorkerRef* aWorkerRef) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
@ -629,10 +627,8 @@ void FetchBodyConsumer::DispatchContinueConsumeBlobBody(
|
||||
* rejected based on whether the fetch succeeded, and the body can be
|
||||
* converted into the expected type of JS object.
|
||||
*/
|
||||
void FetchBodyConsumer::ContinueConsumeBody(nsresult aStatus,
|
||||
uint32_t aResultLength,
|
||||
uint8_t* aResult,
|
||||
bool aShuttingDown) {
|
||||
void BodyConsumer::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength,
|
||||
uint8_t* aResult, bool aShuttingDown) {
|
||||
AssertIsOnTargetThread();
|
||||
|
||||
// This makes sure that we free the data correctly.
|
||||
@ -646,7 +642,7 @@ void FetchBodyConsumer::ContinueConsumeBody(nsresult aStatus,
|
||||
MOZ_ASSERT(mConsumePromise);
|
||||
RefPtr<Promise> localPromise = mConsumePromise.forget();
|
||||
|
||||
RefPtr<FetchBodyConsumer> self = this;
|
||||
RefPtr<BodyConsumer> self = this;
|
||||
auto autoReleaseObject =
|
||||
mozilla::MakeScopeExit([self] { self->ReleaseObject(); });
|
||||
|
||||
@ -745,8 +741,8 @@ void FetchBodyConsumer::ContinueConsumeBody(nsresult aStatus,
|
||||
}
|
||||
}
|
||||
|
||||
void FetchBodyConsumer::ContinueConsumeBlobBody(BlobImpl* aBlobImpl,
|
||||
bool aShuttingDown) {
|
||||
void BodyConsumer::ContinueConsumeBlobBody(BlobImpl* aBlobImpl,
|
||||
bool aShuttingDown) {
|
||||
AssertIsOnTargetThread();
|
||||
MOZ_ASSERT(mConsumeType == CONSUME_BLOB);
|
||||
|
||||
@ -768,12 +764,12 @@ void FetchBodyConsumer::ContinueConsumeBlobBody(BlobImpl* aBlobImpl,
|
||||
ReleaseObject();
|
||||
}
|
||||
|
||||
void FetchBodyConsumer::ShutDownMainThreadConsuming() {
|
||||
void BodyConsumer::ShutDownMainThreadConsuming() {
|
||||
if (!NS_IsMainThread()) {
|
||||
RefPtr<FetchBodyConsumer> self = this;
|
||||
RefPtr<BodyConsumer> self = this;
|
||||
|
||||
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
||||
"FetchBodyConsumer::ShutDownMainThreadConsuming",
|
||||
"BodyConsumer::ShutDownMainThreadConsuming",
|
||||
[self]() { self->ShutDownMainThreadConsuming(); });
|
||||
|
||||
mMainThreadEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
|
||||
@ -790,9 +786,8 @@ void FetchBodyConsumer::ShutDownMainThreadConsuming() {
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP FetchBodyConsumer::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
NS_IMETHODIMP BodyConsumer::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
AssertIsOnMainThread();
|
||||
|
||||
MOZ_ASSERT((strcmp(aTopic, DOM_WINDOW_FROZEN_TOPIC) == 0) ||
|
||||
@ -806,13 +801,13 @@ NS_IMETHODIMP FetchBodyConsumer::Observe(nsISupports* aSubject,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void FetchBodyConsumer::Abort() {
|
||||
void BodyConsumer::Abort() {
|
||||
AssertIsOnTargetThread();
|
||||
ShutDownMainThreadConsuming();
|
||||
ContinueConsumeBody(NS_ERROR_DOM_ABORT_ERR, 0, nullptr);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(FetchBodyConsumer, nsIObserver, nsISupportsWeakReference)
|
||||
NS_IMPL_ISUPPORTS(BodyConsumer, nsIObserver, nsISupportsWeakReference)
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -4,12 +4,12 @@
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_FetchConsumer_h
|
||||
#define mozilla_dom_FetchConsumer_h
|
||||
#ifndef mozilla_dom_BodyConsumer_h
|
||||
#define mozilla_dom_BodyConsumer_h
|
||||
|
||||
#include "Fetch.h"
|
||||
#include "mozilla/dom/AbortSignal.h"
|
||||
#include "mozilla/dom/MutableBlobStorage.h"
|
||||
#include "nsIInputStreamPump.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
@ -21,20 +21,27 @@ namespace dom {
|
||||
class Promise;
|
||||
class ThreadSafeWorkerRef;
|
||||
|
||||
// FetchBody is not thread-safe but we need to move it around threads. In order
|
||||
// to keep it alive all the time, we use a ThreadSafeWorkerRef, if created on
|
||||
// workers.
|
||||
class FetchBodyConsumer final : public nsIObserver,
|
||||
public nsSupportsWeakReference,
|
||||
public AbortFollower {
|
||||
// In order to keep alive the object all the time, we use a ThreadSafeWorkerRef,
|
||||
// if created on workers.
|
||||
class BodyConsumer final : public nsIObserver,
|
||||
public nsSupportsWeakReference,
|
||||
public AbortFollower {
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
enum ConsumeType {
|
||||
CONSUME_ARRAYBUFFER,
|
||||
CONSUME_BLOB,
|
||||
CONSUME_FORMDATA,
|
||||
CONSUME_JSON,
|
||||
CONSUME_TEXT,
|
||||
};
|
||||
|
||||
static already_AddRefed<Promise> Create(
|
||||
nsIGlobalObject* aGlobal, nsIEventTarget* aMainThreadEventTarget,
|
||||
nsIInputStream* aBodyStream, AbortSignalImpl* aSignalImpl,
|
||||
FetchConsumeType aType, const nsACString& aBodyBlobURISpec,
|
||||
ConsumeType aType, const nsACString& aBodyBlobURISpec,
|
||||
const nsAString& aBodyLocalPath, const nsACString& aBodyMimeType,
|
||||
MutableBlobStorage::MutableBlobStorageType aBlobStorageType,
|
||||
ErrorResult& aRv);
|
||||
@ -64,14 +71,14 @@ class FetchBodyConsumer final : public nsIObserver,
|
||||
void Abort() override;
|
||||
|
||||
private:
|
||||
FetchBodyConsumer(
|
||||
nsIEventTarget* aMainThreadEventTarget, nsIGlobalObject* aGlobalObject,
|
||||
nsIInputStream* aBodyStream, Promise* aPromise, FetchConsumeType aType,
|
||||
const nsACString& aBodyBlobURISpec, const nsAString& aBodyLocalPath,
|
||||
const nsACString& aBodyMimeType,
|
||||
MutableBlobStorage::MutableBlobStorageType aBlobStorageType);
|
||||
BodyConsumer(nsIEventTarget* aMainThreadEventTarget,
|
||||
nsIGlobalObject* aGlobalObject, nsIInputStream* aBodyStream,
|
||||
Promise* aPromise, ConsumeType aType,
|
||||
const nsACString& aBodyBlobURISpec,
|
||||
const nsAString& aBodyLocalPath, const nsACString& aBodyMimeType,
|
||||
MutableBlobStorage::MutableBlobStorageType aBlobStorageType);
|
||||
|
||||
~FetchBodyConsumer();
|
||||
~BodyConsumer();
|
||||
|
||||
nsresult GetBodyLocalFile(nsIFile** aFile) const;
|
||||
|
||||
@ -95,7 +102,7 @@ class FetchBodyConsumer final : public nsIObserver,
|
||||
nsCOMPtr<nsIInputStreamPump> mConsumeBodyPump;
|
||||
|
||||
// Only ever set once, always on target thread.
|
||||
FetchConsumeType mConsumeType;
|
||||
ConsumeType mConsumeType;
|
||||
RefPtr<Promise> mConsumePromise;
|
||||
|
||||
// touched only on the target thread.
|
||||
@ -108,4 +115,4 @@ class FetchBodyConsumer final : public nsIObserver,
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FetchConsumer_h
|
||||
#endif // mozilla_dom_BodyConsumer_h
|
@ -228,7 +228,7 @@ using mozilla::dom::ShadowRoot;
|
||||
|
||||
static nsIContent* GetParentOrHostOrSlot(
|
||||
nsIContent* aContent, bool* aCrossedShadowBoundary = nullptr) {
|
||||
HTMLSlotElement* slot = aContent->GetAssignedSlot();
|
||||
mozilla::dom::HTMLSlotElement* slot = aContent->GetAssignedSlot();
|
||||
if (slot) {
|
||||
if (aCrossedShadowBoundary) {
|
||||
*aCrossedShadowBoundary = true;
|
||||
@ -378,7 +378,7 @@ static Directionality GetDirectionFromText(const char* aText,
|
||||
return eDir_NotSet;
|
||||
}
|
||||
|
||||
static Directionality GetDirectionFromText(const Text* aTextNode,
|
||||
static Directionality GetDirectionFromText(const mozilla::dom::Text* aTextNode,
|
||||
uint32_t* aFirstStrong = nullptr) {
|
||||
const nsTextFragment* frag = &aTextNode->TextFragment();
|
||||
if (frag->Is2b()) {
|
||||
@ -399,7 +399,8 @@ static nsTextNode* WalkDescendantsAndGetDirectionFromText(
|
||||
continue;
|
||||
}
|
||||
|
||||
HTMLSlotElement* slot = HTMLSlotElement::FromNode(child);
|
||||
mozilla::dom::HTMLSlotElement* slot =
|
||||
mozilla::dom::HTMLSlotElement::FromNode(child);
|
||||
if (slot) {
|
||||
const nsTArray<RefPtr<nsINode>>& assignedNodes = slot->AssignedNodes();
|
||||
for (uint32_t i = 0; i < assignedNodes.Length(); ++i) {
|
||||
@ -727,7 +728,8 @@ static void SetDirectionalityOnDescendantsInternal(nsINode* aNode,
|
||||
SetDirectionalityOnDescendantsInternal(shadow, aDir, aNotify);
|
||||
}
|
||||
|
||||
HTMLSlotElement* slot = HTMLSlotElement::FromNode(child);
|
||||
mozilla::dom::HTMLSlotElement* slot =
|
||||
mozilla::dom::HTMLSlotElement::FromNode(child);
|
||||
if (slot) {
|
||||
const nsTArray<RefPtr<nsINode>>& assignedNodes = slot->AssignedNodes();
|
||||
for (uint32_t i = 0; i < assignedNodes.Length(); ++i) {
|
||||
@ -819,7 +821,7 @@ void WalkAncestorsResetAutoDirection(Element* aElement, bool aNotify) {
|
||||
}
|
||||
}
|
||||
|
||||
void SlotStateChanged(HTMLSlotElement* aSlot) {
|
||||
void SlotStateChanged(mozilla::dom::HTMLSlotElement* aSlot) {
|
||||
if (!aSlot) {
|
||||
return;
|
||||
}
|
||||
@ -892,7 +894,8 @@ static void SetAncestorHasDirAutoOnDescendants(nsINode* aRoot) {
|
||||
if (!child->GetAssignedSlot()) {
|
||||
MaybeSetAncestorHasDirAutoOnShadowDOM(child);
|
||||
child->SetAncestorHasDirAuto();
|
||||
HTMLSlotElement* slot = HTMLSlotElement::FromNode(child);
|
||||
mozilla::dom::HTMLSlotElement* slot =
|
||||
mozilla::dom::HTMLSlotElement::FromNode(child);
|
||||
if (slot) {
|
||||
const nsTArray<RefPtr<nsINode>>& assignedNodes = slot->AssignedNodes();
|
||||
for (uint32_t i = 0; i < assignedNodes.Length(); ++i) {
|
||||
@ -945,7 +948,8 @@ void WalkDescendantsClearAncestorDirAuto(nsIContent* aContent) {
|
||||
continue;
|
||||
}
|
||||
|
||||
HTMLSlotElement* slot = HTMLSlotElement::FromNode(child);
|
||||
mozilla::dom::HTMLSlotElement* slot =
|
||||
mozilla::dom::HTMLSlotElement::FromNode(child);
|
||||
if (slot) {
|
||||
const nsTArray<RefPtr<nsINode>>& assignedNodes = slot->AssignedNodes();
|
||||
for (uint32_t i = 0; i < assignedNodes.Length(); ++i) {
|
||||
|
@ -7,6 +7,8 @@
|
||||
#ifndef dom_NodeUbiReporting_h
|
||||
#define dom_NodeUbiReporting_h
|
||||
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentInlines.h"
|
||||
#include "nsINode.h"
|
||||
#include "js/UbiNode.h"
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/dom/DOMRect.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIContentInlines.h"
|
||||
#include "nsSVGUtils.h"
|
||||
#include <limits>
|
||||
|
||||
|
@ -6,10 +6,12 @@
|
||||
|
||||
#include "TimeoutExecutor.h"
|
||||
|
||||
#include "mozilla/AbstractEventQueue.h"
|
||||
#include "mozilla/dom/TimeoutManager.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsString.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
extern mozilla::LazyLogModule gTimeoutLog;
|
||||
|
||||
|
@ -142,6 +142,7 @@ EXPORTS.mozilla.dom += [
|
||||
'Attr.h',
|
||||
'BarProps.h',
|
||||
'BindContext.h',
|
||||
'BodyConsumer.h',
|
||||
'BodyStream.h',
|
||||
'BodyUtil.h',
|
||||
'BorrowedAttrInfo.h',
|
||||
@ -261,6 +262,7 @@ UNIFIED_SOURCES += [
|
||||
'Attr.cpp',
|
||||
'AttrArray.cpp',
|
||||
'BarProps.cpp',
|
||||
'BodyConsumer.cpp',
|
||||
'BodyStream.cpp',
|
||||
'BodyUtil.cpp',
|
||||
'BorrowedAttrInfo.cpp',
|
||||
|
@ -84,26 +84,26 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsNodeInfoManager, Release)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsNodeInfoManager)
|
||||
if (tmp->mDocument) {
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(Document)->CanSkip(tmp->mDocument,
|
||||
aRemovingAllowed);
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
||||
->CanSkip(tmp->mDocument, aRemovingAllowed);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsNodeInfoManager)
|
||||
if (tmp->mDocument) {
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(Document)->CanSkipInCC(
|
||||
tmp->mDocument);
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
||||
->CanSkipInCC(tmp->mDocument);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsNodeInfoManager)
|
||||
if (tmp->mDocument) {
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(Document)->CanSkipThis(
|
||||
tmp->mDocument);
|
||||
return NS_CYCLE_COLLECTION_PARTICIPANT(mozilla::dom::Document)
|
||||
->CanSkipThis(tmp->mDocument);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
|
||||
|
||||
nsresult nsNodeInfoManager::Init(Document* aDocument) {
|
||||
nsresult nsNodeInfoManager::Init(mozilla::dom::Document* aDocument) {
|
||||
MOZ_ASSERT(!mPrincipal, "Being inited when we already have a principal?");
|
||||
|
||||
mPrincipal = NullPrincipal::CreateWithoutOriginAttributes();
|
||||
|
@ -5,7 +5,6 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "Fetch.h"
|
||||
#include "FetchConsumer.h"
|
||||
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
@ -22,14 +21,13 @@
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/BodyUtil.h"
|
||||
#include "mozilla/dom/BodyConsumer.h"
|
||||
#include "mozilla/dom/Exceptions.h"
|
||||
#include "mozilla/dom/DOMException.h"
|
||||
#include "mozilla/dom/FetchDriver.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/FormData.h"
|
||||
#include "mozilla/dom/Headers.h"
|
||||
#include "mozilla/dom/MutableBlobStreamListener.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseWorkerProxy.h"
|
||||
#include "mozilla/dom/RemoteWorkerChild.h"
|
||||
@ -1108,7 +1106,7 @@ template void FetchBody<Response>::SetBodyUsed(JSContext* aCx,
|
||||
|
||||
template <class Derived>
|
||||
already_AddRefed<Promise> FetchBody<Derived>::ConsumeBody(
|
||||
JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv) {
|
||||
JSContext* aCx, BodyConsumer::ConsumeType aType, ErrorResult& aRv) {
|
||||
aRv.MightThrowJSException();
|
||||
|
||||
RefPtr<AbortSignalImpl> signalImpl = DerivedClass()->GetSignalImpl();
|
||||
@ -1171,7 +1169,7 @@ already_AddRefed<Promise> FetchBody<Derived>::ConsumeBody(
|
||||
blobStorageType = MutableBlobStorage::eCouldBeInTemporaryFile;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = FetchBodyConsumer::Create(
|
||||
RefPtr<Promise> promise = BodyConsumer::Create(
|
||||
global, mMainThreadEventTarget, bodyStream, signalImpl, aType,
|
||||
BodyBlobURISpec(), BodyLocalPath(), MimeType(), blobStorageType, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
@ -1182,13 +1180,13 @@ already_AddRefed<Promise> FetchBody<Derived>::ConsumeBody(
|
||||
}
|
||||
|
||||
template already_AddRefed<Promise> FetchBody<Request>::ConsumeBody(
|
||||
JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||
JSContext* aCx, BodyConsumer::ConsumeType aType, ErrorResult& aRv);
|
||||
|
||||
template already_AddRefed<Promise> FetchBody<Response>::ConsumeBody(
|
||||
JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||
JSContext* aCx, BodyConsumer::ConsumeType aType, ErrorResult& aRv);
|
||||
|
||||
template already_AddRefed<Promise> FetchBody<EmptyBody>::ConsumeBody(
|
||||
JSContext* aCx, FetchConsumeType aType, ErrorResult& aRv);
|
||||
JSContext* aCx, BodyConsumer::ConsumeType aType, ErrorResult& aRv);
|
||||
|
||||
template <class Derived>
|
||||
void FetchBody<Derived>::SetMimeType() {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/AbortSignal.h"
|
||||
#include "mozilla/dom/BodyConsumer.h"
|
||||
#include "mozilla/dom/BodyStream.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/FetchStreamReader.h"
|
||||
@ -87,14 +88,6 @@ nsresult ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit,
|
||||
nsCString& aContentType,
|
||||
uint64_t& aContentLength);
|
||||
|
||||
enum FetchConsumeType {
|
||||
CONSUME_ARRAYBUFFER,
|
||||
CONSUME_BLOB,
|
||||
CONSUME_FORMDATA,
|
||||
CONSUME_JSON,
|
||||
CONSUME_TEXT,
|
||||
};
|
||||
|
||||
/*
|
||||
* FetchBody's body consumption uses nsIInputStreamPump to read from the
|
||||
* underlying stream to a block of memory, which is then adopted by
|
||||
@ -139,23 +132,23 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
|
||||
bool CheckBodyUsed() const;
|
||||
|
||||
already_AddRefed<Promise> ArrayBuffer(JSContext* aCx, ErrorResult& aRv) {
|
||||
return ConsumeBody(aCx, CONSUME_ARRAYBUFFER, aRv);
|
||||
return ConsumeBody(aCx, BodyConsumer::CONSUME_ARRAYBUFFER, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> Blob(JSContext* aCx, ErrorResult& aRv) {
|
||||
return ConsumeBody(aCx, CONSUME_BLOB, aRv);
|
||||
return ConsumeBody(aCx, BodyConsumer::CONSUME_BLOB, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> FormData(JSContext* aCx, ErrorResult& aRv) {
|
||||
return ConsumeBody(aCx, CONSUME_FORMDATA, aRv);
|
||||
return ConsumeBody(aCx, BodyConsumer::CONSUME_FORMDATA, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> Json(JSContext* aCx, ErrorResult& aRv) {
|
||||
return ConsumeBody(aCx, CONSUME_JSON, aRv);
|
||||
return ConsumeBody(aCx, BodyConsumer::CONSUME_JSON, aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<Promise> Text(JSContext* aCx, ErrorResult& aRv) {
|
||||
return ConsumeBody(aCx, CONSUME_TEXT, aRv);
|
||||
return ConsumeBody(aCx, BodyConsumer::CONSUME_TEXT, aRv);
|
||||
}
|
||||
|
||||
void GetBody(JSContext* aCx, JS::MutableHandle<JSObject*> aBodyOut,
|
||||
@ -218,7 +211,8 @@ class FetchBody : public BodyStreamHolder, public AbortFollower {
|
||||
// AbortFollower
|
||||
void Abort() override;
|
||||
|
||||
already_AddRefed<Promise> ConsumeBody(JSContext* aCx, FetchConsumeType aType,
|
||||
already_AddRefed<Promise> ConsumeBody(JSContext* aCx,
|
||||
BodyConsumer::ConsumeType aType,
|
||||
ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
|
@ -29,7 +29,6 @@ UNIFIED_SOURCES += [
|
||||
'ChannelInfo.cpp',
|
||||
'EmptyBody.cpp',
|
||||
'Fetch.cpp',
|
||||
'FetchConsumer.cpp',
|
||||
'FetchDriver.cpp',
|
||||
'FetchObserver.cpp',
|
||||
'FetchStreamReader.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user