CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent) : FileSystemTaskBase(aFileSystem, aParam, aParent) , mReplace(false) { MOZ_ASSERT(XRE_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)); RefPtr<BlobImpl> blobImpl = bp->GetBlobImpl(); MOZ_ASSERT(blobImpl, "blobData should not be null."); ErrorResult rv; blobImpl->GetInternalStream(getter_AddRefs(mBlobStream), rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); } }
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(); }
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)); }
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; }
/* static */ already_AddRefed<CreateFileTaskParent> CreateFileTaskParent::Create(FileSystemBase* aFileSystem, const FileSystemCreateFileParams& aParam, FileSystemRequestParent* aParent, ErrorResult& aRv) { MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!"); AssertIsOnBackgroundThread(); MOZ_ASSERT(aFileSystem); RefPtr<CreateFileTaskParent> task = new CreateFileTaskParent(aFileSystem, aParam, aParent); NS_ConvertUTF16toUTF8 path(aParam.realPath()); aRv = NS_NewNativeLocalFile(path, true, getter_AddRefs(task->mTargetPath)); if (NS_WARN_IF(aRv.Failed())) { return nullptr; } task->mReplace = aParam.replace(); const FileSystemFileDataValue& data = aParam.data(); if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) { task->mArrayData = data; return task.forget(); } MOZ_ASSERT(data.type() == FileSystemFileDataValue::TPBlobParent); BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data)); task->mBlobImpl = bp->GetBlobImpl(); MOZ_ASSERT(task->mBlobImpl, "blobData should not be null."); return task.forget(); }
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; } } }
BlobParent* nsIContentParent::GetOrCreateActorForBlob(nsIDOMBlob* aBlob) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aBlob); // If the blob represents a remote blob for this ContentParent 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) { BlobParent* actor = remoteBlob->GetBlobParent(); if (actor && 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; } // 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()); ChildBlobConstructorParams params; if (blob->IsSizeUnknown() || blob->IsDateUnknown()) { // We don't want to call GetSize or GetLastModifiedDate // yet since that may stat a file on the main thread // here. Instead we'll learn the size lazily from the // other process. params = MysteryBlobConstructorParams(); } else { 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<nsIDOMFile> file = do_QueryInterface(aBlob); if (file) { FileBlobConstructorParams fileParams; rv = file->GetMozLastModifiedDate(&fileParams.modDate()); NS_ENSURE_SUCCESS(rv, nullptr); rv = file->GetName(fileParams.name()); NS_ENSURE_SUCCESS(rv, nullptr); fileParams.contentType() = contentType; fileParams.length() = length; params = fileParams; } else { NormalBlobConstructorParams blobParams; blobParams.contentType() = contentType; blobParams.length() = length; params = blobParams; } } BlobParent* actor = BlobParent::Create(this, aBlob); NS_ENSURE_TRUE(actor, nullptr); return SendPBlobConstructor(actor, params) ? actor : nullptr; }