Files
palemoon27/dom/network/TCPServerSocketParent.cpp
T
roytam1 fc9fb8b315 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1240411: P6. Clean up OMX headers. r=ayang (114a1df4be)
- Bug 1230385, part 1 - Use MOZ_CRASH in ContentChild::AllocP*() methods. r=billm (6f8016bb29)
- Bug 1230385, part 2 - Use NS_WARNING in unimplemented TabChild methods. r=billm (28a7165773)
- Bug 1234026 - Pass a --display option to gtk_init in content processes. r=karlt (8e3e17858e)
- Bug 1218816 - Remove useless semicolons. Found by coccinelle. r=Ehsan (e029c51e58)
- Bug 1240796 - Implement Uint32x4 <==> Float32x4 conversions. r=sunfish (5a42f571ea)
- Bug 1240796 - Implement unsigned SIMD compares. r=sunfish (93d4979730)
- Bug 1240796 - Implement Uint32x4 extractLane in Ion. r=nbp (b5b7c782b6)
- Bug 1240796 - Add Uint32x4 support to jit-test/lib/simd.js. r=bbouvier (187cbbb1d0)
- Bug 1245547 - Implement RSimdBox for Uint32x4. r=nbp (0186f0355f)
- Bug 1244254 - Move SimdTypeToMIRType into the header. r=nbp (5b15375c4e)
- Bug 1217236 - Block trackers loaded by Flash movies. r=gcp (a1318a33da)
- Bug 1237402 - Allow certain plugins to be loaded in parent process (r=jimm) (e951737778)
- Bug 1172304 - Fix to handle short read in Plugin code. r=johns (625dadd61b)
- Bug 377630 - Preventing filename disclosure, by putting downloaded files in a private directory. r=bz (5aca752a5c)
- Bug 579517 follow-up: Remove NSPR types that crept in (c7cb9ffc11)
- Bug 1245724 - Make plugin network requests bypass service worker interception. r=ehsan (a0b7fab3ee)
- Please enter the commit message for your chang Bug 1244254 - Pass a SimdType to inlineSimd(). r=nbp (6fcacd3c5d)
- Bug 1244254 - Add IonBuilder::unboxSimd(). r=nbp (d5f0922fd9)
- Bug 1244254 - Check SIMD arguments in IonBuilder. r=nbp (832d38940f)
- Bug 1244254 - Replace MaybeSimdUnbox with assertions. r=nbp (9c2ad4a8c5)
- Bug 1244254 - Add SimdType to MSimdBox and MSimdUnbox. r=nbp (74412371f5)
- Bug 1238003 - Part 1: Add BooleanPolicy. r=jandem (79c1716cac)
- Bug 1238003 - Part 2: Use Policy in RegExpMatcher and RegExpTester. r=jandem (a2ef8feec4)
- Bug 1238003 - Part 3: Add test for Policy in RegExpMatcher and RegExpTester. r=jandem (1653bec783)
- Bug 1244254 - Simplify MSimd* constructors. r=nbp (0ab2efcb4c)
- Bug 1244889 - Remove trivial SIMD NewAsmJS factories. r=bbouvier (2f9c41713c)
- Bug 1244828 - Ensure enough ballast space in CallPolicy::adjustInputs. r=bbouvier (d84dae2175)
- Bug 1244828 - Ensure enough ballast space in AllDoublePolicy::adjustInputs. r=bbouvier (361092db86)
- Bug 1245421: Remove dead function CoercesToDouble; r=h4writer (502b9efcee)
2023-09-11 09:34:11 +08:00

165 lines
4.0 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 "nsIScriptSecurityManager.h"
#include "TCPServerSocket.h"
#include "TCPServerSocketParent.h"
#include "nsJSUtils.h"
#include "TCPSocketParent.h"
#include "mozilla/unused.h"
#include "mozilla/AppProcessChecker.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/TabParent.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION(TCPServerSocketParent, mServerSocket)
NS_IMPL_CYCLE_COLLECTING_ADDREF(TCPServerSocketParent)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TCPServerSocketParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TCPServerSocketParent)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
void
TCPServerSocketParent::ReleaseIPDLReference()
{
MOZ_ASSERT(mIPCOpen);
mIPCOpen = false;
this->Release();
}
void
TCPServerSocketParent::AddIPDLReference()
{
MOZ_ASSERT(!mIPCOpen);
mIPCOpen = true;
this->AddRef();
}
TCPServerSocketParent::TCPServerSocketParent(PNeckoParent* neckoParent,
uint16_t aLocalPort,
uint16_t aBacklog,
bool aUseArrayBuffers)
: mNeckoParent(neckoParent)
, mIPCOpen(false)
{
mServerSocket = new TCPServerSocket(nullptr, aLocalPort, aUseArrayBuffers, aBacklog);
mServerSocket->SetServerBridgeParent(this);
}
TCPServerSocketParent::~TCPServerSocketParent()
{
}
void
TCPServerSocketParent::Init()
{
NS_ENSURE_SUCCESS_VOID(mServerSocket->Init());
}
uint32_t
TCPServerSocketParent::GetAppId()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->OwnAppId();
} else {
return nsIScriptSecurityManager::UNKNOWN_APP_ID;
}
}
bool
TCPServerSocketParent::GetInBrowser()
{
const PContentParent *content = Manager()->Manager();
if (PBrowserParent* browser = SingleManagedOrNull(content->ManagedPBrowserParent())) {
TabParent *tab = TabParent::GetFrom(browser);
return tab->IsBrowserElement();
} else {
return false;
}
}
nsresult
TCPServerSocketParent::SendCallbackAccept(TCPSocketParent *socket)
{
socket->AddIPDLReference();
nsresult rv;
nsString host;
rv = socket->GetHost(host);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to get host from nsITCPSocketParent");
return NS_ERROR_FAILURE;
}
uint16_t port;
rv = socket->GetPort(&port);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to get port from nsITCPSocketParent");
return NS_ERROR_FAILURE;
}
if (mNeckoParent) {
if (mNeckoParent->SendPTCPSocketConstructor(socket, host, port)) {
mozilla::Unused << PTCPServerSocketParent::SendCallbackAccept(socket);
}
else {
NS_ERROR("Sending data from PTCPSocketParent was failed.");
}
}
else {
NS_ERROR("The member value for NeckoParent is wrong.");
}
return NS_OK;
}
bool
TCPServerSocketParent::RecvClose()
{
NS_ENSURE_TRUE(mServerSocket, true);
mServerSocket->Close();
return true;
}
void
TCPServerSocketParent::ActorDestroy(ActorDestroyReason why)
{
if (mServerSocket) {
mServerSocket->Close();
mServerSocket = nullptr;
}
mNeckoParent = nullptr;
}
bool
TCPServerSocketParent::RecvRequestDelete()
{
mozilla::Unused << Send__delete__(this);
return true;
}
void
TCPServerSocketParent::OnConnect(TCPServerSocketEvent* event)
{
RefPtr<TCPSocket> socket = event->Socket();
socket->SetAppIdAndBrowser(GetAppId(), GetInBrowser());
RefPtr<TCPSocketParent> socketParent = new TCPSocketParent();
socketParent->SetSocket(socket);
socket->SetSocketBridgeParent(socketParent);
SendCallbackAccept(socketParent);
}
} // namespace dom
} // namespace mozilla