1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/file/File.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "File.h" 1.11 + 1.12 +#include "LockedFile.h" 1.13 + 1.14 +USING_FILE_NAMESPACE 1.15 +using mozilla::dom::indexedDB::IndexedDatabaseManager; 1.16 + 1.17 +// Create slice 1.18 +File::File(const File* aOther, uint64_t aStart, uint64_t aLength, 1.19 + const nsAString& aContentType) 1.20 +: nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength), 1.21 + mFile(aOther->mFile), mLockedFile(aOther->mLockedFile), 1.22 + mWholeFile(false), mStoredFile(aOther->mStoredFile) 1.23 +{ 1.24 + NS_ASSERTION(mFile, "Null file!"); 1.25 + NS_ASSERTION(mLockedFile, "Null locked file!"); 1.26 + 1.27 + if (mStoredFile) { 1.28 + FileInfo* fileInfo; 1.29 + 1.30 + if (IndexedDatabaseManager::IsClosed()) { 1.31 + fileInfo = aOther->GetFileInfo(); 1.32 + } 1.33 + else { 1.34 + MutexAutoLock lock(IndexedDatabaseManager::FileMutex()); 1.35 + fileInfo = aOther->GetFileInfo(); 1.36 + } 1.37 + 1.38 + mFileInfos.AppendElement(fileInfo); 1.39 + } 1.40 +} 1.41 + 1.42 +NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC, 1.43 + mLockedFile) 1.44 + 1.45 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File) 1.46 +NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC) 1.47 + 1.48 +NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC) 1.49 +NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC) 1.50 + 1.51 +NS_IMETHODIMP 1.52 +File::GetInternalStream(nsIInputStream **aStream) 1.53 +{ 1.54 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.55 + 1.56 + nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength, 1.57 + aStream); 1.58 + NS_ENSURE_SUCCESS(rv, rv); 1.59 + 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +already_AddRefed<nsIDOMBlob> 1.64 +File::CreateSlice(uint64_t aStart, uint64_t aLength, 1.65 + const nsAString& aContentType) 1.66 +{ 1.67 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.68 + 1.69 + nsCOMPtr<nsIDOMBlob> t = 1.70 + new File(this, aStart, aLength, aContentType); 1.71 + return t.forget(); 1.72 +} 1.73 + 1.74 +NS_IMETHODIMP 1.75 +File::GetMozFullPathInternal(nsAString &aFilename) 1.76 +{ 1.77 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.78 + NS_ASSERTION(mIsFile, "Should only be called on files"); 1.79 + 1.80 + return mFile->GetPath(aFilename); 1.81 +}