TRRServiceChannel.h (7005B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et tw=80 : */ 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef mozilla_net_TRRServiceChannel_h 9 #define mozilla_net_TRRServiceChannel_h 10 11 #include "HttpBaseChannel.h" 12 #include "mozilla/DataMutex.h" 13 #include "nsIDNSListener.h" 14 #include "nsIProtocolProxyCallback.h" 15 #include "nsIProxiedChannel.h" 16 #include "nsIStreamListener.h" 17 #include "nsWeakReference.h" 18 19 class nsDNSPrefetch; 20 21 namespace mozilla::net { 22 23 class HttpTransactionShell; 24 class nsHttpHandler; 25 26 // Use to support QI nsIChannel to TRRServiceChannel 27 #define NS_TRRSERVICECHANNEL_IID \ 28 {0x361c4bb1, 0xd6b2, 0x493b, {0x86, 0xbc, 0x88, 0xd3, 0x5d, 0x16, 0x38, 0xfa}} 29 30 // TRRServiceChannel is designed to fetch DNS data from DoH server. This channel 31 // MUST only be used by TRR. 32 class TRRServiceChannel : public HttpBaseChannel, 33 public HttpAsyncAborter<TRRServiceChannel>, 34 public nsIDNSListener, 35 public nsIStreamListener, 36 public nsITransportEventSink, 37 public nsIProxiedChannel, 38 public nsIProtocolProxyCallback, 39 public nsSupportsWeakReference { 40 public: 41 NS_DECL_ISUPPORTS_INHERITED 42 NS_DECL_NSIDNSLISTENER 43 NS_DECL_NSIREQUESTOBSERVER 44 NS_DECL_NSISTREAMLISTENER 45 NS_DECL_NSITRANSPORTEVENTSINK 46 NS_DECL_NSIPROXIEDCHANNEL 47 NS_DECL_NSIPROTOCOLPROXYCALLBACK 48 NS_INLINE_DECL_STATIC_IID(NS_TRRSERVICECHANNEL_IID) 49 50 // nsIRequest 51 NS_IMETHOD SetCanceledReason(const nsACString& aReason) override; 52 NS_IMETHOD GetCanceledReason(nsACString& aReason) override; 53 NS_IMETHOD CancelWithReason(nsresult status, 54 const nsACString& reason) override; 55 NS_IMETHOD Cancel(nsresult status) override; 56 NS_IMETHOD Suspend() override; 57 NS_IMETHOD Resume() override; 58 NS_IMETHOD GetLoadFlags(nsLoadFlags* aLoadFlags) override; 59 NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags) override; 60 NS_IMETHOD GetURI(nsIURI** aURI) override; 61 NS_IMETHOD GetNotificationCallbacks( 62 nsIInterfaceRequestor** aCallbacks) override; 63 NS_IMETHOD GetLoadGroup(nsILoadGroup** aLoadGroup) override; 64 NS_IMETHOD GetRequestMethod(nsACString& aMethod) override; 65 // nsIChannel 66 NS_IMETHOD GetSecurityInfo(nsITransportSecurityInfo** aSecurityInfo) override; 67 NS_IMETHOD AsyncOpen(nsIStreamListener* aListener) override; 68 69 NS_IMETHOD LogBlockedCORSRequest(const nsAString& aMessage, 70 const nsACString& aCategory, 71 bool aIsWarning) override; 72 NS_IMETHOD LogMimeTypeMismatch(const nsACString& aMessageName, bool aWarning, 73 const nsAString& aURL, 74 const nsAString& aContentType) override; 75 NS_IMETHOD GetIsAuthChannel(bool* aIsAuthChannel) override; 76 77 NS_IMETHOD SetNotificationCallbacks( 78 nsIInterfaceRequestor* aCallbacks) override; 79 NS_IMETHOD GetDecompressDictionary( 80 DictionaryCacheEntry** aDictionary) override { 81 *aDictionary = nullptr; 82 return NS_OK; 83 } 84 NS_IMETHOD SetDecompressDictionary( 85 DictionaryCacheEntry* aDictionary) override { 86 return NS_OK; 87 } 88 // nsISupportsPriority 89 NS_IMETHOD SetPriority(int32_t value) override; 90 // nsIClassOfService 91 NS_IMETHOD SetClassFlags(uint32_t inFlags) override; 92 NS_IMETHOD AddClassFlags(uint32_t inFlags) override; 93 NS_IMETHOD ClearClassFlags(uint32_t inFlags) override; 94 NS_IMETHOD SetIncremental(bool inFlag) override; 95 NS_IMETHOD SetClassOfService(ClassOfService cos) override; 96 // nsIResumableChannel 97 NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID) override; 98 NS_IMETHOD SetEarlyHintObserver(nsIEarlyHintObserver* aObserver) override { 99 return NS_OK; 100 } 101 NS_IMETHOD SetWebTransportSessionEventListener( 102 WebTransportSessionEventListener* aListener) override { 103 return NS_OK; 104 } 105 106 NS_IMETHOD SetResponseOverride( 107 nsIReplacedHttpResponse* aReplacedHttpResponse) override { 108 return NS_OK; 109 } 110 111 NS_IMETHOD SetResponseStatus(uint32_t aStatus, 112 const nsACString& aStatusText) override { 113 return NS_OK; 114 } 115 116 // nsITimedChannel 117 NS_IMETHOD GetDomainLookupStart( 118 mozilla::TimeStamp* aDomainLookupStart) override; 119 NS_IMETHOD GetDomainLookupEnd(mozilla::TimeStamp* aDomainLookupEnd) override; 120 NS_IMETHOD GetConnectStart(mozilla::TimeStamp* aConnectStart) override; 121 NS_IMETHOD GetTcpConnectEnd(mozilla::TimeStamp* aTcpConnectEnd) override; 122 NS_IMETHOD GetSecureConnectionStart( 123 mozilla::TimeStamp* aSecureConnectionStart) override; 124 NS_IMETHOD GetConnectEnd(mozilla::TimeStamp* aConnectEnd) override; 125 NS_IMETHOD GetRequestStart(mozilla::TimeStamp* aRequestStart) override; 126 NS_IMETHOD GetResponseStart(mozilla::TimeStamp* aResponseStart) override; 127 NS_IMETHOD GetResponseEnd(mozilla::TimeStamp* aResponseEnd) override; 128 NS_IMETHOD SetLoadGroup(nsILoadGroup* aLoadGroup) override; 129 NS_IMETHOD TimingAllowCheck(nsIPrincipal* aOrigin, bool* aResult) override; 130 131 protected: 132 TRRServiceChannel(); 133 virtual ~TRRServiceChannel(); 134 135 void CancelNetworkRequest(nsresult aStatus); 136 nsresult BeginConnect(); 137 nsresult ContinueOnBeforeConnect(); 138 nsresult Connect(); 139 nsresult SetupTransaction(); 140 void OnClassOfServiceUpdated(); 141 virtual void DoNotifyListenerCleanup() override; 142 virtual void DoAsyncAbort(nsresult aStatus) override; 143 bool IsIsolated() { return false; }; 144 void ProcessAltService(nsHttpConnectionInfo* aTransConnInfo); 145 nsresult CallOnStartRequest(); 146 147 void MaybeStartDNSPrefetch(); 148 void DoNotifyListener(); 149 nsresult MaybeResolveProxyAndBeginConnect(); 150 nsresult ResolveProxy(); 151 void AfterApplyContentConversions(nsresult aResult, 152 nsIStreamListener* aListener); 153 nsresult SyncProcessRedirection(uint32_t aHttpStatus); 154 [[nodiscard]] virtual nsresult SetupReplacementChannel( 155 nsIURI* aNewURI, nsIChannel* aNewChannel, bool aPreserveMethod, 156 uint32_t aRedirectFlags) override; 157 // Skip this check for TRRServiceChannel. 158 virtual bool ShouldTaintReplacementChannelOrigin( 159 nsIChannel* aNewChannel, uint32_t aRedirectFlags) override { 160 return false; 161 } 162 virtual bool SameOriginWithOriginalUri(nsIURI* aURI) override; 163 bool DispatchRelease(); 164 165 nsCString mUsername; 166 167 // Needed for accurate DNS timing 168 RefPtr<nsDNSPrefetch> mDNSPrefetch; 169 170 nsCOMPtr<nsIRequest> mTransactionPump; 171 RefPtr<HttpTransactionShell> mTransaction; 172 DataMutex<nsCOMPtr<nsICancelable>> mProxyRequest; 173 nsCOMPtr<nsIEventTarget> mCurrentEventTarget; 174 175 friend class HttpAsyncAborter<TRRServiceChannel>; 176 friend class nsHttpHandler; 177 }; 178 179 } // namespace mozilla::net 180 181 #endif // mozilla_net_TRRServiceChannel_h