mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 669433 Part 1: Clean up File implementations by creating a storage-agnostic base class, nsDOMFileBase. r=khuey
This commit is contained in:
parent
452e2996ff
commit
eb9ce9a027
@ -54,53 +54,111 @@
|
||||
#include "prmem.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#ifndef PR_UINT64_MAX
|
||||
#define PR_UINT64_MAX (~(PRUint64)(0))
|
||||
#endif
|
||||
|
||||
class nsIFile;
|
||||
class nsIInputStream;
|
||||
class nsIClassInfo;
|
||||
class nsIBlobBuilder;
|
||||
|
||||
nsresult NS_NewBlobBuilder(nsISupports* *aSupports);
|
||||
void ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd);
|
||||
|
||||
class nsDOMFile : public nsIDOMFile,
|
||||
public nsIXHRSendable,
|
||||
public nsIJSNativeInitializer
|
||||
class nsDOMFileBase : public nsIDOMFile,
|
||||
public nsIXHRSendable
|
||||
{
|
||||
public:
|
||||
|
||||
nsDOMFileBase(const nsAString& aName, const nsAString& aContentType,
|
||||
PRUint64 aLength)
|
||||
: mIsFile(true), mContentType(aContentType), mName(aName),
|
||||
mStart(0), mLength(aLength)
|
||||
{
|
||||
// Ensure non-null mContentType by default
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
}
|
||||
|
||||
nsDOMFileBase(const nsAString& aContentType, PRUint64 aLength)
|
||||
: mIsFile(false), mContentType(aContentType),
|
||||
mStart(0), mLength(aLength)
|
||||
{
|
||||
// Ensure non-null mContentType by default
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
}
|
||||
|
||||
nsDOMFileBase(const nsAString& aContentType,
|
||||
PRUint64 aStart, PRUint64 aLength)
|
||||
: mIsFile(false), mContentType(aContentType),
|
||||
mStart(aStart), mLength(aLength)
|
||||
{
|
||||
NS_ASSERTION(aLength != PR_UINT64_MAX,
|
||||
"Must know length when creating slice");
|
||||
// Ensure non-null mContentType by default
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
}
|
||||
|
||||
virtual ~nsDOMFileBase() {}
|
||||
|
||||
virtual already_AddRefed<nsIDOMBlob>
|
||||
CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType) = 0;
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMBLOB
|
||||
NS_DECL_NSIDOMFILE
|
||||
NS_DECL_NSIXHRSENDABLE
|
||||
|
||||
nsDOMFile(nsIFile *aFile, const nsAString& aContentType,
|
||||
nsISupports *aCacheToken = nsnull)
|
||||
: mFile(aFile),
|
||||
mCacheToken(aCacheToken),
|
||||
mContentType(aContentType),
|
||||
mIsFullFile(true)
|
||||
{}
|
||||
|
||||
nsDOMFile(nsIFile *aFile)
|
||||
: mFile(aFile),
|
||||
mIsFullFile(true)
|
||||
{}
|
||||
|
||||
nsDOMFile(const nsDOMFile* aOther, PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
: mFile(aOther->mFile),
|
||||
mCacheToken(aOther->mCacheToken),
|
||||
mStart(aOther->mIsFullFile ? aStart :
|
||||
(aOther->mStart + aStart)),
|
||||
mLength(aLength),
|
||||
mContentType(aContentType),
|
||||
mIsFullFile(false)
|
||||
protected:
|
||||
bool IsSizeUnknown()
|
||||
{
|
||||
NS_ASSERTION(mFile, "must have file");
|
||||
// Ensure non-null mContentType
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
return mLength == PR_UINT64_MAX;
|
||||
}
|
||||
|
||||
virtual ~nsDOMFile() {}
|
||||
bool mIsFile;
|
||||
nsString mContentType;
|
||||
nsString mName;
|
||||
|
||||
PRUint64 mStart;
|
||||
PRUint64 mLength;
|
||||
};
|
||||
|
||||
class nsDOMFileFile : public nsDOMFileBase,
|
||||
public nsIJSNativeInitializer
|
||||
{
|
||||
public:
|
||||
// Create as a file
|
||||
nsDOMFileFile(nsIFile *aFile)
|
||||
: nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX),
|
||||
mFile(aFile), mWholeFile(true)
|
||||
{
|
||||
NS_ASSERTION(mFile, "must have file");
|
||||
// Lazily get the content type and size
|
||||
mContentType.SetIsVoid(PR_TRUE);
|
||||
mFile->GetLeafName(mName);
|
||||
}
|
||||
|
||||
// Create as a blob
|
||||
nsDOMFileFile(nsIFile *aFile, const nsAString& aContentType,
|
||||
nsISupports *aCacheToken = nsnull)
|
||||
: nsDOMFileBase(aContentType, PR_UINT64_MAX),
|
||||
mFile(aFile), mWholeFile(true),
|
||||
mCacheToken(aCacheToken)
|
||||
{
|
||||
NS_ASSERTION(mFile, "must have file");
|
||||
}
|
||||
|
||||
// Create as a file to be later initialized
|
||||
nsDOMFileFile()
|
||||
: nsDOMFileBase(EmptyString(), EmptyString(), PR_UINT64_MAX),
|
||||
mWholeFile(true)
|
||||
{
|
||||
// Lazily get the content type and size
|
||||
mContentType.SetIsVoid(PR_TRUE);
|
||||
mName.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner,
|
||||
@ -109,62 +167,74 @@ public:
|
||||
PRUint32 aArgc,
|
||||
jsval* aArgv);
|
||||
|
||||
// Overrides
|
||||
NS_IMETHOD GetSize(PRUint64* aSize);
|
||||
NS_IMETHOD GetType(nsAString& aType);
|
||||
NS_IMETHOD GetMozFullPathInternal(nsAString& aFullPath);
|
||||
NS_IMETHOD GetInternalStream(nsIInputStream**);
|
||||
|
||||
// DOMClassInfo constructor (for File("foo"))
|
||||
static nsresult
|
||||
NewFile(nsISupports* *aNewObject);
|
||||
|
||||
protected:
|
||||
// Create slice
|
||||
nsDOMFileFile(const nsDOMFileFile* aOther, PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFileBase(aContentType, aOther->mStart + aStart, aLength),
|
||||
mFile(aOther->mFile), mWholeFile(false),
|
||||
mCacheToken(aOther->mCacheToken)
|
||||
{
|
||||
NS_ASSERTION(mFile, "must have file");
|
||||
}
|
||||
virtual already_AddRefed<nsIDOMBlob>
|
||||
CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType);
|
||||
|
||||
nsCOMPtr<nsIFile> mFile;
|
||||
bool mWholeFile;
|
||||
nsCOMPtr<nsISupports> mCacheToken;
|
||||
|
||||
// start and length in
|
||||
PRUint64 mStart;
|
||||
PRUint64 mLength;
|
||||
|
||||
nsString mContentType;
|
||||
|
||||
bool mIsFullFile;
|
||||
};
|
||||
|
||||
class nsDOMMemoryFile : public nsDOMFile
|
||||
class nsDOMMemoryFile : public nsDOMFileBase
|
||||
{
|
||||
public:
|
||||
// Create as file
|
||||
nsDOMMemoryFile(void *aMemoryBuffer,
|
||||
PRUint64 aLength,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFile(nsnull, aContentType),
|
||||
mDataOwner(new DataOwner(aMemoryBuffer)),
|
||||
mName(aName)
|
||||
: nsDOMFileBase(aName, aContentType, aLength),
|
||||
mDataOwner(new DataOwner(aMemoryBuffer))
|
||||
{
|
||||
mStart = 0;
|
||||
mLength = aLength;
|
||||
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
|
||||
}
|
||||
|
||||
// Create as blob
|
||||
nsDOMMemoryFile(void *aMemoryBuffer,
|
||||
PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFileBase(aContentType, aLength),
|
||||
mDataOwner(new DataOwner(aMemoryBuffer))
|
||||
{
|
||||
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
|
||||
}
|
||||
|
||||
NS_IMETHOD GetInternalStream(nsIInputStream**);
|
||||
|
||||
protected:
|
||||
// Create slice
|
||||
nsDOMMemoryFile(const nsDOMMemoryFile* aOther, PRUint64 aStart,
|
||||
PRUint64 aLength, const nsAString& aContentType)
|
||||
: nsDOMFile(nsnull, aContentType),
|
||||
: nsDOMFileBase(aContentType, aOther->mStart + aStart, aLength),
|
||||
mDataOwner(aOther->mDataOwner)
|
||||
{
|
||||
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
|
||||
|
||||
mIsFullFile = false;
|
||||
mStart = aOther->mStart + aStart;
|
||||
mLength = aLength;
|
||||
|
||||
// Ensure non-null mContentType
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
}
|
||||
virtual already_AddRefed<nsIDOMBlob>
|
||||
CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType);
|
||||
|
||||
NS_IMETHOD GetName(nsAString&);
|
||||
NS_IMETHOD GetSize(PRUint64*);
|
||||
NS_IMETHOD GetInternalStream(nsIInputStream**);
|
||||
NS_IMETHOD GetMozFullPathInternal(nsAString&);
|
||||
NS_IMETHOD MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType, PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob);
|
||||
|
||||
protected:
|
||||
friend class DataOwnerAdapter; // Needs to see DataOwner
|
||||
class DataOwner {
|
||||
public:
|
||||
@ -181,8 +251,6 @@ protected:
|
||||
|
||||
// Used when backed by a memory store
|
||||
nsRefPtr<DataOwner> mDataOwner;
|
||||
|
||||
nsString mName;
|
||||
};
|
||||
|
||||
class nsDOMFileList : public nsIDOMFileList
|
||||
|
@ -47,7 +47,7 @@ interface nsIURI;
|
||||
interface nsIPrincipal;
|
||||
interface nsIDOMBlob;
|
||||
|
||||
[scriptable, uuid(d5237f31-443a-460b-9e42-449a135346f0)]
|
||||
[scriptable, builtinclass, uuid(d5237f31-443a-460b-9e42-449a135346f0)]
|
||||
interface nsIDOMBlob : nsISupports
|
||||
{
|
||||
readonly attribute unsigned long long size;
|
||||
@ -63,7 +63,7 @@ interface nsIDOMBlob : nsISupports
|
||||
[optional] in DOMString contentType);
|
||||
};
|
||||
|
||||
[scriptable, uuid(b096ef67-7b77-47f8-8e70-5d8ee36416bf)]
|
||||
[scriptable, builtinclass, uuid(b096ef67-7b77-47f8-8e70-5d8ee36416bf)]
|
||||
interface nsIDOMFile : nsIDOMBlob
|
||||
{
|
||||
readonly attribute DOMString name;
|
||||
|
@ -52,24 +52,22 @@
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
class nsDOMMultipartBlob : public nsDOMFile
|
||||
class nsDOMMultipartBlob : public nsDOMFileBase
|
||||
{
|
||||
public:
|
||||
// Create as a blob
|
||||
nsDOMMultipartBlob(nsTArray<nsCOMPtr<nsIDOMBlob> > aBlobs,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFile(nsnull, aContentType),
|
||||
: nsDOMFileBase(aContentType, PR_UINT64_MAX),
|
||||
mBlobs(aBlobs)
|
||||
{
|
||||
mIsFullFile = false;
|
||||
mStart = 0;
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMBlob>
|
||||
CreateSlice(PRUint64 aStart, PRUint64 aLength, const nsAString& aContentType);
|
||||
|
||||
NS_IMETHOD GetSize(PRUint64*);
|
||||
NS_IMETHOD GetInternalStream(nsIInputStream**);
|
||||
NS_IMETHOD MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType, PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob);
|
||||
|
||||
protected:
|
||||
nsTArray<nsCOMPtr<nsIDOMBlob> > mBlobs;
|
||||
@ -78,32 +76,26 @@ protected:
|
||||
NS_IMETHODIMP
|
||||
nsDOMMultipartBlob::GetSize(PRUint64* aLength)
|
||||
{
|
||||
nsresult rv;
|
||||
*aLength = 0;
|
||||
if (mLength == PR_UINT64_MAX) {
|
||||
CheckedUint64 length = 0;
|
||||
|
||||
PRUint32 i;
|
||||
PRUint32 len = mBlobs.Length();
|
||||
for (i = 0; i < len; i++) {
|
||||
nsIDOMBlob* blob = mBlobs.ElementAt(i).get();
|
||||
PRUint64 l = 0;
|
||||
|
||||
nsresult rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
length += l;
|
||||
}
|
||||
|
||||
NS_ENSURE_TRUE(length.valid(), NS_ERROR_FAILURE);
|
||||
|
||||
if (mLength) {
|
||||
*aLength = mLength;
|
||||
return NS_OK;
|
||||
mLength = length.value();
|
||||
}
|
||||
|
||||
CheckedUint64 length = 0;
|
||||
|
||||
PRUint32 i;
|
||||
PRUint32 len = mBlobs.Length();
|
||||
for (i = 0; i < len; i++) {
|
||||
nsIDOMBlob* blob = mBlobs.ElementAt(i).get();
|
||||
PRUint64 l = 0;
|
||||
|
||||
rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
length += l;
|
||||
}
|
||||
|
||||
if (!length.valid())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mLength = length.value();
|
||||
*aLength = mLength;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -133,57 +125,37 @@ nsDOMMultipartBlob::GetInternalStream(nsIInputStream** aStream)
|
||||
return CallQueryInterface(stream, aStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMMultipartBlob::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType,
|
||||
PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob)
|
||||
already_AddRefed<nsIDOMBlob>
|
||||
nsDOMMultipartBlob::CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
{
|
||||
nsresult rv;
|
||||
*aBlob = nsnull;
|
||||
|
||||
// Truncate aStart and aEnd so that we stay within this file.
|
||||
PRUint64 thisLength;
|
||||
rv = GetSize(&thisLength);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!optional_argc) {
|
||||
aEnd = (PRInt64)thisLength;
|
||||
}
|
||||
|
||||
// Modifies aStart and aEnd.
|
||||
ParseSize((PRInt64)thisLength, aStart, aEnd);
|
||||
|
||||
// If we clamped to nothing we create an empty blob
|
||||
nsTArray<nsCOMPtr<nsIDOMBlob> > blobs;
|
||||
|
||||
PRUint64 length = aEnd - aStart;
|
||||
PRUint64 length = aLength;
|
||||
PRUint64 skipStart = aStart;
|
||||
|
||||
NS_ABORT_IF_FALSE(PRUint64(aStart) + length <= thisLength, "Er, what?");
|
||||
|
||||
// Prune the list of blobs if we can
|
||||
PRUint32 i;
|
||||
for (i = 0; length && skipStart && i < mBlobs.Length(); i++) {
|
||||
nsIDOMBlob* blob = mBlobs[i].get();
|
||||
|
||||
PRUint64 l;
|
||||
rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
if (skipStart < l) {
|
||||
PRUint64 upperBound = NS_MIN<PRUint64>(l - skipStart, length);
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> firstBlob;
|
||||
rv = mBlobs.ElementAt(i)->MozSlice(skipStart, skipStart + upperBound,
|
||||
aContentType, 2,
|
||||
getter_AddRefs(firstBlob));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = blob->MozSlice(skipStart, skipStart + upperBound,
|
||||
aContentType, 2,
|
||||
getter_AddRefs(firstBlob));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
// Avoid wrapping a single blob inside an nsDOMMultipartBlob
|
||||
if (length == upperBound) {
|
||||
firstBlob.forget(aBlob);
|
||||
return NS_OK;
|
||||
return firstBlob.forget();
|
||||
}
|
||||
|
||||
blobs.AppendElement(firstBlob);
|
||||
@ -199,14 +171,14 @@ nsDOMMultipartBlob::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
nsIDOMBlob* blob = mBlobs[i].get();
|
||||
|
||||
PRUint64 l;
|
||||
rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv = blob->GetSize(&l);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
if (length < l) {
|
||||
nsCOMPtr<nsIDOMBlob> lastBlob;
|
||||
rv = mBlobs.ElementAt(i)->MozSlice(0, length, aContentType, 2,
|
||||
getter_AddRefs(lastBlob));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = blob->MozSlice(0, length, aContentType, 2,
|
||||
getter_AddRefs(lastBlob));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
blobs.AppendElement(lastBlob);
|
||||
} else {
|
||||
@ -217,8 +189,7 @@ nsDOMMultipartBlob::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
|
||||
// we can create our blob now
|
||||
nsCOMPtr<nsIDOMBlob> blob = new nsDOMMultipartBlob(blobs, aContentType);
|
||||
blob.forget(aBlob);
|
||||
return NS_OK;
|
||||
return blob.forget();
|
||||
}
|
||||
|
||||
class nsDOMBlobBuilder : public nsIDOMMozBlobBuilder
|
||||
|
@ -132,23 +132,23 @@ nsresult DataOwnerAdapter::Create(DataOwner* aDataOwner,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsDOMFile implementation
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMFileBase implementation
|
||||
|
||||
DOMCI_DATA(File, nsDOMFile)
|
||||
DOMCI_DATA(Blob, nsDOMFile)
|
||||
DOMCI_DATA(File, nsDOMFileBase)
|
||||
DOMCI_DATA(Blob, nsDOMFileBase)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMFile)
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMFileBase)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMBlob)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, mIsFullFile)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, mIsFile)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIXHRSendable)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(File, mIsFullFile)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(Blob, !mIsFullFile)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(File, mIsFile)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(Blob, !mIsFile)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMFile)
|
||||
NS_IMPL_RELEASE(nsDOMFile)
|
||||
NS_IMPL_ADDREF(nsDOMFileBase)
|
||||
NS_IMPL_RELEASE(nsDOMFileBase)
|
||||
|
||||
static nsresult
|
||||
DOMFileResult(nsresult rv)
|
||||
@ -165,24 +165,25 @@ DOMFileResult(nsresult rv)
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsDOMFile::NewFile(nsISupports* *aNewObject)
|
||||
nsDOMFileFile::NewFile(nsISupports* *aNewObject)
|
||||
{
|
||||
nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMFile(nsnull));
|
||||
nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMFileFile());
|
||||
file.forget(aNewObject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetName(nsAString &aFileName)
|
||||
nsDOMFileBase::GetName(nsAString &aFileName)
|
||||
{
|
||||
NS_ASSERTION(mIsFullFile, "Should only be called on files");
|
||||
return mFile->GetLeafName(aFileName);
|
||||
NS_ASSERTION(mIsFile, "Should only be called on files");
|
||||
aFileName = mName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetMozFullPath(nsAString &aFileName)
|
||||
nsDOMFileBase::GetMozFullPath(nsAString &aFileName)
|
||||
{
|
||||
NS_ASSERTION(mIsFullFile, "Should only be called on files");
|
||||
NS_ASSERTION(mIsFile, "Should only be called on files");
|
||||
if (nsContentUtils::IsCallerTrustedForCapability("UniversalFileRead")) {
|
||||
return GetMozFullPathInternal(aFileName);
|
||||
}
|
||||
@ -191,16 +192,19 @@ nsDOMFile::GetMozFullPath(nsAString &aFileName)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetMozFullPathInternal(nsAString &aFilename)
|
||||
nsDOMFileBase::GetMozFullPathInternal(nsAString &aFileName)
|
||||
{
|
||||
NS_ASSERTION(mIsFullFile, "Should only be called on files");
|
||||
return mFile->GetPath(aFilename);
|
||||
NS_ASSERTION(mIsFile, "Should only be called on files");
|
||||
aFileName.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetSize(PRUint64 *aFileSize)
|
||||
nsDOMFileFile::GetSize(PRUint64 *aFileSize)
|
||||
{
|
||||
if (mIsFullFile) {
|
||||
if (IsSizeUnknown()) {
|
||||
NS_ASSERTION(mWholeFile,
|
||||
"Should only use lazy size when using the whole file");
|
||||
PRInt64 fileSize;
|
||||
nsresult rv = mFile->GetFileSize(&fileSize);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@ -209,19 +213,20 @@ nsDOMFile::GetSize(PRUint64 *aFileSize)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aFileSize = fileSize;
|
||||
}
|
||||
else {
|
||||
*aFileSize = mLength;
|
||||
mLength = fileSize;
|
||||
}
|
||||
|
||||
*aFileSize = mLength;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetType(nsAString &aType)
|
||||
nsDOMFileFile::GetType(nsAString &aType)
|
||||
{
|
||||
if (mContentType.IsEmpty() && mFile && mIsFullFile) {
|
||||
if (mContentType.IsVoid()) {
|
||||
NS_ASSERTION(mWholeFile,
|
||||
"Should only use lazy ContentType when using the whole file");
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMIMEService> mimeService =
|
||||
do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
|
||||
@ -230,11 +235,11 @@ nsDOMFile::GetType(nsAString &aType)
|
||||
nsCAutoString mimeType;
|
||||
rv = mimeService->GetTypeFromFile(mFile, mimeType);
|
||||
if (NS_FAILED(rv)) {
|
||||
aType.Truncate();
|
||||
return NS_OK;
|
||||
mimeType.Truncate();
|
||||
}
|
||||
|
||||
AppendUTF8toUTF16(mimeType, mContentType);
|
||||
mContentType.SetIsVoid(PR_FALSE);
|
||||
}
|
||||
|
||||
aType = mContentType;
|
||||
@ -242,9 +247,39 @@ nsDOMFile::GetType(nsAString &aType)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFileBase::GetSize(PRUint64 *aSize)
|
||||
{
|
||||
*aSize = mLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFileBase::GetType(nsAString &aType)
|
||||
{
|
||||
aType = mContentType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFileBase::GetInternalStream(nsIInputStream **aStream)
|
||||
{
|
||||
// Must be overridden
|
||||
NS_NOTREACHED("Must override GetInternalStream");
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFileFile::GetMozFullPathInternal(nsAString &aFilename)
|
||||
{
|
||||
NS_ASSERTION(mIsFile, "Should only be called on files");
|
||||
return mFile->GetPath(aFilename);
|
||||
}
|
||||
|
||||
// Makes sure that aStart and aEnd is less then or equal to aSize and greater
|
||||
// than 0
|
||||
void
|
||||
static void
|
||||
ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd)
|
||||
{
|
||||
CheckedInt64 newStartOffset = aStart;
|
||||
@ -280,9 +315,9 @@ ParseSize(PRInt64 aSize, PRInt64& aStart, PRInt64& aEnd)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType, PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob)
|
||||
nsDOMFileBase::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType, PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob)
|
||||
{
|
||||
*aBlob = nsnull;
|
||||
|
||||
@ -298,9 +333,10 @@ nsDOMFile::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
ParseSize((PRInt64)thisLength, aStart, aEnd);
|
||||
|
||||
// Create the new file
|
||||
NS_ADDREF(*aBlob = new nsDOMFile(this, aStart, aEnd - aStart, aContentType));
|
||||
|
||||
return NS_OK;
|
||||
*aBlob = CreateSlice((PRUint64)aStart, (PRUint64)(aEnd - aStart),
|
||||
aContentType).get();
|
||||
|
||||
return *aBlob ? NS_OK : NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
const PRUint32 sFileStreamFlags =
|
||||
@ -309,16 +345,16 @@ const PRUint32 sFileStreamFlags =
|
||||
nsIFileInputStream::DEFER_OPEN;
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetInternalStream(nsIInputStream **aStream)
|
||||
nsDOMFileFile::GetInternalStream(nsIInputStream **aStream)
|
||||
{
|
||||
return mIsFullFile ?
|
||||
return mWholeFile ?
|
||||
NS_NewLocalFileInputStream(aStream, mFile, -1, -1, sFileStreamFlags) :
|
||||
NS_NewPartialLocalFileInputStream(aStream, mFile, mStart, mLength,
|
||||
-1, -1, sFileStreamFlags);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetInternalUrl(nsIPrincipal* aPrincipal, nsAString& aURL)
|
||||
nsDOMFileBase::GetInternalUrl(nsIPrincipal* aPrincipal, nsAString& aURL)
|
||||
{
|
||||
NS_ENSURE_STATE(aPrincipal);
|
||||
|
||||
@ -346,9 +382,9 @@ nsDOMFile::GetInternalUrl(nsIPrincipal* aPrincipal, nsAString& aURL)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::GetSendInfo(nsIInputStream** aBody,
|
||||
nsACString& aContentType,
|
||||
nsACString& aCharset)
|
||||
nsDOMFileBase::GetSendInfo(nsIInputStream** aBody,
|
||||
nsACString& aContentType,
|
||||
nsACString& aCharset)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -368,12 +404,26 @@ nsDOMFile::GetSendInfo(nsIInputStream** aBody,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMFileFile implementation
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsDOMFileFile, nsDOMFileBase,
|
||||
nsIJSNativeInitializer)
|
||||
|
||||
already_AddRefed<nsIDOMBlob>
|
||||
nsDOMFileFile::CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
{
|
||||
nsCOMPtr<nsIDOMBlob> t = new nsDOMFileFile(this, aStart, aLength, aContentType);
|
||||
return t.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMFile::Initialize(nsISupports* aOwner,
|
||||
JSContext* aCx,
|
||||
JSObject* aObj,
|
||||
PRUint32 aArgc,
|
||||
jsval* aArgv)
|
||||
nsDOMFileFile::Initialize(nsISupports* aOwner,
|
||||
JSContext* aCx,
|
||||
JSObject* aObj,
|
||||
PRUint32 aArgc,
|
||||
jsval* aArgv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -430,44 +480,21 @@ nsDOMFile::Initialize(nsISupports* aOwner,
|
||||
NS_ENSURE_FALSE(isDir, NS_ERROR_FILE_IS_DIRECTORY);
|
||||
|
||||
mFile = file;
|
||||
file->GetLeafName(mName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsDOMMemoryFile Implementation
|
||||
NS_IMETHODIMP
|
||||
nsDOMMemoryFile::GetName(nsAString &aFileName)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMMemoryFile implementation
|
||||
|
||||
already_AddRefed<nsIDOMBlob>
|
||||
nsDOMMemoryFile::CreateSlice(PRUint64 aStart, PRUint64 aLength,
|
||||
const nsAString& aContentType)
|
||||
{
|
||||
NS_ASSERTION(mIsFullFile, "Should only be called on files");
|
||||
aFileName = mName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMMemoryFile::GetSize(PRUint64 *aFileSize)
|
||||
{
|
||||
*aFileSize = mLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMMemoryFile::MozSlice(PRInt64 aStart, PRInt64 aEnd,
|
||||
const nsAString& aContentType, PRUint8 optional_argc,
|
||||
nsIDOMBlob **aBlob)
|
||||
{
|
||||
*aBlob = nsnull;
|
||||
|
||||
if (!optional_argc) {
|
||||
aEnd = (PRInt64)mLength;
|
||||
}
|
||||
|
||||
// Truncate aLength and aStart so that we stay within this file.
|
||||
ParseSize((PRInt64)mLength, aStart, aEnd);
|
||||
|
||||
// Create the new file
|
||||
NS_ADDREF(*aBlob = new nsDOMMemoryFile(this, aStart, aEnd - aStart,
|
||||
aContentType));
|
||||
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIDOMBlob> t =
|
||||
new nsDOMMemoryFile(this, aStart, aLength, aContentType);
|
||||
return t.forget();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -479,14 +506,7 @@ nsDOMMemoryFile::GetInternalStream(nsIInputStream **aStream)
|
||||
return DataOwnerAdapter::Create(mDataOwner, mStart, mLength, aStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMMemoryFile::GetMozFullPathInternal(nsAString &aFilename)
|
||||
{
|
||||
NS_ASSERTION(mIsFullFile, "Should only be called on files");
|
||||
aFilename.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMFileList implementation
|
||||
|
||||
DOMCI_DATA(FileList, nsDOMFileList)
|
||||
@ -516,6 +536,7 @@ nsDOMFileList::Item(PRUint32 aIndex, nsIDOMFile **aFile)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMFileError implementation
|
||||
|
||||
DOMCI_DATA(FileError, nsDOMFileError)
|
||||
@ -536,6 +557,9 @@ nsDOMFileError::GetCode(PRUint16* aCode)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsDOMFileInternalUrlHolder implementation
|
||||
|
||||
nsDOMFileInternalUrlHolder::nsDOMFileInternalUrlHolder(nsIDOMBlob* aFile,
|
||||
nsIPrincipal* aPrincipal
|
||||
MOZILLA_GUARD_OBJECT_NOTIFIER_PARAM_IN_IMPL) {
|
||||
|
@ -1600,13 +1600,6 @@ void nsXMLHttpRequest::CreateResponseBlob(nsIRequest *request)
|
||||
nsCOMPtr<nsICachingChannel> cc(do_QueryInterface(request));
|
||||
if (cc) {
|
||||
cc->GetCacheFile(getter_AddRefs(file));
|
||||
if (!file) {
|
||||
// cacheAsFile returns false if caching is inhibited
|
||||
PRBool cacheAsFile = PR_FALSE;
|
||||
if (NS_SUCCEEDED(cc->GetCacheAsFile(&cacheAsFile)) && cacheAsFile) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(request);
|
||||
if (fc) {
|
||||
@ -1621,20 +1614,8 @@ void nsXMLHttpRequest::CreateResponseBlob(nsIRequest *request)
|
||||
cc->GetCacheToken(getter_AddRefs(cacheToken));
|
||||
}
|
||||
|
||||
NS_ConvertASCIItoUTF16 wideContentType(contentType);
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> blob =
|
||||
new nsDOMFile(file, wideContentType, cacheToken);
|
||||
|
||||
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
|
||||
// The response blob here should not be a File object, it should only
|
||||
// be a Blob. Unfortunately, because nsDOMFile has grown through
|
||||
// accretion over the years and is in dangerous need of a refactoring,
|
||||
// slicing it is the easiest way to get there ...
|
||||
PRUint64 size = 0;
|
||||
blob->GetSize(&size);
|
||||
blob->MozSlice(0, size, wideContentType, 2, getter_AddRefs(mResponseBlob));
|
||||
|
||||
mResponseBlob =
|
||||
new nsDOMFileFile(file, NS_ConvertASCIItoUTF16(contentType), cacheToken);
|
||||
mResponseBody.Truncate();
|
||||
mResponseBodyUnicode.SetIsVoid(PR_TRUE);
|
||||
}
|
||||
@ -1906,19 +1887,9 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
|
||||
if (blobData) {
|
||||
memcpy(blobData, mResponseBody.BeginReading(), blobLen);
|
||||
|
||||
NS_ConvertASCIItoUTF16 wideContentType(contentType);
|
||||
nsCOMPtr<nsIDOMBlob> blob =
|
||||
new nsDOMMemoryFile(blobData, blobLen, EmptyString(),
|
||||
wideContentType);
|
||||
|
||||
// XXXkhuey this is a complete hack ... but we need to get 6 out the door
|
||||
// The response blob here should not be a File object, it should only
|
||||
// be a Blob. Unfortunately, because nsDOMFile has grown through
|
||||
// accretion over the years and is in dangerous need of a refactoring,
|
||||
// slicing it is the easiest way to get there ...
|
||||
blob->MozSlice(0, blobLen, wideContentType,
|
||||
2, getter_AddRefs(mResponseBlob));
|
||||
|
||||
mResponseBlob =
|
||||
new nsDOMMemoryFile(blobData, blobLen,
|
||||
NS_ConvertASCIItoUTF16(contentType));
|
||||
mResponseBody.Truncate();
|
||||
}
|
||||
NS_ASSERTION(mResponseBodyUnicode.IsVoid(),
|
||||
|
@ -255,7 +255,7 @@ nsDOMDataTransfer::GetFiles(nsIDOMFileList** aFileList)
|
||||
if (!file)
|
||||
continue;
|
||||
|
||||
nsRefPtr<nsDOMFile> domFile = new nsDOMFile(file);
|
||||
nsRefPtr<nsDOMFileFile> domFile = new nsDOMFileFile(file);
|
||||
|
||||
if (!mFiles->Append(domFile))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
@ -404,7 +404,7 @@ AsyncClickHandler::Run()
|
||||
rv = localFile->GetPath(unicodePath);
|
||||
if (!unicodePath.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMFile> domFile =
|
||||
do_QueryObject(new nsDOMFile(localFile));
|
||||
do_QueryObject(new nsDOMFileFile(localFile));
|
||||
newFiles.AppendObject(domFile);
|
||||
}
|
||||
if (!prefSaved) {
|
||||
@ -424,7 +424,7 @@ AsyncClickHandler::Run()
|
||||
rv = localFile->GetPath(unicodePath);
|
||||
if (!unicodePath.IsEmpty()) {
|
||||
nsCOMPtr<nsIDOMFile> domFile=
|
||||
do_QueryObject(new nsDOMFile(localFile));
|
||||
do_QueryObject(new nsDOMFileFile(localFile));
|
||||
newFiles.AppendObject(domFile);
|
||||
}
|
||||
// Store the last used directory using the content pref service
|
||||
@ -1149,7 +1149,7 @@ nsHTMLInputElement::MozSetFileNameArray(const PRUnichar **aFileNames, PRUint32 a
|
||||
}
|
||||
|
||||
if (file) {
|
||||
nsCOMPtr<nsIDOMFile> domFile = new nsDOMFile(file);
|
||||
nsCOMPtr<nsIDOMFile> domFile = new nsDOMFileFile(file);
|
||||
files.AppendObject(domFile);
|
||||
} else {
|
||||
continue; // Not much we can do if the file doesn't exist
|
||||
|
@ -1574,7 +1574,7 @@ static const nsConstructorFuncMapData kConstructorFuncMap[] =
|
||||
{
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(Worker, nsDOMWorker::NewWorker)
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(ChromeWorker, nsDOMWorker::NewChromeWorker)
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, nsDOMFile::NewFile)
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, nsDOMFileFile::NewFile)
|
||||
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(MozBlobBuilder, NS_NewBlobBuilder)
|
||||
};
|
||||
|
||||
|
@ -246,7 +246,7 @@ File(JSContext *cx, uintN argc, jsval *vp)
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> native;
|
||||
rv = nsDOMFile::NewFile(getter_AddRefs(native));
|
||||
rv = nsDOMFileFile::NewFile(getter_AddRefs(native));
|
||||
if (NS_FAILED(rv)) {
|
||||
XPCThrower::Throw(rv, cx);
|
||||
return JS_FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user