Bug 1043843 - Avoid accessing nsIDOMBlob from worker thread. r=dhylands
This commit is contained in:
@@ -31,15 +31,18 @@ CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem,
|
|||||||
ErrorResult& aRv)
|
ErrorResult& aRv)
|
||||||
: FileSystemTaskBase(aFileSystem)
|
: FileSystemTaskBase(aFileSystem)
|
||||||
, mTargetRealPath(aPath)
|
, mTargetRealPath(aPath)
|
||||||
, mBlobData(aBlobData)
|
|
||||||
, mReplace(replace)
|
, mReplace(replace)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
||||||
MOZ_ASSERT(aFileSystem);
|
MOZ_ASSERT(aFileSystem);
|
||||||
GetOutputBufferSize();
|
GetOutputBufferSize();
|
||||||
if (mBlobData) {
|
if (aBlobData) {
|
||||||
nsresult rv = mBlobData->GetInternalStream(getter_AddRefs(mBlobStream));
|
if (FileSystemUtils::IsParentProcess()) {
|
||||||
NS_WARN_IF(NS_FAILED(rv));
|
nsresult rv = aBlobData->GetInternalStream(getter_AddRefs(mBlobStream));
|
||||||
|
NS_WARN_IF(NS_FAILED(rv));
|
||||||
|
} else {
|
||||||
|
mBlobData = aBlobData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mArrayData.SwapElements(aArrayData);
|
mArrayData.SwapElements(aArrayData);
|
||||||
nsCOMPtr<nsIGlobalObject> globalObject =
|
nsCOMPtr<nsIGlobalObject> globalObject =
|
||||||
@@ -74,16 +77,17 @@ CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data));
|
BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data));
|
||||||
mBlobData = bp->GetBlob();
|
nsCOMPtr<nsIDOMBlob> blobData = bp->GetBlob();
|
||||||
MOZ_ASSERT(mBlobData, "mBlobData should not be null.");
|
MOZ_ASSERT(blobData, "blobData should not be null.");
|
||||||
nsresult rv = mBlobData->GetInternalStream(getter_AddRefs(mBlobStream));
|
nsresult rv = blobData->GetInternalStream(getter_AddRefs(mBlobStream));
|
||||||
NS_WARN_IF(NS_FAILED(rv));
|
NS_WARN_IF(NS_FAILED(rv));
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateFileTask::~CreateFileTask()
|
CreateFileTask::~CreateFileTask()
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(!mPromise || NS_IsMainThread(),
|
MOZ_ASSERT((!mPromise && !mBlobData) || NS_IsMainThread(),
|
||||||
"mPromise should be released on main thread!");
|
"mPromise and mBlobData should be released on main thread!");
|
||||||
|
|
||||||
if (mBlobStream) {
|
if (mBlobStream) {
|
||||||
mBlobStream->Close();
|
mBlobStream->Close();
|
||||||
}
|
}
|
||||||
@@ -283,6 +287,7 @@ CreateFileTask::HandlerCallback()
|
|||||||
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
|
||||||
if (mFileSystem->IsShutdown()) {
|
if (mFileSystem->IsShutdown()) {
|
||||||
mPromise = nullptr;
|
mPromise = nullptr;
|
||||||
|
mBlobData = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,12 +296,14 @@ CreateFileTask::HandlerCallback()
|
|||||||
mErrorValue);
|
mErrorValue);
|
||||||
mPromise->MaybeRejectBrokenly(domError);
|
mPromise->MaybeRejectBrokenly(domError);
|
||||||
mPromise = nullptr;
|
mPromise = nullptr;
|
||||||
|
mBlobData = nullptr;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMFile> file = new DOMFile(mTargetFileImpl);
|
nsCOMPtr<nsIDOMFile> file = new DOMFile(mTargetFileImpl);
|
||||||
mPromise->MaybeResolve(file);
|
mPromise->MaybeResolve(file);
|
||||||
mPromise = nullptr;
|
mPromise = nullptr;
|
||||||
|
mBlobData = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -66,7 +66,10 @@ private:
|
|||||||
static uint32_t sOutputBufferSize;
|
static uint32_t sOutputBufferSize;
|
||||||
nsRefPtr<Promise> mPromise;
|
nsRefPtr<Promise> mPromise;
|
||||||
nsString mTargetRealPath;
|
nsString mTargetRealPath;
|
||||||
|
|
||||||
|
// Not thread-safe and should be released on main thread.
|
||||||
nsCOMPtr<nsIDOMBlob> mBlobData;
|
nsCOMPtr<nsIDOMBlob> mBlobData;
|
||||||
|
|
||||||
nsCOMPtr<nsIInputStream> mBlobStream;
|
nsCOMPtr<nsIInputStream> mBlobStream;
|
||||||
InfallibleTArray<uint8_t> mArrayData;
|
InfallibleTArray<uint8_t> mArrayData;
|
||||||
bool mReplace;
|
bool mReplace;
|
||||||
|
|||||||
Reference in New Issue
Block a user