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(); }
bool nsFileInputStream::Deserialize(const InputStreamParams& aParams, const FileDescriptorArray& aFileDescriptors) { NS_ASSERTION(!mFD, "Already have a file descriptor?!"); NS_ASSERTION(!mDeferredOpen, "Deferring open?!"); NS_ASSERTION(!mFile, "Should never have a file here!"); NS_ASSERTION(!mPerm, "This should always be 0!"); if (aParams.type() != InputStreamParams::TFileInputStreamParams) { NS_WARNING("Received unknown parameters from the other process!"); return false; } const FileInputStreamParams& params = aParams.get_FileInputStreamParams(); uint32_t fileDescriptorIndex = params.fileDescriptorIndex(); FileDescriptor fd; if (fileDescriptorIndex < aFileDescriptors.Length()) { fd = aFileDescriptors[fileDescriptorIndex]; NS_WARNING_ASSERTION(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; } mFD = fileDesc; } mBehaviorFlags = params.behaviorFlags(); if (!XRE_IsParentProcess()) { // A child process shouldn't close when it reads the end because it will // not be able to reopen the file later. mBehaviorFlags &= ~nsIFileInputStream::CLOSE_ON_EOF; // A child process will not be able to reopen the file so this flag is // meaningless. mBehaviorFlags &= ~nsIFileInputStream::REOPEN_ON_REWIND; } mIOFlags = params.ioFlags(); return true; }
UniquePtr<Transport> OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode) { auto rawFD = aFd.ClonePlatformHandle(); return MakeUnique<Transport>(rawFD.release(), aMode, nullptr); }