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;
}
예제 #2
0
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;
}
예제 #3
0
mozilla::ipc::IPCResult
PDFiumChild::RecvConvertToEMF(const FileDescriptor& aFD,
                              const int& aPageWidth,
                              const int& aPageHeight)
{
  MOZ_ASSERT(aFD.IsValid() && aPageWidth != 0 && aPageHeight != 0);

  ipc::Shmem smem;
  PDFViaEMFPrintHelper convertor;
  if (NS_FAILED(convertor.OpenDocument(aFD))) {
    Unused << SendConvertToEMFDone(NS_ERROR_FAILURE, smem);
    return IPC_OK();
  }

  MOZ_ASSERT(convertor.GetPageCount() == 1, "we assume each given PDF contains"                                        "one page only");

  if (!convertor.SavePageToBuffer(0, aPageWidth, aPageHeight, smem, this)) {
    Unused << SendConvertToEMFDone(NS_ERROR_FAILURE, smem);
    return IPC_OK();
  }

  if (!smem.IsReadable()) {
    Unused << SendConvertToEMFDone(NS_ERROR_FAILURE, smem);
    return IPC_OK();
  }

  Unused << SendConvertToEMFDone(NS_OK, smem);
  return IPC_OK();
}
GeckoExistingProcessHost::
GeckoExistingProcessHost(GeckoProcessType aProcessType,
                         base::ProcessHandle aProcess,
                         const FileDescriptor& aFileDescriptor,
                         ChildPrivileges aPrivileges)
  : GeckoChildProcessHost(aProcessType, aPrivileges)
  , mExistingProcessHandle(aProcess)
  , mExistingFileDescriptor(aFileDescriptor)
{
  NS_ASSERTION(aFileDescriptor.IsValid(),
               "Expected file descriptor to be valid");
}
예제 #5
0
CloseFileRunnable::CloseFileRunnable(const FileDescriptor& aFileDescriptor)
: mFileDescriptor(aFileDescriptor)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aFileDescriptor.IsValid());
}