Bug 1359172 - RemoteInputStream must create a correct inputStream when used and sliced in a separate process, r=smaug

This commit is contained in:
Andrea Marchesini 2017-04-25 14:07:31 +02:00
Родитель 4c39212973
Коммит 74d79c82a7
1 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

@ -50,6 +50,7 @@
#include "nsStringStream.h" #include "nsStringStream.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
#include "SlicedInputStream.h"
#include "StreamBlobImpl.h" #include "StreamBlobImpl.h"
#include "WorkerPrivate.h" #include "WorkerPrivate.h"
#include "WorkerRunnable.h" #include "WorkerRunnable.h"
@ -2765,19 +2766,44 @@ CreateStreamHelper::GetStream(nsIInputStream** aInputStream)
MOZ_ASSERT(baseRemoteBlobImpl); MOZ_ASSERT(baseRemoteBlobImpl);
if (EventTargetIsOnCurrentThread(baseRemoteBlobImpl->GetActorEventTarget())) { if (EventTargetIsOnCurrentThread(baseRemoteBlobImpl->GetActorEventTarget())) {
// RunInternal will populate mInputStream using the correct mStart/mLength
// value.
RunInternal(baseRemoteBlobImpl, false); RunInternal(baseRemoteBlobImpl, false);
} else if (PBackgroundChild* manager = mozilla::ipc::BackgroundChild::GetForCurrentThread()) { } else if (PBackgroundChild* manager = mozilla::ipc::BackgroundChild::GetForCurrentThread()) {
// In case we are on a PBackground thread and this is not the owning thread,
// we need to create a new actor here. This actor must be created for the
// baseRemoteBlobImpl, which can be the mRemoteBlobImpl or the parent one,
// in case we are dealing with a sliced blob.
BlobChild* blobChild = BlobChild::GetOrCreate(manager, baseRemoteBlobImpl); BlobChild* blobChild = BlobChild::GetOrCreate(manager, baseRemoteBlobImpl);
MOZ_ASSERT(blobChild); MOZ_ASSERT(blobChild);
RefPtr<BlobImpl> blobImpl = blobChild->GetBlobImpl(); // Note that baseBlobImpl is generated by the actor, and the actor is
MOZ_ASSERT(blobImpl); // created from the baseRemoteBlobImpl. This means that baseBlobImpl is the
// remote blobImpl on PBackground of baseRemoteBlobImpl.
RefPtr<BlobImpl> baseBlobImpl = blobChild->GetBlobImpl();
MOZ_ASSERT(baseBlobImpl);
ErrorResult rv; ErrorResult rv;
blobImpl->GetInternalStream(aInputStream, rv); nsCOMPtr<nsIInputStream> baseInputStream;
baseBlobImpl->GetInternalStream(getter_AddRefs(baseInputStream), rv);
if (NS_WARN_IF(rv.Failed())) {
return rv.StealNSResult();
}
// baseInputStream is the stream of the baseRemoteBlobImpl. If
// mRemoteBlobImpl is a slice of baseRemoteBlobImpl, here we need to slice
// baseInputStream.
if (mRemoteBlobImpl->IsSlice()) {
RefPtr<SlicedInputStream> slicedInputStream =
new SlicedInputStream(baseInputStream, mStart, mLength);
slicedInputStream.forget(aInputStream);
} else {
baseInputStream.forget(aInputStream);
}
mRemoteBlobImpl = nullptr; mRemoteBlobImpl = nullptr;
mDone = true; mDone = true;
return rv.StealNSResult(); return NS_OK;
} else { } else {
nsresult rv = baseRemoteBlobImpl->DispatchToTarget(this); nsresult rv = baseRemoteBlobImpl->DispatchToTarget(this);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {