5353#include " nsIXMLHttpRequest.h"
5454#include " prmem.h"
5555#include " nsAutoPtr.h"
56+ #include " mozilla/dom/indexedDB/FileInfo.h"
57+ #include " mozilla/dom/indexedDB/FileManager.h"
58+ #include " mozilla/dom/indexedDB/IndexedDatabaseManager.h"
5659
5760#include " mozilla/GuardObjects.h"
5861
@@ -67,12 +70,13 @@ class nsIBlobBuilder;
6770
6871nsresult NS_NewBlobBuilder (nsISupports* *aSupports);
6972
73+ using namespace mozilla ::dom;
74+
7075class nsDOMFileBase : public nsIDOMFile ,
7176 public nsIXHRSendable,
7277 public nsIMutable
7378{
7479public:
75-
7680 nsDOMFileBase (const nsAString& aName, const nsAString& aContentType,
7781 PRUint64 aLength)
7882 : mIsFile (true ), mImmutable (false ), mContentType (aContentType),
@@ -119,13 +123,31 @@ class nsDOMFileBase : public nsIDOMFile,
119123 return mLength == PR_UINT64_MAX ;
120124 }
121125
126+ virtual bool IsStoredFile ()
127+ {
128+ return false ;
129+ }
130+
131+ virtual bool IsWholeFile ()
132+ {
133+ NS_NOTREACHED (" Should only be called on dom blobs backed by files!" );
134+ return false ;
135+ }
136+
137+ indexedDB::FileInfo*
138+ GetFileInfoInternal (indexedDB::FileManager* aFileManager,
139+ PRUint32 aStartIndex);
140+
122141 bool mIsFile ;
123142 bool mImmutable ;
124143 nsString mContentType ;
125144 nsString mName ;
126145
127146 PRUint64 mStart ;
128147 PRUint64 mLength ;
148+
149+ // Protected by IndexedDatabaseManager::FileMutex()
150+ nsTArray<nsRefPtr<indexedDB::FileInfo> > mFileInfos ;
129151};
130152
131153class nsDOMFileFile : public nsDOMFileBase ,
@@ -135,7 +157,7 @@ class nsDOMFileFile : public nsDOMFileBase,
135157 // Create as a file
136158 nsDOMFileFile (nsIFile *aFile)
137159 : nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX ),
138- mFile (aFile), mWholeFile(true )
160+ mFile (aFile), mWholeFile(true ), mStoredFile( false )
139161 {
140162 NS_ASSERTION (mFile , " must have file" );
141163 // Lazily get the content type and size
@@ -147,16 +169,37 @@ class nsDOMFileFile : public nsDOMFileBase,
147169 nsDOMFileFile (nsIFile *aFile, const nsAString& aContentType,
148170 nsISupports *aCacheToken = nsnull)
149171 : nsDOMFileBase(aContentType, PR_UINT64_MAX ),
150- mFile(aFile), mWholeFile(true ),
172+ mFile(aFile), mWholeFile(true ), mStoredFile( false ),
151173 mCacheToken(aCacheToken)
152174 {
153175 NS_ASSERTION (mFile , " must have file" );
154176 }
155177
178+ // Create as a stored file
179+ nsDOMFileFile (const nsAString& aName, const nsAString& aContentType,
180+ PRUint64 aLength, nsIFile* aFile,
181+ indexedDB::FileInfo* aFileInfo)
182+ : nsDOMFileBase(aName, aContentType, aLength),
183+ mFile(aFile), mWholeFile(true ), mStoredFile(true )
184+ {
185+ NS_ASSERTION (mFile , " must have file" );
186+ mFileInfos .AppendElement (aFileInfo);
187+ }
188+
189+ // Create as a stored blob
190+ nsDOMFileFile (const nsAString& aContentType, PRUint64 aLength,
191+ nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
192+ : nsDOMFileBase(aContentType, aLength),
193+ mFile(aFile), mWholeFile(true ), mStoredFile(true )
194+ {
195+ NS_ASSERTION (mFile , " must have file" );
196+ mFileInfos .AppendElement (aFileInfo);
197+ }
198+
156199 // Create as a file to be later initialized
157200 nsDOMFileFile ()
158201 : nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX),
159- mWholeFile(true )
202+ mWholeFile(true ), mStoredFile( false )
160203 {
161204 // Lazily get the content type and size
162205 mContentType .SetIsVoid (true );
@@ -188,17 +231,47 @@ class nsDOMFileFile : public nsDOMFileBase,
188231 const nsAString& aContentType)
189232 : nsDOMFileBase(aContentType, aOther->mStart + aStart, aLength),
190233 mFile(aOther->mFile ), mWholeFile(false ),
191- mCacheToken(aOther->mCacheToken )
234+ mStoredFile(aOther-> mStoredFile ), mCacheToken(aOther->mCacheToken )
192235 {
193236 NS_ASSERTION (mFile , " must have file" );
194237 mImmutable = aOther->mImmutable ;
238+
239+ if (mStoredFile ) {
240+ indexedDB::FileInfo* fileInfo;
241+
242+ if (!indexedDB::IndexedDatabaseManager::IsClosed ()) {
243+ indexedDB::IndexedDatabaseManager::FileMutex ().Lock ();
244+ }
245+
246+ NS_ASSERTION (!aOther->mFileInfos .IsEmpty(),
247+ "A stored file must have at least one file info!");
248+
249+ fileInfo = aOther->mFileInfos .ElementAt (0 );
250+
251+ if (!indexedDB::IndexedDatabaseManager::IsClosed ()) {
252+ indexedDB::IndexedDatabaseManager::FileMutex ().Unlock ();
253+ }
254+
255+ mFileInfos .AppendElement (fileInfo);
256+ }
195257 }
196258 virtual already_AddRefed<nsIDOMBlob>
197259 CreateSlice (PRUint64 aStart, PRUint64 aLength,
198260 const nsAString& aContentType);
199261
262+ virtual bool IsStoredFile ()
263+ {
264+ return mStoredFile ;
265+ }
266+
267+ virtual bool IsWholeFile ()
268+ {
269+ return mWholeFile ;
270+ }
271+
200272 nsCOMPtr<nsIFile> mFile ;
201273 bool mWholeFile ;
274+ bool mStoredFile ;
202275 nsCOMPtr<nsISupports> mCacheToken ;
203276};
204277
0 commit comments