GetFileOrDirectoryTask.h (2504B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_GetFileOrDirectory_h 8 #define mozilla_dom_GetFileOrDirectory_h 9 10 #include "mozilla/dom/Directory.h" 11 #include "mozilla/dom/FileSystemTaskBase.h" 12 13 namespace mozilla { 14 class ErrorResult; 15 16 namespace dom { 17 18 class BlobImpl; 19 class FileSystemGetFileOrDirectoryParams; 20 21 class GetFileOrDirectoryTaskChild final : public FileSystemTaskChildBase { 22 public: 23 static already_AddRefed<GetFileOrDirectoryTaskChild> Create( 24 FileSystemBase* aFileSystem, nsIFile* aTargetPath, ErrorResult& aRv); 25 26 virtual ~GetFileOrDirectoryTaskChild(); 27 28 already_AddRefed<Promise> GetPromise(); 29 30 protected: 31 virtual FileSystemParams GetRequestParams(const nsString& aSerializedDOMPath, 32 ErrorResult& aRv) const override; 33 34 virtual void SetSuccessRequestResult(const FileSystemResponseValue& aValue, 35 ErrorResult& aRv) override; 36 virtual void HandlerCallback() override; 37 38 private: 39 GetFileOrDirectoryTaskChild(nsIGlobalObject* aGlobalObject, 40 FileSystemBase* aFileSystem, 41 nsIFile* aTargetPath); 42 43 RefPtr<Promise> mPromise; 44 nsCOMPtr<nsIFile> mTargetPath; 45 46 RefPtr<File> mResultFile; 47 RefPtr<Directory> mResultDirectory; 48 }; 49 50 class GetFileOrDirectoryTaskParent final : public FileSystemTaskParentBase { 51 public: 52 static already_AddRefed<GetFileOrDirectoryTaskParent> Create( 53 FileSystemBase* aFileSystem, 54 const FileSystemGetFileOrDirectoryParams& aParam, 55 FileSystemRequestParent* aParent, ErrorResult& aRv); 56 57 nsresult GetTargetPath(nsAString& aPath) const override; 58 59 protected: 60 virtual FileSystemResponseValue GetSuccessRequestResult( 61 ErrorResult& aRv) const override; 62 63 virtual nsresult IOWork() override; 64 65 private: 66 GetFileOrDirectoryTaskParent(FileSystemBase* aFileSystem, 67 const FileSystemGetFileOrDirectoryParams& aParam, 68 FileSystemRequestParent* aParent); 69 70 nsCOMPtr<nsIFile> mTargetPath; 71 72 // Whether we get a directory. 73 bool mIsDirectory; 74 }; 75 76 } // namespace dom 77 } // namespace mozilla 78 79 #endif // mozilla_dom_GetFileOrDirectory_h