|
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_file_h__ |
|
8 #define mozilla_dom_file_file_h__ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "FileCommon.h" |
|
12 |
|
13 #include "nsDOMFile.h" |
|
14 |
|
15 #include "LockedFile.h" |
|
16 |
|
17 BEGIN_FILE_NAMESPACE |
|
18 |
|
19 class File : public nsDOMFileCC |
|
20 { |
|
21 public: |
|
22 NS_DECL_ISUPPORTS_INHERITED |
|
23 |
|
24 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(File, nsDOMFileCC) |
|
25 |
|
26 // Create as a file |
|
27 File(const nsAString& aName, const nsAString& aContentType, |
|
28 uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile) |
|
29 : nsDOMFileCC(aName, aContentType, aLength), |
|
30 mFile(aFile), mLockedFile(aLockedFile), |
|
31 mWholeFile(true), mStoredFile(false) |
|
32 { |
|
33 NS_ASSERTION(mFile, "Null file!"); |
|
34 NS_ASSERTION(mLockedFile, "Null locked file!"); |
|
35 } |
|
36 |
|
37 // Create as a stored file |
|
38 File(const nsAString& aName, const nsAString& aContentType, |
|
39 uint64_t aLength, nsIFile* aFile, LockedFile* aLockedFile, |
|
40 FileInfo* aFileInfo) |
|
41 : nsDOMFileCC(aName, aContentType, aLength), |
|
42 mFile(aFile), mLockedFile(aLockedFile), |
|
43 mWholeFile(true), mStoredFile(true) |
|
44 { |
|
45 NS_ASSERTION(mFile, "Null file!"); |
|
46 NS_ASSERTION(mLockedFile, "Null locked file!"); |
|
47 mFileInfos.AppendElement(aFileInfo); |
|
48 } |
|
49 |
|
50 // Overrides |
|
51 NS_IMETHOD |
|
52 GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE; |
|
53 |
|
54 NS_IMETHOD |
|
55 GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE; |
|
56 |
|
57 protected: |
|
58 // Create slice |
|
59 File(const File* aOther, uint64_t aStart, uint64_t aLength, |
|
60 const nsAString& aContentType); |
|
61 |
|
62 virtual ~File() |
|
63 { } |
|
64 |
|
65 virtual already_AddRefed<nsIDOMBlob> |
|
66 CreateSlice(uint64_t aStart, uint64_t aLength, |
|
67 const nsAString& aContentType) MOZ_OVERRIDE; |
|
68 |
|
69 virtual bool |
|
70 IsStoredFile() const MOZ_OVERRIDE |
|
71 { |
|
72 return mStoredFile; |
|
73 } |
|
74 |
|
75 virtual bool |
|
76 IsWholeFile() const MOZ_OVERRIDE |
|
77 { |
|
78 return mWholeFile; |
|
79 } |
|
80 |
|
81 virtual bool |
|
82 IsSnapshot() const MOZ_OVERRIDE |
|
83 { |
|
84 return true; |
|
85 } |
|
86 |
|
87 private: |
|
88 nsCOMPtr<nsIFile> mFile; |
|
89 nsRefPtr<LockedFile> mLockedFile; |
|
90 |
|
91 bool mWholeFile; |
|
92 bool mStoredFile; |
|
93 }; |
|
94 |
|
95 END_FILE_NAMESPACE |
|
96 |
|
97 #endif // mozilla_dom_file_file_h__ |