Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / dom / streams / ReadableStreamController.h
blob766c93301766e8c4c1906fe454ed6fb2b47ae3e0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
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/. */
7 #ifndef mozilla_dom_ReadableStreamController_h
8 #define mozilla_dom_ReadableStreamController_h
10 #include "mozilla/ErrorResult.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsIGlobalObject.h"
13 #include "nsISupports.h"
14 #include "UnderlyingSourceCallbackHelpers.h"
16 namespace mozilla::dom {
17 struct ReadRequest;
18 class ReadableStream;
19 class ReadableStreamDefaultController;
20 class ReadableByteStreamController;
22 class ReadableStreamController : public nsISupports {
23 public:
24 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
25 NS_DECL_CYCLE_COLLECTION_CLASS(ReadableStreamController)
27 ReadableStreamController(nsIGlobalObject* aGlobal);
29 nsIGlobalObject* GetParentObject() const { return mGlobal; }
31 virtual bool IsDefault() = 0;
32 virtual bool IsByte() = 0;
33 virtual ReadableStreamDefaultController* AsDefault() = 0;
34 virtual ReadableByteStreamController* AsByte() = 0;
36 MOZ_CAN_RUN_SCRIPT
37 virtual already_AddRefed<Promise> CancelSteps(JSContext* aCx,
38 JS::Handle<JS::Value> aReason,
39 ErrorResult& aRv) = 0;
40 MOZ_CAN_RUN_SCRIPT
41 virtual void PullSteps(JSContext* aCx, ReadRequest* aReadRequest,
42 ErrorResult& aRv) = 0;
44 // No JS implementable UnderlyingSource callback exists for this.
45 virtual void ReleaseSteps() = 0;
47 UnderlyingSourceAlgorithmsBase* GetAlgorithms() const { return mAlgorithms; }
48 void SetAlgorithms(UnderlyingSourceAlgorithmsBase& aAlgorithms) {
49 mAlgorithms = &aAlgorithms;
51 void ClearAlgorithms() {
52 MOZ_ASSERT(mAlgorithms);
53 mAlgorithms->ReleaseObjects();
54 mAlgorithms = nullptr;
57 ReadableStream* Stream() const { return mStream; }
58 void SetStream(ReadableStream* aStream);
60 protected:
61 nsCOMPtr<nsIGlobalObject> mGlobal;
63 // The algorithms for the underlying source
64 RefPtr<UnderlyingSourceAlgorithmsBase> mAlgorithms;
66 RefPtr<ReadableStream> mStream;
68 virtual ~ReadableStreamController() = default;
71 } // namespace mozilla::dom
73 #endif