diff options
Diffstat (limited to 'dom/fetch/Request.cpp')
-rw-r--r-- | dom/fetch/Request.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index 6a7885b1a..ba268d331 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -37,15 +37,18 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Request) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END -Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest) +Request::Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal) : FetchBody<Request>() , mOwner(aOwner) , mRequest(aRequest) + , mSignal(aSignal) { MOZ_ASSERT(aRequest->Headers()->Guard() == HeadersGuardEnum::Immutable || aRequest->Headers()->Guard() == HeadersGuardEnum::Request || aRequest->Headers()->Guard() == HeadersGuardEnum::Request_no_cors); SetMimeType(); + + // aSignal can be null. } Request::~Request() @@ -286,6 +289,8 @@ Request::Constructor(const GlobalObject& aGlobal, RefPtr<InternalRequest> request; nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports()); + + RefPtr<AbortSignal> signal; if (aInput.IsRequest()) { RefPtr<Request> inputReq = &aInput.GetAsRequest(); @@ -300,6 +305,7 @@ Request::Constructor(const GlobalObject& aGlobal, } request = inputReq->GetInternalRequest(); + signal = inputReq->GetOrCreateSignal(); } else { // aInput is USVString. // We need to get url before we create a InternalRequest. @@ -418,6 +424,10 @@ Request::Constructor(const GlobalObject& aGlobal, request->SetReferrerPolicy(aInit.mReferrerPolicy.Value()); } + if (aInit.mSignal.WasPassed()) { + signal = &aInit.mSignal.Value(); + } + if (NS_IsMainThread()) { nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(global); if (window) { @@ -579,7 +589,7 @@ Request::Constructor(const GlobalObject& aGlobal, } } - RefPtr<Request> domRequest = new Request(global, request); + RefPtr<Request> domRequest = new Request(global, request, signal); domRequest->SetMimeType(); if (aInput.IsRequest()) { @@ -595,7 +605,7 @@ Request::Constructor(const GlobalObject& aGlobal, } already_AddRefed<Request> -Request::Clone(ErrorResult& aRv) const +Request::Clone(ErrorResult& aRv) { if (BodyUsed()) { aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>(); @@ -608,7 +618,7 @@ Request::Clone(ErrorResult& aRv) const return nullptr; } - RefPtr<Request> request = new Request(mOwner, ir); + RefPtr<Request> request = new Request(mOwner, ir, GetOrCreateSignal()); return request.forget(); } @@ -622,5 +632,21 @@ Request::Headers_() return mHeaders; } +AbortSignal* +Request::GetOrCreateSignal() +{ + if (!mSignal) { + mSignal = new AbortSignal(false); + } + + return mSignal; +} + +AbortSignal* +Request::GetSignal() const +{ + return mSignal; +} + } // namespace dom } // namespace mozilla |