HttpConnectionMgrChild.cpp (6314B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* vim:set ts=4 sw=4 sts=4 et cin: */ 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 // HttpLog.h should generally be included first 8 #include "HttpLog.h" 9 10 #include "HttpConnectionMgrChild.h" 11 #include "HttpTransactionChild.h" 12 #include "AltSvcTransactionChild.h" 13 #include "EventTokenBucket.h" 14 #include "mozilla/net/WebSocketConnectionChild.h" 15 #include "nsHttpConnectionInfo.h" 16 #include "nsHttpConnectionMgr.h" 17 #include "nsHttpHandler.h" 18 #include "nsISpeculativeConnect.h" 19 20 namespace mozilla::net { 21 22 HttpConnectionMgrChild::HttpConnectionMgrChild() 23 : mConnMgr(gHttpHandler->ConnMgr()) { 24 MOZ_ASSERT(mConnMgr); 25 } 26 27 HttpConnectionMgrChild::~HttpConnectionMgrChild() { 28 LOG(("HttpConnectionMgrChild dtor:%p", this)); 29 } 30 31 void HttpConnectionMgrChild::ActorDestroy(ActorDestroyReason aWhy) { 32 LOG(("HttpConnectionMgrChild::ActorDestroy [this=%p]\n", this)); 33 } 34 35 mozilla::ipc::IPCResult 36 HttpConnectionMgrChild::RecvDoShiftReloadConnectionCleanupWithConnInfo( 37 const HttpConnectionInfoCloneArgs& aArgs) { 38 RefPtr<nsHttpConnectionInfo> cinfo = 39 nsHttpConnectionInfo::DeserializeHttpConnectionInfoCloneArgs(aArgs); 40 nsresult rv = mConnMgr->DoShiftReloadConnectionCleanupWithConnInfo(cinfo); 41 if (NS_FAILED(rv)) { 42 LOG( 43 ("HttpConnectionMgrChild::DoShiftReloadConnectionCleanupWithConnInfo " 44 "failed " 45 "(%08x)\n", 46 static_cast<uint32_t>(rv))); 47 } 48 return IPC_OK(); 49 } 50 51 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvUpdateCurrentBrowserId( 52 const uint64_t& aId) { 53 mConnMgr->UpdateCurrentBrowserId(aId); 54 return IPC_OK(); 55 } 56 57 nsHttpTransaction* ToRealHttpTransaction(PHttpTransactionChild* aTrans) { 58 HttpTransactionChild* transChild = static_cast<HttpTransactionChild*>(aTrans); 59 LOG(("ToRealHttpTransaction: [transChild=%p] \n", transChild)); 60 RefPtr<nsHttpTransaction> trans = transChild->GetHttpTransaction(); 61 MOZ_ASSERT(trans); 62 return trans; 63 } 64 65 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvAddTransaction( 66 PHttpTransactionChild* aTrans, const int32_t& aPriority) { 67 (void)mConnMgr->AddTransaction(ToRealHttpTransaction(aTrans), aPriority); 68 return IPC_OK(); 69 } 70 71 mozilla::ipc::IPCResult 72 HttpConnectionMgrChild::RecvAddTransactionWithStickyConn( 73 PHttpTransactionChild* aTrans, const int32_t& aPriority, 74 PHttpTransactionChild* aTransWithStickyConn) { 75 (void)mConnMgr->AddTransactionWithStickyConn( 76 ToRealHttpTransaction(aTrans), aPriority, 77 ToRealHttpTransaction(aTransWithStickyConn)); 78 return IPC_OK(); 79 } 80 81 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvRescheduleTransaction( 82 PHttpTransactionChild* aTrans, const int32_t& aPriority) { 83 (void)mConnMgr->RescheduleTransaction(ToRealHttpTransaction(aTrans), 84 aPriority); 85 return IPC_OK(); 86 } 87 88 mozilla::ipc::IPCResult 89 HttpConnectionMgrChild::RecvUpdateClassOfServiceOnTransaction( 90 PHttpTransactionChild* aTrans, const ClassOfService& aClassOfService) { 91 mConnMgr->UpdateClassOfServiceOnTransaction(ToRealHttpTransaction(aTrans), 92 aClassOfService); 93 return IPC_OK(); 94 } 95 96 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvCancelTransaction( 97 PHttpTransactionChild* aTrans, const nsresult& aReason) { 98 (void)mConnMgr->CancelTransaction(ToRealHttpTransaction(aTrans), aReason); 99 return IPC_OK(); 100 } 101 102 namespace { 103 104 class SpeculativeConnectionOverrider final 105 : public nsIInterfaceRequestor, 106 public nsISpeculativeConnectionOverrider { 107 public: 108 NS_DECL_THREADSAFE_ISUPPORTS 109 NS_DECL_NSIINTERFACEREQUESTOR 110 NS_DECL_NSISPECULATIVECONNECTIONOVERRIDER 111 112 explicit SpeculativeConnectionOverrider( 113 SpeculativeConnectionOverriderArgs&& aArgs) 114 : mArgs(std::move(aArgs)) {} 115 116 private: 117 virtual ~SpeculativeConnectionOverrider() = default; 118 119 SpeculativeConnectionOverriderArgs mArgs; 120 }; 121 122 NS_IMPL_ISUPPORTS(SpeculativeConnectionOverrider, nsIInterfaceRequestor, 123 nsISpeculativeConnectionOverrider) 124 125 NS_IMETHODIMP 126 SpeculativeConnectionOverrider::GetInterface(const nsIID& iid, void** result) { 127 if (NS_SUCCEEDED(QueryInterface(iid, result)) && *result) { 128 return NS_OK; 129 } 130 return NS_ERROR_NO_INTERFACE; 131 } 132 133 NS_IMETHODIMP 134 SpeculativeConnectionOverrider::GetIgnoreIdle(bool* aIgnoreIdle) { 135 *aIgnoreIdle = mArgs.ignoreIdle(); 136 return NS_OK; 137 } 138 139 NS_IMETHODIMP 140 SpeculativeConnectionOverrider::GetParallelSpeculativeConnectLimit( 141 uint32_t* aParallelSpeculativeConnectLimit) { 142 *aParallelSpeculativeConnectLimit = mArgs.parallelSpeculativeConnectLimit(); 143 return NS_OK; 144 } 145 146 NS_IMETHODIMP 147 SpeculativeConnectionOverrider::GetAllow1918(bool* aAllow) { 148 *aAllow = mArgs.allow1918(); 149 return NS_OK; 150 } 151 152 } // anonymous namespace 153 154 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvSpeculativeConnect( 155 const HttpConnectionInfoCloneArgs& aConnInfo, 156 Maybe<SpeculativeConnectionOverriderArgs> aOverriderArgs, uint32_t aCaps, 157 Maybe<PAltSvcTransactionChild*> aTrans, const bool& aFetchHTTPSRR) { 158 RefPtr<nsHttpConnectionInfo> cinfo = 159 nsHttpConnectionInfo::DeserializeHttpConnectionInfoCloneArgs(aConnInfo); 160 nsCOMPtr<nsIInterfaceRequestor> overrider = 161 aOverriderArgs 162 ? new SpeculativeConnectionOverrider(std::move(aOverriderArgs.ref())) 163 : nullptr; 164 RefPtr<SpeculativeTransaction> trans; 165 if (aTrans) { 166 trans = static_cast<AltSvcTransactionChild*>(*aTrans)->CreateTransaction(); 167 } 168 169 (void)mConnMgr->SpeculativeConnect(cinfo, overrider, aCaps, trans, 170 aFetchHTTPSRR); 171 return IPC_OK(); 172 } 173 174 mozilla::ipc::IPCResult HttpConnectionMgrChild::RecvStartWebSocketConnection( 175 PHttpTransactionChild* aTransWithStickyConn, uint32_t aListenerId) { 176 RefPtr<WebSocketConnectionChild> child = new WebSocketConnectionChild(); 177 child->Init(aListenerId); 178 nsCOMPtr<nsIHttpUpgradeListener> listener = 179 static_cast<nsIHttpUpgradeListener*>(child.get()); 180 (void)mConnMgr->CompleteUpgrade(ToRealHttpTransaction(aTransWithStickyConn), 181 listener); 182 return IPC_OK(); 183 } 184 185 } // namespace mozilla::net