Issue #1442 - Part 12 - Label FetchBody. https://bugzilla.mozilla.org/show_bug.cgi?id=1363318 FetchSignal is not in our tree so this is a partial patch to get mOwner changes. Pre-requisite for Part 13.

This commit is contained in:
Brian Smith 2023-09-28 16:54:19 -05:00 • committed by roytam1
commit 346e8a87d7
6 changed files with 17 additions and 10 deletions

View file

@ -877,22 +877,27 @@ ExtractByteStreamFromBody(const fetch::ResponseBodyInit& aBodyInit,
template <class Derived> template <class Derived>
FetchBody<Derived>::FetchBody() FetchBody<Derived>::FetchBody(nsIGlobalObject* aOwner)
: mWorkerPrivate(nullptr) : mWorkerPrivate(nullptr)
, mOwner(aOwner)
, mReadableStreamBody(nullptr) , mReadableStreamBody(nullptr)
, mBodyUsed(false) , mBodyUsed(false)
{ {
MOZ_ASSERT(aOwner);
if (!NS_IsMainThread()) { if (!NS_IsMainThread()) {
mWorkerPrivate = GetCurrentThreadWorkerPrivate(); mWorkerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(mWorkerPrivate); MOZ_ASSERT(mWorkerPrivate);
} else {
mWorkerPrivate = nullptr;
} }
} }
template template
FetchBody<Request>::FetchBody(); FetchBody<Request>::FetchBody(nsIGlobalObject* aOwner);
template template
FetchBody<Response>::FetchBody(); FetchBody<Response>::FetchBody(nsIGlobalObject* aOwner);
template <class Derived> template <class Derived>
FetchBody<Derived>::~FetchBody() FetchBody<Derived>::~FetchBody()

View file

@ -20,6 +20,7 @@
#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/RequestBinding.h"
class nsIGlobalObject; class nsIGlobalObject;
class nsIEventTarget;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -208,7 +209,9 @@ public:
GetSignal() const = 0; GetSignal() const = 0;
protected: protected:
FetchBody(); nsCOMPtr<nsIGlobalObject> mOwner;
explicit FetchBody(nsIGlobalObject* aOwner);
// Always set whenever the FetchBody is created on the worker thread. // Always set whenever the FetchBody is created on the worker thread.
workers::WorkerPrivate* mWorkerPrivate; workers::WorkerPrivate* mWorkerPrivate;
@ -252,6 +255,9 @@ private:
// Only ever set once, always on target thread. // Only ever set once, always on target thread.
bool mBodyUsed; bool mBodyUsed;
nsCString mMimeType; nsCString mMimeType;
// The main-thread event target for runnable dispatching.
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
}; };
} // namespace dom } // namespace dom

View file

@ -54,8 +54,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal) Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal)
: FetchBody<Request>() : FetchBody<Request>(aOwner)
, mOwner(aOwner)
, mRequest(aRequest) , mRequest(aRequest)
, mSignal(aSignal) , mSignal(aSignal)
{ {

View file

@ -164,7 +164,6 @@ public:
private: private:
~Request(); ~Request();
nsCOMPtr<nsIGlobalObject> mOwner;
RefPtr<InternalRequest> mRequest; RefPtr<InternalRequest> mRequest;
// Lazily created. // Lazily created.

View file

@ -57,8 +57,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Response)
NS_INTERFACE_MAP_END NS_INTERFACE_MAP_END
Response::Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse, AbortSignal* aSignal) Response::Response(nsIGlobalObject* aGlobal, InternalResponse* aInternalResponse, AbortSignal* aSignal)
: FetchBody<Response>() : FetchBody<Response>(aGlobal)
, mOwner(aGlobal)
, mInternalResponse(aInternalResponse) , mInternalResponse(aInternalResponse)
, mSignal(aSignal) , mSignal(aSignal)
{ {

View file

@ -144,7 +144,6 @@ public:
private: private:
~Response(); ~Response();
nsCOMPtr<nsIGlobalObject> mOwner;
RefPtr<InternalResponse> mInternalResponse; RefPtr<InternalResponse> mInternalResponse;
// Lazily created // Lazily created