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 mozilla_dom_PresentationSessionTransport_h 8 #define mozilla_dom_PresentationSessionTransport_h 9 10 #include "mozilla/RefPtr.h" 11 #include "nsCOMPtr.h" 12 #include "nsIAsyncInputStream.h" 13 #include "nsIPresentationSessionTransport.h" 14 #include "nsIPresentationSessionTransportBuilder.h" 15 #include "nsIStreamListener.h" 16 #include "nsISupportsImpl.h" 17 #include "nsITransport.h" 18 19 class nsISocketTransport; 20 class nsIInputStreamPump; 21 class nsIScriptableInputStream; 22 class nsIMultiplexInputStream; 23 class nsIAsyncStreamCopier; 24 class nsIInputStream; 25 26 namespace mozilla { 27 namespace dom { 28 29 /* 30 * App-to-App transport channel for the presentation session. It's usually 31 * initialized with an |InitWithSocketTransport| call if at the presenting 32 * sender side; whereas it's initialized with an |InitWithChannelDescription| if 33 * at the presenting receiver side. The lifetime is managed in either 34 * |PresentationControllingInfo| (sender side) or |PresentationPresentingInfo| 35 * (receiver side) in PresentationSessionInfo.cpp. 36 */ 37 class PresentationTCPSessionTransport final 38 : public nsIPresentationSessionTransport, 39 public nsIPresentationTCPSessionTransportBuilder, 40 public nsITransportEventSink, 41 public nsIInputStreamCallback, 42 public nsIStreamListener { 43 public: 44 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 45 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PresentationTCPSessionTransport, 46 nsIPresentationSessionTransport) 47 48 NS_DECL_NSIPRESENTATIONSESSIONTRANSPORT 49 NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTBUILDER 50 NS_DECL_NSIPRESENTATIONTCPSESSIONTRANSPORTBUILDER 51 NS_DECL_NSITRANSPORTEVENTSINK 52 NS_DECL_NSIINPUTSTREAMCALLBACK 53 NS_DECL_NSIREQUESTOBSERVER 54 NS_DECL_NSISTREAMLISTENER 55 56 PresentationTCPSessionTransport(); 57 58 void NotifyCopyComplete(nsresult aStatus); 59 60 private: 61 ~PresentationTCPSessionTransport(); 62 63 nsresult CreateStream(); 64 65 nsresult CreateInputStreamPump(); 66 67 nsresult EnsureCopying(); 68 69 enum class ReadyState { CONNECTING, OPEN, CLOSING, CLOSED }; 70 71 void SetReadyState(ReadyState aReadyState); 72 IsReadyToNotifyData()73 bool IsReadyToNotifyData() { 74 return mDataNotificationEnabled && mReadyState == ReadyState::OPEN; 75 } 76 77 ReadyState mReadyState; 78 bool mAsyncCopierActive; 79 nsresult mCloseStatus; 80 bool mDataNotificationEnabled; 81 82 uint8_t mRole = 0; 83 84 // Raw socket streams 85 nsCOMPtr<nsISocketTransport> mTransport; 86 nsCOMPtr<nsIInputStream> mSocketInputStream; 87 nsCOMPtr<nsIOutputStream> mSocketOutputStream; 88 89 // Input stream machinery 90 nsCOMPtr<nsIInputStreamPump> mInputStreamPump; 91 nsCOMPtr<nsIScriptableInputStream> mInputStreamScriptable; 92 93 nsCOMPtr<nsIPresentationSessionTransportCallback> mCallback; 94 nsCOMPtr<nsIPresentationSessionTransportBuilderListener> mListener; 95 96 // The data to be sent. 97 nsTArray<nsCOMPtr<nsIInputStream>> mPendingData; 98 }; 99 100 } // namespace dom 101 } // namespace mozilla 102 103 #endif // mozilla_dom_PresentationSessionTransport_h 104