CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent) : FileSystemTaskBase(aFileSystem, aParam, aParent) , mReplace(false) { MOZ_ASSERT(FileSystemUtils::IsParentProcess(), "Only call from parent process!"); MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); MOZ_ASSERT(aFileSystem); GetOutputBufferSize(); mTargetRealPath = aParam.realPath(); mReplace = aParam.replace(); auto& data = aParam.data(); if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) { mArrayData = data; return; } BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data)); nsCOMPtr<nsIDOMBlob> blobData = bp->GetBlob(); MOZ_ASSERT(blobData, "blobData should not be null."); nsresult rv = blobData->GetInternalStream(getter_AddRefs(mBlobStream)); NS_WARN_IF(NS_FAILED(rv)); }
RemoveTask::RemoveTask(FileSystemBase* aFileSystem, const FileSystemRemoveParams& aParam, FileSystemRequestParent* aParent) : FileSystemTaskBase(aFileSystem, aParam, aParent) , mRecursive(false) , mReturnValue(false) { MOZ_ASSERT(FileSystemUtils::IsParentProcess(), "Only call from parent process!"); MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); MOZ_ASSERT(aFileSystem); mDirRealPath = aParam.directory(); mRecursive = aParam.recursive(); const FileSystemPathOrFileValue& target = aParam.target(); if (target.type() == FileSystemPathOrFileValue::TnsString) { mTargetRealPath = target; return; } BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(target)); nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob(); MOZ_ASSERT(blob); mTargetFileImpl = static_cast<DOMFile*>(blob.get())->Impl(); }
bool ContentParent::RecvAsyncMessage(const nsString& aMsg, const ClonedMessageData& aData) { nsRefPtr<nsFrameMessageManager> ppm = mMessageManager; if (ppm) { const SerializedStructuredCloneBuffer& buffer = aData.data(); const InfallibleTArray<PBlobParent*>& blobParents = aData.blobsParent(); StructuredCloneData cloneData; cloneData.mData = buffer.data; cloneData.mDataLength = buffer.dataLength; if (!blobParents.IsEmpty()) { PRUint32 length = blobParents.Length(); cloneData.mClosure.mBlobs.SetCapacity(length); for (PRUint32 index = 0; index < length; index++) { BlobParent* blobParent = static_cast<BlobParent*>(blobParents[index]); MOZ_ASSERT(blobParent); nsCOMPtr<nsIDOMBlob> blob = blobParent->GetBlob(); MOZ_ASSERT(blob); cloneData.mClosure.mBlobs.AppendElement(blob); } } ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), aMsg, false, &cloneData, nullptr, nullptr); } return true; }
DeviceStorageRequestParent::DeviceStorageRequestParent(const DeviceStorageParams& aParams) { MOZ_COUNT_CTOR(DeviceStorageRequestParent); switch (aParams.type()) { case DeviceStorageParams::TDeviceStorageAddParams: { DeviceStorageAddParams p = aParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f); BlobParent* bp = static_cast<BlobParent*>(p.blobParent()); nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob(); nsCOMPtr<nsIInputStream> stream; blob->GetInternalStream(getter_AddRefs(stream)); nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageGetParams: { DeviceStorageGetParams p = aParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f); dsf->SetPath(p.name()); nsRefPtr<CancelableRunnable> r = new ReadFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageDeleteParams: { DeviceStorageDeleteParams p = aParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f); nsRefPtr<CancelableRunnable> r = new DeleteFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageStatParams: { DeviceStorageStatParams p = aParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f); nsRefPtr<StatFileEvent> r = new StatFileEvent(this, dsf); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } case DeviceStorageParams::TDeviceStorageEnumerationParams: { DeviceStorageEnumerationParams p = aParams; nsCOMPtr<nsIFile> f; NS_NewLocalFile(p.fullpath(), false, getter_AddRefs(f)); nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(f); nsRefPtr<CancelableRunnable> r = new EnumerateFileEvent(this, dsf, p.since()); nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service"); target->Dispatch(r, NS_DISPATCH_NORMAL); break; } default: { NS_RUNTIMEABORT("not reached"); break; } } }