Exemplo n.º 1
0
void
ReadStream::Inner::Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv)
{
  MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread);
  MOZ_ASSERT(aReadStreamOut);

  if (mState != Open) {
    aRv.ThrowTypeError<MSG_CACHE_STREAM_CLOSED>();
    return;
  }

  MOZ_ASSERT(mControl);

  // If we are sending a ReadStream, then we never want to set the
  // pushStream actors at the same time.
  aReadStreamOut->pushStreamChild() = nullptr;
  aReadStreamOut->pushStreamParent() = nullptr;

  aReadStreamOut->id() = mId;
  mControl->SerializeControl(aReadStreamOut);

  AutoTArray<FileDescriptor, 4> fds;
  SerializeInputStream(mStream, aReadStreamOut->params(), fds);

  mControl->SerializeFds(aReadStreamOut, fds);

  // We're passing ownership across the IPC barrier with the control, so
  // do not signal that the stream is closed here.
  Forget();
}
Exemplo n.º 2
0
nsresult
SerializeInternal(BlobImpl* aBlobImpl, M* aManager, IPCBlob& aIPCBlob)
{
  MOZ_ASSERT(aBlobImpl);

  nsAutoString value;
  aBlobImpl->GetType(value);
  aIPCBlob.type() = value;

  ErrorResult rv;
  aIPCBlob.size() = aBlobImpl->GetSize(rv);
  if (NS_WARN_IF(rv.Failed())) {
    return rv.StealNSResult();
  }

  if (!aBlobImpl->IsFile()) {
    aIPCBlob.file() = void_t();
  } else {
    IPCFile file;

    aBlobImpl->GetName(value);
    file.name() = value;

    file.lastModified() = aBlobImpl->GetLastModified(rv) * PR_USEC_PER_MSEC;
    if (NS_WARN_IF(rv.Failed())) {
      return rv.StealNSResult();
    }

    aBlobImpl->GetDOMPath(value);
    file.DOMPath() = value;

    aBlobImpl->GetMozFullPathInternal(value, rv);
    if (NS_WARN_IF(rv.Failed())) {
      return rv.StealNSResult();
    }
    file.fullPath() = value;

    file.isDirectory() = aBlobImpl->IsDirectory();

    aIPCBlob.file() = file;
  }

  aIPCBlob.fileId() = aBlobImpl->GetFileId();

  nsCOMPtr<nsIInputStream> inputStream;
  aBlobImpl->CreateInputStream(getter_AddRefs(inputStream), rv);
  if (NS_WARN_IF(rv.Failed())) {
    return rv.StealNSResult();
  }

  rv = SerializeInputStream(inputStream, aIPCBlob.size(),
                            ChildIDFromManager(aManager), aIPCBlob, aManager);
  if (NS_WARN_IF(rv.Failed())) {
    return rv.StealNSResult();
  }

  return NS_OK;
}
Exemplo n.º 3
0
void
SerializeInputStream(nsIInputStream* aInputStream,
                     OptionalInputStreamParams& aParams,
                     nsTArray<FileDescriptor>& aFileDescriptors)
{
  if (aInputStream) {
    InputStreamParams params;
    SerializeInputStream(aInputStream, params, aFileDescriptors);
    aParams = params;
  }
  else {
    aParams = mozilla::void_t();
  }
}
Exemplo n.º 4
0
void
SerializeInputStream(nsIInputStream* aInputStream,
                     OptionalInputStreamParams& aParams)
{
  MOZ_ASSERT(NS_IsMainThread());

  if (aInputStream) {
    InputStreamParams params;
    SerializeInputStream(aInputStream, params);
    aParams = params;
  }
  else {
    aParams = mozilla::void_t();
  }
}
Exemplo n.º 5
0
BlobChild*
nsIContentChild::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
{
  MOZ_ASSERT(NS_IsMainThread());
  MOZ_ASSERT(aBlob);

  // If the blob represents a remote blob then we can simply pass its actor back
  // here.
  const auto* domFile = static_cast<DOMFile*>(aBlob);
  nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(domFile->Impl());
  if (remoteBlob) {
    BlobChild* actor = remoteBlob->GetBlobChild();
    MOZ_ASSERT(actor);

    if (actor->GetContentManager() == this) {
      return actor;
    }
  }

  // All blobs shared between processes must be immutable.
  nsCOMPtr<nsIMutable> mutableBlob = do_QueryInterface(aBlob);
  if (!mutableBlob || NS_FAILED(mutableBlob->SetMutable(false))) {
    NS_WARNING("Failed to make blob immutable!");
    return nullptr;
  }

#ifdef DEBUG
  {
    // XXX This is only safe so long as all blob implementations in our tree
    //     inherit DOMFileImplBase. If that ever changes then this will need to
    //     grow a real interface or something.
    const auto* blob = static_cast<DOMFileImplBase*>(domFile->Impl());

    MOZ_ASSERT(!blob->IsSizeUnknown());
    MOZ_ASSERT(!blob->IsDateUnknown());
  }
#endif

  ParentBlobConstructorParams params;

  nsString contentType;
  nsresult rv = aBlob->GetType(contentType);
  NS_ENSURE_SUCCESS(rv, nullptr);

  uint64_t length;
  rv = aBlob->GetSize(&length);
  NS_ENSURE_SUCCESS(rv, nullptr);

  nsCOMPtr<nsIInputStream> stream;
  rv = aBlob->GetInternalStream(getter_AddRefs(stream));
  NS_ENSURE_SUCCESS(rv, nullptr);

  InputStreamParams inputStreamParams;
  nsTArray<mozilla::ipc::FileDescriptor> fds;
  SerializeInputStream(stream, inputStreamParams, fds);

  MOZ_ASSERT(fds.IsEmpty());

  params.optionalInputStreamParams() = inputStreamParams;

  nsCOMPtr<nsIDOMFile> file = do_QueryInterface(aBlob);
  if (file) {
    FileBlobConstructorParams fileParams;

    rv = file->GetName(fileParams.name());
    NS_ENSURE_SUCCESS(rv, nullptr);

    rv = file->GetMozLastModifiedDate(&fileParams.modDate());
    NS_ENSURE_SUCCESS(rv, nullptr);

    fileParams.contentType() = contentType;
    fileParams.length() = length;

    params.blobParams() = fileParams;
  } else {
    NormalBlobConstructorParams blobParams;
    blobParams.contentType() = contentType;
    blobParams.length() = length;
    params.blobParams() = blobParams;
  }

  BlobChild* actor = BlobChild::Create(this, aBlob);
  NS_ENSURE_TRUE(actor, nullptr);

  return SendPBlobConstructor(actor, params) ? actor : nullptr;
}