dom/file/File.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "File.h"
michael@0 8
michael@0 9 #include "LockedFile.h"
michael@0 10
michael@0 11 USING_FILE_NAMESPACE
michael@0 12 using mozilla::dom::indexedDB::IndexedDatabaseManager;
michael@0 13
michael@0 14 // Create slice
michael@0 15 File::File(const File* aOther, uint64_t aStart, uint64_t aLength,
michael@0 16 const nsAString& aContentType)
michael@0 17 : nsDOMFileCC(aContentType, aOther->mStart + aStart, aLength),
michael@0 18 mFile(aOther->mFile), mLockedFile(aOther->mLockedFile),
michael@0 19 mWholeFile(false), mStoredFile(aOther->mStoredFile)
michael@0 20 {
michael@0 21 NS_ASSERTION(mFile, "Null file!");
michael@0 22 NS_ASSERTION(mLockedFile, "Null locked file!");
michael@0 23
michael@0 24 if (mStoredFile) {
michael@0 25 FileInfo* fileInfo;
michael@0 26
michael@0 27 if (IndexedDatabaseManager::IsClosed()) {
michael@0 28 fileInfo = aOther->GetFileInfo();
michael@0 29 }
michael@0 30 else {
michael@0 31 MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
michael@0 32 fileInfo = aOther->GetFileInfo();
michael@0 33 }
michael@0 34
michael@0 35 mFileInfos.AppendElement(fileInfo);
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC,
michael@0 40 mLockedFile)
michael@0 41
michael@0 42 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
michael@0 43 NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC)
michael@0 44
michael@0 45 NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC)
michael@0 46 NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC)
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 File::GetInternalStream(nsIInputStream **aStream)
michael@0 50 {
michael@0 51 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
michael@0 52
michael@0 53 nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength,
michael@0 54 aStream);
michael@0 55 NS_ENSURE_SUCCESS(rv, rv);
michael@0 56
michael@0 57 return NS_OK;
michael@0 58 }
michael@0 59
michael@0 60 already_AddRefed<nsIDOMBlob>
michael@0 61 File::CreateSlice(uint64_t aStart, uint64_t aLength,
michael@0 62 const nsAString& aContentType)
michael@0 63 {
michael@0 64 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
michael@0 65
michael@0 66 nsCOMPtr<nsIDOMBlob> t =
michael@0 67 new File(this, aStart, aLength, aContentType);
michael@0 68 return t.forget();
michael@0 69 }
michael@0 70
michael@0 71 NS_IMETHODIMP
michael@0 72 File::GetMozFullPathInternal(nsAString &aFilename)
michael@0 73 {
michael@0 74 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
michael@0 75 NS_ASSERTION(mIsFile, "Should only be called on files");
michael@0 76
michael@0 77 return mFile->GetPath(aFilename);
michael@0 78 }

mercurial