From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../webrtc/transport/ipc/WebrtcTCPSocketParent.cpp | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 dom/media/webrtc/transport/ipc/WebrtcTCPSocketParent.cpp (limited to 'dom/media/webrtc/transport/ipc/WebrtcTCPSocketParent.cpp') diff --git a/dom/media/webrtc/transport/ipc/WebrtcTCPSocketParent.cpp b/dom/media/webrtc/transport/ipc/WebrtcTCPSocketParent.cpp new file mode 100644 index 0000000000..0df8962757 --- /dev/null +++ b/dom/media/webrtc/transport/ipc/WebrtcTCPSocketParent.cpp @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=8 et tw=80 ft=cpp : */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "WebrtcTCPSocketParent.h" + +#include "mozilla/net/NeckoParent.h" + +#include "WebrtcTCPSocket.h" +#include "WebrtcTCPSocketLog.h" + +using namespace mozilla::dom; +using namespace mozilla::ipc; + +namespace mozilla::net { + +mozilla::ipc::IPCResult WebrtcTCPSocketParent::RecvAsyncOpen( + const nsACString& aHost, const int& aPort, const nsACString& aLocalAddress, + const int& aLocalPort, const bool& aUseTls, + const Maybe& aProxyConfig) { + LOG(("WebrtcTCPSocketParent::RecvAsyncOpen %p to %s:%d\n", this, + PromiseFlatCString(aHost).get(), aPort)); + + MOZ_ASSERT(mChannel, "webrtc TCP socket should be non-null"); + if (!mChannel) { + return IPC_FAIL(this, "Called with null channel."); + } + + mChannel->Open(aHost, aPort, aLocalAddress, aLocalPort, aUseTls, + aProxyConfig); + + return IPC_OK(); +} + +mozilla::ipc::IPCResult WebrtcTCPSocketParent::RecvWrite( + nsTArray&& aWriteData) { + LOG(("WebrtcTCPSocketParent::RecvWrite %p for %zu\n", this, + aWriteData.Length())); + + // Need to check this here in case there are Writes in the queue after OnClose + if (mChannel) { + mChannel->Write(std::move(aWriteData)); + } + + return IPC_OK(); +} + +mozilla::ipc::IPCResult WebrtcTCPSocketParent::RecvClose() { + LOG(("WebrtcTCPSocketParent::RecvClose %p\n", this)); + + CleanupChannel(); + + IProtocol* mgr = Manager(); + if (!Send__delete__(this)) { + return IPC_FAIL_NO_REASON(mgr); + } + + return IPC_OK(); +} + +void WebrtcTCPSocketParent::ActorDestroy(ActorDestroyReason aWhy) { + LOG(("WebrtcTCPSocketParent::ActorDestroy %p for %d\n", this, aWhy)); + + CleanupChannel(); +} + +WebrtcTCPSocketParent::WebrtcTCPSocketParent(const Maybe& aTabId) { + MOZ_COUNT_CTOR(WebrtcTCPSocketParent); + + LOG(("WebrtcTCPSocketParent::WebrtcTCPSocketParent %p\n", this)); + + mChannel = new WebrtcTCPSocket(this); + if (aTabId.isSome()) { + mChannel->SetTabId(*aTabId); + } +} + +WebrtcTCPSocketParent::~WebrtcTCPSocketParent() { + MOZ_COUNT_DTOR(WebrtcTCPSocketParent); + + LOG(("WebrtcTCPSocketParent::~WebrtcTCPSocketParent %p\n", this)); + + CleanupChannel(); +} + +// WebrtcTCPSocketCallback +void WebrtcTCPSocketParent::OnClose(nsresult aReason) { + LOG(("WebrtcTCPSocketParent::OnClose %p\n", this)); + + if (mChannel) { + Unused << SendOnClose(aReason); + } + + CleanupChannel(); +} + +void WebrtcTCPSocketParent::OnRead(nsTArray&& aReadData) { + LOG(("WebrtcTCPSocketParent::OnRead %p %zu\n", this, aReadData.Length())); + + if (mChannel && !SendOnRead(std::move(aReadData))) { + CleanupChannel(); + } +} + +void WebrtcTCPSocketParent::OnConnected(const nsACString& aProxyType) { + LOG(("WebrtcTCPSocketParent::OnConnected %p\n", this)); + + if (mChannel && !SendOnConnected(aProxyType)) { + CleanupChannel(); + } +} + +void WebrtcTCPSocketParent::CleanupChannel() { + if (mChannel) { + mChannel->Close(); + mChannel = nullptr; + } +} + +} // namespace mozilla::net -- cgit v1.2.3