1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef HttpTransactionChild_h__
7 #define HttpTransactionChild_h__
8
9 #include "mozilla/Atomics.h"
10 #include "mozilla/net/NeckoChannelParams.h"
11 #include "mozilla/net/PHttpTransactionChild.h"
12 #include "nsHttpRequestHead.h"
13 #include "nsIEarlyHintObserver.h"
14 #include "nsIRequest.h"
15 #include "nsIStreamListener.h"
16 #include "nsIThreadRetargetableStreamListener.h"
17 #include "nsIThrottledInputChannel.h"
18 #include "nsITransport.h"
19
20 class nsInputStreamPump;
21
22 namespace mozilla {
23 namespace net {
24
25 class BackgroundDataBridgeParent;
26 class InputChannelThrottleQueueChild;
27 class nsHttpConnectionInfo;
28 class nsHttpTransaction;
29 class nsProxyInfo;
30
31 //-----------------------------------------------------------------------------
32 // HttpTransactionChild commutes between parent process and socket process,
33 // manages the real nsHttpTransaction and transaction pump.
34 //-----------------------------------------------------------------------------
35 class HttpTransactionChild final : public PHttpTransactionChild,
36 public nsIStreamListener,
37 public nsITransportEventSink,
38 public nsIThrottledInputChannel,
39 public nsIThreadRetargetableStreamListener,
40 public nsIEarlyHintObserver {
41 public:
42 NS_DECL_THREADSAFE_ISUPPORTS
43 NS_DECL_NSIREQUESTOBSERVER
44 NS_DECL_NSISTREAMLISTENER
45 NS_DECL_NSITRANSPORTEVENTSINK
46 NS_DECL_NSITHROTTLEDINPUTCHANNEL
47 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
48 NS_DECL_NSIEARLYHINTOBSERVER
49
50 explicit HttpTransactionChild();
51
52 mozilla::ipc::IPCResult RecvInit(
53 const uint32_t& aCaps, const HttpConnectionInfoCloneArgs& aArgs,
54 const nsHttpRequestHead& aReqHeaders,
55 const Maybe<IPCStream>& aRequestBody, const uint64_t& aReqContentLength,
56 const bool& aReqBodyIncludesHeaders,
57 const uint64_t& aTopLevelOuterContentWindowId,
58 const uint8_t& aHttpTrafficCategory, const uint64_t& aRequestContextID,
59 const uint32_t& aClassOfService, const uint32_t& aInitialRwin,
60 const bool& aResponseTimeoutEnabled, const uint64_t& aChannelId,
61 const bool& aHasTransactionObserver,
62 const Maybe<H2PushedStreamArg>& aPushedStreamArg,
63 const mozilla::Maybe<PInputChannelThrottleQueueChild*>& aThrottleQueue,
64 const bool& aIsDocumentLoad, const TimeStamp& aRedirectStart,
65 const TimeStamp& aRedirectEnd);
66 mozilla::ipc::IPCResult RecvCancelPump(const nsresult& aStatus);
67 mozilla::ipc::IPCResult RecvSuspendPump();
68 mozilla::ipc::IPCResult RecvResumePump();
69 mozilla::ipc::IPCResult RecvSetDNSWasRefreshed();
70 mozilla::ipc::IPCResult RecvDontReuseConnection();
71 mozilla::ipc::IPCResult RecvSetH2WSConnRefTaken();
72 void ActorDestroy(ActorDestroyReason aWhy) override;
73
74 nsHttpTransaction* GetHttpTransaction();
75
76 private:
77 virtual ~HttpTransactionChild();
78
79 nsProxyInfo* ProxyInfoCloneArgsToProxyInfo(
80 const nsTArray<ProxyInfoCloneArgs>& aArgs);
81 already_AddRefed<nsHttpConnectionInfo> DeserializeHttpConnectionInfoCloneArgs(
82 const HttpConnectionInfoCloneArgs& aInfoArgs);
83 // Initialize the *real* nsHttpTransaction. See |nsHttpTransaction::Init|
84 // for the parameters.
85 [[nodiscard]] nsresult InitInternal(
86 uint32_t caps, const HttpConnectionInfoCloneArgs& infoArgs,
87 nsHttpRequestHead* requestHead,
88 nsIInputStream* requestBody, // use the trick in bug 1277681
89 uint64_t requestContentLength, bool requestBodyHasHeaders,
90 uint64_t topLevelOuterContentWindowId, uint8_t httpTrafficCategory,
91 uint64_t requestContextID, uint32_t classOfService, uint32_t initialRwin,
92 bool responseTimeoutEnabled, uint64_t channelId,
93 bool aHasTransactionObserver,
94 const Maybe<H2PushedStreamArg>& aPushedStreamArg);
95
96 void CancelInternal(nsresult aStatus);
97
98 bool CanSendODAToContentProcessDirectly(
99 const Maybe<nsHttpResponseHead>& aHead);
100
101 ResourceTimingStructArgs GetTimingAttributes();
102
103 // Use Release-Acquire ordering to ensure the OMT ODA is ignored while
104 // transaction is canceled on main thread.
105 Atomic<bool, ReleaseAcquire> mCanceled{false};
106 Atomic<nsresult, ReleaseAcquire> mStatus{NS_OK};
107 uint64_t mChannelId{0};
108 nsHttpRequestHead mRequestHead;
109 bool mIsDocumentLoad{false};
110 uint64_t mLogicalOffset{0};
111 TimeStamp mRedirectStart;
112 TimeStamp mRedirectEnd;
113 nsCString mProtocolVersion;
114
115 nsCOMPtr<nsIInputStream> mUploadStream;
116 RefPtr<nsHttpTransaction> mTransaction;
117 nsCOMPtr<nsIRequest> mTransactionPump;
118 Maybe<TransactionObserverResult> mTransactionObserverResult;
119 RefPtr<InputChannelThrottleQueueChild> mThrottleQueue;
120 RefPtr<BackgroundDataBridgeParent> mDataBridgeParent;
121 };
122
123 } // namespace net
124 } // namespace mozilla
125
ToSupports(mozilla::net::HttpTransactionChild * p)126 inline nsISupports* ToSupports(mozilla::net::HttpTransactionChild* p) {
127 return static_cast<nsIStreamListener*>(p);
128 }
129
130 #endif // nsHttpTransactionChild_h__
131