|
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 #include "File.h" |
|
8 |
|
9 #include "LockedFile.h" |
|
10 |
|
11 USING_FILE_NAMESPACE |
|
12 using mozilla::dom::indexedDB::IndexedDatabaseManager; |
|
13 |
|
14 // Create slice |
|
15 File::File(const File* aOther, uint64_t aStart, uint64_t aLength, |
|
16 const nsAString& aContentType) |
|
17 : nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength), |
|
18 mFile(aOther->mFile), mLockedFile(aOther->mLockedFile), |
|
19 mWholeFile(false), mStoredFile(aOther->mStoredFile) |
|
20 { |
|
21 NS_ASSERTION(mFile, "Null file!"); |
|
22 NS_ASSERTION(mLockedFile, "Null locked file!"); |
|
23 |
|
24 if (mStoredFile) { |
|
25 FileInfo* fileInfo; |
|
26 |
|
27 if (IndexedDatabaseManager::IsClosed()) { |
|
28 fileInfo = aOther->GetFileInfo(); |
|
29 } |
|
30 else { |
|
31 MutexAutoLock lock(IndexedDatabaseManager::FileMutex()); |
|
32 fileInfo = aOther->GetFileInfo(); |
|
33 } |
|
34 |
|
35 mFileInfos.AppendElement(fileInfo); |
|
36 } |
|
37 } |
|
38 |
|
39 NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC, |
|
40 mLockedFile) |
|
41 |
|
42 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File) |
|
43 NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC) |
|
44 |
|
45 NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC) |
|
46 NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC) |
|
47 |
|
48 NS_IMETHODIMP |
|
49 File::GetInternalStream(nsIInputStream **aStream) |
|
50 { |
|
51 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
|
52 |
|
53 nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength, |
|
54 aStream); |
|
55 NS_ENSURE_SUCCESS(rv, rv); |
|
56 |
|
57 return NS_OK; |
|
58 } |
|
59 |
|
60 already_AddRefed<nsIDOMBlob> |
|
61 File::CreateSlice(uint64_t aStart, uint64_t aLength, |
|
62 const nsAString& aContentType) |
|
63 { |
|
64 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
|
65 |
|
66 nsCOMPtr<nsIDOMBlob> t = |
|
67 new File(this, aStart, aLength, aContentType); |
|
68 return t.forget(); |
|
69 } |
|
70 |
|
71 NS_IMETHODIMP |
|
72 File::GetMozFullPathInternal(nsAString &aFilename) |
|
73 { |
|
74 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); |
|
75 NS_ASSERTION(mIsFile, "Should only be called on files"); |
|
76 |
|
77 return mFile->GetPath(aFilename); |
|
78 } |