tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ReadableStreamControllerBase.h (2377B)


      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/. */
      6 
      7 #ifndef mozilla_dom_ReadableStreamControllerBase_h
      8 #define mozilla_dom_ReadableStreamControllerBase_h
      9 
     10 #include "UnderlyingSourceCallbackHelpers.h"
     11 #include "mozilla/ErrorResult.h"
     12 #include "nsCycleCollectionParticipant.h"
     13 #include "nsIGlobalObject.h"
     14 #include "nsISupports.h"
     15 
     16 namespace mozilla::dom {
     17 struct ReadRequest;
     18 class ReadableStream;
     19 class ReadableStreamDefaultController;
     20 class ReadableByteStreamController;
     21 
     22 class ReadableStreamControllerBase : public nsISupports {
     23 public:
     24  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     25  NS_DECL_CYCLE_COLLECTION_CLASS(ReadableStreamControllerBase)
     26 
     27  ReadableStreamControllerBase(nsIGlobalObject* aGlobal);
     28 
     29  nsIGlobalObject* GetParentObject() const { return mGlobal; }
     30 
     31  virtual bool IsDefault() = 0;
     32  virtual bool IsByte() = 0;
     33  virtual ReadableStreamDefaultController* AsDefault() = 0;
     34  virtual ReadableByteStreamController* AsByte() = 0;
     35 
     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;
     43 
     44  // No JS implementable UnderlyingSource callback exists for this.
     45  virtual void ReleaseSteps() = 0;
     46 
     47  UnderlyingSourceAlgorithmsBase* GetAlgorithms() const { return mAlgorithms; }
     48  void SetAlgorithms(UnderlyingSourceAlgorithmsBase& aAlgorithms) {
     49    mAlgorithms = &aAlgorithms;
     50  }
     51  void ClearAlgorithms() {
     52    MOZ_ASSERT(mAlgorithms);
     53    mAlgorithms->ReleaseObjects();
     54    mAlgorithms = nullptr;
     55  }
     56 
     57  ReadableStream* Stream() const { return mStream; }
     58  void SetStream(ReadableStream* aStream);
     59 
     60 protected:
     61  nsCOMPtr<nsIGlobalObject> mGlobal;
     62 
     63  // The algorithms for the underlying source
     64  RefPtr<UnderlyingSourceAlgorithmsBase> mAlgorithms;
     65 
     66  RefPtr<ReadableStream> mStream;
     67 
     68  virtual ~ReadableStreamControllerBase() = default;
     69 };
     70 
     71 }  // namespace mozilla::dom
     72 
     73 #endif