|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_file_filehandle_h__ |
|
8 #define mozilla_dom_file_filehandle_h__ |
|
9 |
|
10 #include "FileCommon.h" |
|
11 |
|
12 #include "nsIFile.h" |
|
13 #include "nsIFileStorage.h" |
|
14 |
|
15 #include "mozilla/Attributes.h" |
|
16 #include "mozilla/DOMEventTargetHelper.h" |
|
17 #include "mozilla/dom/FileModeBinding.h" |
|
18 |
|
19 class nsIDOMFile; |
|
20 class nsIFileStorage; |
|
21 class nsPIDOMWindow; |
|
22 |
|
23 namespace mozilla { |
|
24 namespace dom { |
|
25 class DOMRequest; |
|
26 namespace indexedDB { |
|
27 class FileInfo; |
|
28 } // namespace indexedDB |
|
29 } // namespace dom |
|
30 } // namespace mozilla |
|
31 |
|
32 BEGIN_FILE_NAMESPACE |
|
33 |
|
34 class FileService; |
|
35 class LockedFile; |
|
36 class FinishHelper; |
|
37 class FileHelper; |
|
38 |
|
39 /** |
|
40 * This class provides a default FileHandle implementation, but it can be also |
|
41 * subclassed. The subclass can override implementation of GetFileId, |
|
42 * GetFileInfo, CreateStream and CreateFileObject. |
|
43 * (for example IDBFileHandle provides IndexedDB specific implementation). |
|
44 */ |
|
45 class FileHandle : public DOMEventTargetHelper |
|
46 { |
|
47 friend class FileService; |
|
48 friend class LockedFile; |
|
49 friend class FinishHelper; |
|
50 friend class FileHelper; |
|
51 |
|
52 public: |
|
53 NS_DECL_ISUPPORTS_INHERITED |
|
54 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FileHandle, DOMEventTargetHelper) |
|
55 |
|
56 static already_AddRefed<FileHandle> |
|
57 Create(nsPIDOMWindow* aWindow, |
|
58 nsIFileStorage* aFileStorage, |
|
59 nsIFile* aFile); |
|
60 |
|
61 const nsAString& |
|
62 Name() const |
|
63 { |
|
64 return mName; |
|
65 } |
|
66 |
|
67 const nsAString& |
|
68 Type() const |
|
69 { |
|
70 return mType; |
|
71 } |
|
72 |
|
73 virtual int64_t |
|
74 GetFileId() |
|
75 { |
|
76 return -1; |
|
77 } |
|
78 |
|
79 virtual mozilla::dom::indexedDB::FileInfo* |
|
80 GetFileInfo() |
|
81 { |
|
82 return nullptr; |
|
83 } |
|
84 |
|
85 virtual already_AddRefed<nsISupports> |
|
86 CreateStream(nsIFile* aFile, bool aReadOnly); |
|
87 |
|
88 virtual already_AddRefed<nsIDOMFile> |
|
89 CreateFileObject(LockedFile* aLockedFile, uint32_t aFileSize); |
|
90 |
|
91 // nsWrapperCache |
|
92 virtual JSObject* |
|
93 WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
94 |
|
95 // WebIDL |
|
96 nsPIDOMWindow* |
|
97 GetParentObject() const |
|
98 { |
|
99 return GetOwner(); |
|
100 } |
|
101 |
|
102 void |
|
103 GetName(nsString& aName) const |
|
104 { |
|
105 aName = mName; |
|
106 } |
|
107 |
|
108 void |
|
109 GetType(nsString& aType) const |
|
110 { |
|
111 aType = mType; |
|
112 } |
|
113 |
|
114 already_AddRefed<LockedFile> |
|
115 Open(FileMode aMode, ErrorResult& aError); |
|
116 |
|
117 already_AddRefed<DOMRequest> |
|
118 GetFile(ErrorResult& aError); |
|
119 |
|
120 IMPL_EVENT_HANDLER(abort) |
|
121 IMPL_EVENT_HANDLER(error) |
|
122 |
|
123 protected: |
|
124 FileHandle(nsPIDOMWindow* aWindow) |
|
125 : DOMEventTargetHelper(aWindow) |
|
126 { |
|
127 } |
|
128 |
|
129 FileHandle(DOMEventTargetHelper* aOwner) |
|
130 : DOMEventTargetHelper(aOwner) |
|
131 { |
|
132 } |
|
133 |
|
134 ~FileHandle() |
|
135 { |
|
136 } |
|
137 |
|
138 nsCOMPtr<nsIFileStorage> mFileStorage; |
|
139 |
|
140 nsString mName; |
|
141 nsString mType; |
|
142 |
|
143 nsCOMPtr<nsIFile> mFile; |
|
144 nsString mFileName; |
|
145 }; |
|
146 |
|
147 END_FILE_NAMESPACE |
|
148 |
|
149 #endif // mozilla_dom_file_filehandle_h__ |