diff --git a/media/mtransport/WebrtcTCPSocketWrapper.cpp b/media/mtransport/WebrtcTCPSocketWrapper.cpp index 8e55276d0c9c..b52c322d26c9 100644 --- a/media/mtransport/WebrtcTCPSocketWrapper.cpp +++ b/media/mtransport/WebrtcTCPSocketWrapper.cpp @@ -125,13 +125,13 @@ void WebrtcTCPSocketWrapper::OnRead(nsTArray&& aReadData) { &WebrtcTCPSocketCallback::OnRead, std::move(aReadData)))); } -void WebrtcTCPSocketWrapper::OnConnected() { +void WebrtcTCPSocketWrapper::OnConnected(const nsCString& aProxyType) { MOZ_ASSERT(NS_IsMainThread(), "not on main thread"); MOZ_ASSERT(mProxyCallbacks, "webrtc TCP callbacks should be non-null"); - MOZ_ALWAYS_SUCCEEDS(mSocketThread->Dispatch( - NewRunnableMethod("WebrtcTCPSocketWrapper::OnConnected", mProxyCallbacks, - &WebrtcTCPSocketCallback::OnConnected))); + MOZ_ALWAYS_SUCCEEDS(mSocketThread->Dispatch(NewRunnableMethod( + "WebrtcTCPSocketWrapper::OnConnected", mProxyCallbacks, + &WebrtcTCPSocketCallback::OnConnected, aProxyType))); } } // namespace net diff --git a/media/mtransport/WebrtcTCPSocketWrapper.h b/media/mtransport/WebrtcTCPSocketWrapper.h index 6d352cc7fdac..476eacb43f6d 100644 --- a/media/mtransport/WebrtcTCPSocketWrapper.h +++ b/media/mtransport/WebrtcTCPSocketWrapper.h @@ -50,7 +50,7 @@ class WebrtcTCPSocketWrapper : public WebrtcTCPSocketCallback { // WebrtcTCPSocketCallback virtual void OnClose(nsresult aReason) override; - virtual void OnConnected() override; + virtual void OnConnected(const nsCString& aProxyType) override; virtual void OnRead(nsTArray&& aReadData) override; protected: diff --git a/media/mtransport/ipc/PWebrtcTCPSocket.ipdl b/media/mtransport/ipc/PWebrtcTCPSocket.ipdl index 2344560d221f..4c0d91d066ad 100644 --- a/media/mtransport/ipc/PWebrtcTCPSocket.ipdl +++ b/media/mtransport/ipc/PWebrtcTCPSocket.ipdl @@ -32,7 +32,7 @@ parent: child: async OnClose(nsresult aReason); - async OnConnected(); + async OnConnected(nsCString aProxyType); async OnRead(uint8_t[] aReadData); async __delete__(); diff --git a/media/mtransport/ipc/WebrtcTCPSocket.cpp b/media/mtransport/ipc/WebrtcTCPSocket.cpp index 7b80aa1fc49f..3ade3697ef17 100644 --- a/media/mtransport/ipc/WebrtcTCPSocket.cpp +++ b/media/mtransport/ipc/WebrtcTCPSocket.cpp @@ -231,17 +231,16 @@ NS_IMETHODIMP WebrtcTCPSocket::OnProxyAvailable(nsICancelable* aRequest, nsresult rv; if (NS_SUCCEEDED(aResult) && aProxyinfo) { - nsCString proxyType; - rv = aProxyinfo->GetType(proxyType); + rv = aProxyinfo->GetType(mProxyType); if (NS_WARN_IF(NS_FAILED(rv))) { CloseWithReason(rv); return rv; } - if (proxyType == "http" || proxyType == "https") { + if (mProxyType == "http" || mProxyType == "https") { rv = OpenWithHttpProxy(); - } else if (proxyType == "socks" || proxyType == "socks4" || - proxyType == "direct") { + } else if (mProxyType == "socks" || mProxyType == "socks4" || + mProxyType == "direct") { rv = OpenWithoutHttpProxy(aProxyinfo); } } else { @@ -452,7 +451,7 @@ void WebrtcTCPSocket::InvokeOnConnected() { MOZ_ASSERT(mProxyCallbacks, "webrtc TCP callback should be non-null"); - mProxyCallbacks->OnConnected(); + mProxyCallbacks->OnConnected(mProxyType); } void WebrtcTCPSocket::InvokeOnRead(nsTArray&& aReadData) { diff --git a/media/mtransport/ipc/WebrtcTCPSocket.h b/media/mtransport/ipc/WebrtcTCPSocket.h index 06f9cd56a10d..9455289c610e 100644 --- a/media/mtransport/ipc/WebrtcTCPSocket.h +++ b/media/mtransport/ipc/WebrtcTCPSocket.h @@ -82,6 +82,7 @@ class WebrtcTCPSocket : public nsIHttpUpgradeListener, bool mForceProxy = false; nsCString mLocalAddress; uint16_t mLocalPort = 0; + nsCString mProxyType; nsresult DoProxyConfigLookup(); nsresult OpenWithHttpProxy(); diff --git a/media/mtransport/ipc/WebrtcTCPSocketCallback.h b/media/mtransport/ipc/WebrtcTCPSocketCallback.h index 68c192b818ef..271b1301b006 100644 --- a/media/mtransport/ipc/WebrtcTCPSocketCallback.h +++ b/media/mtransport/ipc/WebrtcTCPSocketCallback.h @@ -17,7 +17,7 @@ class WebrtcTCPSocketCallback { NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING virtual void OnClose(nsresult aReason) = 0; - virtual void OnConnected() = 0; + virtual void OnConnected(const nsCString& aProxyType) = 0; virtual void OnRead(nsTArray&& aReadData) = 0; protected: diff --git a/media/mtransport/ipc/WebrtcTCPSocketChild.cpp b/media/mtransport/ipc/WebrtcTCPSocketChild.cpp index e506fe391f56..d36eb95ef854 100644 --- a/media/mtransport/ipc/WebrtcTCPSocketChild.cpp +++ b/media/mtransport/ipc/WebrtcTCPSocketChild.cpp @@ -30,11 +30,12 @@ mozilla::ipc::IPCResult WebrtcTCPSocketChild::RecvOnClose( return IPC_OK(); } -mozilla::ipc::IPCResult WebrtcTCPSocketChild::RecvOnConnected() { +mozilla::ipc::IPCResult WebrtcTCPSocketChild::RecvOnConnected( + const nsCString& aProxyType) { LOG(("WebrtcTCPSocketChild::RecvOnConnected %p\n", this)); MOZ_ASSERT(mProxyCallbacks, "webrtc TCP callbacks should be non-null"); - mProxyCallbacks->OnConnected(); + mProxyCallbacks->OnConnected(aProxyType); return IPC_OK(); } diff --git a/media/mtransport/ipc/WebrtcTCPSocketChild.h b/media/mtransport/ipc/WebrtcTCPSocketChild.h index aac43ee81c80..3b849eef09ec 100644 --- a/media/mtransport/ipc/WebrtcTCPSocketChild.h +++ b/media/mtransport/ipc/WebrtcTCPSocketChild.h @@ -23,7 +23,7 @@ class WebrtcTCPSocketChild : public PWebrtcTCPSocketChild { mozilla::ipc::IPCResult RecvOnClose(const nsresult& aReason) override; - mozilla::ipc::IPCResult RecvOnConnected() override; + mozilla::ipc::IPCResult RecvOnConnected(const nsCString& aProxyType) override; mozilla::ipc::IPCResult RecvOnRead(nsTArray&& aReadData) override; diff --git a/media/mtransport/ipc/WebrtcTCPSocketParent.cpp b/media/mtransport/ipc/WebrtcTCPSocketParent.cpp index e76afed261f2..83b8ac4f123e 100644 --- a/media/mtransport/ipc/WebrtcTCPSocketParent.cpp +++ b/media/mtransport/ipc/WebrtcTCPSocketParent.cpp @@ -107,10 +107,10 @@ void WebrtcTCPSocketParent::OnRead(nsTArray&& aReadData) { } } -void WebrtcTCPSocketParent::OnConnected() { +void WebrtcTCPSocketParent::OnConnected(const nsCString& aProxyType) { LOG(("WebrtcTCPSocketParent::OnConnected %p\n", this)); - if (mChannel && !SendOnConnected()) { + if (mChannel && !SendOnConnected(aProxyType)) { CleanupChannel(); } } diff --git a/media/mtransport/ipc/WebrtcTCPSocketParent.h b/media/mtransport/ipc/WebrtcTCPSocketParent.h index ae2b43d90ac8..2fecb08cd5ef 100644 --- a/media/mtransport/ipc/WebrtcTCPSocketParent.h +++ b/media/mtransport/ipc/WebrtcTCPSocketParent.h @@ -39,7 +39,7 @@ class WebrtcTCPSocketParent : public PWebrtcTCPSocketParent, // WebrtcTCPSocketCallback void OnClose(nsresult aReason) override; - void OnConnected() override; + void OnConnected(const nsCString& aProxyType) override; void OnRead(nsTArray&& bytes) override; void AddIPDLReference() { AddRef(); } diff --git a/media/mtransport/nr_socket_tcp.cpp b/media/mtransport/nr_socket_tcp.cpp index 9797a2d12a41..2abd39068778 100644 --- a/media/mtransport/nr_socket_tcp.cpp +++ b/media/mtransport/nr_socket_tcp.cpp @@ -246,8 +246,9 @@ void NrTcpSocket::OnClose(nsresult aReason) { DoCallbacks(); } -void NrTcpSocket::OnConnected() { +void NrTcpSocket::OnConnected(const nsCString& aProxyType) { r_log(LOG_GENERIC, LOG_DEBUG, "NrTcpSocket::OnConnected %p\n", this); + mProxyType = aProxyType; DoCallbacks(); } diff --git a/media/mtransport/nr_socket_tcp.h b/media/mtransport/nr_socket_tcp.h index 741c2cfc4b2c..bb206bcde55c 100644 --- a/media/mtransport/nr_socket_tcp.h +++ b/media/mtransport/nr_socket_tcp.h @@ -86,11 +86,13 @@ class NrTcpSocket : public NrSocketBase, public WebrtcTCPSocketCallback { int listen(int aBacklog) override; int accept(nr_transport_addr* aAddr, nr_socket** aSocket) override; - bool IsProxied() const override { return true; } + bool IsProxied() const override { + return mProxyType != "" && mProxyType != "direct"; + } // WebrtcTCPSocketCallback void OnClose(nsresult aReason) override; - void OnConnected() override; + void OnConnected(const nsCString& aProxyType) override; void OnRead(nsTArray&& aReadData) override; size_t CountUnreadBytes() const; @@ -107,6 +109,7 @@ class NrTcpSocket : public NrSocketBase, public WebrtcTCPSocketCallback { bool mClosed; size_t mReadOffset; + nsCString mProxyType; std::list mReadQueue; std::shared_ptr mConfig; diff --git a/media/mtransport/test/proxy_tunnel_socket_unittest.cpp b/media/mtransport/test/proxy_tunnel_socket_unittest.cpp index f90cb2e741f7..16057d23c319 100644 --- a/media/mtransport/test/proxy_tunnel_socket_unittest.cpp +++ b/media/mtransport/test/proxy_tunnel_socket_unittest.cpp @@ -110,7 +110,7 @@ TEST_F(NrTcpSocketTest, TestConnected) { // still not connected just registered for writes... ASSERT_TRUE(!mConnected); - mSProxy->OnConnected(); + mSProxy->OnConnected(NS_LITERAL_CSTRING("http")); ASSERT_TRUE(mConnected); } diff --git a/media/mtransport/test/webrtcproxychannel_unittest.cpp b/media/mtransport/test/webrtcproxychannel_unittest.cpp index edae5659d786..e957ae8bcb23 100644 --- a/media/mtransport/test/webrtcproxychannel_unittest.cpp +++ b/media/mtransport/test/webrtcproxychannel_unittest.cpp @@ -472,7 +472,7 @@ void FakeWebrtcTCPSocket::InvokeOnClose(nsresult aReason) { } void FakeWebrtcTCPSocket::InvokeOnConnected() { - mProxyCallbacks->OnConnected(); + mProxyCallbacks->OnConnected(NS_LITERAL_CSTRING("http")); } void FakeWebrtcTCPSocket::InvokeOnRead(nsTArray&& aReadData) { @@ -494,7 +494,7 @@ class WebrtcTCPSocketTest : public MtransportTest { // WebrtcTCPSocketCallback forwards from mCallback void OnClose(nsresult aReason); - void OnConnected(); + void OnConnected(const nsCString& aProxyType); void OnRead(nsTArray&& aReadData); void SetUp() override; @@ -534,7 +534,7 @@ class WebrtcTCPSocketTestCallback : public WebrtcTCPSocketCallback { // WebrtcTCPSocketCallback void OnClose(nsresult aReason) override; - void OnConnected() override; + void OnConnected(const nsCString& aProxyType) override; void OnRead(nsTArray&& aReadData) override; protected: @@ -566,7 +566,9 @@ void WebrtcTCPSocketTest::OnRead(nsTArray&& aReadData) { AppendReadData(aReadData.Elements(), aReadData.Length()); } -void WebrtcTCPSocketTest::OnConnected() { mOnConnectedCalled = true; } +void WebrtcTCPSocketTest::OnConnected(const nsCString& aProxyType) { + mOnConnectedCalled = true; +} void WebrtcTCPSocketTest::OnClose(nsresult aReason) { mOnCloseCalled = true; } @@ -614,7 +616,9 @@ void WebrtcTCPSocketTestCallback::OnClose(nsresult aReason) { mTest->OnClose(aReason); } -void WebrtcTCPSocketTestCallback::OnConnected() { mTest->OnConnected(); } +void WebrtcTCPSocketTestCallback::OnConnected(const nsCString& aProxyType) { + mTest->OnConnected(aProxyType); +} void WebrtcTCPSocketTestCallback::OnRead(nsTArray&& aReadData) { mTest->OnRead(std::move(aReadData));