dom/file/File.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 #include "File.h"
     9 #include "LockedFile.h"
    11 USING_FILE_NAMESPACE
    12 using mozilla::dom::indexedDB::IndexedDatabaseManager;
    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!");
    24   if (mStoredFile) {
    25     FileInfo* fileInfo;
    27     if (IndexedDatabaseManager::IsClosed()) {
    28       fileInfo = aOther->GetFileInfo();
    29     }
    30     else {
    31       MutexAutoLock lock(IndexedDatabaseManager::FileMutex());
    32       fileInfo = aOther->GetFileInfo();
    33     }
    35     mFileInfos.AppendElement(fileInfo);
    36   }
    37 }
    39 NS_IMPL_CYCLE_COLLECTION_INHERITED(File, nsDOMFileCC,
    40                                    mLockedFile)
    42 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
    43 NS_INTERFACE_MAP_END_INHERITING(nsDOMFileCC)
    45 NS_IMPL_ADDREF_INHERITED(File, nsDOMFileCC)
    46 NS_IMPL_RELEASE_INHERITED(File, nsDOMFileCC)
    48 NS_IMETHODIMP
    49 File::GetInternalStream(nsIInputStream **aStream)
    50 {
    51   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
    53   nsresult rv = mLockedFile->OpenInputStream(mWholeFile, mStart, mLength,
    54                                              aStream);
    55   NS_ENSURE_SUCCESS(rv, rv);
    57   return NS_OK;
    58 }
    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!");
    66   nsCOMPtr<nsIDOMBlob> t =
    67     new File(this, aStart, aLength, aContentType);
    68   return t.forget();
    69 }
    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");
    77   return mFile->GetPath(aFilename);
    78 }

mercurial