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