tor-browser

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

WebTransportBidirectionalStream.h (2402B)


      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/. */
      6 
      7 #ifndef DOM_WEBTRANSPORT_API_WEBTRANSPORTBIDIRECTIONALSTREAM__H_
      8 #define DOM_WEBTRANSPORT_API_WEBTRANSPORTBIDIRECTIONALSTREAM__H_
      9 
     10 #include "mozilla/dom/Promise.h"
     11 #include "mozilla/dom/ReadableStream.h"
     12 #include "mozilla/dom/WebTransport.h"
     13 #include "mozilla/dom/WebTransportSendReceiveStreamBinding.h"
     14 #include "mozilla/dom/WritableStream.h"
     15 #include "mozilla/ipc/DataPipe.h"
     16 #include "nsCOMPtr.h"
     17 #include "nsISupports.h"
     18 #include "nsWrapperCache.h"
     19 
     20 // #include "mozilla/dom/WebTransportReceiveStream.h"
     21 // #include "mozilla/dom/WebTransportSendStream.h"
     22 
     23 namespace mozilla::dom {
     24 class WebTransportBidirectionalStream final : public nsISupports,
     25                                              public nsWrapperCache {
     26 public:
     27  explicit WebTransportBidirectionalStream(nsIGlobalObject* aGlobal,
     28                                           WebTransportReceiveStream* aReadable,
     29                                           WebTransportSendStream* aWritable)
     30      : mGlobal(aGlobal), mReadable(aReadable), mWritable(aWritable) {}
     31 
     32  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     33  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WebTransportBidirectionalStream)
     34 
     35  static already_AddRefed<WebTransportBidirectionalStream> Create(
     36      WebTransport* aWebTransport, nsIGlobalObject* aGlobal, uint64_t aStreamId,
     37      ::mozilla::ipc::DataPipeReceiver* receiver,
     38      ::mozilla::ipc::DataPipeSender* aSender, Maybe<int64_t> aSendOrder,
     39      ErrorResult& aRv);
     40 
     41  // WebIDL Boilerplate
     42  nsIGlobalObject* GetParentObject() const;
     43 
     44  JSObject* WrapObject(JSContext* aCx,
     45                       JS::Handle<JSObject*> aGivenProto) override;
     46 
     47  // WebIDL Interface
     48  already_AddRefed<WebTransportReceiveStream> Readable() const {
     49    return do_AddRef(mReadable);
     50  }
     51  already_AddRefed<WebTransportSendStream> Writable() const {
     52    return do_AddRef(mWritable);
     53  }
     54 
     55 private:
     56  ~WebTransportBidirectionalStream() = default;
     57 
     58  nsCOMPtr<nsIGlobalObject> mGlobal;
     59  RefPtr<WebTransportReceiveStream> mReadable;
     60  RefPtr<WebTransportSendStream> mWritable;
     61 };
     62 
     63 }  // namespace mozilla::dom
     64 
     65 #endif