Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / dom / streams / ReadableStreamDefaultController.h
blobf94a692f15273de81d09af9d6f26da7273065d54
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_ReadableStreamDefaultController_h
8 #define mozilla_dom_ReadableStreamDefaultController_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/Attributes.h"
13 #include "mozilla/ErrorResult.h"
14 #include "mozilla/dom/BindingDeclarations.h"
15 #include "mozilla/dom/QueuingStrategyBinding.h"
16 #include "mozilla/dom/QueueWithSizes.h"
17 #include "mozilla/dom/ReadableStreamController.h"
18 #include "mozilla/dom/ReadRequest.h"
19 #include "mozilla/dom/UnderlyingSourceCallbackHelpers.h"
20 #include "nsCycleCollectionParticipant.h"
21 #include "nsIGlobalObject.h"
22 #include "nsISupports.h"
23 #include "nsWrapperCache.h"
24 #include "mozilla/dom/Nullable.h"
25 #include "nsTArray.h"
27 namespace mozilla::dom {
29 class ReadableStream;
30 class ReadableStreamDefaultReader;
31 struct UnderlyingSource;
32 class ReadableStreamGenericReader;
34 class ReadableStreamDefaultController final : public ReadableStreamController,
35 public nsWrapperCache {
36 public:
37 NS_DECL_ISUPPORTS_INHERITED
38 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(
39 ReadableStreamDefaultController, ReadableStreamController)
41 public:
42 explicit ReadableStreamDefaultController(nsIGlobalObject* aGlobal);
44 protected:
45 ~ReadableStreamDefaultController() override;
47 public:
48 bool IsDefault() override { return true; }
49 bool IsByte() override { return false; }
50 ReadableStreamDefaultController* AsDefault() override { return this; }
51 ReadableByteStreamController* AsByte() override { return nullptr; }
53 JSObject* WrapObject(JSContext* aCx,
54 JS::Handle<JSObject*> aGivenProto) override;
56 Nullable<double> GetDesiredSize();
58 MOZ_CAN_RUN_SCRIPT void Close(JSContext* aCx, ErrorResult& aRv);
60 MOZ_CAN_RUN_SCRIPT void Enqueue(JSContext* aCx, JS::Handle<JS::Value> aChunk,
61 ErrorResult& aRv);
63 void Error(JSContext* aCx, JS::Handle<JS::Value> aError, ErrorResult& aRv);
65 MOZ_CAN_RUN_SCRIPT already_AddRefed<Promise> CancelSteps(
66 JSContext* aCx, JS::Handle<JS::Value> aReason, ErrorResult& aRv) override;
67 MOZ_CAN_RUN_SCRIPT void PullSteps(JSContext* aCx, ReadRequest* aReadRequest,
68 ErrorResult& aRv) override;
70 void ReleaseSteps() override;
72 // Internal Slot Accessors
73 bool CloseRequested() const { return mCloseRequested; }
74 void SetCloseRequested(bool aCloseRequested) {
75 mCloseRequested = aCloseRequested;
78 bool PullAgain() const { return mPullAgain; }
79 void SetPullAgain(bool aPullAgain) { mPullAgain = aPullAgain; }
81 bool Pulling() const { return mPulling; }
82 void SetPulling(bool aPulling) { mPulling = aPulling; }
84 QueueWithSizes& Queue() { return mQueue; }
86 double QueueTotalSize() const { return mQueueTotalSize; }
87 void SetQueueTotalSize(double aQueueTotalSize) {
88 mQueueTotalSize = aQueueTotalSize;
91 bool Started() const { return mStarted; }
92 void SetStarted(bool aStarted) { mStarted = aStarted; }
94 double StrategyHWM() const { return mStrategyHWM; }
95 void SetStrategyHWM(double aStrategyHWM) { mStrategyHWM = aStrategyHWM; }
97 QueuingStrategySize* StrategySizeAlgorithm() const {
98 return mStrategySizeAlgorithm;
100 void setStrategySizeAlgorithm(QueuingStrategySize* aStrategySizeAlgorithm) {
101 mStrategySizeAlgorithm = aStrategySizeAlgorithm;
104 private:
105 // Internal Slots:
106 bool mCloseRequested = false;
107 bool mPullAgain = false;
108 bool mPulling = false;
109 QueueWithSizes mQueue = {};
110 double mQueueTotalSize = 0.0;
111 bool mStarted = false;
112 double mStrategyHWM = false;
113 RefPtr<QueuingStrategySize> mStrategySizeAlgorithm;
116 namespace streams_abstract {
118 MOZ_CAN_RUN_SCRIPT void SetUpReadableStreamDefaultController(
119 JSContext* aCx, ReadableStream* aStream,
120 ReadableStreamDefaultController* aController,
121 UnderlyingSourceAlgorithmsBase* aAlgorithms, double aHighWaterMark,
122 QueuingStrategySize* aSizeAlgorithm, ErrorResult& aRv);
124 MOZ_CAN_RUN_SCRIPT void
125 SetupReadableStreamDefaultControllerFromUnderlyingSource(
126 JSContext* aCx, ReadableStream* aStream,
127 JS::Handle<JSObject*> aUnderlyingSource,
128 UnderlyingSource& aUnderlyingSourceDict, double aHighWaterMark,
129 QueuingStrategySize* aSizeAlgorithm, ErrorResult& aRv);
131 MOZ_CAN_RUN_SCRIPT void ReadableStreamDefaultControllerEnqueue(
132 JSContext* aCx, ReadableStreamDefaultController* aController,
133 JS::Handle<JS::Value> aChunk, ErrorResult& aRv);
135 MOZ_CAN_RUN_SCRIPT void ReadableStreamDefaultControllerClose(
136 JSContext* aCx, ReadableStreamDefaultController* aController,
137 ErrorResult& aRv);
139 MOZ_CAN_RUN_SCRIPT void ReadableStreamDefaultReaderRead(
140 JSContext* aCx, ReadableStreamGenericReader* reader, ReadRequest* aRequest,
141 ErrorResult& aRv);
143 void ReadableStreamDefaultControllerError(
144 JSContext* aCx, ReadableStreamDefaultController* aController,
145 JS::Handle<JS::Value> aValue, ErrorResult& aRv);
147 Nullable<double> ReadableStreamDefaultControllerGetDesiredSize(
148 ReadableStreamDefaultController* aController);
150 enum class CloseOrEnqueue { Close, Enqueue };
152 bool ReadableStreamDefaultControllerCanCloseOrEnqueueAndThrow(
153 ReadableStreamDefaultController* aController,
154 CloseOrEnqueue aCloseOrEnqueue, ErrorResult& aRv);
156 bool ReadableStreamDefaultControllerShouldCallPull(
157 ReadableStreamDefaultController* aController);
159 } // namespace streams_abstract
161 } // namespace mozilla::dom
163 #endif // mozilla_dom_ReadableStreamDefaultController_h