tor-browser

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

WebTransportBidirectionalStream.cpp (2401B)


      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 #include "WebTransportBidirectionalStream.h"
      8 
      9 #include "mozilla/dom/Promise.h"
     10 
     11 namespace mozilla::dom {
     12 
     13 using namespace mozilla::ipc;
     14 
     15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(WebTransportBidirectionalStream, mGlobal,
     16                                      mReadable, mWritable)
     17 
     18 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebTransportBidirectionalStream)
     19 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebTransportBidirectionalStream)
     20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebTransportBidirectionalStream)
     21  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     22  NS_INTERFACE_MAP_ENTRY(nsISupports)
     23 NS_INTERFACE_MAP_END
     24 
     25 // WebIDL Boilerplate
     26 
     27 nsIGlobalObject* WebTransportBidirectionalStream::GetParentObject() const {
     28  return mGlobal;
     29 }
     30 
     31 JSObject* WebTransportBidirectionalStream::WrapObject(
     32    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     33  return WebTransportBidirectionalStream_Binding::Wrap(aCx, this, aGivenProto);
     34 }
     35 
     36 // static
     37 already_AddRefed<WebTransportBidirectionalStream>
     38 WebTransportBidirectionalStream::Create(
     39    WebTransport* aWebTransport, nsIGlobalObject* aGlobal, uint64_t aStreamId,
     40    DataPipeReceiver* receiver, DataPipeSender* aSender,
     41    Maybe<int64_t> aSendOrder, ErrorResult& aRv) {
     42  // https://w3c.github.io/webtransport/#pullbidirectionalstream (and
     43  // createBidirectionalStream)
     44 
     45  // Step 7.1: Let stream be the result of creating a
     46  // WebTransportBidirectionalStream with internalStream and transport
     47  RefPtr<WebTransportReceiveStream> readableStream =
     48      WebTransportReceiveStream::Create(aWebTransport, aGlobal, aStreamId,
     49                                        receiver, aRv);
     50  if (!readableStream) {
     51    return nullptr;
     52  }
     53  RefPtr<WebTransportSendStream> writableStream =
     54      WebTransportSendStream::Create(aWebTransport, aGlobal, aStreamId, aSender,
     55                                     aSendOrder, aRv);
     56  if (!writableStream) {
     57    return nullptr;
     58    ;
     59  }
     60 
     61  auto stream = MakeRefPtr<WebTransportBidirectionalStream>(
     62      aGlobal, readableStream, writableStream);
     63  return stream.forget();
     64 }
     65 
     66 // WebIDL Interface
     67 
     68 }  // namespace mozilla::dom