bool nsTemporaryFileInputStream::Deserialize(const InputStreamParams& aParams, const FileDescriptorArray& aFileDescriptors) { const TemporaryFileInputStreamParams& params = aParams.get_TemporaryFileInputStreamParams(); uint32_t fileDescriptorIndex = params.fileDescriptorIndex(); FileDescriptor fd; if (fileDescriptorIndex < aFileDescriptors.Length()) { fd = aFileDescriptors[fileDescriptorIndex]; NS_WARN_IF_FALSE(fd.IsValid(), "Received an invalid file descriptor!"); } else { NS_WARNING("Received a bad file descriptor index!"); } if (fd.IsValid()) { auto rawFD = fd.ClonePlatformHandle(); PRFileDesc* fileDesc = PR_ImportFile(PROsfd(rawFD.release())); if (!fileDesc) { NS_WARNING("Failed to import file handle!"); return false; } mFileDescOwner = new FileDescOwner(fileDesc); } else { mClosed = true; } mStartPos = mCurPos = params.startPos(); mEndPos = params.endPos(); return true; }
mozilla::ipc::IPCResult TemporaryIPCBlobParent::RecvOperationDone(const nsCString& aContentType, const FileDescriptor& aFD) { MOZ_ASSERT(mActive); mActive = false; // We have received a file descriptor because in this way we have kept the // file locked on windows during the IPC communication. After the creation of // the TemporaryFileBlobImpl, this prfile can be closed. auto rawFD = aFD.ClonePlatformHandle(); PRFileDesc* prfile = PR_ImportFile(PROsfd(rawFD.release())); // Let's create the BlobImpl. nsCOMPtr<nsIFile> file = Move(mFile); RefPtr<TemporaryFileBlobImpl> blobImpl = new TemporaryFileBlobImpl(file, NS_ConvertUTF8toUTF16(aContentType)); PR_Close(prfile); IPCBlob ipcBlob; nsresult rv = IPCBlobUtils::Serialize(blobImpl, Manager(), ipcBlob); if (NS_WARN_IF(NS_FAILED(rv))) { Unused << Send__delete__(this, NS_ERROR_FAILURE); return IPC_OK(); } Unused << Send__delete__(this, ipcBlob); return IPC_OK(); }
/* static */ already_AddRefed<FileDescriptorOutputStream> FileDescriptorOutputStream::Create( const ipc::FileDescriptor& fileDescriptor) { if (NS_WARN_IF(!fileDescriptor.IsValid())) return nullptr; auto rawFD = fileDescriptor.ClonePlatformHandle(); PRFileDesc* prfd = PR_ImportFile(PROsfd(rawFD.release())); if (NS_WARN_IF(!prfd)) return nullptr; RefPtr<FileDescriptorOutputStream> stream = new FileDescriptorOutputStream(prfd); return stream.forget(); }
/* static */ already_AddRefed<FileDescriptorOutputStream> FileDescriptorOutputStream::Create(const ipc::FileDescriptor& fileDescriptor) { if (NS_WARN_IF(!fileDescriptor.IsValid())) return nullptr; PRFileDesc* prfd = PR_ImportFile(PROsfd(fileDescriptor.PlatformHandle())); if (NS_WARN_IF(!prfd)) return nullptr; nsRefPtr<FileDescriptorOutputStream> stream = new FileDescriptorOutputStream(prfd); return stream.forget(); }
void RemotePrintJobChild::SetNextPageFD(const mozilla::ipc::FileDescriptor& aFd) { auto handle = aFd.ClonePlatformHandle(); mNextPageFD = PR_ImportFile(PROsfd(handle.release())); }