michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_file_filehandle_h__ michael@0: #define mozilla_dom_file_filehandle_h__ michael@0: michael@0: #include "FileCommon.h" michael@0: michael@0: #include "nsIFile.h" michael@0: #include "nsIFileStorage.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/FileModeBinding.h" michael@0: michael@0: class nsIDOMFile; michael@0: class nsIFileStorage; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class DOMRequest; michael@0: namespace indexedDB { michael@0: class FileInfo; michael@0: } // namespace indexedDB michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: BEGIN_FILE_NAMESPACE michael@0: michael@0: class FileService; michael@0: class LockedFile; michael@0: class FinishHelper; michael@0: class FileHelper; michael@0: michael@0: /** michael@0: * This class provides a default FileHandle implementation, but it can be also michael@0: * subclassed. The subclass can override implementation of GetFileId, michael@0: * GetFileInfo, CreateStream and CreateFileObject. michael@0: * (for example IDBFileHandle provides IndexedDB specific implementation). michael@0: */ michael@0: class FileHandle : public DOMEventTargetHelper michael@0: { michael@0: friend class FileService; michael@0: friend class LockedFile; michael@0: friend class FinishHelper; michael@0: friend class FileHelper; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper) michael@0: michael@0: static already_AddRefed michael@0: Create(nsPIDOMWindow* aWindow, michael@0: nsIFileStorage* aFileStorage, michael@0: nsIFile* aFile); michael@0: michael@0: const nsAString& michael@0: Name() const michael@0: { michael@0: return mName; michael@0: } michael@0: michael@0: const nsAString& michael@0: Type() const michael@0: { michael@0: return mType; michael@0: } michael@0: michael@0: virtual int64_t michael@0: GetFileId() michael@0: { michael@0: return -1; michael@0: } michael@0: michael@0: virtual mozilla::dom::indexedDB::FileInfo* michael@0: GetFileInfo() michael@0: { michael@0: return nullptr; michael@0: } michael@0: michael@0: virtual already_AddRefed michael@0: CreateStream(nsIFile* aFile, bool aReadOnly); michael@0: michael@0: virtual already_AddRefed michael@0: CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize); michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsPIDOMWindow* michael@0: GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: void michael@0: GetName(nsString& aName) const michael@0: { michael@0: aName = mName; michael@0: } michael@0: michael@0: void michael@0: GetType(nsString& aType) const michael@0: { michael@0: aType = mType; michael@0: } michael@0: michael@0: already_AddRefed michael@0: Open(FileMode aMode, ErrorResult& aError); michael@0: michael@0: already_AddRefed michael@0: GetFile(ErrorResult& aError); michael@0: michael@0: IMPL_EVENT_HANDLER(abort) michael@0: IMPL_EVENT_HANDLER(error) michael@0: michael@0: protected: michael@0: FileHandle(nsPIDOMWindow* aWindow) michael@0: : DOMEventTargetHelper(aWindow) michael@0: { michael@0: } michael@0: michael@0: FileHandle(DOMEventTargetHelper* aOwner) michael@0: : DOMEventTargetHelper(aOwner) michael@0: { michael@0: } michael@0: michael@0: ~FileHandle() michael@0: { michael@0: } michael@0: michael@0: nsCOMPtr mFileStorage; michael@0: michael@0: nsString mName; michael@0: nsString mType; michael@0: michael@0: nsCOMPtr mFile; michael@0: nsString mFileName; michael@0: }; michael@0: michael@0: END_FILE_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_file_filehandle_h__