1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef HttpTransactionShell_h__ 6 #define HttpTransactionShell_h__ 7 8 #include <functional> 9 #include "nsISupports.h" 10 #include "TimingStruct.h" 11 #include "nsInputStreamPump.h" 12 #include "nsIEarlyHintObserver.h" 13 #include "mozilla/Maybe.h" 14 #include "mozilla/UniquePtr.h" 15 16 class nsIEventTraget; 17 class nsIInputStream; 18 class nsIInterfaceRequestor; 19 class nsIRequest; 20 class nsIRequestContext; 21 class nsITransportEventSink; 22 23 namespace mozilla { 24 namespace net { 25 26 enum HttpTrafficCategory : uint8_t; 27 class Http2PushedStreamWrapper; 28 class HttpTransactionParent; 29 class nsHttpConnectionInfo; 30 class nsHttpHeaderArray; 31 class nsHttpRequestHead; 32 class nsHttpTransaction; 33 class TransactionObserverResult; 34 union NetAddr; 35 36 //---------------------------------------------------------------------------- 37 // Abstract base class for a HTTP transaction in the chrome process 38 //---------------------------------------------------------------------------- 39 40 // 95e5a5b7-6aa2-4011-920a-0908b52f95d4 41 #define HTTPTRANSACTIONSHELL_IID \ 42 { \ 43 0x95e5a5b7, 0x6aa2, 0x4011, { \ 44 0x92, 0x0a, 0x09, 0x08, 0xb5, 0x2f, 0x95, 0xd4 \ 45 } \ 46 } 47 48 class HttpTransactionShell : public nsISupports { 49 public: 50 NS_DECLARE_STATIC_IID_ACCESSOR(HTTPTRANSACTIONSHELL_IID) 51 52 using TransactionObserverFunc = 53 std::function<void(TransactionObserverResult&&)>; 54 using OnPushCallback = std::function<nsresult( 55 uint32_t, const nsACString&, const nsACString&, HttpTransactionShell*)>; 56 57 // 58 // called to initialize the transaction 59 // 60 // @param caps 61 // the transaction capabilities (see nsHttp.h) 62 // @param connInfo 63 // the connection type for this transaction. 64 // @param reqHeaders 65 // the request header struct 66 // @param reqBody 67 // the request body (POST or PUT data stream) 68 // @param reqBodyIncludesHeaders 69 // fun stuff to support NPAPI plugins. 70 // @param target 71 // the dispatch target were notifications should be sent. 72 // @param callbacks 73 // the notification callbacks to be given to PSM. 74 // @param topBrowsingContextId 75 // indicate the id of the top browsing context in which 76 // this transaction is being loaded. 77 [[nodiscard]] nsresult virtual Init( 78 uint32_t caps, nsHttpConnectionInfo* connInfo, 79 nsHttpRequestHead* reqHeaders, nsIInputStream* reqBody, 80 uint64_t reqContentLength, bool reqBodyIncludesHeaders, 81 nsIEventTarget* consumerTarget, nsIInterfaceRequestor* callbacks, 82 nsITransportEventSink* eventsink, uint64_t topBrowsingContextId, 83 HttpTrafficCategory trafficCategory, nsIRequestContext* requestContext, 84 uint32_t classOfService, uint32_t initialRwin, 85 bool responseTimeoutEnabled, uint64_t channelId, 86 TransactionObserverFunc&& transactionObserver, 87 OnPushCallback&& aOnPushCallback, 88 HttpTransactionShell* aTransWithPushedStream, 89 uint32_t aPushedStreamId) = 0; 90 91 // @param aListener 92 // receives notifications. 93 // @param pump 94 // the pump that will contain the response data. async wait on this 95 // input stream for data. On first notification, headers should be 96 // available (check transaction status). 97 virtual nsresult AsyncRead(nsIStreamListener* listener, 98 nsIRequest** pump) = 0; 99 100 // Called to take ownership of the response headers; the transaction 101 // will drop any reference to the response headers after this call. 102 virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() = 0; 103 104 // Called to take ownership of the trailer headers. 105 // Returning null if there is no trailer. 106 virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() = 0; 107 108 virtual already_AddRefed<nsISupports> SecurityInfo() = 0; 109 virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) = 0; 110 111 virtual void GetNetworkAddresses(NetAddr& self, NetAddr& peer, 112 bool& aResolvedByTRR, 113 bool& aEchConfigUsed) = 0; 114 115 // Functions for Timing interface 116 virtual mozilla::TimeStamp GetDomainLookupStart() = 0; 117 virtual mozilla::TimeStamp GetDomainLookupEnd() = 0; 118 virtual mozilla::TimeStamp GetConnectStart() = 0; 119 virtual mozilla::TimeStamp GetTcpConnectEnd() = 0; 120 virtual mozilla::TimeStamp GetSecureConnectionStart() = 0; 121 122 virtual mozilla::TimeStamp GetConnectEnd() = 0; 123 virtual mozilla::TimeStamp GetRequestStart() = 0; 124 virtual mozilla::TimeStamp GetResponseStart() = 0; 125 virtual mozilla::TimeStamp GetResponseEnd() = 0; 126 127 virtual void SetDomainLookupStart(mozilla::TimeStamp timeStamp, 128 bool onlyIfNull = false) = 0; 129 virtual void SetDomainLookupEnd(mozilla::TimeStamp timeStamp, 130 bool onlyIfNull = false) = 0; 131 132 virtual TimingStruct Timings() = 0; 133 134 // Called to set/find out if the transaction generated a complete response. 135 virtual bool ResponseIsComplete() = 0; 136 virtual int64_t GetTransferSize() = 0; 137 virtual int64_t GetRequestSize() = 0; 138 virtual bool IsHttp3Used() = 0; 139 140 // Called to notify that a requested DNS cache entry was refreshed. 141 virtual void SetDNSWasRefreshed() = 0; 142 143 virtual void DontReuseConnection() = 0; 144 virtual bool HasStickyConnection() const = 0; 145 146 virtual void SetH2WSConnRefTaken() = 0; 147 148 virtual bool ProxyConnectFailed() = 0; 149 virtual int32_t GetProxyConnectResponseCode() = 0; 150 151 virtual bool DataSentToChildProcess() = 0; 152 153 virtual nsHttpTransaction* AsHttpTransaction() = 0; 154 virtual HttpTransactionParent* AsHttpTransactionParent() = 0; 155 156 virtual bool TakeRestartedState() = 0; 157 virtual uint32_t HTTPSSVCReceivedStage() = 0; 158 159 virtual bool Http2Disabled() const = 0; 160 virtual bool Http3Disabled() const = 0; 161 virtual already_AddRefed<nsHttpConnectionInfo> GetConnInfo() const = 0; 162 163 virtual bool GetSupportsHTTP3() = 0; 164 }; 165 166 NS_DEFINE_STATIC_IID_ACCESSOR(HttpTransactionShell, HTTPTRANSACTIONSHELL_IID) 167 168 #define NS_DECL_HTTPTRANSACTIONSHELL \ 169 virtual nsresult Init( \ 170 uint32_t caps, nsHttpConnectionInfo* connInfo, \ 171 nsHttpRequestHead* reqHeaders, nsIInputStream* reqBody, \ 172 uint64_t reqContentLength, bool reqBodyIncludesHeaders, \ 173 nsIEventTarget* consumerTarget, nsIInterfaceRequestor* callbacks, \ 174 nsITransportEventSink* eventsink, uint64_t topBrowsingContextId, \ 175 HttpTrafficCategory trafficCategory, nsIRequestContext* requestContext, \ 176 uint32_t classOfService, uint32_t initialRwin, \ 177 bool responseTimeoutEnabled, uint64_t channelId, \ 178 TransactionObserverFunc&& transactionObserver, \ 179 OnPushCallback&& aOnPushCallback, \ 180 HttpTransactionShell* aTransWithPushedStream, uint32_t aPushedStreamId) \ 181 override; \ 182 virtual nsresult AsyncRead(nsIStreamListener* listener, nsIRequest** pump) \ 183 override; \ 184 virtual UniquePtr<nsHttpResponseHead> TakeResponseHead() override; \ 185 virtual UniquePtr<nsHttpHeaderArray> TakeResponseTrailers() override; \ 186 virtual already_AddRefed<nsISupports> SecurityInfo() override; \ 187 virtual void SetSecurityCallbacks(nsIInterfaceRequestor* aCallbacks) \ 188 override; \ 189 virtual void GetNetworkAddresses(NetAddr& self, NetAddr& peer, \ 190 bool& aResolvedByTRR, bool& aEchConfigUsed) \ 191 override; \ 192 virtual mozilla::TimeStamp GetDomainLookupStart() override; \ 193 virtual mozilla::TimeStamp GetDomainLookupEnd() override; \ 194 virtual mozilla::TimeStamp GetConnectStart() override; \ 195 virtual mozilla::TimeStamp GetTcpConnectEnd() override; \ 196 virtual mozilla::TimeStamp GetSecureConnectionStart() override; \ 197 virtual mozilla::TimeStamp GetConnectEnd() override; \ 198 virtual mozilla::TimeStamp GetRequestStart() override; \ 199 virtual mozilla::TimeStamp GetResponseStart() override; \ 200 virtual mozilla::TimeStamp GetResponseEnd() override; \ 201 virtual void SetDomainLookupStart(mozilla::TimeStamp timeStamp, \ 202 bool onlyIfNull = false) override; \ 203 virtual void SetDomainLookupEnd(mozilla::TimeStamp timeStamp, \ 204 bool onlyIfNull = false) override; \ 205 virtual TimingStruct Timings() override; \ 206 virtual bool ResponseIsComplete() override; \ 207 virtual int64_t GetTransferSize() override; \ 208 virtual int64_t GetRequestSize() override; \ 209 virtual bool IsHttp3Used() override; \ 210 virtual void SetDNSWasRefreshed() override; \ 211 virtual void DontReuseConnection() override; \ 212 virtual bool HasStickyConnection() const override; \ 213 virtual void SetH2WSConnRefTaken() override; \ 214 virtual bool ProxyConnectFailed() override; \ 215 virtual int32_t GetProxyConnectResponseCode() override; \ 216 virtual bool DataSentToChildProcess() override; \ 217 virtual nsHttpTransaction* AsHttpTransaction() override; \ 218 virtual HttpTransactionParent* AsHttpTransactionParent() override; \ 219 virtual bool TakeRestartedState() override; \ 220 virtual uint32_t HTTPSSVCReceivedStage() override; \ 221 virtual bool Http2Disabled() const override; \ 222 virtual bool Http3Disabled() const override; \ 223 virtual already_AddRefed<nsHttpConnectionInfo> GetConnInfo() const override; \ 224 virtual bool GetSupportsHTTP3() override; 225 } // namespace net 226 } // namespace mozilla 227 228 #endif // HttpTransactionShell_h__ 229