1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/file/FileHandle.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,149 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_file_filehandle_h__ 1.11 +#define mozilla_dom_file_filehandle_h__ 1.12 + 1.13 +#include "FileCommon.h" 1.14 + 1.15 +#include "nsIFile.h" 1.16 +#include "nsIFileStorage.h" 1.17 + 1.18 +#include "mozilla/Attributes.h" 1.19 +#include "mozilla/DOMEventTargetHelper.h" 1.20 +#include "mozilla/dom/FileModeBinding.h" 1.21 + 1.22 +class nsIDOMFile; 1.23 +class nsIFileStorage; 1.24 +class nsPIDOMWindow; 1.25 + 1.26 +namespace mozilla { 1.27 +namespace dom { 1.28 +class DOMRequest; 1.29 +namespace indexedDB { 1.30 +class FileInfo; 1.31 +} // namespace indexedDB 1.32 +} // namespace dom 1.33 +} // namespace mozilla 1.34 + 1.35 +BEGIN_FILE_NAMESPACE 1.36 + 1.37 +class FileService; 1.38 +class LockedFile; 1.39 +class FinishHelper; 1.40 +class FileHelper; 1.41 + 1.42 +/** 1.43 + * This class provides a default FileHandle implementation, but it can be also 1.44 + * subclassed. The subclass can override implementation of GetFileId, 1.45 + * GetFileInfo, CreateStream and CreateFileObject. 1.46 + * (for example IDBFileHandle provides IndexedDB specific implementation). 1.47 + */ 1.48 +class FileHandle : public DOMEventTargetHelper 1.49 +{ 1.50 + friend class FileService; 1.51 + friend class LockedFile; 1.52 + friend class FinishHelper; 1.53 + friend class FileHelper; 1.54 + 1.55 +public: 1.56 + NS_DECL_ISUPPORTS_INHERITED 1.57 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper) 1.58 + 1.59 + static already_AddRefed<FileHandle> 1.60 + Create(nsPIDOMWindow* aWindow, 1.61 + nsIFileStorage* aFileStorage, 1.62 + nsIFile* aFile); 1.63 + 1.64 + const nsAString& 1.65 + Name() const 1.66 + { 1.67 + return mName; 1.68 + } 1.69 + 1.70 + const nsAString& 1.71 + Type() const 1.72 + { 1.73 + return mType; 1.74 + } 1.75 + 1.76 + virtual int64_t 1.77 + GetFileId() 1.78 + { 1.79 + return -1; 1.80 + } 1.81 + 1.82 + virtual mozilla::dom::indexedDB::FileInfo* 1.83 + GetFileInfo() 1.84 + { 1.85 + return nullptr; 1.86 + } 1.87 + 1.88 + virtual already_AddRefed<nsISupports> 1.89 + CreateStream(nsIFile* aFile, bool aReadOnly); 1.90 + 1.91 + virtual already_AddRefed<nsIDOMFile> 1.92 + CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize); 1.93 + 1.94 + // nsWrapperCache 1.95 + virtual JSObject* 1.96 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.97 + 1.98 + // WebIDL 1.99 + nsPIDOMWindow* 1.100 + GetParentObject() const 1.101 + { 1.102 + return GetOwner(); 1.103 + } 1.104 + 1.105 + void 1.106 + GetName(nsString& aName) const 1.107 + { 1.108 + aName = mName; 1.109 + } 1.110 + 1.111 + void 1.112 + GetType(nsString& aType) const 1.113 + { 1.114 + aType = mType; 1.115 + } 1.116 + 1.117 + already_AddRefed<LockedFile> 1.118 + Open(FileMode aMode, ErrorResult& aError); 1.119 + 1.120 + already_AddRefed<DOMRequest> 1.121 + GetFile(ErrorResult& aError); 1.122 + 1.123 + IMPL_EVENT_HANDLER(abort) 1.124 + IMPL_EVENT_HANDLER(error) 1.125 + 1.126 +protected: 1.127 + FileHandle(nsPIDOMWindow* aWindow) 1.128 + : DOMEventTargetHelper(aWindow) 1.129 + { 1.130 + } 1.131 + 1.132 + FileHandle(DOMEventTargetHelper* aOwner) 1.133 + : DOMEventTargetHelper(aOwner) 1.134 + { 1.135 + } 1.136 + 1.137 + ~FileHandle() 1.138 + { 1.139 + } 1.140 + 1.141 + nsCOMPtr<nsIFileStorage> mFileStorage; 1.142 + 1.143 + nsString mName; 1.144 + nsString mType; 1.145 + 1.146 + nsCOMPtr<nsIFile> mFile; 1.147 + nsString mFileName; 1.148 +}; 1.149 + 1.150 +END_FILE_NAMESPACE 1.151 + 1.152 +#endif // mozilla_dom_file_filehandle_h__