зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1381748 - Cleanup FetchConsumer workflow - part 1 - no mBody, r=catalinb
This commit is contained in:
Родитель
3bacd995dc
Коммит
cad3905562
|
@ -316,6 +316,15 @@ FetchBodyConsumer<Derived>::Create(nsIGlobalObject* aGlobal,
|
|||
MOZ_ASSERT(aBody);
|
||||
MOZ_ASSERT(aMainThreadEventTarget);
|
||||
|
||||
nsCOMPtr<nsIInputStream> bodyStream;
|
||||
aBody->DerivedClass()->GetBody(getter_AddRefs(bodyStream));
|
||||
if (!bodyStream) {
|
||||
aRv = NS_NewCStringInputStream(getter_AddRefs(bodyStream), EmptyCString());
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
|
@ -329,7 +338,8 @@ FetchBodyConsumer<Derived>::Create(nsIGlobalObject* aGlobal,
|
|||
|
||||
RefPtr<FetchBodyConsumer<Derived>> consumer =
|
||||
new FetchBodyConsumer<Derived>(aMainThreadEventTarget, aGlobal,
|
||||
workerPrivate, aBody, promise, aType);
|
||||
workerPrivate, aBody, bodyStream, promise,
|
||||
aType);
|
||||
|
||||
if (!NS_IsMainThread()) {
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
|
@ -380,7 +390,10 @@ FetchBodyConsumer<Derived>::ReleaseObject()
|
|||
|
||||
mGlobal = nullptr;
|
||||
mWorkerHolder = nullptr;
|
||||
|
||||
#ifdef DEBUG
|
||||
mBody = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
|
@ -388,11 +401,16 @@ FetchBodyConsumer<Derived>::FetchBodyConsumer(nsIEventTarget* aMainThreadEventTa
|
|||
nsIGlobalObject* aGlobalObject,
|
||||
WorkerPrivate* aWorkerPrivate,
|
||||
FetchBody<Derived>* aBody,
|
||||
nsIInputStream* aBodyStream,
|
||||
Promise* aPromise,
|
||||
FetchConsumeType aType)
|
||||
: mTargetThread(NS_GetCurrentThread())
|
||||
, mMainThreadEventTarget(aMainThreadEventTarget)
|
||||
#ifdef DEBUG
|
||||
, mBody(aBody)
|
||||
#endif
|
||||
, mBodyStream(aBodyStream)
|
||||
, mBlobStorageType(MutableBlobStorage::eOnlyInMemory)
|
||||
, mGlobal(aGlobalObject)
|
||||
, mWorkerPrivate(aWorkerPrivate)
|
||||
, mConsumeType(aType)
|
||||
|
@ -402,7 +420,21 @@ FetchBodyConsumer<Derived>::FetchBodyConsumer(nsIEventTarget* aMainThreadEventTa
|
|||
{
|
||||
MOZ_ASSERT(aMainThreadEventTarget);
|
||||
MOZ_ASSERT(aBody);
|
||||
MOZ_ASSERT(aBodyStream);
|
||||
MOZ_ASSERT(aPromise);
|
||||
|
||||
const mozilla::UniquePtr<mozilla::ipc::PrincipalInfo>& principalInfo =
|
||||
aBody->DerivedClass()->GetPrincipalInfo();
|
||||
// We support temporary file for blobs only if the principal is known and
|
||||
// it's system or content not in private Browsing.
|
||||
if (principalInfo &&
|
||||
(principalInfo->type() == mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo ||
|
||||
(principalInfo->type() == mozilla::ipc::PrincipalInfo::TContentPrincipalInfo &&
|
||||
principalInfo->get_ContentPrincipalInfo().attrs().mPrivateBrowsingId == 0))) {
|
||||
mBlobStorageType = MutableBlobStorage::eCouldBeInTemporaryFile;
|
||||
}
|
||||
|
||||
mBodyMimeType = aBody->MimeType();
|
||||
}
|
||||
|
||||
template <class Derived>
|
||||
|
@ -454,20 +486,10 @@ FetchBodyConsumer<Derived>::BeginConsumeBodyMainThread()
|
|||
|
||||
AutoFailConsumeBody<Derived> autoReject(this);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
mBody->DerivedClass()->GetBody(getter_AddRefs(stream));
|
||||
if (!stream) {
|
||||
rv = NS_NewCStringInputStream(getter_AddRefs(stream), EmptyCString());
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStreamPump> pump;
|
||||
rv = NS_NewInputStreamPump(getter_AddRefs(pump),
|
||||
stream, -1, -1, 0, 0, false,
|
||||
mMainThreadEventTarget);
|
||||
nsresult rv = NS_NewInputStreamPump(getter_AddRefs(pump),
|
||||
mBodyStream, -1, -1, 0, 0, false,
|
||||
mMainThreadEventTarget);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return;
|
||||
}
|
||||
|
@ -477,22 +499,9 @@ FetchBodyConsumer<Derived>::BeginConsumeBodyMainThread()
|
|||
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
if (mConsumeType == CONSUME_BLOB) {
|
||||
MutableBlobStorage::MutableBlobStorageType type =
|
||||
MutableBlobStorage::eOnlyInMemory;
|
||||
|
||||
const mozilla::UniquePtr<mozilla::ipc::PrincipalInfo>& principalInfo =
|
||||
mBody->DerivedClass()->GetPrincipalInfo();
|
||||
// We support temporary file for blobs only if the principal is known and
|
||||
// it's system or content not in private Browsing.
|
||||
if (principalInfo &&
|
||||
(principalInfo->type() == mozilla::ipc::PrincipalInfo::TSystemPrincipalInfo ||
|
||||
(principalInfo->type() == mozilla::ipc::PrincipalInfo::TContentPrincipalInfo &&
|
||||
principalInfo->get_ContentPrincipalInfo().attrs().mPrivateBrowsingId == 0))) {
|
||||
type = MutableBlobStorage::eCouldBeInTemporaryFile;
|
||||
}
|
||||
|
||||
listener = new MutableBlobStreamListener(type, nullptr, mBody->MimeType(),
|
||||
p, mMainThreadEventTarget);
|
||||
listener = new MutableBlobStreamListener(mBlobStorageType, nullptr,
|
||||
mBodyMimeType, p,
|
||||
mMainThreadEventTarget);
|
||||
} else {
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), p);
|
||||
|
@ -573,7 +582,7 @@ FetchBodyConsumer<Derived>::ContinueConsumeBody(nsresult aStatus,
|
|||
MOZ_ASSERT(aResult);
|
||||
|
||||
AutoJSAPI jsapi;
|
||||
if (!jsapi.Init(mBody->DerivedClass()->GetParentObject())) {
|
||||
if (!jsapi.Init(mGlobal)) {
|
||||
localPromise->MaybeReject(NS_ERROR_UNEXPECTED);
|
||||
return;
|
||||
}
|
||||
|
@ -607,8 +616,7 @@ FetchBodyConsumer<Derived>::ContinueConsumeBody(nsresult aStatus,
|
|||
aResult = nullptr;
|
||||
|
||||
RefPtr<dom::FormData> fd =
|
||||
BodyUtil::ConsumeFormData(mBody->DerivedClass()->GetParentObject(),
|
||||
mBody->MimeType(), data, error);
|
||||
BodyUtil::ConsumeFormData(mGlobal, mBodyMimeType, data, error);
|
||||
if (!error.Failed()) {
|
||||
localPromise->MaybeResolve(fd);
|
||||
}
|
||||
|
@ -663,8 +671,7 @@ FetchBodyConsumer<Derived>::ContinueConsumeBlobBody(BlobImpl* aBlobImpl)
|
|||
// Release the pump.
|
||||
ShutDownMainThreadConsuming();
|
||||
|
||||
RefPtr<dom::Blob> blob =
|
||||
dom::Blob::Create(mBody->DerivedClass()->GetParentObject(), aBlobImpl);
|
||||
RefPtr<dom::Blob> blob = dom::Blob::Create(mGlobal, aBlobImpl);
|
||||
MOZ_ASSERT(blob);
|
||||
|
||||
localPromise->MaybeResolve(blob);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_dom_FetchConsumer_h
|
||||
|
||||
#include "Fetch.h"
|
||||
#include "mozilla/dom/MutableBlobStorage.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
|
@ -46,12 +47,6 @@ public:
|
|||
void
|
||||
ReleaseObject();
|
||||
|
||||
FetchBody<Derived>*
|
||||
Body() const
|
||||
{
|
||||
return mBody;
|
||||
}
|
||||
|
||||
void
|
||||
BeginConsumeBodyMainThread();
|
||||
|
||||
|
@ -81,6 +76,7 @@ private:
|
|||
nsIGlobalObject* aGlobalObject,
|
||||
workers::WorkerPrivate* aWorkerPrivate,
|
||||
FetchBody<Derived>* aBody,
|
||||
nsIInputStream* aBodyStream,
|
||||
Promise* aPromise,
|
||||
FetchConsumeType aType);
|
||||
|
||||
|
@ -94,7 +90,15 @@ private:
|
|||
|
||||
nsCOMPtr<nsIThread> mTargetThread;
|
||||
nsCOMPtr<nsIEventTarget> mMainThreadEventTarget;
|
||||
|
||||
#ifdef DEBUG
|
||||
// This is used only to check if the body has been correctly consumed.
|
||||
RefPtr<FetchBody<Derived>> mBody;
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIInputStream> mBodyStream;
|
||||
MutableBlobStorage::MutableBlobStorageType mBlobStorageType;
|
||||
nsCString mBodyMimeType;
|
||||
|
||||
// Set when consuming the body is attempted on a worker.
|
||||
// Unset when consumption is done/aborted.
|
||||
|
|
Загрузка…
Ссылка в новой задаче