2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 12:40:48 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_CreateFileTask_h
|
|
|
|
#define mozilla_dom_CreateFileTask_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/FileSystemTaskBase.h"
|
2014-07-19 05:31:11 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
class nsIInputStream;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
class Blob;
|
2015-05-12 15:11:03 +03:00
|
|
|
class BlobImpl;
|
2014-03-05 12:40:48 +04:00
|
|
|
class Promise;
|
|
|
|
|
2016-04-09 21:17:28 +03:00
|
|
|
class CreateFileTaskChild final : public FileSystemTaskChildBase
|
2014-03-05 12:40:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-04-09 21:17:28 +03:00
|
|
|
static already_AddRefed<CreateFileTaskChild>
|
2016-03-20 13:56:10 +03:00
|
|
|
Create(FileSystemBase* aFileSystem,
|
|
|
|
nsIFile* aFile,
|
|
|
|
Blob* aBlobData,
|
|
|
|
InfallibleTArray<uint8_t>& aArrayData,
|
|
|
|
bool replace,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2014-03-05 12:40:48 +04:00
|
|
|
virtual
|
2016-04-09 21:17:28 +03:00
|
|
|
~CreateFileTaskChild();
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
GetPromise();
|
|
|
|
|
|
|
|
virtual void
|
2015-03-21 19:28:04 +03:00
|
|
|
GetPermissionAccessType(nsCString& aAccess) const override;
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual FileSystemParams
|
2016-03-20 13:56:10 +03:00
|
|
|
GetRequestParams(const nsString& aSerializedDOMPath,
|
|
|
|
ErrorResult& aRv) const override;
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
virtual void
|
2016-03-20 13:56:10 +03:00
|
|
|
SetSuccessRequestResult(const FileSystemResponseValue& aValue,
|
|
|
|
ErrorResult& aRv) override;
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
virtual void
|
2015-03-21 19:28:04 +03:00
|
|
|
HandlerCallback() override;
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
private:
|
2016-04-09 21:17:28 +03:00
|
|
|
CreateFileTaskChild(FileSystemBase* aFileSystem,
|
|
|
|
nsIFile* aFile,
|
|
|
|
bool aReplace);
|
2016-03-20 13:56:10 +03:00
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
RefPtr<Promise> mPromise;
|
|
|
|
nsCOMPtr<nsIFile> mTargetPath;
|
2016-03-20 13:56:10 +03:00
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
RefPtr<BlobImpl> mBlobImpl;
|
|
|
|
|
|
|
|
// This is going to be the content of the file, received by createFile()
|
|
|
|
// params.
|
|
|
|
InfallibleTArray<uint8_t> mArrayData;
|
|
|
|
|
|
|
|
bool mReplace;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CreateFileTaskParent final : public FileSystemTaskParentBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static already_AddRefed<CreateFileTaskParent>
|
|
|
|
Create(FileSystemBase* aFileSystem,
|
|
|
|
const FileSystemCreateFileParams& aParam,
|
|
|
|
FileSystemRequestParent* aParent,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
NeedToGoToMainThread() const override { return true; }
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
MainThreadWork() override;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
GetPermissionAccessType(nsCString& aAccess) const override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual FileSystemResponseValue
|
|
|
|
GetSuccessRequestResult(ErrorResult& aRv) const override;
|
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
IOWork() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CreateFileTaskParent(FileSystemBase* aFileSystem,
|
|
|
|
const FileSystemCreateFileParams& aParam,
|
|
|
|
FileSystemRequestParent* aParent);
|
2014-03-05 12:40:48 +04:00
|
|
|
|
|
|
|
static uint32_t sOutputBufferSize;
|
2016-04-09 21:17:02 +03:00
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
nsCOMPtr<nsIFile> mTargetPath;
|
2014-08-18 08:00:06 +04:00
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
RefPtr<BlobImpl> mBlobImpl;
|
2014-08-18 08:00:06 +04:00
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
// This is going to be the content of the file, received by createFile()
|
|
|
|
// params.
|
2014-03-05 12:40:48 +04:00
|
|
|
InfallibleTArray<uint8_t> mArrayData;
|
2016-04-09 21:17:02 +03:00
|
|
|
|
2014-03-05 12:40:48 +04:00
|
|
|
bool mReplace;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_CreateFileTask_h
|