bool TCPSocketParent::RecvData(const SendableData& aData, const uint32_t& aTrackingNumber) { ErrorResult rv; switch (aData.type()) { case SendableData::TArrayOfuint8_t: { AutoSafeJSContext autoCx; JS::Rooted<JS::Value> val(autoCx); const nsTArray<uint8_t>& buffer = aData.get_ArrayOfuint8_t(); bool ok = IPC::DeserializeArrayBuffer(autoCx, buffer, &val); NS_ENSURE_TRUE(ok, true); RootedTypedArray<ArrayBuffer> data(autoCx); data.Init(&val.toObject()); Optional<uint32_t> byteLength(buffer.Length()); mSocket->SendWithTrackingNumber(autoCx, data, 0, byteLength, aTrackingNumber, rv); break; } case SendableData::TnsCString: { const nsCString& strData = aData.get_nsCString(); mSocket->SendWithTrackingNumber(strData, aTrackingNumber, rv); break; } default: MOZ_CRASH("unexpected SendableData type"); } NS_ENSURE_FALSE(rv.Failed(), true); return true; }
bool TCPSocketParent::RecvData(const SendableData& aData, const uint32_t& aTrackingNumber) { ErrorResult rv; if (mFilter) { mozilla::net::NetAddr addr; // dummy value bool allowed; MOZ_ASSERT(aData.type() == SendableData::TArrayOfuint8_t, "Unsupported data type for filtering"); const InfallibleTArray<uint8_t>& data(aData.get_ArrayOfuint8_t()); nsresult nsrv = mFilter->FilterPacket(&addr, data.Elements(), data.Length(), nsISocketFilter::SF_OUTGOING, &allowed); // Reject sending of unallowed data if (NS_WARN_IF(NS_FAILED(nsrv)) || !allowed) { TCPSOCKET_LOG(("%s: Dropping outgoing TCP packet", __FUNCTION__)); return false; } } switch (aData.type()) { case SendableData::TArrayOfuint8_t: { AutoSafeJSContext autoCx; JS::Rooted<JS::Value> val(autoCx); const nsTArray<uint8_t>& buffer = aData.get_ArrayOfuint8_t(); bool ok = IPC::DeserializeArrayBuffer(autoCx, buffer, &val); NS_ENSURE_TRUE(ok, true); RootedTypedArray<ArrayBuffer> data(autoCx); data.Init(&val.toObject()); Optional<uint32_t> byteLength(buffer.Length()); mSocket->SendWithTrackingNumber(autoCx, data, 0, byteLength, aTrackingNumber, rv); break; } case SendableData::TnsCString: { const nsCString& strData = aData.get_nsCString(); mSocket->SendWithTrackingNumber(strData, aTrackingNumber, rv); break; } default: MOZ_CRASH("unexpected SendableData type"); } NS_ENSURE_SUCCESS(rv.StealNSResult(), true); return true; }