bool UDPSocketParent::RecvDataWithAddress(const InfallibleTArray<uint8_t>& aData, const mozilla::net::NetAddr& aAddr) { NS_ENSURE_TRUE(mSocket, true); NS_ASSERTION(mFilter, "No packet filter"); uint32_t count; nsresult rv; bool allowed; rv = mFilter->FilterPacket(&aAddr, aData.Elements(), aData.Length(), nsIUDPSocketFilter::SF_OUTGOING, &allowed); // Sending unallowed data, kill content. NS_ENSURE_SUCCESS(rv, false); NS_ENSURE_TRUE(allowed, false); rv = mSocket->SendWithAddress(&aAddr, aData.Elements(), aData.Length(), &count); mozilla::unused << PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onsent"), UDPSendResult(rv), NS_LITERAL_CSTRING("connected")); NS_ENSURE_SUCCESS(rv, true); NS_ENSURE_TRUE(count > 0, true); return true; }
void UDPSocketParent::Send(const InfallibleTArray<uint8_t>& aData, const UDPSocketAddr& aAddr) { nsresult rv; uint32_t count; switch(aAddr.type()) { case UDPSocketAddr::TUDPAddressInfo: { const UDPAddressInfo& addrInfo(aAddr.get_UDPAddressInfo()); rv = mSocket->Send(addrInfo.addr(), addrInfo.port(), aData.Elements(), aData.Length(), &count); break; } case UDPSocketAddr::TNetAddr: { const NetAddr& addr(aAddr.get_NetAddr()); rv = mSocket->SendWithAddress(&addr, aData.Elements(), aData.Length(), &count); break; } default: MOZ_ASSERT(false, "Invalid address type!"); return; } if (NS_WARN_IF(NS_FAILED(rv)) || count == 0) { FireInternalError(__LINE__); } }
bool UDPSocketParent::RecvData(const InfallibleTArray<uint8_t> &aData, const nsCString& aRemoteAddress, const uint16_t& aPort) { NS_ENSURE_TRUE(mSocket, true); NS_ASSERTION(mFilter, "No packet filter"); // TODO, Bug 933102, filter packets that are sent with hostname. // Until then we simply throw away packets that are sent to a hostname. return true; #if 0 // Enable this once we have filtering working with hostname delivery. uint32_t count; nsresult rv = mSocket->Send(aRemoteAddress, aPort, aData.Elements(), aData.Length(), &count); mozilla::unused << PUDPSocketParent::SendCallback(NS_LITERAL_CSTRING("onsent"), UDPSendResult(rv), NS_LITERAL_CSTRING("connected")); NS_ENSURE_SUCCESS(rv, true); NS_ENSURE_TRUE(count > 0, true); return true; #endif }
bool GMPStorageParent::RecvWrite(const nsCString& aRecordName, const InfallibleTArray<uint8_t>& aBytes) { LOGD(("%s::%s: %p record=%s", __CLASS__, __FUNCTION__, this, aRecordName.get())); if (mShutdown) { return true; } if (aBytes.Length() > GMP_MAX_RECORD_SIZE) { unused << SendWriteComplete(aRecordName, GMPQuotaExceededErr); return true; } PRFileDesc* fd = mFiles.Get(aRecordName); if (!fd) { unused << SendWriteComplete(aRecordName, GMPGenericErr); return true; } // Write operations overwrite the entire record. So re-open the file // in truncate mode, to clear its contents. PR_Close(fd); mFiles.Remove(aRecordName); if (NS_FAILED(OpenStorageFile(aRecordName, mOrigin, Truncate, &fd))) { unused << SendWriteComplete(aRecordName, GMPGenericErr); return true; } mFiles.Put(aRecordName, fd); int32_t bytesWritten = PR_Write(fd, aBytes.Elements(), aBytes.Length()); auto res = (bytesWritten == (int32_t)aBytes.Length()) ? GMPNoErr : GMPGenericErr; unused << SendWriteComplete(aRecordName, res); return true; }
nsresult nsLookAndFeel::CallRemoteGetSystemColors() { // An array has to be used to get data from remote process InfallibleTArray<PRUint32> colors; PRUint32 colorsCount = sizeof(AndroidSystemColors) / sizeof(nscolor); if (!ContentChild::GetSingleton()->SendGetSystemColors(colorsCount, &colors)) return NS_ERROR_FAILURE; NS_ASSERTION(colors.Length() == colorsCount, "System colors array is incomplete"); if (colors.Length() == 0) return NS_ERROR_FAILURE; if (colors.Length() < colorsCount) colorsCount = colors.Length(); // Array elements correspond to the members of mSystemColors structure, // so just copy the memory block memcpy(&mSystemColors, colors.Elements(), sizeof(nscolor) * colorsCount); mInitializedSystemColors = PR_TRUE; return NS_OK; }
bool UDPSocketChild::RecvCallbackReceivedData(const UDPAddressInfo& aAddressInfo, const InfallibleTArray<uint8_t>& aData) { nsresult rv = mSocket->CallListenerReceivedData(aAddressInfo.addr(), aAddressInfo.port(), aData.Elements(), aData.Length()); mozilla::unused << NS_WARN_IF(NS_FAILED(rv)); return true; }
bool GMPStorageChild::RecvReadComplete(const nsCString& aRecordName, const GMPErr& aStatus, const InfallibleTArray<uint8_t>& aBytes) { if (mShutdown) { return true; } nsRefPtr<GMPRecordImpl> record = GetRecord(aRecordName); if (!record) { // Not fatal. return true; } record->ReadComplete(aStatus, aBytes.Elements(), aBytes.Length()); return true; }
bool DeserializeArrayBuffer(JS::Handle<JSObject*> aObj, const InfallibleTArray<uint8_t>& aBuffer, JS::MutableHandle<JS::Value> aVal) { mozilla::AutoSafeJSContext cx; JSAutoCompartment ac(cx, aObj); JS::Rooted<JSObject*> obj(cx, JS_NewArrayBuffer(cx, aBuffer.Length())); if (!obj) return false; uint8_t* data = JS_GetArrayBufferData(obj); if (!data) return false; memcpy(data, aBuffer.Elements(), aBuffer.Length()); aVal.set(OBJECT_TO_JSVAL(obj)); return true; }
bool DeserializeArrayBuffer(JSContext* cx, const InfallibleTArray<uint8_t>& aBuffer, JS::MutableHandle<JS::Value> aVal) { mozilla::UniquePtr<uint8_t[], JS::FreePolicy> data(js_pod_malloc<uint8_t>(aBuffer.Length())); if (!data) return false; memcpy(data.get(), aBuffer.Elements(), aBuffer.Length()); JSObject* obj = JS_NewArrayBufferWithContents(cx, aBuffer.Length(), data.get()); if (!obj) return false; // If JS_NewArrayBufferWithContents returns non-null, the ownership of // the data is transfered to obj, so we release the ownership here. mozilla::Unused << data.release(); aVal.setObject(*obj); return true; }
static nsresult CallRemoteGetIconForExtension(const nsACString& aFileExt, uint32_t aIconSize, uint8_t * const aBuf) { NS_ENSURE_TRUE(aBuf != nullptr, NS_ERROR_NULL_POINTER); // An array has to be used to get data from remote process InfallibleTArray<uint8_t> bits; uint32_t bufSize = aIconSize * aIconSize * 4; if (!ContentChild::GetSingleton()->SendGetIconForExtension(PromiseFlatCString(aFileExt), aIconSize, &bits)) return NS_ERROR_FAILURE; NS_ASSERTION(bits.Length() == bufSize, "Pixels array is incomplete"); if (bits.Length() != bufSize) return NS_ERROR_FAILURE; memcpy(aBuf, bits.Elements(), bufSize); return NS_OK; }
bool GMPStorageChild::RecvReadComplete(const nsCString& aRecordName, const GMPErr& aStatus, const InfallibleTArray<uint8_t>& aBytes) { if (mShutdown) { return true; } nsRefPtr<GMPRecordImpl> record; if (!mRecords.Get(aRecordName, getter_AddRefs(record)) || !record) { // Not fatal. return true; } record->ReadComplete(aStatus, aBytes.Elements(), aBytes.Length()); if (GMP_FAILED(aStatus)) { Close(record); } return true; }
void TCPSocketParent::FireArrayBufferDataEvent(nsTArray<uint8_t>& aBuffer, TCPReadyState aReadyState) { InfallibleTArray<uint8_t> arr; arr.SwapElements(aBuffer); if (mFilter) { bool allowed; mozilla::net::NetAddr addr; nsresult nsrv = mFilter->FilterPacket(&addr, arr.Elements(), arr.Length(), nsISocketFilter::SF_INCOMING, &allowed); // receiving unallowed data, drop it. if (NS_WARN_IF(NS_FAILED(nsrv)) || !allowed) { TCPSOCKET_LOG(("%s: Dropping incoming TCP packet", __FUNCTION__)); return; } } SendableData data(arr); SendEvent(NS_LITERAL_STRING("data"), data, aReadyState); }