Bug 891986 - Keep the source ArrayBuffer to a decodeAudioData call alive until the...
[gecko.git] / dom / file / FileHandle.h
blob967979129839207fcf8ac3b1a1edbba82242f6e2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=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/. */
7 #ifndef mozilla_dom_file_filehandle_h__
8 #define mozilla_dom_file_filehandle_h__
10 #include "FileCommon.h"
12 #include "nsIDOMFileHandle.h"
13 #include "nsIFile.h"
14 #include "nsIFileStorage.h"
16 #include "nsDOMEventTargetHelper.h"
18 #include "mozilla/Attributes.h"
19 #include "mozilla/dom/FileModeBinding.h"
21 class nsIDOMFile;
22 class nsIFileStorage;
24 namespace mozilla {
25 namespace dom {
26 class DOMRequest;
27 } // namespace dom
28 } // namespace mozilla
30 BEGIN_FILE_NAMESPACE
32 class FileService;
33 class LockedFile;
34 class FinishHelper;
35 class FileHelper;
37 /**
38 * Must be subclassed. The subclass must implement CreateStream and
39 * CreateFileObject. Basically, every file storage implementation provides its
40 * own FileHandle implementation (for example IDBFileHandle provides IndexedDB
41 * specific implementation).
43 class FileHandle : public nsDOMEventTargetHelper,
44 public nsIDOMFileHandle
46 friend class FileService;
47 friend class LockedFile;
48 friend class FinishHelper;
49 friend class FileHelper;
51 public:
52 NS_DECL_ISUPPORTS_INHERITED
53 NS_DECL_NSIDOMFILEHANDLE
55 nsPIDOMWindow* GetParentObject() const
57 return GetOwner();
59 virtual JSObject* WrapObject(JSContext* aCx,
60 JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
62 void GetName(nsString& aName) const
64 aName = mName;
66 void GetType(nsString& aType) const
68 aType = mType;
70 already_AddRefed<nsIDOMLockedFile> Open(FileMode aMode, ErrorResult& aError);
71 already_AddRefed<DOMRequest> GetFile(ErrorResult& aError);
72 IMPL_EVENT_HANDLER(abort)
73 IMPL_EVENT_HANDLER(error)
75 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, nsDOMEventTargetHelper)
77 const nsAString&
78 Name() const
80 return mName;
83 const nsAString&
84 Type() const
86 return mType;
89 virtual already_AddRefed<nsISupports>
90 CreateStream(nsIFile* aFile, bool aReadOnly) = 0;
92 virtual already_AddRefed<nsIDOMFile>
93 CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize) = 0;
95 protected:
96 FileHandle()
98 SetIsDOMBinding();
101 ~FileHandle()
104 nsCOMPtr<nsIFileStorage> mFileStorage;
106 nsString mName;
107 nsString mType;
109 nsCOMPtr<nsIFile> mFile;
110 nsString mFileName;
113 END_FILE_NAMESPACE
115 #endif // mozilla_dom_file_filehandle_h__