1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "mozilla/ipc/PBackgroundSharedTypes.h"
10 #include "nsStringStream.h"
12 namespace mozilla::dom
{
14 NS_IMPL_ADDREF_INHERITED(EmptyBody
, FetchBody
<EmptyBody
>)
15 NS_IMPL_RELEASE_INHERITED(EmptyBody
, FetchBody
<EmptyBody
>)
17 NS_IMPL_CYCLE_COLLECTION_CLASS(EmptyBody
)
19 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(EmptyBody
, FetchBody
<EmptyBody
>)
20 AbortFollower::Unlink(static_cast<AbortFollower
*>(tmp
));
21 NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner
)
22 NS_IMPL_CYCLE_COLLECTION_UNLINK(mAbortSignalImpl
)
23 NS_IMPL_CYCLE_COLLECTION_UNLINK(mFetchStreamReader
)
24 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
26 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(EmptyBody
,
28 AbortFollower::Traverse(static_cast<AbortFollower
*>(tmp
), cb
);
29 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner
)
30 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAbortSignalImpl
)
31 NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFetchStreamReader
)
32 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
34 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(EmptyBody
, FetchBody
<EmptyBody
>)
35 NS_IMPL_CYCLE_COLLECTION_TRACE_END
37 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(EmptyBody
)
38 NS_INTERFACE_MAP_END_INHERITING(FetchBody
<EmptyBody
>)
40 EmptyBody::EmptyBody(nsIGlobalObject
* aGlobal
,
41 mozilla::ipc::PrincipalInfo
* aPrincipalInfo
,
42 AbortSignalImpl
* aAbortSignalImpl
,
43 const nsACString
& aMimeType
,
44 already_AddRefed
<nsIInputStream
> aBodyStream
)
45 : FetchBody
<EmptyBody
>(aGlobal
),
46 mAbortSignalImpl(aAbortSignalImpl
),
48 mBodyStream(std::move(aBodyStream
)) {
50 mPrincipalInfo
= MakeUnique
<mozilla::ipc::PrincipalInfo
>(*aPrincipalInfo
);
54 EmptyBody::~EmptyBody() = default;
57 already_AddRefed
<EmptyBody
> EmptyBody::Create(
58 nsIGlobalObject
* aGlobal
, mozilla::ipc::PrincipalInfo
* aPrincipalInfo
,
59 AbortSignalImpl
* aAbortSignalImpl
, const nsACString
& aMimeType
,
61 nsCOMPtr
<nsIInputStream
> bodyStream
;
62 aRv
= NS_NewCStringInputStream(getter_AddRefs(bodyStream
), ""_ns
);
63 if (NS_WARN_IF(aRv
.Failed())) {
67 RefPtr
<EmptyBody
> emptyBody
=
68 new EmptyBody(aGlobal
, aPrincipalInfo
, aAbortSignalImpl
, aMimeType
,
70 return emptyBody
.forget();
73 void EmptyBody::GetBody(nsIInputStream
** aStream
, int64_t* aBodyLength
) {
80 nsCOMPtr
<nsIInputStream
> bodyStream
= mBodyStream
;
81 bodyStream
.forget(aStream
);
84 } // namespace mozilla::dom