Backed out 7 changesets (bug 1047483, bug 1079301, bug 1079335) for webplatform test failures.

Backed out changeset 7d06b68c44d0 (bug 1079335)
Backed out changeset 92030169528e (bug 1079301)
Backed out changeset c09d7f95554a (bug 1047483)
Backed out changeset c199f1057d7e (bug 1047483)
Backed out changeset 18830d07884c (bug 1047483)
Backed out changeset e087289ccfbb (bug 1047483)
Backed out changeset 6238ff5d3ed0 (bug 1047483)

CLOSED TREE

--HG--
rename : content/base/public/File.h => content/base/public/nsDOMFile.h
rename : content/base/src/MultipartFileImpl.cpp => content/base/src/nsDOMBlobBuilder.cpp
rename : content/base/src/MultipartFileImpl.h => content/base/src/nsDOMBlobBuilder.h
rename : content/base/src/File.cpp => content/base/src/nsDOMFile.cpp
This commit is contained in:
Ryan VanderMeulen 2014-10-07 13:16:11 -04:00
parent 227cb189b8
commit cd3e8a6f73
180 changed files with 3915 additions and 3417 deletions

View File

@ -22,4 +22,4 @@
# changes to stick? As of bug 928195, this shouldn't be necessary! Please
# don't change CLOBBER for WebIDL changes any more.
Bug 1047483 - Porting DOMFile/DOMBlob to WebIDL requires CLOBBER
Bug 1069071: IPDL changes require CLOBBER

View File

@ -181,7 +181,7 @@ FilePicker.prototype = {
}
// The name to be shown can be part of the message, or can be taken from
// the File (if the blob is a File).
// the DOMFile (if the blob is a DOMFile).
let name = data.result.name;
if (!name &&
(data.result.blob instanceof this.mParent.File) &&
@ -207,9 +207,9 @@ FilePicker.prototype = {
}
}
let file = new this.mParent.File([data.result.blob],
name,
{ type: data.result.blob.type });
let file = new this.mParent.File(data.result.blob,
{ name: name,
type: data.result.blob.type });
if (file) {
this.fireSuccess(file);

View File

@ -67,7 +67,7 @@ var testCases = [
},
fileName: 'test5.txt'},
// case 6: returns file without name. This case may fail because we
// need to make sure the File can be sent through
// need to make sure the DOMFile can be sent through
// sendAsyncMessage API.
{ pickedResult: { success: true,
result: {
@ -96,7 +96,7 @@ function handleMessage(data) {
break;
case 'file-picked-posted':
is(fileInput.value, activeTestCase.fileName,
'File should be able to send through message.');
'DOMFile should be able to send through message.');
processTestCase();
break;
}
@ -127,4 +127,4 @@ function processTestCase() {
</script>
<input type="file" id="fileInput">
</body>
</html>
</html>

View File

@ -3,7 +3,7 @@
Cu.import("resource://gre/modules/NetUtil.jsm");
function test() {
var file = new File([new Blob(['test'], {type: 'text/plain'})], "test-name");
var file = new File(new Blob(['test'], {type: 'text/plain'}), {name: 'test-name'});
var url = URL.createObjectURL(file);
var channel = NetUtil.newChannel(url);

View File

@ -1,88 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_BlobSet_h
#define mozilla_dom_BlobSet_h
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/File.h"
namespace mozilla {
namespace dom {
class BlobSet {
public:
BlobSet()
: mData(nullptr), mDataLen(0), mDataBufferLen(0)
{}
~BlobSet()
{
moz_free(mData);
}
nsresult AppendVoidPtr(const void* aData, uint32_t aLength);
nsresult AppendString(const nsAString& aString, bool nativeEOL, JSContext* aCx);
nsresult AppendBlobImpl(FileImpl* aBlobImpl);
nsresult AppendBlobImpls(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls);
nsTArray<nsRefPtr<FileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }
already_AddRefed<File> GetBlobInternal(nsISupports* aParent,
const nsACString& aContentType);
protected:
bool ExpandBufferSize(uint64_t aSize)
{
using mozilla::CheckedUint32;
if (mDataBufferLen >= mDataLen + aSize) {
mDataLen += aSize;
return true;
}
// Start at 1 or we'll loop forever.
CheckedUint32 bufferLen =
std::max<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
while (bufferLen.isValid() && bufferLen.value() < mDataLen + aSize)
bufferLen *= 2;
if (!bufferLen.isValid())
return false;
void* data = moz_realloc(mData, bufferLen.value());
if (!data)
return false;
mData = data;
mDataBufferLen = bufferLen.value();
mDataLen += aSize;
return true;
}
void Flush() {
if (mData) {
// If we have some data, create a blob for it
// and put it on the stack
nsRefPtr<FileImpl> blobImpl =
new FileImplMemory(mData, mDataLen, EmptyString());
mBlobImpls.AppendElement(blobImpl);
mData = nullptr; // The nsDOMMemoryFile takes ownership of the buffer
mDataLen = 0;
mDataBufferLen = 0;
}
}
nsTArray<nsRefPtr<FileImpl>> mBlobImpls;
void* mData;
uint64_t mDataLen;
uint64_t mDataBufferLen;
};
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_BlobSet_h

View File

@ -43,6 +43,7 @@ EXPORTS += [
'nsCopySupport.h',
'nsDeprecatedOperationList.h',
'nsDocElementCreatedNotificationRunner.h',
'nsDOMFile.h',
'nsHostObjectProtocolHandler.h',
'nsIAttribute.h',
'nsIContent.h',
@ -66,11 +67,9 @@ EXPORTS += [
]
EXPORTS.mozilla.dom += [
'BlobSet.h',
'DirectionalityUtils.h',
'Element.h',
'ElementInlines.h',
'File.h',
'FragmentOrElement.h',
'FromParser.h',
]

View File

@ -1669,7 +1669,6 @@ public:
JSObject** aResult);
static nsresult CreateBlobBuffer(JSContext* aCx,
nsISupports* aParent,
const nsACString& aData,
JS::MutableHandle<JS::Value> aBlob);

View File

@ -3,31 +3,36 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_File_h
#define mozilla_dom_File_h
#ifndef nsDOMFile_h__
#define nsDOMFile_h__
#include "mozilla/Attributes.h"
#include "nsICharsetDetectionObserver.h"
#include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIInputStream.h"
#include "nsIJSNativeInitializer.h"
#include "nsIMutable.h"
#include "nsCOMArray.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIXMLHttpRequest.h"
#include "nsAutoPtr.h"
#include "nsFileStreams.h"
#include "nsTemporaryFileInputStream.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/LinkedList.h"
#include <stdint.h>
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/dom/Date.h"
#include "mozilla/dom/DOMError.h"
#include "mozilla/dom/indexedDB/FileInfo.h"
#include "mozilla/dom/indexedDB/FileManager.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "mozilla/dom/UnionTypes.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIFile.h"
#include "nsIMutable.h"
#include "nsIXMLHttpRequest.h"
#include "nsString.h"
#include "nsTemporaryFileInputStream.h"
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWeakReference.h"
class nsDOMMultipartFile;
@ -35,17 +40,17 @@ class nsIFile;
class nsIInputStream;
class nsIClassInfo;
#define PIFILEIMPL_IID \
#define PIDOMFILEIMPL_IID \
{ 0x218ee173, 0xf44f, 0x4d30, \
{ 0xab, 0x0c, 0xd6, 0x66, 0xea, 0xc2, 0x84, 0x47 } }
class PIFileImpl : public nsISupports
class PIDOMFileImpl : public nsISupports
{
public:
NS_DECLARE_STATIC_IID_ACCESSOR(PIFILEIMPL_IID)
NS_DECLARE_STATIC_IID_ACCESSOR(PIDOMFILEIMPL_IID)
};
NS_DEFINE_STATIC_IID_ACCESSOR(PIFileImpl, PIFILEIMPL_IID)
NS_DEFINE_STATIC_IID_ACCESSOR(PIDOMFileImpl, PIDOMFILEIMPL_IID)
namespace mozilla {
namespace dom {
@ -54,16 +59,13 @@ namespace indexedDB {
class FileInfo;
};
struct BlobPropertyBag;
struct ChromeFilePropertyBag;
struct FilePropertyBag;
class FileImpl;
class DOMFileImpl;
class File MOZ_FINAL : public nsIDOMFile
, public nsIXHRSendable
, public nsIMutable
, public nsSupportsWeakReference
, public nsWrapperCache
class DOMFile MOZ_FINAL : public nsIDOMFile
, public nsIXHRSendable
, public nsIMutable
, public nsIJSNativeInitializer
, public nsSupportsWeakReference
{
public:
NS_DECL_NSIDOMBLOB
@ -72,68 +74,68 @@ public:
NS_DECL_NSIMUTABLE
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(File, nsIDOMFile)
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DOMFile, nsIDOMFile)
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
uint64_t aLastModifiedDate);
static already_AddRefed<DOMFile>
Create(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType,
static already_AddRefed<DOMFile>
Create(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType, uint64_t aStart,
static already_AddRefed<DOMFile>
Create(const nsAString& aContentType, uint64_t aLength);
static already_AddRefed<DOMFile>
Create(const nsAString& aContentType, uint64_t aStart,
uint64_t aLength);
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
static already_AddRefed<DOMFile>
CreateMemoryFile(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName, const nsAString& aContentType,
uint64_t aLastModifiedDate);
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
static already_AddRefed<DOMFile>
CreateMemoryFile(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<File>
CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
static already_AddRefed<DOMFile>
CreateTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile);
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength,
static already_AddRefed<DOMFile>
CreateFromFile(const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo);
static already_AddRefed<DOMFile>
CreateFromFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName,
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo);
static already_AddRefed<DOMFile>
CreateFromFile(nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType);
File(nsISupports* aParent, FileImpl* aImpl);
explicit DOMFile(DOMFileImpl* aImpl)
: mImpl(aImpl)
{
MOZ_ASSERT(mImpl);
}
FileImpl* Impl() const
DOMFileImpl* Impl() const
{
return mImpl;
}
const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const;
const nsTArray<nsRefPtr<DOMFileImpl>>* GetSubBlobImpls() const;
bool IsSizeUnknown() const;
@ -144,119 +146,59 @@ public:
void SetLazyData(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate);
already_AddRefed<File>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv);
already_AddRefed<nsIDOMBlob>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType);
// WebIDL methods
nsISupports* GetParentObject() const
{
return mParent;
}
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv);
// File constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aName,
const FilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
File& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
nsIFile* aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
uint64_t GetSize(ErrorResult& aRv);
// XPCOM GetType is OK
// XPCOM GetName is OK
int64_t GetLastModified(ErrorResult& aRv);
Date GetLastModifiedDate(ErrorResult& aRv);
void GetMozFullPath(nsAString& aFilename, ErrorResult& aRv);
already_AddRefed<File> Slice(const Optional<int64_t>& aStart,
const Optional<int64_t>& aEnd,
const nsAString& aContentType,
ErrorResult& aRv);
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
const JS::CallArgs& aArgs) MOZ_OVERRIDE;
private:
~File() {};
~DOMFile() {};
// The member is the real backend implementation of this File/Blob.
// The member is the real backend implementation of this DOMFile/DOMBlob.
// It's thread-safe and not CC-able and it's the only element that is moved
// between threads.
// Note: we should not store any other state in this class!
const nsRefPtr<FileImpl> mImpl;
nsCOMPtr<nsISupports> mParent;
const nsRefPtr<DOMFileImpl> mImpl;
};
// This is the abstract class for any File backend. It must be nsISupports
// This is the abstract class for any DOMFile backend. It must be nsISupports
// because this class must be ref-counted and it has to work with IPC.
class FileImpl : public PIFileImpl
class DOMFileImpl : public PIDOMFileImpl
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
FileImpl() {}
DOMFileImpl() {}
virtual void GetName(nsAString& aName) = 0;
virtual nsresult GetName(nsAString& aName) = 0;
virtual nsresult GetPath(nsAString& aName) = 0;
virtual int64_t GetLastModified(ErrorResult& aRv) = 0;
virtual nsresult
GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate) = 0;
virtual void GetMozFullPath(nsAString& aName, ErrorResult& aRv) = 0;
virtual nsresult GetMozFullPath(nsAString& aName) = 0;
virtual void GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) = 0;
virtual nsresult GetMozFullPathInternal(nsAString &aFileName) = 0;
virtual uint64_t GetSize(ErrorResult& aRv) = 0;
virtual nsresult GetSize(uint64_t* aSize) = 0;
virtual void GetType(nsAString& aType) = 0;
virtual nsresult GetType(nsAString& aType) = 0;
already_AddRefed<FileImpl>
Slice(const Optional<int64_t>& aStart, const Optional<int64_t>& aEnd,
const nsAString& aContentType, ErrorResult& aRv);
virtual nsresult GetMozLastModifiedDate(uint64_t* aDate) = 0;
virtual already_AddRefed<FileImpl>
nsresult Slice(int64_t aStart, int64_t aEnd, const nsAString& aContentType,
uint8_t aArgc, DOMFileImpl** aBlobImpl);
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType, ErrorResult& aRv) = 0;
const nsAString& aContentType) = 0;
virtual const nsTArray<nsRefPtr<FileImpl>>*
virtual const nsTArray<nsRefPtr<DOMFileImpl>>*
GetSubBlobImpls() const = 0;
virtual nsresult GetInternalStream(nsIInputStream** aStream) = 0;
@ -290,6 +232,9 @@ public:
virtual bool IsFile() const = 0;
virtual nsresult Initialize(nsISupports* aOwner, JSContext* aCx,
JSObject* aObj, const JS::CallArgs& aArgs) = 0;
// These 2 methods are used when the implementation has to CC something.
virtual void Unlink() = 0;
virtual void Traverse(nsCycleCollectionTraversalCallback &aCb) = 0;
@ -300,14 +245,14 @@ public:
}
protected:
virtual ~FileImpl() {}
virtual ~DOMFileImpl() {}
};
class FileImplBase : public FileImpl
class DOMFileImplBase : public DOMFileImpl
{
public:
FileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate)
DOMFileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, uint64_t aLastModifiedDate)
: mIsFile(true)
, mImmutable(false)
, mContentType(aContentType)
@ -320,8 +265,8 @@ public:
mContentType.SetIsVoid(false);
}
FileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength)
DOMFileImplBase(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength)
: mIsFile(true)
, mImmutable(false)
, mContentType(aContentType)
@ -334,7 +279,7 @@ public:
mContentType.SetIsVoid(false);
}
FileImplBase(const nsAString& aContentType, uint64_t aLength)
DOMFileImplBase(const nsAString& aContentType, uint64_t aLength)
: mIsFile(false)
, mImmutable(false)
, mContentType(aContentType)
@ -346,8 +291,8 @@ public:
mContentType.SetIsVoid(false);
}
FileImplBase(const nsAString& aContentType, uint64_t aStart,
uint64_t aLength)
DOMFileImplBase(const nsAString& aContentType, uint64_t aStart,
uint64_t aLength)
: mIsFile(false)
, mImmutable(false)
, mContentType(aContentType)
@ -361,41 +306,34 @@ public:
mContentType.SetIsVoid(false);
}
virtual void GetName(nsAString& aName) MOZ_OVERRIDE;
virtual nsresult GetName(nsAString& aName) MOZ_OVERRIDE;
virtual nsresult GetPath(nsAString& aName) MOZ_OVERRIDE;
virtual int64_t GetLastModified(ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate) MOZ_OVERRIDE;
virtual void GetMozFullPath(nsAString& aName, ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetMozFullPath(nsAString& aName) MOZ_OVERRIDE;
virtual void GetMozFullPathInternal(nsAString& aFileName,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetMozFullPathInternal(nsAString& aFileName) MOZ_OVERRIDE;
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE
{
return mLength;
}
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual void GetType(nsAString& aType) MOZ_OVERRIDE;
virtual nsresult GetType(nsAString& aType) MOZ_OVERRIDE;
virtual already_AddRefed<FileImpl>
virtual nsresult GetMozLastModifiedDate(uint64_t* aDate) MOZ_OVERRIDE;
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE
{
return nullptr;
}
const nsAString& aContentType) MOZ_OVERRIDE;
virtual const nsTArray<nsRefPtr<FileImpl>>*
virtual const nsTArray<nsRefPtr<DOMFileImpl>>*
GetSubBlobImpls() const MOZ_OVERRIDE
{
return nullptr;
}
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE
{
return NS_ERROR_NOT_IMPLEMENTED;
}
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual int64_t GetFileId() MOZ_OVERRIDE;
@ -462,11 +400,17 @@ public:
return mLength == UINT64_MAX;
}
virtual nsresult Initialize(nsISupports* aOwner, JSContext* aCx,
JSObject* aObj, const JS::CallArgs& aArgs)
{
return NS_OK;
}
virtual void Unlink() {}
virtual void Traverse(nsCycleCollectionTraversalCallback &aCb) {}
protected:
virtual ~FileImplBase() {}
virtual ~DOMFileImplBase() {}
indexedDB::FileInfo* GetFileInfo() const
{
@ -496,22 +440,25 @@ protected:
* This class may be used off the main thread, and in particular, its
* constructor and destructor may not run on the same thread. Be careful!
*/
class FileImplMemory MOZ_FINAL : public FileImplBase
class DOMFileImplMemory MOZ_FINAL : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
FileImplMemory(void* aMemoryBuffer, uint64_t aLength, const nsAString& aName,
const nsAString& aContentType, uint64_t aLastModifiedDate)
: FileImplBase(aName, aContentType, aLength, aLastModifiedDate)
DOMFileImplMemory(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aName,
const nsAString& aContentType,
uint64_t aLastModifiedDate)
: DOMFileImplBase(aName, aContentType, aLength, aLastModifiedDate)
, mDataOwner(new DataOwner(aMemoryBuffer, aLength))
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
}
FileImplMemory(void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType)
: FileImplBase(aContentType, aLength)
DOMFileImplMemory(void* aMemoryBuffer,
uint64_t aLength,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
, mDataOwner(new DataOwner(aMemoryBuffer, aLength))
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
@ -519,9 +466,9 @@ public:
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual already_AddRefed<FileImpl>
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
const nsAString& aContentType) MOZ_OVERRIDE;
virtual bool IsMemoryFile() const MOZ_OVERRIDE
{
@ -574,29 +521,29 @@ public:
private:
// Create slice
FileImplMemory(const FileImplMemory* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: FileImplBase(aContentType, aOther->mStart + aStart, aLength)
DOMFileImplMemory(const DOMFileImplMemory* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aOther->mStart + aStart, aLength)
, mDataOwner(aOther->mDataOwner)
{
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
mImmutable = aOther->mImmutable;
}
~FileImplMemory() {}
~DOMFileImplMemory() {}
// Used when backed by a memory store
nsRefPtr<DataOwner> mDataOwner;
};
class FileImplTemporaryFileBlob MOZ_FINAL : public FileImplBase
class DOMFileImplTemporaryFileBlob MOZ_FINAL : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
FileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength, const nsAString& aContentType)
: FileImplBase(aContentType, aLength)
DOMFileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
, mLength(aLength)
, mStartPos(aStartPos)
, mContentType(aContentType)
@ -606,21 +553,21 @@ public:
virtual nsresult GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE;
virtual already_AddRefed<FileImpl>
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
const nsAString& aContentType) MOZ_OVERRIDE;
private:
FileImplTemporaryFileBlob(const FileImplTemporaryFileBlob* aOther,
uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
: FileImplBase(aContentType, aLength)
DOMFileImplTemporaryFileBlob(const DOMFileImplTemporaryFileBlob* aOther,
uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, aLength)
, mLength(aLength)
, mStartPos(aStart)
, mFileDescOwner(aOther->mFileDescOwner)
, mContentType(aContentType) {}
~FileImplTemporaryFileBlob() {}
~DOMFileImplTemporaryFileBlob() {}
uint64_t mLength;
uint64_t mStartPos;
@ -628,14 +575,14 @@ private:
nsString mContentType;
};
class FileImplFile : public FileImplBase
class DOMFileImplFile : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
explicit FileImplFile(nsIFile* aFile)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
explicit DOMFileImplFile(nsIFile* aFile)
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -646,8 +593,8 @@ public:
mFile->GetLeafName(mName);
}
FileImplFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
DOMFileImplFile(nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -662,9 +609,9 @@ public:
}
// Create as a file
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile)
: FileImplBase(aName, aContentType, aLength, UINT64_MAX)
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile)
: DOMFileImplBase(aName, aContentType, aLength, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -672,10 +619,10 @@ public:
NS_ASSERTION(mFile, "must have file");
}
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
uint64_t aLastModificationDate)
: FileImplBase(aName, aContentType, aLength, aLastModificationDate)
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
uint64_t aLastModificationDate)
: DOMFileImplBase(aName, aContentType, aLength, aLastModificationDate)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -684,9 +631,9 @@ public:
}
// Create as a file with custom name
FileImplFile(nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType)
: FileImplBase(aName, aContentType, UINT64_MAX, UINT64_MAX)
DOMFileImplFile(nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType)
: DOMFileImplBase(aName, aContentType, UINT64_MAX, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(false)
@ -699,10 +646,10 @@ public:
}
// Create as a stored file
FileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo)
: FileImplBase(aName, aContentType, aLength, UINT64_MAX)
DOMFileImplFile(const nsAString& aName, const nsAString& aContentType,
uint64_t aLength, nsIFile* aFile,
indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(aName, aContentType, aLength, UINT64_MAX)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -712,9 +659,9 @@ public:
}
// Create as a stored blob
FileImplFile(const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: FileImplBase(aContentType, aLength)
DOMFileImplFile(const nsAString& aContentType, uint64_t aLength,
nsIFile* aFile, indexedDB::FileInfo* aFileInfo)
: DOMFileImplBase(aContentType, aLength)
, mFile(aFile)
, mWholeFile(true)
, mStoredFile(true)
@ -724,8 +671,8 @@ public:
}
// Create as a file to be later initialized
FileImplFile()
: FileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
DOMFileImplFile()
: DOMFileImplBase(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
, mWholeFile(true)
, mStoredFile(false)
{
@ -735,23 +682,24 @@ public:
}
// Overrides
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE;
virtual void GetType(nsAString& aType) MOZ_OVERRIDE;
virtual int64_t GetLastModified(ErrorResult& aRv) MOZ_OVERRIDE;
virtual void GetMozFullPathInternal(nsAString& aFullPath,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual nsresult GetType(nsAString& aType) MOZ_OVERRIDE;
virtual nsresult GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aLastModifiedDate) MOZ_OVERRIDE;
virtual nsresult GetMozLastModifiedDate(uint64_t* aLastModifiedDate) MOZ_OVERRIDE;
virtual nsresult GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE;
virtual nsresult GetInternalStream(nsIInputStream**) MOZ_OVERRIDE;
void SetPath(const nsAString& aFullPath);
protected:
virtual ~FileImplFile() {}
virtual ~DOMFileImplFile() {}
private:
// Create slice
FileImplFile(const FileImplFile* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: FileImplBase(aContentType, aOther->mStart + aStart, aLength)
DOMFileImplFile(const DOMFileImplFile* aOther, uint64_t aStart,
uint64_t aLength, const nsAString& aContentType)
: DOMFileImplBase(aContentType, aOther->mStart + aStart, aLength)
, mFile(aOther->mFile)
, mWholeFile(false)
, mStoredFile(aOther->mStoredFile)
@ -776,9 +724,9 @@ private:
}
}
virtual already_AddRefed<FileImpl>
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType, ErrorResult& aRv) MOZ_OVERRIDE;
const nsAString& aContentType) MOZ_OVERRIDE;
virtual bool IsStoredFile() const MOZ_OVERRIDE
{
@ -795,18 +743,21 @@ private:
bool mStoredFile;
};
class FileList MOZ_FINAL : public nsIDOMFileList,
public nsWrapperCache
} // dom namespace
} // file namespace
class nsDOMFileList MOZ_FINAL : public nsIDOMFileList,
public nsWrapperCache
{
~FileList() {}
~nsDOMFileList() {}
public:
explicit FileList(nsISupports *aParent) : mParent(aParent)
explicit nsDOMFileList(nsISupports *aParent) : mParent(aParent)
{
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMFileList)
NS_DECL_NSIDOMFILELIST
@ -822,20 +773,12 @@ public:
mParent = nullptr;
}
bool Append(File *aFile) { return mFiles.AppendElement(aFile); }
bool Remove(uint32_t aIndex) {
if (aIndex < mFiles.Length()) {
mFiles.RemoveElementAt(aIndex);
return true;
}
return false;
}
bool Append(nsIDOMFile *aFile) { return mFiles.AppendObject(aFile); }
bool Remove(uint32_t aIndex) { return mFiles.RemoveObjectAt(aIndex); }
void Clear() { return mFiles.Clear(); }
static FileList* FromSupports(nsISupports* aSupports)
static nsDOMFileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
@ -849,29 +792,26 @@ public:
}
#endif
return static_cast<FileList*>(aSupports);
return static_cast<nsDOMFileList*>(aSupports);
}
File* Item(uint32_t aIndex)
nsIDOMFile* Item(uint32_t aIndex)
{
return mFiles.SafeElementAt(aIndex);
return mFiles.SafeObjectAt(aIndex);
}
File* IndexedGetter(uint32_t aIndex, bool& aFound)
nsIDOMFile* IndexedGetter(uint32_t aIndex, bool& aFound)
{
aFound = aIndex < mFiles.Length();
return aFound ? mFiles.ElementAt(aIndex) : nullptr;
aFound = aIndex < static_cast<uint32_t>(mFiles.Count());
return aFound ? mFiles.ObjectAt(aIndex) : nullptr;
}
uint32_t Length()
{
return mFiles.Length();
return mFiles.Count();
}
private:
nsTArray<nsRefPtr<File>> mFiles;
nsCOMArray<nsIDOMFile> mFiles;
nsISupports *mParent;
};
} // dom namespace
} // file namespace
#endif // mozilla_dom_File_h
#endif

File diff suppressed because it is too large Load Diff

View File

@ -4,12 +4,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FileIOObject.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ProgressEvent.h"
#include "mozilla/EventDispatcher.h"
#include "nsComponentManagerUtils.h"
#include "nsDOMFile.h"
#include "nsError.h"
#include "nsIDOMEvent.h"
#include "mozilla/dom/ProgressEvent.h"
#include "nsComponentManagerUtils.h"
#define ERROR_STR "error"
#define ABORT_STR "abort"

View File

@ -1,353 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MultipartFileImpl.h"
#include "jsfriendapi.h"
#include "mozilla/dom/BlobSet.h"
#include "mozilla/dom/FileBinding.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfoID.h"
#include "nsIMultiplexInputStream.h"
#include "nsStringStream.h"
#include "nsTArray.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#include "nsIXPConnect.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS_INHERITED0(MultipartFileImpl, FileImpl)
nsresult
MultipartFileImpl::GetInternalStream(nsIInputStream** aStream)
{
nsresult rv;
*aStream = nullptr;
nsCOMPtr<nsIMultiplexInputStream> stream =
do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
uint32_t i;
for (i = 0; i < mBlobImpls.Length(); i++) {
nsCOMPtr<nsIInputStream> scratchStream;
FileImpl* blobImpl = mBlobImpls.ElementAt(i).get();
rv = blobImpl->GetInternalStream(getter_AddRefs(scratchStream));
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AppendStream(scratchStream);
NS_ENSURE_SUCCESS(rv, rv);
}
return CallQueryInterface(stream, aStream);
}
already_AddRefed<FileImpl>
MultipartFileImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
// If we clamped to nothing we create an empty blob
nsTArray<nsRefPtr<FileImpl>> blobImpls;
uint64_t length = aLength;
uint64_t skipStart = aStart;
// Prune the list of blobs if we can
uint32_t i;
for (i = 0; length && skipStart && i < mBlobImpls.Length(); i++) {
FileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (skipStart < l) {
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);
nsRefPtr<FileImpl> firstBlobImpl =
blobImpl->CreateSlice(skipStart, upperBound,
aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
// Avoid wrapping a single blob inside an MultipartFileImpl
if (length == upperBound) {
return firstBlobImpl.forget();
}
blobImpls.AppendElement(firstBlobImpl);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobImpls.Length(); i++) {
FileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l = blobImpl->GetSize(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (length < l) {
nsRefPtr<FileImpl> lastBlobImpl =
blobImpl->CreateSlice(0, length, aContentType, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
blobImpls.AppendElement(lastBlobImpl);
} else {
blobImpls.AppendElement(blobImpl);
}
length -= std::min<uint64_t>(l, length);
}
// we can create our blob now
nsRefPtr<FileImpl> impl =
new MultipartFileImpl(blobImpls, aContentType);
return impl.forget();
}
void
MultipartFileImpl::InitializeBlob()
{
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeBlob(
JSContext* aCx,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv)
{
mContentType = aContentType;
BlobSet blobSet;
for (uint32_t i = 0, len = aData.Length(); i < len; ++i) {
const OwningArrayBufferOrArrayBufferViewOrBlobOrString& data = aData[i];
if (data.IsBlob()) {
nsRefPtr<File> file = data.GetAsBlob().get();
blobSet.AppendBlobImpl(file->Impl());
}
else if (data.IsString()) {
aRv = blobSet.AppendString(data.GetAsString(), aNativeEOL, aCx);
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBuffer()) {
const ArrayBuffer& buffer = data.GetAsArrayBuffer();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else if (data.IsArrayBufferView()) {
const ArrayBufferView& buffer = data.GetAsArrayBufferView();
buffer.ComputeLengthAndData();
aRv = blobSet.AppendVoidPtr(buffer.Data(), buffer.Length());
if (aRv.Failed()) {
return;
}
}
else {
MOZ_CRASH("Impossible blob data type.");
}
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::SetLengthAndModifiedDate()
{
MOZ_ASSERT(mLength == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == UINT64_MAX);
uint64_t totalLength = 0;
for (uint32_t index = 0, count = mBlobImpls.Length(); index < count; index++) {
nsRefPtr<FileImpl>& blob = mBlobImpls[index];
#ifdef DEBUG
MOZ_ASSERT(!blob->IsSizeUnknown());
MOZ_ASSERT(!blob->IsDateUnknown());
#endif
ErrorResult error;
uint64_t subBlobLength = blob->GetSize(error);
MOZ_ALWAYS_TRUE(!error.Failed());
MOZ_ASSERT(UINT64_MAX - subBlobLength >= totalLength);
totalLength += subBlobLength;
}
mLength = totalLength;
if (mIsFile) {
// We cannot use PR_Now() because bug 493756 and, for this reason:
// var x = new Date(); var f = new File(...);
// x.getTime() < f.dateModified.getTime()
// could fail.
mLastModificationDate = JS_Now();
}
}
void
MultipartFileImpl::GetMozFullPathInternal(nsAString& aFilename,
ErrorResult& aRv)
{
if (!mIsFromNsIFile || mBlobImpls.Length() == 0) {
FileImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
FileImpl* blobImpl = mBlobImpls.ElementAt(0).get();
if (!blobImpl) {
FileImplBase::GetMozFullPathInternal(aFilename, aRv);
return;
}
blobImpl->GetMozFullPathInternal(aFilename, aRv);
}
void
MultipartFileImpl::InitializeChromeFile(File& aBlob,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
if (mImmutable) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
mName = aBag.mName;
mContentType = aBag.mType;
mIsFromNsIFile = true;
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
aBlob.GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(aBlob.Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
nsIFile* aFile,
const ChromeFilePropertyBag& aBag,
bool aIsFromNsIFile,
ErrorResult& aRv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
if (mImmutable) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
mName = aBag.mName;
mContentType = aBag.mType;
mIsFromNsIFile = aIsFromNsIFile;
bool exists;
aRv = aFile->Exists(&exists);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (!exists) {
aRv.Throw(NS_ERROR_FILE_NOT_FOUND);
return;
}
bool isDir;
aRv = aFile->IsDirectory(&isDir);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (isDir) {
aRv.Throw(NS_ERROR_FILE_IS_DIRECTORY);
return;
}
if (mName.IsEmpty()) {
aFile->GetLeafName(mName);
}
nsRefPtr<File> blob = File::CreateFromFile(aWindow, aFile);
// Pre-cache size.
uint64_t unused;
aRv = blob->GetSize(&unused);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
// Pre-cache modified date.
aRv = blob->GetMozLastModifiedDate(&unused);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<File*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
}
void
MultipartFileImpl::InitializeChromeFile(nsPIDOMWindow* aWindow,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
nsCOMPtr<nsIFile> file;
aRv = NS_NewLocalFile(aData, false, getter_AddRefs(file));
if (NS_WARN_IF(aRv.Failed())) {
return;
}
InitializeChromeFile(aWindow, file, aBag, false, aRv);
}

View File

@ -1,123 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_MultipartFileImpl_h
#define mozilla_dom_MultipartFileImpl_h
#include "mozilla/Attributes.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/FileBinding.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
class MultipartFileImpl MOZ_FINAL : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
MultipartFileImpl(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls,
const nsAString& aName,
const nsAString& aContentType)
: FileImplBase(aName, aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsIFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a blob
MultipartFileImpl(const nsTArray<nsRefPtr<FileImpl>>& aBlobImpls,
const nsAString& aContentType)
: FileImplBase(aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsIFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a file to be later initialized
explicit MultipartFileImpl(const nsAString& aName)
: FileImplBase(aName, EmptyString(), UINT64_MAX),
mIsFromNsIFile(false)
{
}
// Create as a blob to be later initialized
MultipartFileImpl()
: FileImplBase(EmptyString(), UINT64_MAX),
mIsFromNsIFile(false)
{
}
void InitializeBlob();
void InitializeBlob(
JSContext* aCx,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const nsAString& aContentType,
bool aNativeEOL,
ErrorResult& aRv);
void InitializeChromeFile(File& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
void InitializeChromeFile(nsPIDOMWindow* aWindow,
const nsAString& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
void InitializeChromeFile(nsPIDOMWindow* aWindow,
nsIFile* aData,
const ChromeFilePropertyBag& aBag,
bool aIsFromNsIFile,
ErrorResult& aRv);
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual uint64_t GetSize(ErrorResult& aRv) MOZ_OVERRIDE
{
return mLength;
}
virtual nsresult GetInternalStream(nsIInputStream** aInputStream) MOZ_OVERRIDE;
virtual const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const MOZ_OVERRIDE
{
return &mBlobImpls;
}
virtual void GetMozFullPathInternal(nsAString& aFullPath,
ErrorResult& aRv) MOZ_OVERRIDE;
void SetName(const nsAString& aName)
{
mName = aName;
}
void SetFromNsIFile(bool aValue)
{
mIsFromNsIFile = aValue;
}
protected:
virtual ~MultipartFileImpl() {}
void SetLengthAndModifiedDate();
nsTArray<nsRefPtr<FileImpl>> mBlobImpls;
bool mIsFromNsIFile;
};
#endif // mozilla_dom_MultipartFileImpl_h

View File

@ -11,7 +11,6 @@
#include "jsfriendapi.h"
#include "js/OldDebugAPI.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDOMWindow.h"
@ -39,6 +38,7 @@
#include "mozilla/Preferences.h"
#include "xpcpublic.h"
#include "nsContentPolicyUtils.h"
#include "nsDOMFile.h"
#include "nsWrapperCacheInlines.h"
#include "nsIObserverService.h"
#include "nsIWebSocketChannel.h"
@ -898,7 +898,7 @@ WebSocket::CreateAndDispatchMessageEvent(const nsACString& aData,
JS::Rooted<JS::Value> jsData(cx);
if (isBinary) {
if (mBinaryType == dom::BinaryType::Blob) {
rv = nsContentUtils::CreateBlobBuffer(cx, GetOwner(), aData, &jsData);
rv = nsContentUtils::CreateBlobBuffer(cx, aData, &jsData);
NS_ENSURE_SUCCESS(rv, rv);
} else if (mBinaryType == dom::BinaryType::Arraybuffer) {
JS::Rooted<JSObject*> arrayBuf(cx);
@ -1194,19 +1194,20 @@ WebSocket::Send(const nsAString& aData,
}
void
WebSocket::Send(File& aData, ErrorResult& aRv)
WebSocket::Send(nsIDOMBlob* aData,
ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsCOMPtr<nsIInputStream> msgStream;
nsresult rv = aData.GetInternalStream(getter_AddRefs(msgStream));
nsresult rv = aData->GetInternalStream(getter_AddRefs(msgStream));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
uint64_t msgLength;
rv = aData.GetSize(&msgLength);
rv = aData->GetSize(&msgLength);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;

View File

@ -32,8 +32,6 @@
namespace mozilla {
namespace dom {
class File;
class WebSocket MOZ_FINAL : public DOMEventTargetHelper,
public nsIInterfaceRequestor,
public nsIWebSocketListener,
@ -133,7 +131,7 @@ public: // WebIDL interface:
// webIDL: void send(DOMString|Blob|ArrayBufferView data);
void Send(const nsAString& aData,
ErrorResult& aRv);
void Send(File& aData,
void Send(nsIDOMBlob* aData,
ErrorResult& aRv);
void Send(const ArrayBuffer& aData,
ErrorResult& aRv);

View File

@ -99,12 +99,10 @@ UNIFIED_SOURCES += [
'DOMStringList.cpp',
'Element.cpp',
'EventSource.cpp',
'File.cpp',
'FileIOObject.cpp',
'FragmentOrElement.cpp',
'ImportManager.cpp',
'Link.cpp',
'MultipartFileImpl.cpp',
'NodeIterator.cpp',
'nsAtomListUtils.cpp',
'nsAttrAndChildArray.cpp',
@ -126,7 +124,9 @@ UNIFIED_SOURCES += [
'nsDataDocumentContentPolicy.cpp',
'nsDocumentEncoder.cpp',
'nsDOMAttributeMap.cpp',
'nsDOMBlobBuilder.cpp',
'nsDOMCaretPosition.cpp',
'nsDOMFile.cpp',
'nsDOMFileReader.cpp',
'nsDOMMutationObserver.cpp',
'nsDOMSerializer.cpp',

View File

@ -90,7 +90,6 @@
#include "nsICategoryManager.h"
#include "nsIChannelEventSink.h"
#include "nsIChannelPolicy.h"
#include "nsICharsetDetectionObserver.h"
#include "nsIChromeRegistry.h"
#include "nsIConsoleService.h"
#include "nsIContent.h"
@ -5993,26 +5992,20 @@ nsContentUtils::CreateArrayBuffer(JSContext *aCx, const nsACString& aData,
// TODO: bug 704447: large file support
nsresult
nsContentUtils::CreateBlobBuffer(JSContext* aCx,
nsISupports* aParent,
const nsACString& aData,
JS::MutableHandle<JS::Value> aBlob)
{
uint32_t blobLen = aData.Length();
void* blobData = moz_malloc(blobLen);
nsRefPtr<File> blob;
nsCOMPtr<nsIDOMBlob> blob;
if (blobData) {
memcpy(blobData, aData.BeginReading(), blobLen);
blob = mozilla::dom::File::CreateMemoryFile(aParent, blobData, blobLen,
EmptyString());
blob = mozilla::dom::DOMFile::CreateMemoryFile(blobData, blobLen,
EmptyString());
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!WrapNewBindingObject(aCx, blob, aBlob)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
return nsContentUtils::WrapNative(aCx, blob, aBlob);
}
void

View File

@ -0,0 +1,520 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDOMBlobBuilder.h"
#include "jsfriendapi.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/FileBinding.h"
#include "nsAutoPtr.h"
#include "nsDOMClassInfoID.h"
#include "nsIMultiplexInputStream.h"
#include "nsStringStream.h"
#include "nsTArray.h"
#include "nsJSUtils.h"
#include "nsContentUtils.h"
#include "nsIScriptError.h"
#include "nsIXPConnect.h"
#include <algorithm>
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS_INHERITED0(DOMMultipartFileImpl, DOMFileImpl)
nsresult
DOMMultipartFileImpl::GetSize(uint64_t* aLength)
{
*aLength = mLength;
return NS_OK;
}
nsresult
DOMMultipartFileImpl::GetInternalStream(nsIInputStream** aStream)
{
nsresult rv;
*aStream = nullptr;
nsCOMPtr<nsIMultiplexInputStream> stream =
do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
NS_ENSURE_TRUE(stream, NS_ERROR_FAILURE);
uint32_t i;
for (i = 0; i < mBlobImpls.Length(); i++) {
nsCOMPtr<nsIInputStream> scratchStream;
DOMFileImpl* blobImpl = mBlobImpls.ElementAt(i).get();
rv = blobImpl->GetInternalStream(getter_AddRefs(scratchStream));
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AppendStream(scratchStream);
NS_ENSURE_SUCCESS(rv, rv);
}
return CallQueryInterface(stream, aStream);
}
already_AddRefed<DOMFileImpl>
DOMMultipartFileImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
{
// If we clamped to nothing we create an empty blob
nsTArray<nsRefPtr<DOMFileImpl>> blobImpls;
uint64_t length = aLength;
uint64_t skipStart = aStart;
// Prune the list of blobs if we can
uint32_t i;
for (i = 0; length && skipStart && i < mBlobImpls.Length(); i++) {
DOMFileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l;
nsresult rv = blobImpl->GetSize(&l);
NS_ENSURE_SUCCESS(rv, nullptr);
if (skipStart < l) {
uint64_t upperBound = std::min<uint64_t>(l - skipStart, length);
nsRefPtr<DOMFileImpl> firstImpl;
rv = blobImpl->Slice(skipStart, skipStart + upperBound, aContentType, 3,
getter_AddRefs(firstImpl));
NS_ENSURE_SUCCESS(rv, nullptr);
// Avoid wrapping a single blob inside an DOMMultipartFileImpl
if (length == upperBound) {
return firstImpl.forget();
}
blobImpls.AppendElement(firstImpl);
length -= upperBound;
i++;
break;
}
skipStart -= l;
}
// Now append enough blobs until we're done
for (; length && i < mBlobImpls.Length(); i++) {
DOMFileImpl* blobImpl = mBlobImpls[i].get();
uint64_t l;
nsresult rv = blobImpl->GetSize(&l);
NS_ENSURE_SUCCESS(rv, nullptr);
if (length < l) {
nsRefPtr<DOMFileImpl> lastBlob;
rv = blobImpl->Slice(0, length, aContentType, 3,
getter_AddRefs(lastBlob));
NS_ENSURE_SUCCESS(rv, nullptr);
blobImpls.AppendElement(lastBlob);
} else {
blobImpls.AppendElement(blobImpl);
}
length -= std::min<uint64_t>(l, length);
}
// we can create our blob now
nsRefPtr<DOMFileImpl> impl =
new DOMMultipartFileImpl(blobImpls, aContentType);
return impl.forget();
}
/* static */ nsresult
DOMMultipartFileImpl::NewFile(const nsAString& aName, nsISupports** aNewObject)
{
nsCOMPtr<nsISupports> file =
do_QueryObject(new DOMFile(new DOMMultipartFileImpl(aName)));
file.forget(aNewObject);
return NS_OK;
}
/* static */ nsresult
DOMMultipartFileImpl::NewBlob(nsISupports** aNewObject)
{
nsCOMPtr<nsISupports> file =
do_QueryObject(new DOMFile(new DOMMultipartFileImpl()));
file.forget(aNewObject);
return NS_OK;
}
static nsIDOMBlob*
GetXPConnectNative(JSContext* aCx, JSObject* aObj) {
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, aObj));
return blob;
}
nsresult
DOMMultipartFileImpl::Initialize(nsISupports* aOwner,
JSContext* aCx,
JSObject* aObj,
const JS::CallArgs& aArgs)
{
if (!mIsFile) {
return InitBlob(aCx, aArgs.length(), aArgs.array(), GetXPConnectNative);
}
if (!nsContentUtils::IsCallerChrome()) {
return InitFile(aCx, aArgs.length(), aArgs.array());
}
if (aArgs.length() > 0) {
JS::Value* argv = aArgs.array();
if (argv[0].isObject()) {
JS::Rooted<JSObject*> obj(aCx, &argv[0].toObject());
if (JS_IsArrayObject(aCx, obj)) {
return InitFile(aCx, aArgs.length(), aArgs.array());
}
}
}
return InitChromeFile(aCx, aArgs.length(), aArgs.array());
}
nsresult
DOMMultipartFileImpl::InitBlob(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv,
UnwrapFuncPtr aUnwrapFunc)
{
bool nativeEOL = false;
if (aArgc > 1) {
BlobPropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]))) {
return NS_ERROR_TYPE_ERR;
}
mContentType = d.mType;
nativeEOL = d.mEndings == EndingTypes::Native;
}
if (aArgc > 0) {
return ParseBlobArrayArgument(aCx, aArgv[0], nativeEOL, aUnwrapFunc);
}
SetLengthAndModifiedDate();
return NS_OK;
}
nsresult
DOMMultipartFileImpl::ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
bool aNativeEOL,
UnwrapFuncPtr aUnwrapFunc)
{
if (!aValue.isObject()) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
if (!JS_IsArrayObject(aCx, obj)) {
return NS_ERROR_TYPE_ERR; // We're not interested
}
BlobSet blobSet;
uint32_t length;
MOZ_ALWAYS_TRUE(JS_GetArrayLength(aCx, obj, &length));
for (uint32_t i = 0; i < length; ++i) {
JS::Rooted<JS::Value> element(aCx);
if (!JS_GetElement(aCx, obj, i, &element))
return NS_ERROR_TYPE_ERR;
if (element.isObject()) {
JS::Rooted<JSObject*> obj(aCx, &element.toObject());
nsCOMPtr<nsIDOMBlob> blob = aUnwrapFunc(aCx, obj);
if (blob) {
nsRefPtr<DOMFileImpl> blobImpl =
static_cast<DOMFile*>(blob.get())->Impl();
// Flatten so that multipart blobs will never nest
const nsTArray<nsRefPtr<DOMFileImpl>>* subBlobImpls =
blobImpl->GetSubBlobImpls();
if (subBlobImpls) {
blobSet.AppendBlobImpls(*subBlobImpls);
} else {
blobSet.AppendBlobImpl(blobImpl);
}
continue;
}
if (JS_IsArrayBufferViewObject(obj)) {
nsresult rv = blobSet.AppendVoidPtr(
JS_GetArrayBufferViewData(obj),
JS_GetArrayBufferViewByteLength(obj));
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
if (JS_IsArrayBufferObject(obj)) {
nsresult rv = blobSet.AppendArrayBuffer(obj);
NS_ENSURE_SUCCESS(rv, rv);
continue;
}
}
// coerce it to a string
JSString* str = JS::ToString(aCx, element);
NS_ENSURE_TRUE(str, NS_ERROR_TYPE_ERR);
nsresult rv = blobSet.AppendString(str, aNativeEOL, aCx);
NS_ENSURE_SUCCESS(rv, rv);
}
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
return NS_OK;
}
void
DOMMultipartFileImpl::SetLengthAndModifiedDate()
{
MOZ_ASSERT(mLength == UINT64_MAX);
MOZ_ASSERT(mLastModificationDate == UINT64_MAX);
uint64_t totalLength = 0;
for (uint32_t index = 0, count = mBlobImpls.Length(); index < count; index++) {
nsRefPtr<DOMFileImpl>& blob = mBlobImpls[index];
#ifdef DEBUG
MOZ_ASSERT(!blob->IsSizeUnknown());
MOZ_ASSERT(!blob->IsDateUnknown());
#endif
uint64_t subBlobLength;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetSize(&subBlobLength)));
MOZ_ASSERT(UINT64_MAX - subBlobLength >= totalLength);
totalLength += subBlobLength;
}
mLength = totalLength;
if (mIsFile) {
mLastModificationDate = PR_Now();
}
}
nsresult
DOMMultipartFileImpl::GetMozFullPathInternal(nsAString& aFilename)
{
if (!mIsFromNsiFile || mBlobImpls.Length() == 0) {
return DOMFileImplBase::GetMozFullPathInternal(aFilename);
}
DOMFileImpl* blobImpl = mBlobImpls.ElementAt(0).get();
if (!blobImpl) {
return DOMFileImplBase::GetMozFullPathInternal(aFilename);
}
return blobImpl->GetMozFullPathInternal(aFilename);
}
nsresult
DOMMultipartFileImpl::InitChromeFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv)
{
nsresult rv;
NS_ASSERTION(!mImmutable, "Something went wrong ...");
NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
MOZ_ASSERT(nsContentUtils::IsCallerChrome());
NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
if (aArgc > 1) {
FilePropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]))) {
return NS_ERROR_TYPE_ERR;
}
mName = d.mName;
mContentType = d.mType;
}
// We expect to get a path to represent as a File object or
// Blob object, an nsIFile, or an nsIDOMFile.
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIDOMBlob> blob;
if (!aArgv[0].isString()) {
// Lets see if it's an nsIFile
if (!aArgv[0].isObject()) {
return NS_ERROR_UNEXPECTED; // We're not interested
}
JSObject* obj = &aArgv[0].toObject();
nsISupports* supports =
nsContentUtils::XPConnect()->GetNativeOfWrapper(aCx, obj);
if (!supports) {
return NS_ERROR_UNEXPECTED;
}
blob = do_QueryInterface(supports);
file = do_QueryInterface(supports);
if (!blob && !file) {
return NS_ERROR_UNEXPECTED;
}
mIsFromNsiFile = true;
} else {
// It's a string
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[0]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, str)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
rv = NS_NewLocalFile(xpcomStr, false, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
}
if (file) {
bool exists;
rv = file->Exists(&exists);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(exists, NS_ERROR_FILE_NOT_FOUND);
bool isDir;
rv = file->IsDirectory(&isDir);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_FALSE(isDir, NS_ERROR_FILE_IS_DIRECTORY);
if (mName.IsEmpty()) {
file->GetLeafName(mName);
}
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(file);
// Pre-cache size.
uint64_t unused;
rv = domFile->GetSize(&unused);
NS_ENSURE_SUCCESS(rv, rv);
// Pre-cache modified date.
rv = domFile->GetMozLastModifiedDate(&unused);
NS_ENSURE_SUCCESS(rv, rv);
blob = domFile.forget();
}
// XXXkhuey this is terrible
if (mContentType.IsEmpty()) {
blob->GetType(mContentType);
}
BlobSet blobSet;
blobSet.AppendBlobImpl(static_cast<DOMFile*>(blob.get())->Impl());
mBlobImpls = blobSet.GetBlobImpls();
SetLengthAndModifiedDate();
return NS_OK;
}
nsresult
DOMMultipartFileImpl::InitFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv)
{
NS_ASSERTION(!mImmutable, "Something went wrong ...");
NS_ENSURE_TRUE(!mImmutable, NS_ERROR_UNEXPECTED);
if (aArgc < 2) {
return NS_ERROR_TYPE_ERR;
}
// File name
JSString* str = JS::ToString(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[1]));
NS_ENSURE_TRUE(str, NS_ERROR_XPC_BAD_CONVERT_JS);
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, str)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
mName = xpcomStr;
// Optional params
bool nativeEOL = false;
if (aArgc > 2) {
BlobPropertyBag d;
if (!d.Init(aCx, JS::Handle<JS::Value>::fromMarkedLocation(&aArgv[2]))) {
return NS_ERROR_TYPE_ERR;
}
mContentType = d.mType;
nativeEOL = d.mEndings == EndingTypes::Native;
}
return ParseBlobArrayArgument(aCx, aArgv[0], nativeEOL, GetXPConnectNative);
}
nsresult
BlobSet::AppendVoidPtr(const void* aData, uint32_t aLength)
{
NS_ENSURE_ARG_POINTER(aData);
uint64_t offset = mDataLen;
if (!ExpandBufferSize(aLength))
return NS_ERROR_OUT_OF_MEMORY;
memcpy((char*)mData + offset, aData, aLength);
return NS_OK;
}
nsresult
BlobSet::AppendString(JSString* aString, bool nativeEOL, JSContext* aCx)
{
nsAutoJSString xpcomStr;
if (!xpcomStr.init(aCx, aString)) {
return NS_ERROR_XPC_BAD_CONVERT_JS;
}
nsCString utf8Str = NS_ConvertUTF16toUTF8(xpcomStr);
if (nativeEOL) {
if (utf8Str.FindChar('\r') != kNotFound) {
utf8Str.ReplaceSubstring("\r\n", "\n");
utf8Str.ReplaceSubstring("\r", "\n");
}
#ifdef XP_WIN
utf8Str.ReplaceSubstring("\n", "\r\n");
#endif
}
return AppendVoidPtr((void*)utf8Str.Data(),
utf8Str.Length());
}
nsresult
BlobSet::AppendBlobImpl(DOMFileImpl* aBlobImpl)
{
NS_ENSURE_ARG_POINTER(aBlobImpl);
Flush();
mBlobImpls.AppendElement(aBlobImpl);
return NS_OK;
}
nsresult
BlobSet::AppendBlobImpls(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls)
{
Flush();
mBlobImpls.AppendElements(aBlobImpls);
return NS_OK;
}
nsresult
BlobSet::AppendArrayBuffer(JSObject* aBuffer)
{
return AppendVoidPtr(JS_GetArrayBufferData(aBuffer),
JS_GetArrayBufferByteLength(aBuffer));
}

View File

@ -0,0 +1,198 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsDOMBlobBuilder_h
#define nsDOMBlobBuilder_h
#include "nsDOMFile.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Attributes.h"
#include <algorithm>
#define NS_DOMMULTIPARTBLOB_CID { 0x47bf0b43, 0xf37e, 0x49ef, \
{ 0x81, 0xa0, 0x18, 0xba, 0xc0, 0x57, 0xb5, 0xcc } }
#define NS_DOMMULTIPARTBLOB_CONTRACTID "@mozilla.org/dom/multipart-blob;1"
#define NS_DOMMULTIPARTFILE_CID { 0xc3361f77, 0x60d1, 0x4ea9, \
{ 0x94, 0x96, 0xdf, 0x5d, 0x6f, 0xcd, 0xd7, 0x8f } }
#define NS_DOMMULTIPARTFILE_CONTRACTID "@mozilla.org/dom/multipart-file;1"
using namespace mozilla::dom;
class DOMMultipartFileImpl MOZ_FINAL : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
// Create as a file
DOMMultipartFileImpl(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls,
const nsAString& aName,
const nsAString& aContentType)
: DOMFileImplBase(aName, aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsiFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a blob
DOMMultipartFileImpl(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls,
const nsAString& aContentType)
: DOMFileImplBase(aContentType, UINT64_MAX),
mBlobImpls(aBlobImpls),
mIsFromNsiFile(false)
{
SetLengthAndModifiedDate();
}
// Create as a file to be later initialized
explicit DOMMultipartFileImpl(const nsAString& aName)
: DOMFileImplBase(aName, EmptyString(), UINT64_MAX),
mIsFromNsiFile(false)
{
}
// Create as a blob to be later initialized
DOMMultipartFileImpl()
: DOMFileImplBase(EmptyString(), UINT64_MAX),
mIsFromNsiFile(false)
{
}
virtual nsresult
Initialize(nsISupports* aOwner, JSContext* aCx, JSObject* aObj,
const JS::CallArgs& aArgs) MOZ_OVERRIDE;
typedef nsIDOMBlob* (*UnwrapFuncPtr)(JSContext*, JSObject*);
nsresult InitBlob(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv,
UnwrapFuncPtr aUnwrapFunc);
nsresult InitFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv);
nsresult InitChromeFile(JSContext* aCx,
uint32_t aArgc,
JS::Value* aArgv);
virtual already_AddRefed<DOMFileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
virtual nsresult GetSize(uint64_t* aSize) MOZ_OVERRIDE;
virtual nsresult GetInternalStream(nsIInputStream** aInputStream) MOZ_OVERRIDE;
static nsresult NewFile(const nsAString& aName, nsISupports** aNewObject);
// DOMClassInfo constructor (for Blob([b1, "foo"], { type: "image/png" }))
static nsresult NewBlob(nsISupports* *aNewObject);
// DOMClassInfo constructor (for File([b1, "foo"], { type: "image/png",
// name: "foo.png" }))
inline static nsresult NewFile(nsISupports** aNewObject)
{
// Initialization will set the filename, so we can pass in an empty string
// for now.
return NewFile(EmptyString(), aNewObject);
}
virtual const nsTArray<nsRefPtr<DOMFileImpl>>* GetSubBlobImpls() const MOZ_OVERRIDE
{
return &mBlobImpls;
}
virtual nsresult GetMozFullPathInternal(nsAString& aFullPath) MOZ_OVERRIDE;
protected:
virtual ~DOMMultipartFileImpl() {}
nsresult ParseBlobArrayArgument(JSContext* aCx, JS::Value& aValue,
bool aNativeEOL, UnwrapFuncPtr aUnwrapFunc);
void SetLengthAndModifiedDate();
nsTArray<nsRefPtr<DOMFileImpl>> mBlobImpls;
bool mIsFromNsiFile;
};
class BlobSet {
public:
BlobSet()
: mData(nullptr), mDataLen(0), mDataBufferLen(0)
{}
~BlobSet()
{
moz_free(mData);
}
nsresult AppendVoidPtr(const void* aData, uint32_t aLength);
nsresult AppendString(JSString* aString, bool nativeEOL, JSContext* aCx);
nsresult AppendBlobImpl(DOMFileImpl* aBlobImpl);
nsresult AppendArrayBuffer(JSObject* aBuffer);
nsresult AppendBlobImpls(const nsTArray<nsRefPtr<DOMFileImpl>>& aBlobImpls);
nsTArray<nsRefPtr<DOMFileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }
already_AddRefed<nsIDOMBlob>
GetBlobInternal(const nsACString& aContentType)
{
nsCOMPtr<nsIDOMBlob> blob = new DOMFile(
new DOMMultipartFileImpl(GetBlobImpls(), NS_ConvertASCIItoUTF16(aContentType)));
return blob.forget();
}
protected:
bool ExpandBufferSize(uint64_t aSize)
{
using mozilla::CheckedUint32;
if (mDataBufferLen >= mDataLen + aSize) {
mDataLen += aSize;
return true;
}
// Start at 1 or we'll loop forever.
CheckedUint32 bufferLen =
std::max<uint32_t>(static_cast<uint32_t>(mDataBufferLen), 1);
while (bufferLen.isValid() && bufferLen.value() < mDataLen + aSize)
bufferLen *= 2;
if (!bufferLen.isValid())
return false;
void* data = moz_realloc(mData, bufferLen.value());
if (!data)
return false;
mData = data;
mDataBufferLen = bufferLen.value();
mDataLen += aSize;
return true;
}
void Flush() {
if (mData) {
// If we have some data, create a blob for it
// and put it on the stack
nsRefPtr<DOMFileImpl> blobImpl =
new DOMFileImplMemory(mData, mDataLen, EmptyString());
mBlobImpls.AppendElement(blobImpl);
mData = nullptr; // The nsDOMMemoryFile takes ownership of the buffer
mDataLen = 0;
mDataBufferLen = 0;
}
}
nsTArray<nsRefPtr<DOMFileImpl>> mBlobImpls;
void* mData;
uint64_t mDataLen;
uint64_t mDataBufferLen;
};
#endif

View File

@ -22,10 +22,10 @@ extern PRLogModuleInfo* GetDataChannelLog();
#include "nsDOMDataChannelDeclarations.h"
#include "nsDOMDataChannel.h"
#include "nsIDOMFile.h"
#include "nsIDOMDataChannel.h"
#include "nsIDOMMessageEvent.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "nsError.h"
@ -34,6 +34,7 @@ extern PRLogModuleInfo* GetDataChannelLog();
#include "nsCycleCollectionParticipant.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsNetUtil.h"
#include "nsDOMFile.h"
#include "DataChannel.h"
@ -271,19 +272,19 @@ nsDOMDataChannel::Send(const nsAString& aData, ErrorResult& aRv)
}
void
nsDOMDataChannel::Send(File& aData, ErrorResult& aRv)
nsDOMDataChannel::Send(nsIDOMBlob* aData, ErrorResult& aRv)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsCOMPtr<nsIInputStream> msgStream;
nsresult rv = aData.GetInternalStream(getter_AddRefs(msgStream));
nsresult rv = aData->GetInternalStream(getter_AddRefs(msgStream));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
}
uint64_t msgLength;
rv = aData.GetSize(&msgLength);
rv = aData->GetSize(&msgLength);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return;
@ -392,7 +393,7 @@ nsDOMDataChannel::DoOnMessageAvailable(const nsACString& aData,
if (aBinary) {
if (mBinaryType == DC_BINARY_TYPE_BLOB) {
rv = nsContentUtils::CreateBlobBuffer(cx, GetOwner(), aData, &jsData);
rv = nsContentUtils::CreateBlobBuffer(cx, aData, &jsData);
NS_ENSURE_SUCCESS(rv, rv);
} else if (mBinaryType == DC_BINARY_TYPE_ARRAYBUFFER) {
JS::Rooted<JSObject*> arrayBuf(cx);

View File

@ -17,10 +17,6 @@
namespace mozilla {
namespace dom {
class File;
}
class DataChannel;
};
@ -70,7 +66,7 @@ public:
static_cast<int>(aType));
}
void Send(const nsAString& aData, mozilla::ErrorResult& aRv);
void Send(mozilla::dom::File& aData, mozilla::ErrorResult& aRv);
void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv);
void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv);
void Send(const mozilla::dom::ArrayBufferView& aData,
mozilla::ErrorResult& aRv);

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,7 @@
#include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsDOMClassInfoID.h"
#include "nsDOMFile.h"
#include "nsError.h"
#include "nsIFile.h"
#include "nsNetCID.h"
@ -19,7 +20,6 @@
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Base64.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileReaderBinding.h"
#include "xpcpublic.h"
#include "nsDOMJSUtils.h"
@ -186,8 +186,7 @@ nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aFile, JSContext* aCx)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsArrayBuffer(aCx, *file, rv);
ReadAsArrayBuffer(aCx, aFile, rv);
return rv.ErrorCode();
}
@ -196,8 +195,7 @@ nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aFile)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsBinaryString(*file, rv);
ReadAsBinaryString(aFile, rv);
return rv.ErrorCode();
}
@ -207,8 +205,7 @@ nsDOMFileReader::ReadAsText(nsIDOMBlob* aFile,
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsText(*file, aCharset, rv);
ReadAsText(aFile, aCharset, rv);
return rv.ErrorCode();
}
@ -217,8 +214,7 @@ nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsDataURL(*file, rv);
ReadAsDataURL(aFile, rv);
return rv.ErrorCode();
}
@ -370,11 +366,13 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
void
nsDOMFileReader::ReadFileContent(JSContext* aCx,
File& aFile,
nsIDOMBlob* aFile,
const nsAString &aCharset,
eDataFormat aDataFormat,
ErrorResult& aRv)
{
MOZ_ASSERT(aFile);
//Implicit abort to clear any other activity going on
Abort();
mError = nullptr;
@ -384,7 +382,7 @@ nsDOMFileReader::ReadFileContent(JSContext* aCx,
mReadyState = nsIDOMFileReader::EMPTY;
FreeFileData();
mFile = &aFile;
mFile = aFile;
mDataFormat = aDataFormat;
CopyUTF16toUTF8(aCharset, mCharset);

View File

@ -19,18 +19,13 @@
#include "nsITimer.h"
#include "nsIAsyncInputStream.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileReader.h"
#include "nsIDOMFileList.h"
#include "nsCOMPtr.h"
#include "FileIOObject.h"
namespace mozilla {
namespace dom {
class File;
}
}
class nsDOMFileReader : public mozilla::dom::FileIOObject,
public nsIDOMFileReader,
public nsIInterfaceRequestor,
@ -38,7 +33,6 @@ class nsDOMFileReader : public mozilla::dom::FileIOObject,
{
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::GlobalObject GlobalObject;
typedef mozilla::dom::File File;
public:
nsDOMFileReader();
@ -68,18 +62,21 @@ public:
// WebIDL
static already_AddRefed<nsDOMFileReader>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
void ReadAsArrayBuffer(JSContext* aCx, File& aBlob, ErrorResult& aRv)
void ReadAsArrayBuffer(JSContext* aCx, nsIDOMBlob* aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(aCx, aBlob, EmptyString(), FILE_AS_ARRAYBUFFER, aRv);
}
void ReadAsText(File& aBlob, const nsAString& aLabel, ErrorResult& aRv)
void ReadAsText(nsIDOMBlob* aBlob, const nsAString& aLabel, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, aLabel, FILE_AS_TEXT, aRv);
}
void ReadAsDataURL(File& aBlob, ErrorResult& aRv)
void ReadAsDataURL(nsIDOMBlob* aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, EmptyString(), FILE_AS_DATAURL, aRv);
}
@ -102,8 +99,9 @@ public:
using FileIOObject::SetOnerror;
IMPL_EVENT_HANDLER(loadend)
void ReadAsBinaryString(File& aBlob, ErrorResult& aRv)
void ReadAsBinaryString(nsIDOMBlob* aBlob, ErrorResult& aRv)
{
MOZ_ASSERT(aBlob);
ReadFileContent(nullptr, aBlob, EmptyString(), FILE_AS_BINARY, aRv);
}
@ -124,7 +122,7 @@ protected:
FILE_AS_DATAURL
};
void ReadFileContent(JSContext* aCx, File& aBlob,
void ReadFileContent(JSContext* aCx, nsIDOMBlob* aBlob,
const nsAString &aCharset, eDataFormat aDataFormat,
ErrorResult& aRv);
nsresult GetAsText(nsIDOMBlob *aFile, const nsACString &aCharset,

View File

@ -5,8 +5,7 @@
#include "nsFormData.h"
#include "nsIVariant.h"
#include "nsIInputStream.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/File.h"
#include "nsIDOMFile.h"
#include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/FormDataBinding.h"
@ -22,34 +21,9 @@ nsFormData::nsFormData(nsISupports* aOwner)
// -------------------------------------------------------------------------
// nsISupports
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormData)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFormData)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
ImplCycleCollectionUnlink(tmp->mFormData[i].fileValue);
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFormData)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
for (uint32_t i = 0, len = tmp->mFormData.Length(); i < len; ++i) {
ImplCycleCollectionTraverse(cb,tmp->mFormData[i].fileValue,
"mFormData[i].fileValue", 0);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsFormData)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsFormData, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormData)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMFormData)
@ -74,7 +48,7 @@ nsFormData::Append(const nsAString& aName, const nsAString& aValue)
}
void
nsFormData::Append(const nsAString& aName, File& aBlob,
nsFormData::Append(const nsAString& aName, nsIDOMBlob* aBlob,
const Optional<nsAString>& aFilename)
{
nsString filename;
@ -83,7 +57,7 @@ nsFormData::Append(const nsAString& aName, File& aBlob,
} else {
filename.SetIsVoid(true);
}
AddNameFilePair(aName, &aBlob, filename);
AddNameFilePair(aName, aBlob, filename);
}
// -------------------------------------------------------------------------
@ -106,10 +80,9 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
nsMemory::Free(iid);
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
nsRefPtr<File> blob = static_cast<File*>(domBlob.get());
if (domBlob) {
Optional<nsAString> temp;
Append(aName, *blob, temp);
Append(aName, domBlob, temp);
return NS_OK;
}
}

View File

@ -6,6 +6,7 @@
#define nsFormData_h__
#include "mozilla/Attributes.h"
#include "nsIDOMFile.h"
#include "nsIDOMFormData.h"
#include "nsIXMLHttpRequest.h"
#include "nsFormSubmission.h"
@ -14,11 +15,12 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
class nsIDOMFile;
namespace mozilla {
class ErrorResult;
namespace dom {
class File;
class HTMLFormElement;
class GlobalObject;
} // namespace dom
@ -55,7 +57,7 @@ public:
const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement,
mozilla::ErrorResult& aRv);
void Append(const nsAString& aName, const nsAString& aValue);
void Append(const nsAString& aName, mozilla::dom::File& aBlob,
void Append(const nsAString& aName, nsIDOMBlob* aBlob,
const mozilla::dom::Optional<nsAString>& aFilename);
// nsFormSubmission

View File

@ -27,10 +27,10 @@
#include "nsIScriptSecurityManager.h"
#include "nsIJSRuntimeService.h"
#include "nsIDOMClassInfo.h"
#include "nsIDOMFile.h"
#include "xpcpublic.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/ScriptSettings.h"
@ -204,7 +204,7 @@ BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType*
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsRefPtr<File>>& blobs = aData.mClosure.mBlobs;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
@ -255,13 +255,8 @@ UnpackClonedMessageData(const ClonedMessageData& aData)
auto* blob =
static_cast<typename BlobTraits<Flavor>::BlobType*>(blobs[i]);
MOZ_ASSERT(blob);
nsRefPtr<FileImpl> blobImpl = blob->GetBlobImpl();
MOZ_ASSERT(blobImpl);
// This object will be duplicated with a correct parent before being
// exposed to JS.
nsRefPtr<File> domBlob = new File(nullptr, blobImpl);
nsCOMPtr<nsIDOMBlob> domBlob = blob->GetBlob();
MOZ_ASSERT(domBlob);
cloneData.mClosure.mBlobs.AppendElement(domBlob);
}
}

View File

@ -10,15 +10,14 @@
#include "nsClassHashtable.h"
#include "nsNetUtil.h"
#include "nsIPrincipal.h"
#include "nsDOMFile.h"
#include "DOMMediaStream.h"
#include "mozilla/dom/MediaSource.h"
#include "nsIMemoryReporter.h"
#include "mozilla/dom/File.h"
#include "mozilla/Preferences.h"
#include "mozilla/LoadInfo.h"
using mozilla::dom::FileImpl;
using mozilla::ErrorResult;
using mozilla::dom::DOMFileImpl;
using mozilla::LoadInfo;
// -----------------------------------------------------------------------
@ -497,7 +496,7 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
return NS_ERROR_DOM_BAD_URI;
}
nsCOMPtr<PIFileImpl> blobImpl = do_QueryInterface(info->mObject);
nsCOMPtr<PIDOMFileImpl> blobImpl = do_QueryInterface(info->mObject);
if (!blobImpl) {
return NS_ERROR_DOM_BAD_URI;
}
@ -511,7 +510,7 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
}
#endif
FileImpl* blob = static_cast<FileImpl*>(blobImpl.get());
DOMFileImpl* blob = static_cast<DOMFileImpl*>(blobImpl.get());
nsCOMPtr<nsIInputStream> stream;
nsresult rv = blob->GetInternalStream(getter_AddRefs(stream));
NS_ENSURE_SUCCESS(rv, rv);
@ -523,19 +522,19 @@ nsHostObjectProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
NS_ENSURE_SUCCESS(rv, rv);
nsString type;
blob->GetType(type);
rv = blob->GetType(type);
NS_ENSURE_SUCCESS(rv, rv);
if (blob->IsFile()) {
nsString filename;
blob->GetName(filename);
rv = blob->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);
channel->SetContentDispositionFilename(filename);
}
ErrorResult error;
uint64_t size = blob->GetSize(error);
if (NS_WARN_IF(error.Failed())) {
return error.ErrorCode();
}
uint64_t size;
rv = blob->GetSize(&size);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILoadInfo> loadInfo =
new mozilla::LoadInfo(info->mPrincipal,
@ -596,12 +595,12 @@ NS_GetStreamForBlobURI(nsIURI* aURI, nsIInputStream** aStream)
*aStream = nullptr;
nsCOMPtr<PIFileImpl> blobImpl = do_QueryInterface(GetDataObject(aURI));
nsCOMPtr<PIDOMFileImpl> blobImpl = do_QueryInterface(GetDataObject(aURI));
if (!blobImpl) {
return NS_ERROR_DOM_BAD_URI;
}
FileImpl* blob = static_cast<FileImpl*>(blobImpl.get());
DOMFileImpl* blob = static_cast<DOMFileImpl*>(blobImpl.get());
return blob->GetInternalStream(aStream);
}

View File

@ -10,13 +10,12 @@
#include <unistd.h>
#endif
#include "mozilla/ArrayUtils.h"
#include "mozilla/dom/BlobSet.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/XMLHttpRequestUploadBinding.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/LoadInfo.h"
#include "mozilla/MemoryReporting.h"
#include "nsDOMBlobBuilder.h"
#include "nsIDOMDocument.h"
#include "mozilla/dom/ProgressEvent.h"
#include "nsIJARChannel.h"
@ -57,6 +56,7 @@
#include "nsIContentSecurityPolicy.h"
#include "nsAsyncRedirectVerifyHelper.h"
#include "nsStringBuffer.h"
#include "nsDOMFile.h"
#include "nsIFileChannel.h"
#include "mozilla/Telemetry.h"
#include "jsfriendapi.h"
@ -784,9 +784,8 @@ nsXMLHttpRequest::CreatePartialBlob()
if (mLoadTotal == mLoadTransferred) {
mResponseBlob = mDOMFile;
} else {
ErrorResult rv;
mResponseBlob = mDOMFile->CreateSlice(0, mDataAvailable,
EmptyString(), rv);
mResponseBlob =
mDOMFile->CreateSlice(0, mDataAvailable, EmptyString());
}
return;
}
@ -801,7 +800,7 @@ nsXMLHttpRequest::CreatePartialBlob()
mChannel->GetContentType(contentType);
}
mResponseBlob = mBlobSet->GetBlobInternal(GetOwner(), contentType);
mResponseBlob = mBlobSet->GetBlobInternal(contentType);
}
/* attribute AString responseType; */
@ -1008,7 +1007,7 @@ nsXMLHttpRequest::GetResponse(JSContext* aCx,
return;
}
WrapNewBindingObject(aCx, mResponseBlob, aResponse);
aRv = nsContentUtils::WrapNative(aCx, mResponseBlob, aResponse);
return;
}
case XML_HTTP_RESPONSE_TYPE_DOCUMENT:
@ -1898,8 +1897,9 @@ bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request)
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mDOMFile = File::CreateFromFile(GetOwner(), file, EmptyString(),
NS_ConvertASCIItoUTF16(contentType));
mDOMFile =
DOMFile::CreateFromFile(file, EmptyString(),
NS_ConvertASCIItoUTF16(contentType));
mBlobSet = nullptr;
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
@ -2243,7 +2243,7 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
// Also, no-store response cannot be written in persistent cache.
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mResponseBlob = mBlobSet->GetBlobInternal(GetOwner(), contentType);
mResponseBlob = mBlobSet->GetBlobInternal(contentType);
mBlobSet = nullptr;
}
NS_ASSERTION(mResponseBody.IsEmpty(), "mResponseBody should be empty");
@ -2618,8 +2618,7 @@ nsXMLHttpRequest::GetRequestBody(nsIVariant* aVariant,
case nsXMLHttpRequest::RequestBody::Blob:
{
nsresult rv;
nsCOMPtr<nsIDOMBlob> blob = value.mBlob;
nsCOMPtr<nsIXHRSendable> sendable = do_QueryInterface(blob, &rv);
nsCOMPtr<nsIXHRSendable> sendable = do_QueryInterface(value.mBlob, &rv);
NS_ENSURE_SUCCESS(rv, rv);
return ::GetRequestBody(sendable, aResult, aContentLength, aContentType, aCharset);

View File

@ -41,6 +41,8 @@
#endif
class AsyncVerifyRedirectCallbackForwarder;
class BlobSet;
class nsDOMFile;
class nsFormData;
class nsIJARChannel;
class nsILoadGroup;
@ -50,8 +52,7 @@ class nsIJSID;
namespace mozilla {
namespace dom {
class BlobSet;
class File;
class DOMFile;
}
// A helper for building up an ArrayBuffer object's data
@ -349,9 +350,9 @@ private:
{
mValue.mArrayBufferView = aArrayBufferView;
}
explicit RequestBody(mozilla::dom::File& aBlob) : mType(Blob)
explicit RequestBody(nsIDOMBlob* aBlob) : mType(Blob)
{
mValue.mBlob = &aBlob;
mValue.mBlob = aBlob;
}
explicit RequestBody(nsIDocument* aDocument) : mType(Document)
{
@ -383,7 +384,7 @@ private:
union Value {
const mozilla::dom::ArrayBuffer* mArrayBuffer;
const mozilla::dom::ArrayBufferView* mArrayBufferView;
mozilla::dom::File* mBlob;
nsIDOMBlob* mBlob;
nsIDocument* mDocument;
const nsAString* mString;
nsFormData* mFormData;
@ -439,8 +440,9 @@ public:
{
aRv = Send(RequestBody(&aArrayBufferView));
}
void Send(mozilla::dom::File& aBlob, ErrorResult& aRv)
void Send(nsIDOMBlob* aBlob, ErrorResult& aRv)
{
NS_ASSERTION(aBlob, "Null should go to string version");
aRv = Send(RequestBody(aBlob));
}
void Send(nsIDocument& aDoc, ErrorResult& aRv)
@ -670,13 +672,13 @@ protected:
// It is either a cached blob-response from the last call to GetResponse,
// but is also explicitly set in OnStopRequest.
nsRefPtr<mozilla::dom::File> mResponseBlob;
nsCOMPtr<nsIDOMBlob> mResponseBlob;
// Non-null only when we are able to get a os-file representation of the
// response, i.e. when loading from a file.
nsRefPtr<mozilla::dom::File> mDOMFile;
nsRefPtr<mozilla::dom::DOMFile> mDOMFile;
// We stream data to mBlobSet when response type is "blob" or "moz-blob"
// and mDOMFile is null.
nsAutoPtr<mozilla::dom::BlobSet> mBlobSet;
nsAutoPtr<BlobSet> mBlobSet;
nsString mOverrideMimeType;

View File

@ -33,13 +33,13 @@ function createFileWithData(fileData) {
return testFile;
}
/** Test for Bug 914381. File's created in JS using an nsIFile should allow mozGetFullPathInternal calls to succeed **/
/** Test for Bug 914381. DOMFile's created in JS using an nsIFile should allow mozGetFullPathInternal calls to succeed **/
var file = createFileWithData("Test bug 914381");
var f = new File(file);
var f = File(file);
is(f.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, file.path, "mozFullPath returns path if created with nsIFile");
f = new File(file.path);
f = File(file.path);
is(f.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, "", "mozFullPath returns blank if created with a string");
</script>

View File

@ -20,65 +20,65 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=721569
<script class="testbody" type="text/javascript;version=1.7">
"use strict";
/** Test for Bug 721569 **/
var blob = new Blob();
var blob = Blob();
ok(blob, "Blob should exist");
ok(blob.size !== undefined, "Blob should have a size property");
ok(blob.type !== undefined, "Blob should have a type property");
ok(blob.slice, "Blob should have a slice method");
blob = new Blob([], {type: null});
blob = Blob([], {type: null});
ok(blob, "Blob should exist");
is(blob.type, "null", "Blob type should be stringified");
blob = new Blob([], {type: undefined});
blob = Blob([], {type: undefined});
ok(blob, "Blob should exist");
is(blob.type, "", "Blob type should be treated as missing");
try {
blob = new Blob([]);
blob = Blob([]);
ok(true, "an empty blobParts argument should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = new Blob(null);
blob = Blob(null);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a null blobParts member should throw");
}
try {
blob = new Blob([], null);
blob = Blob([], null);
ok(true, "a null options member should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = new Blob([], undefined);
blob = Blob([], undefined);
ok(true, "an undefined options member should not throw");
} catch(e) {
ok(false, "NOT REACHED");
}
try {
blob = new Blob([], false);
blob = Blob([], false);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a boolean options member should throw");
}
try {
blob = new Blob([], 0);
blob = Blob([], 0);
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a numeric options member should throw");
}
try {
blob = new Blob([], "");
blob = Blob([], "");
ok(false, "NOT REACHED");
} catch(e) {
ok(true, "a string options member should throw");
@ -100,13 +100,13 @@ ok(true, "a string options member should throw");
is(JSON.stringify(called), JSON.stringify(["endings", "type"]), "dictionary members should be get in lexicographical order");
})();
let blob1 = new Blob(["squiggle"]);
let blob1 = Blob(["squiggle"]);
ok(blob1 instanceof Blob, "Blob constructor should produce Blobs");
ok(!(blob1 instanceof File), "Blob constructor should not produce Files");
is(blob1.type, "", "Blob constructor with no options should return Blob with empty type");
is(blob1.size, 8, "Blob constructor should return Blob with correct size");
let blob2 = new Blob(["steak"], {type: "content/type"});
let blob2 = Blob(["steak"], {type: "content/type"});
ok(blob2 instanceof Blob, "Blob constructor should produce Blobs");
ok(!(blob2 instanceof File), "Blob constructor should not produce Files");
is(blob2.type, "content/type", "Blob constructor with a type option should return Blob with the type");

View File

@ -13,6 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=403852
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=403852">Mozilla Bug 403852</a>
<p id="display">
<input id="fileList" type="file"></input>
<canvas id="canvas"></canvas>
</p>
<div id="content" style="display: none">
</div>
@ -36,14 +37,10 @@ ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
var d = new Date(testFile.lastModifiedTime);
ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same.");
var cf = document.getElementById("canvas").mozGetAsFile("canvFile");
var x = new Date();
// In our implementation of File object, lastModifiedDate is unknown only for new objects.
// Using canvas or input[type=file] elements, we 'often' have a valid lastModifiedDate values.
// For canvas we use memory files and the lastModifiedDate is now().
var f = new File([new Blob(['test'], {type: 'text/plain'})], "test-name");
var y = f.lastModifiedDate;
var y = cf.lastModifiedDate;
var z = new Date();
ok((x.getTime() <= y.getTime()) && (y.getTime() <= z.getTime()), "lastModifiedDate of file which does not have last modified date should be current time");

View File

@ -16,6 +16,7 @@
#include "mozilla/gfx/Rect.h"
class nsICanvasRenderingContextInternal;
class nsIDOMFile;
class nsITimerCallback;
namespace mozilla {
@ -30,7 +31,6 @@ class SourceSurface;
namespace dom {
class File;
class FileCallback;
class HTMLCanvasPrintState;
class PrintCallback;
@ -102,9 +102,9 @@ public:
{
SetHTMLBoolAttr(nsGkAtoms::moz_opaque, aValue, aRv);
}
already_AddRefed<File> MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv);
already_AddRefed<nsIDOMFile> MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv);
already_AddRefed<nsISupports> MozGetIPCContext(const nsAString& aContextId,
ErrorResult& aRv)
{

View File

@ -12,7 +12,6 @@
#include "mozilla/Base64.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/dom/CanvasRenderingContext2D.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLCanvasElementBinding.h"
#include "mozilla/dom/UnionTypes.h"
#include "mozilla/dom/MouseEvent.h"
@ -24,6 +23,7 @@
#include "nsAttrValueInlines.h"
#include "nsContentUtils.h"
#include "nsDisplayList.h"
#include "nsDOMFile.h"
#include "nsDOMJSUtils.h"
#include "nsIScriptSecurityManager.h"
#include "nsITimer.h"
@ -549,9 +549,9 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
, mFileCallback(aCallback) {}
// This is called on main thread.
nsresult ReceiveBlob(already_AddRefed<File> aBlob)
nsresult ReceiveBlob(already_AddRefed<DOMFile> aBlob)
{
nsRefPtr<File> blob = aBlob;
nsRefPtr<DOMFile> blob = aBlob;
uint64_t size;
nsresult rv = blob->GetSize(&size);
if (NS_SUCCEEDED(rv)) {
@ -560,10 +560,8 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
JS_updateMallocCounter(jsapi.cx(), size);
}
nsRefPtr<File> newBlob = new File(mGlobal, blob->Impl());
mozilla::ErrorResult error;
mFileCallback->Call(*newBlob, error);
mFileCallback->Call(blob, error);
mGlobal = nullptr;
mFileCallback = nullptr;
@ -587,15 +585,14 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
callback);
}
already_AddRefed<File>
already_AddRefed<nsIDOMFile>
HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType,
ErrorResult& aRv)
{
nsCOMPtr<nsIDOMFile> file;
aRv = MozGetAsFile(aName, aType, getter_AddRefs(file));
nsRefPtr<File> tmp = static_cast<File*>(file.get());
return tmp.forget();
return file.forget();
}
NS_IMETHODIMP
@ -638,12 +635,10 @@ HTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
JS_updateMallocCounter(cx, imgSize);
}
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScopeObject());
// The File takes ownership of the buffer
nsRefPtr<File> file =
File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type,
PR_Now());
// The DOMFile takes ownership of the buffer
nsRefPtr<DOMFile> file =
DOMFile::CreateMemoryFile(imgData, (uint32_t)imgSize, aName, type,
PR_Now());
file.forget(aResult);
return NS_OK;

View File

@ -73,9 +73,9 @@
#include "nsIRadioGroupContainer.h"
// input type=file
#include "mozilla/dom/File.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
#include "nsDOMFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIContentPrefService.h"
#include "nsIMIMEService.h"
@ -236,11 +236,11 @@ class HTMLInputElementState MOZ_FINAL : public nsISupports
mValue = aValue;
}
const nsTArray<nsRefPtr<File>>& GetFiles() {
const nsTArray<nsCOMPtr<nsIDOMFile> >& GetFiles() {
return mFiles;
}
void SetFiles(const nsTArray<nsRefPtr<File>>& aFiles) {
void SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles) {
mFiles.Clear();
mFiles.AppendElements(aFiles);
}
@ -255,7 +255,7 @@ class HTMLInputElementState MOZ_FINAL : public nsISupports
~HTMLInputElementState() {}
nsString mValue;
nsTArray<nsRefPtr<File>> mFiles;
nsTArray<nsCOMPtr<nsIDOMFile> > mFiles;
bool mChecked;
bool mCheckedSet;
};
@ -316,7 +316,7 @@ UploadLastDir::ContentPrefCallback::HandleError(nsresult error)
namespace {
/**
* This enumerator returns File objects after wrapping a single
* This enumerator returns nsDOMFileFile objects after wrapping a single
* nsIFile representing a directory. It enumerates the files under that
* directory and its subdirectories as a flat list of files, ignoring/skipping
* over symbolic links.
@ -374,9 +374,7 @@ public:
if (!mNextFile) {
return NS_ERROR_FAILURE;
}
// The parent for this object will be set on the main thread.
nsRefPtr<File> domFile = File::CreateFromFile(nullptr, mNextFile);
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(mNextFile);
nsCString relDescriptor;
nsresult rv =
mNextFile->GetRelativeDescriptor(mTopDirsParent, relDescriptor);
@ -389,7 +387,8 @@ public:
MOZ_ASSERT(length >= 0);
if (length > 0) {
// Note that we leave the trailing "/" on the path.
FileImplFile* fileImpl = static_cast<FileImplFile*>(domFile->Impl());
DOMFileImplFile* fileImpl =
static_cast<DOMFileImplFile*>(domFile->Impl());
MOZ_ASSERT(fileImpl);
fileImpl->SetPath(Substring(path, 0, uint32_t(length)));
}
@ -513,7 +512,7 @@ public:
NS_IMETHOD Run() {
if (!NS_IsMainThread()) {
// Build up list of File objects on this dedicated thread:
// Build up list of nsDOMFileFile objects on this dedicated thread:
nsCOMPtr<nsISimpleEnumerator> iter =
new DirPickerRecursiveFileEnumerator(mTopDir);
bool hasMore = true;
@ -522,7 +521,7 @@ public:
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
MOZ_ASSERT(domFile);
mFileList.AppendElement(static_cast<File*>(domFile.get()));
mFileList.AppendElement(domFile);
mFileListLength = mFileList.Length();
if (mCanceled) {
MOZ_ASSERT(!mInput, "This is bad - how did this happen?");
@ -552,13 +551,6 @@ public:
return NS_OK;
}
// Recreate File with the correct parent object.
nsCOMPtr<nsIGlobalObject> global = mInput->OwnerDoc()->GetScopeObject();
for (uint32_t i = 0; i < mFileList.Length(); ++i) {
MOZ_ASSERT(!mFileList[i]->GetParentObject());
mFileList[i] = new File(global, mFileList[i]->Impl());
}
// The text control frame (if there is one) isn't going to send a change
// event because it will think this is done by a script.
// So, we can safely send one by ourself.
@ -602,7 +594,7 @@ public:
private:
nsRefPtr<HTMLInputElement> mInput;
nsCOMPtr<nsIFile> mTopDir;
nsTArray<nsRefPtr<File>> mFileList;
nsTArray<nsCOMPtr<nsIDOMFile> > mFileList;
// We access the list length on both threads, so we need the indirection of
// this atomic member to make the access thread safe:
@ -628,7 +620,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
if (mode == static_cast<int16_t>(nsIFilePicker::modeGetFolder)) {
// Directory picking is different, since we still need to do more I/O to
// build up the list of File objects. Since this may block for a
// build up the list of nsDOMFileFile objects. Since this may block for a
// long time, we need to build the list off on another dedicated thread to
// avoid blocking any other activities that the browser is carrying out.
@ -663,7 +655,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
}
// Collect new selected filenames
nsTArray<nsRefPtr<File>> newFiles;
nsTArray<nsCOMPtr<nsIDOMFile> > newFiles;
if (mode == static_cast<int16_t>(nsIFilePicker::modeOpenMultiple)) {
nsCOMPtr<nsISimpleEnumerator> iter;
nsresult rv = mFilePicker->GetDomfiles(getter_AddRefs(iter));
@ -680,7 +672,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp);
MOZ_ASSERT(domFile);
newFiles.AppendElement(static_cast<File*>(domFile.get()));
newFiles.AppendElement(domFile);
}
} else {
MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen));
@ -688,7 +680,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(domFile));
NS_ENSURE_SUCCESS(rv, rv);
if (domFile) {
newFiles.AppendElement(static_cast<File*>(domFile.get()));
newFiles.AppendElement(domFile);
}
}
@ -944,7 +936,7 @@ HTMLInputElement::InitFilePicker(FilePickerType aType)
// Set default directry and filename
nsAutoString defaultName;
const nsTArray<nsRefPtr<File>>& oldFiles = GetFilesInternal();
const nsTArray<nsCOMPtr<nsIDOMFile> >& oldFiles = GetFilesInternal();
nsCOMPtr<nsIFilePickerShownCallback> callback =
new HTMLInputElement::nsFilePickerShownCallback(this, filePicker);
@ -1724,7 +1716,7 @@ HTMLInputElement::IsValueEmpty() const
void
HTMLInputElement::ClearFiles(bool aSetValueChanged)
{
nsTArray<nsRefPtr<File>> files;
nsTArray<nsCOMPtr<nsIDOMFile> > files;
SetFiles(files, aSetValueChanged);
}
@ -2318,7 +2310,7 @@ HTMLInputElement::MozGetFileNameArray(uint32_t* aLength, char16_t*** aFileNames)
void
HTMLInputElement::MozSetFileNameArray(const Sequence< nsString >& aFileNames)
{
nsTArray<nsRefPtr<File>> files;
nsTArray<nsCOMPtr<nsIDOMFile> > files;
for (uint32_t i = 0; i < aFileNames.Length(); ++i) {
nsCOMPtr<nsIFile> file;
@ -2336,8 +2328,7 @@ HTMLInputElement::MozSetFileNameArray(const Sequence< nsString >& aFileNames)
}
if (file) {
nsCOMPtr<nsIGlobalObject> global = OwnerDoc()->GetScopeObject();
nsRefPtr<File> domFile = File::CreateFromFile(global, file);
nsCOMPtr<nsIDOMFile> domFile = DOMFile::CreateFromFile(file);
files.AppendElement(domFile);
} else {
continue; // Not much we can do if the file doesn't exist
@ -2573,7 +2564,7 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
}
void
HTMLInputElement::SetFiles(const nsTArray<nsRefPtr<File>>& aFiles,
HTMLInputElement::SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles,
bool aSetValueChanged)
{
mFiles.Clear();
@ -2586,14 +2577,14 @@ void
HTMLInputElement::SetFiles(nsIDOMFileList* aFiles,
bool aSetValueChanged)
{
nsRefPtr<FileList> files = static_cast<FileList*>(aFiles);
mFiles.Clear();
if (aFiles) {
uint32_t listLength;
aFiles->GetLength(&listLength);
for (uint32_t i = 0; i < listLength; i++) {
nsRefPtr<File> file = files->Item(i);
nsCOMPtr<nsIDOMFile> file;
aFiles->Item(i, getter_AddRefs(file));
mFiles.AppendElement(file);
}
}
@ -2641,7 +2632,7 @@ HTMLInputElement::FireChangeEventIfNeeded()
false);
}
FileList*
nsDOMFileList*
HTMLInputElement::GetFiles()
{
if (mType != NS_FORM_INPUT_FILE) {
@ -2649,7 +2640,7 @@ HTMLInputElement::GetFiles()
}
if (!mFileList) {
mFileList = new FileList(static_cast<nsIContent*>(this));
mFileList = new nsDOMFileList(static_cast<nsIContent*>(this));
UpdateFileList();
}
@ -2793,7 +2784,7 @@ HTMLInputElement::UpdateFileList()
if (mFileList) {
mFileList->Clear();
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
for (uint32_t i = 0; i < files.Length(); ++i) {
if (!mFileList->Append(files[i])) {
return NS_ERROR_FAILURE;
@ -5376,7 +5367,7 @@ HTMLInputElement::SetSelectionEnd(int32_t aSelectionEnd)
NS_IMETHODIMP
HTMLInputElement::GetFiles(nsIDOMFileList** aFileList)
{
nsRefPtr<FileList> list = GetFiles();
nsRefPtr<nsDOMFileList> list = GetFiles();
list.forget(aFileList);
return NS_OK;
}
@ -5643,7 +5634,7 @@ HTMLInputElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
if (mType == NS_FORM_INPUT_FILE) {
// Submit files
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
for (uint32_t i = 0; i < files.Length(); ++i) {
aFormSubmission->AddNameFilePair(name, files[i], NullString());
@ -5891,7 +5882,7 @@ HTMLInputElement::RestoreState(nsPresState* aState)
break;
case VALUE_MODE_FILENAME:
{
const nsTArray<nsRefPtr<File>>& files = inputState->GetFiles();
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = inputState->GetFiles();
SetFiles(files, true);
}
break;
@ -6401,7 +6392,7 @@ HTMLInputElement::IsValueMissing() const
return IsValueEmpty();
case VALUE_MODE_FILENAME:
{
const nsTArray<nsRefPtr<File>>& files = GetFilesInternal();
const nsTArray<nsCOMPtr<nsIDOMFile> >& files = GetFilesInternal();
return files.IsEmpty();
}
case VALUE_MODE_DEFAULT_ON:

View File

@ -24,6 +24,7 @@
#include "nsContentUtils.h"
#include "nsTextEditorState.h"
class nsDOMFileList;
class nsIRadioGroupContainer;
class nsIRadioGroupVisitor;
class nsIRadioVisitor;
@ -37,8 +38,6 @@ namespace dom {
class Date;
class DirPickerFileListBuilderTask;
class File;
class FileList;
class UploadLastDir MOZ_FINAL : public nsIObserver, public nsSupportsWeakReference {
@ -211,12 +210,12 @@ public:
void GetDisplayFileName(nsAString& aFileName) const;
const nsTArray<nsRefPtr<File>>& GetFilesInternal() const
const nsTArray<nsCOMPtr<nsIDOMFile> >& GetFilesInternal() const
{
return mFiles;
}
void SetFiles(const nsTArray<nsRefPtr<File>>& aFiles, bool aSetValueChanged);
void SetFiles(const nsTArray<nsCOMPtr<nsIDOMFile> >& aFiles, bool aSetValueChanged);
void SetFiles(nsIDOMFileList* aFiles, bool aSetValueChanged);
// Called when a nsIFilePicker or a nsIColorPicker terminate.
@ -433,7 +432,7 @@ public:
// XPCOM GetForm() is OK
FileList* GetFiles();
nsDOMFileList* GetFiles();
void OpenDirectoryPicker(ErrorResult& aRv);
void CancelDirectoryPickerScanIfRunning();
@ -1252,9 +1251,9 @@ protected:
* the frame. Whenever the frame wants to change the filename it has to call
* SetFileNames to update this member.
*/
nsTArray<nsRefPtr<File>> mFiles;
nsTArray<nsCOMPtr<nsIDOMFile> > mFiles;
nsRefPtr<FileList> mFileList;
nsRefPtr<nsDOMFileList> mFileList;
nsRefPtr<DirPickerFileListBuilderTask> mDirPickerFileListBuilderTask;

View File

@ -52,11 +52,11 @@ function runTest() {
fd.append("empty", blob);
fd.append("explicit", blob, "explicit-file-name");
fd.append("explicit-empty", blob, "");
file = new File([blob], 'testname', {type: 'text/plain'});
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: 'testname'}));
fd.append("file-name", file);
file = new File([blob], '', {type: 'text/plain'});
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: ''}));
fd.append("empty-file-name", file);
file = new File([blob], 'testname', {type: 'text/plain'});
file = SpecialPowers.unwrap(SpecialPowers.wrap(window).File(blob, {name: 'testname'}));
fd.append("file-name-overwrite", file, "overwrite");
xhr.responseType = 'json';
xhr.send(fd);
@ -65,4 +65,4 @@ function runTest() {
runTest()
</script>
</body>
</html>
</html>

View File

@ -5,8 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "EncodedBufferCache.h"
#include "mozilla/dom/File.h"
#include "nsAnonymousTemporaryFile.h"
#include "nsDOMFile.h"
#include "prio.h"
namespace mozilla {
@ -39,16 +39,15 @@ EncodedBufferCache::AppendBuffer(nsTArray<uint8_t> & aBuf)
}
already_AddRefed<dom::File>
EncodedBufferCache::ExtractBlob(nsISupports* aParent,
const nsAString &aContentType)
already_AddRefed<nsIDOMBlob>
EncodedBufferCache::ExtractBlob(const nsAString &aContentType)
{
MutexAutoLock lock(mMutex);
nsRefPtr<dom::File> blob;
nsCOMPtr<nsIDOMBlob> blob;
if (mTempFileEnabled) {
// generate new temporary file to write
blob = dom::File::CreateTemporaryFileBlob(aParent, mFD, 0, mDataSize,
aContentType);
blob = dom::DOMFile::CreateTemporaryFileBlob(mFD, 0, mDataSize,
aContentType);
// fallback to memory blob
mTempFileEnabled = false;
mDataSize = 0;
@ -63,8 +62,7 @@ EncodedBufferCache::ExtractBlob(nsISupports* aParent,
mEncodedBuffers.ElementAt(i).Length());
offset += mEncodedBuffers.ElementAt(i).Length();
}
blob = dom::File::CreateMemoryFile(aParent, blobData, mDataSize,
aContentType);
blob = dom::DOMFile::CreateMemoryFile(blobData, mDataSize, aContentType);
mEncodedBuffers.Clear();
} else
return nullptr;

View File

@ -16,10 +16,6 @@ class nsIDOMBlob;
namespace mozilla {
namespace dom {
class File;
}
class ReentrantMonitor;
/**
* Data is moved into a temporary file when it grows beyond
@ -43,7 +39,7 @@ public:
// aBuf will append to mEncodedBuffers or temporary File, aBuf also be cleared
void AppendBuffer(nsTArray<uint8_t> & aBuf);
// Read all buffer from memory or file System, also Remove the temporary file or clean the buffers in memory.
already_AddRefed<dom::File> ExtractBlob(nsISupports* aParent, const nsAString &aContentType);
already_AddRefed<nsIDOMBlob> ExtractBlob(const nsAString &aContentType);
private:
//array for storing the encoded data.

View File

@ -15,11 +15,11 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/AudioStreamTrack.h"
#include "mozilla/dom/BlobEvent.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/RecordErrorEvent.h"
#include "mozilla/dom/VideoStreamTrack.h"
#include "nsError.h"
#include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIPrincipal.h"
#include "nsMimeTypes.h"
#include "nsProxyRelease.h"
@ -389,8 +389,7 @@ public:
already_AddRefed<nsIDOMBlob> GetEncodedData()
{
MOZ_ASSERT(NS_IsMainThread());
return mEncodedBufferCache->ExtractBlob(mRecorder->GetParentObject(),
mMimeType);
return mEncodedBufferCache->ExtractBlob(mMimeType);
}
bool IsEncoderError()
@ -921,10 +920,7 @@ MediaRecorder::CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob)
BlobEventInit init;
init.mBubbles = false;
init.mCancelable = false;
nsCOMPtr<nsIDOMBlob> blob = aBlob;
init.mData = static_cast<File*>(blob.get());
init.mData = aBlob;
nsRefPtr<BlobEvent> event =
BlobEvent::Constructor(this,
NS_LITERAL_STRING("dataavailable"),

View File

@ -15,20 +15,14 @@
namespace mozilla {
nsresult
CaptureTask::TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv)
CaptureTask::TaskComplete(already_AddRefed<dom::DOMFile> aBlob, nsresult aRv)
{
MOZ_ASSERT(NS_IsMainThread());
DetachStream();
nsresult rv;
nsRefPtr<dom::File> blob(aBlob);
// We have to set the parent because the blob has been generated with a valid one.
if (blob) {
blob = new dom::File(mImageCapture->GetParentObject(), blob->Impl());
}
nsRefPtr<dom::DOMFile> blob(aBlob);
if (mPrincipalChanged) {
aRv = NS_ERROR_DOM_SECURITY_ERR;
IC_LOG("MediaStream principal should not change during TakePhoto().");
@ -104,9 +98,9 @@ CaptureTask::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
public:
explicit EncodeComplete(CaptureTask* aTask) : mTask(aTask) {}
nsresult ReceiveBlob(already_AddRefed<dom::File> aBlob) MOZ_OVERRIDE
nsresult ReceiveBlob(already_AddRefed<dom::DOMFile> aBlob) MOZ_OVERRIDE
{
nsRefPtr<dom::File> blob(aBlob);
nsRefPtr<dom::DOMFile> blob(aBlob);
mTask->TaskComplete(blob.forget(), NS_OK);
mTask = nullptr;
return NS_OK;

View File

@ -13,8 +13,8 @@
namespace mozilla {
namespace dom {
class File;
class ImageCapture;
class DOMFile;
}
/**
@ -51,7 +51,7 @@ public:
//
// Note:
// this function should be called on main thread.
nsresult TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv);
nsresult TaskComplete(already_AddRefed<dom::DOMFile> aBlob, nsresult aRv);
// Add listeners into MediaStream and PrincipalChangeObserver. It should be on
// main thread only.

View File

@ -7,11 +7,11 @@
#include "ImageCapture.h"
#include "mozilla/dom/BlobEvent.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ImageCaptureError.h"
#include "mozilla/dom/ImageCaptureErrorEvent.h"
#include "mozilla/dom/ImageCaptureErrorEventBinding.h"
#include "mozilla/dom/VideoStreamTrack.h"
#include "nsDOMFile.h"
#include "nsIDocument.h"
#include "CaptureTask.h"
#include "MediaEngine.h"
@ -102,9 +102,9 @@ ImageCapture::TakePhotoByMediaEngine()
mPrincipalChanged = true;
}
nsresult PhotoComplete(already_AddRefed<File> aBlob) MOZ_OVERRIDE
nsresult PhotoComplete(already_AddRefed<DOMFile> aBlob) MOZ_OVERRIDE
{
nsRefPtr<File> blob = aBlob;
nsRefPtr<DOMFile> blob = aBlob;
if (mPrincipalChanged) {
return PhotoError(NS_ERROR_DOM_SECURITY_ERR);
@ -172,7 +172,7 @@ ImageCapture::TakePhoto(ErrorResult& aResult)
}
nsresult
ImageCapture::PostBlobEvent(File* aBlob)
ImageCapture::PostBlobEvent(nsIDOMBlob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
if (!CheckPrincipal()) {

View File

@ -32,7 +32,6 @@ PRLogModuleInfo* GetICLog();
namespace dom {
class File;
class VideoStreamTrack;
/**
@ -80,7 +79,7 @@ public:
ImageCapture(VideoStreamTrack* aVideoStreamTrack, nsPIDOMWindow* aOwnerWindow);
// Post a Blob event to script.
nsresult PostBlobEvent(File* aBlob);
nsresult PostBlobEvent(nsIDOMBlob* aBlob);
// Post an error event to script.
// aErrorCode should be one of error codes defined in ImageCaptureError.h.

View File

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
class File;
class DOMFile;
}
struct VideoTrackConstraintsN;
@ -150,7 +150,7 @@ public:
// aBlob is the image captured by MediaEngineSource. It is
// called on main thread.
virtual nsresult PhotoComplete(already_AddRefed<dom::File> aBlob) = 0;
virtual nsresult PhotoComplete(already_AddRefed<dom::DOMFile> aBlob) = 0;
// It is called on main thread. aRv is the error code.
virtual nsresult PhotoError(nsresult aRv) = 0;

View File

@ -5,7 +5,7 @@
#include "MediaEngineDefault.h"
#include "nsCOMPtr.h"
#include "mozilla/dom/File.h"
#include "nsDOMFile.h"
#include "nsILocalFile.h"
#include "Layers.h"
#include "ImageContainer.h"
@ -208,7 +208,7 @@ MediaEngineDefaultVideoSource::Snapshot(uint32_t aDuration, nsIDOMFile** aFile)
return NS_OK;
}
nsCOMPtr<nsIDOMFile> domFile = dom::File::CreateFromFile(nullptr, localFile);
nsCOMPtr<nsIDOMFile> domFile = dom::DOMFile::CreateFromFile(localFile);
domFile.forget(aFile);
return NS_OK;
#endif

View File

@ -10,10 +10,10 @@
#include "nsIThread.h"
#include "nsIRunnable.h"
#include "mozilla/dom/File.h"
#include "mozilla/Mutex.h"
#include "mozilla/Monitor.h"
#include "nsCOMPtr.h"
#include "nsDOMFile.h"
#include "nsThreadUtils.h"
#include "DOMMediaStream.h"
#include "nsDirectoryServiceDefs.h"

View File

@ -943,11 +943,11 @@ MediaEngineWebRTCVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLe
NS_IMETHOD Run()
{
nsRefPtr<dom::File> blob =
dom::File::CreateMemoryFile(nullptr, mPhoto.Elements(), mPhoto.Length(), mMimeType);
nsRefPtr<dom::DOMFile> blob =
dom::DOMFile::CreateMemoryFile(mPhoto.Elements(), mPhoto.Length(), mMimeType);
uint32_t callbackCounts = mCallbacks.Length();
for (uint8_t i = 0; i < callbackCounts; i++) {
nsRefPtr<dom::File> tempBlob = blob;
nsRefPtr<dom::DOMFile> tempBlob = blob;
mCallbacks[i]->PhotoComplete(tempBlob.forget());
}
// PhotoCallback needs to dereference on main thread.

View File

@ -130,7 +130,7 @@ ArchiveReaderEvent::ShareMainThread()
}
}
// This is a File:
// This is a nsDOMFile:
nsRefPtr<nsIDOMFile> file = item->File(mArchiveReader);
if (file) {
fileList.AppendElement(file);

View File

@ -9,9 +9,9 @@
#include "ArchiveReader.h"
#include "mozilla/dom/File.h"
#include "nsISeekableStream.h"
#include "nsIMIMEService.h"
#include "nsDOMFile.h"
#include "ArchiveReaderCommon.h"
@ -35,7 +35,7 @@ public:
// Getter for the filename
virtual nsresult GetFilename(nsString& aFilename) = 0;
// Generate a File
// Generate a DOMFile
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) = 0;
protected:

View File

@ -14,9 +14,8 @@
#include "mozilla/dom/ArchiveReaderBinding.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/EncodingUtils.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -24,10 +23,12 @@ USING_ARCHIVEREADER_NAMESPACE
/* static */ already_AddRefed<ArchiveReader>
ArchiveReader::Constructor(const GlobalObject& aGlobal,
File& aBlob,
nsIDOMBlob* aBlob,
const ArchiveReaderOptions& aOptions,
ErrorResult& aError)
{
MOZ_ASSERT(aBlob);
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aError.Throw(NS_ERROR_UNEXPECTED);
@ -46,13 +47,14 @@ ArchiveReader::Constructor(const GlobalObject& aGlobal,
return reader.forget();
}
ArchiveReader::ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader::ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding)
: mBlob(&aBlob)
: mBlob(aBlob)
, mWindow(aWindow)
, mStatus(NOT_STARTED)
, mEncoding(aEncoding)
{
MOZ_ASSERT(aBlob);
MOZ_ASSERT(aWindow);
}

View File

@ -19,7 +19,6 @@
namespace mozilla {
namespace dom {
struct ArchiveReaderOptions;
class File;
class GlobalObject;
} // namespace dom
} // namespace mozilla
@ -39,10 +38,10 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)
static already_AddRefed<ArchiveReader>
Constructor(const GlobalObject& aGlobal, File& aBlob,
Constructor(const GlobalObject& aGlobal, nsIDOMBlob* aBlob,
const ArchiveReaderOptions& aOptions, ErrorResult& aError);
ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader(nsIDOMBlob* aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding);
nsIDOMWindow* GetParentObject() const
@ -76,7 +75,7 @@ private:
protected:
// The archive blob/file
nsRefPtr<File> mBlob;
nsCOMPtr<nsIDOMBlob> mBlob;
// The window is needed by the requests
nsCOMPtr<nsPIDOMWindow> mWindow;

View File

@ -74,7 +74,7 @@ ArchiveZipItem::GetFilename(nsString& aFilename)
return NS_OK;
}
// From zipItem to File:
// From zipItem to DOMFile:
nsIDOMFile*
ArchiveZipItem::File(ArchiveReader* aArchiveReader)
{
@ -84,7 +84,7 @@ ArchiveZipItem::File(ArchiveReader* aArchiveReader)
return nullptr;
}
return new dom::File(aArchiveReader,
return new DOMFile(
new ArchiveZipFileImpl(filename,
NS_ConvertUTF8toUTF16(GetType()),
StrToInt32(mCentralStruct.orglen),

View File

@ -30,7 +30,7 @@ protected:
public:
nsresult GetFilename(nsString& aFilename) MOZ_OVERRIDE;
// From zipItem to File:
// From zipItem to DOMFile:
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) MOZ_OVERRIDE;
public: // for the event

View File

@ -10,9 +10,7 @@
#include "nsIInputStream.h"
#include "zlib.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
using namespace mozilla::dom;
USING_ARCHIVEREADER_NAMESPACE
#define ZIP_CHUNK 16384
@ -398,16 +396,15 @@ ArchiveZipFileImpl::Traverse(nsCycleCollectionTraversalCallback &cb)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mArchiveReader);
}
already_AddRefed<mozilla::dom::FileImpl>
already_AddRefed<mozilla::dom::DOMFileImpl>
ArchiveZipFileImpl::CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
const nsAString& aContentType)
{
nsRefPtr<FileImpl> impl =
nsRefPtr<DOMFileImpl> impl =
new ArchiveZipFileImpl(mFilename, mContentType, aStart, mLength, mCentral,
mArchiveReader);
return impl.forget();
}
NS_IMPL_ISUPPORTS_INHERITED0(ArchiveZipFileImpl, FileImpl)
NS_IMPL_ISUPPORTS_INHERITED0(ArchiveZipFileImpl, DOMFileImpl)

View File

@ -8,7 +8,7 @@
#define mozilla_dom_archivereader_domarchivefile_h__
#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
#include "nsDOMFile.h"
#include "ArchiveReader.h"
@ -18,9 +18,9 @@
BEGIN_ARCHIVEREADER_NAMESPACE
/**
* ArchiveZipFileImpl to FileImpl
* ArchiveZipFileImpl to DOMFileImpl
*/
class ArchiveZipFileImpl : public FileImplBase
class ArchiveZipFileImpl : public DOMFileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
@ -30,7 +30,7 @@ public:
uint64_t aLength,
ZipCentral& aCentral,
ArchiveReader* aReader)
: FileImplBase(aName, aContentType, aLength),
: DOMFileImplBase(aName, aContentType, aLength),
mCentral(aCentral),
mArchiveReader(aReader),
mFilename(aName)
@ -45,7 +45,7 @@ public:
uint64_t aLength,
ZipCentral& aCentral,
ArchiveReader* aReader)
: FileImplBase(aContentType, aStart, aLength),
: DOMFileImplBase(aContentType, aStart, aLength),
mCentral(aCentral),
mArchiveReader(aReader),
mFilename(aName)
@ -71,9 +71,9 @@ protected:
MOZ_COUNT_DTOR(ArchiveZipFileImpl);
}
virtual already_AddRefed<FileImpl>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv) MOZ_OVERRIDE;
virtual already_AddRefed<DOMFileImpl> CreateSlice(uint64_t aStart,
uint64_t aLength,
const nsAString& aContentType) MOZ_OVERRIDE;
private: // Data
ZipCentral mCentral;

View File

@ -88,10 +88,8 @@ public:
MOZ_ASSERT(NS_IsMainThread());
if (!mFailed) {
// The correct parentObject has to be set by the mEncodeCompleteCallback.
nsRefPtr<File> blob =
File::CreateMemoryFile(nullptr, mImgData, mImgSize, mType);
MOZ_ASSERT(blob);
nsRefPtr<DOMFile> blob =
DOMFile::CreateMemoryFile(mImgData, mImgSize, mType);
rv = mEncodeCompleteCallback->ReceiveBlob(blob.forget());
}

View File

@ -7,8 +7,8 @@
#define ImageEncoder_h
#include "imgIEncoder.h"
#include "nsDOMFile.h"
#include "nsError.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLCanvasElementBinding.h"
#include "nsLayoutUtils.h"
#include "nsNetUtil.h"
@ -51,8 +51,6 @@ public:
// successful dispatching of the extraction step to the encoding thread.
// aEncodeCallback will be called on main thread when encoding process is
// success.
// Note: The callback has to set a valid parent for content for the generated
// Blob object.
static nsresult ExtractDataAsync(nsAString& aType,
const nsAString& aOptions,
bool aUsingCustomOptions,
@ -64,8 +62,6 @@ public:
// Extract an Image asynchronously. Its function is same as ExtractDataAsync
// except for the parameters. aImage is the uncompressed data. aEncodeCallback
// will be called on main thread when encoding process is success.
// Note: The callback has to set a valid parent for content for the generated
// Blob object.
static nsresult ExtractDataFromLayersImageAsync(nsAString& aType,
const nsAString& aOptions,
bool aUsingCustomOptions,
@ -115,7 +111,7 @@ class EncodeCompleteCallback
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodeCompleteCallback)
virtual nsresult ReceiveBlob(already_AddRefed<File> aBlob) = 0;
virtual nsresult ReceiveBlob(already_AddRefed<DOMFile> aBlob) = 0;
protected:
virtual ~EncodeCompleteCallback() {}

View File

@ -5,9 +5,7 @@
#include "MessagePort.h"
#include "MessageEvent.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MessageChannel.h"
#include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/MessagePortList.h"
@ -18,6 +16,7 @@
#include "ScriptSettings.h"
#include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIPresShell.h"
@ -104,37 +103,7 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data,
void* closure)
{
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
if (tag == SCTAG_DOM_BLOB) {
NS_ASSERTION(!data, "Data should be empty");
// What we get back from the reader is a FileImpl.
// From that we create a new File.
FileImpl* blobImpl;
if (JS_ReadBytes(reader, &blobImpl, sizeof(blobImpl))) {
MOZ_ASSERT(blobImpl);
// nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
JS::Rooted<JS::Value> val(cx);
{
nsRefPtr<File> blob = new File(scInfo->mPort->GetParentObject(),
blobImpl);
if (!WrapNewBindingObject(cx, blob, &val)) {
return nullptr;
}
}
return &val.toObject();
}
}
if (tag == SCTAG_DOM_FILELIST) {
if (tag == SCTAG_DOM_BLOB || tag == SCTAG_DOM_FILELIST) {
NS_ASSERTION(!data, "Data should be empty");
nsISupports* supports;
@ -165,19 +134,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
// See if this is a File/Blob object.
{
File* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&
JS_WriteBytes(writer, &blobImpl, sizeof(blobImpl))) {
scInfo->mEvent->StoreISupports(blobImpl);
return true;
}
}
}
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -185,6 +141,11 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native();
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(supports);
if (blob) {
scTag = SCTAG_DOM_BLOB;
}
nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list) {
scTag = SCTAG_DOM_FILELIST;

View File

@ -13,7 +13,6 @@
#include "nsMimeTypeArray.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/DesktopNotification.h"
#include "mozilla/dom/File.h"
#include "nsGeolocation.h"
#include "nsIHttpProtocolHandler.h"
#include "nsIContentPolicy.h"
@ -1156,14 +1155,14 @@ Navigator::SendBeacon(const nsAString& aUrl,
in = strStream;
} else if (aData.Value().IsBlob()) {
File& blob = aData.Value().GetAsBlob();
rv = blob.GetInternalStream(getter_AddRefs(in));
nsCOMPtr<nsIDOMBlob> blob = aData.Value().GetAsBlob();
rv = blob->GetInternalStream(getter_AddRefs(in));
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);
return false;
}
nsAutoString type;
rv = blob.GetType(type);
rv = blob->GetType(type);
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);
return false;

View File

@ -25,6 +25,7 @@ class nsPIDOMWindow;
class nsIDOMNavigatorSystemMessages;
class nsDOMCameraManager;
class nsDOMDeviceStorage;
class nsIDOMBlob;
class nsIPrincipal;
class nsIURI;

View File

@ -6,8 +6,8 @@
#include "URL.h"
#include "nsGlobalWindow.h"
#include "nsDOMFile.h"
#include "DOMMediaStream.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MediaSource.h"
#include "mozilla/dom/URLBinding.h"
#include "nsHostObjectProtocolHandler.h"
@ -111,12 +111,15 @@ URL::Constructor(const GlobalObject& aGlobal, const nsAString& aUrl,
void
URL::CreateObjectURL(const GlobalObject& aGlobal,
File& aBlob,
nsIDOMBlob* aBlob,
const objectURLOptions& aOptions,
nsString& aResult,
ErrorResult& aError)
{
CreateObjectURLInternal(aGlobal, aBlob.Impl(),
DOMFile* blob = static_cast<DOMFile*>(aBlob);
MOZ_ASSERT(blob);
CreateObjectURLInternal(aGlobal, blob->Impl(),
NS_LITERAL_CSTRING(BLOBURI_SCHEME), aOptions, aResult,
aError);
}

View File

@ -23,7 +23,6 @@ class DOMMediaStream;
namespace dom {
class File;
class MediaSource;
class GlobalObject;
struct objectURLOptions;
@ -54,7 +53,7 @@ public:
const nsAString& aBase, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal,
File& aBlob,
nsIDOMBlob* aBlob,
const objectURLOptions& aOptions,
nsString& aResult,
ErrorResult& aError);

View File

@ -35,6 +35,7 @@
#include "nsIXPConnect.h"
#include "xptcall.h"
#include "nsTArray.h"
#include "nsDOMBlobBuilder.h"
// General helper includes
#include "nsGlobalWindow.h"
@ -100,6 +101,10 @@
#endif
#include "nsIDOMXPathNSResolver.h"
// Drag and drop
#include "nsIDOMFile.h"
#include "nsDOMBlobBuilder.h" // nsDOMMultipartFile
#include "nsIEventListenerService.h"
#include "nsIMessageManager.h"
@ -289,6 +294,11 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(XPathNSResolver, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(Blob, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(File, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(MozSmsMessage, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -362,6 +372,8 @@ struct nsConstructorFuncMapData
static const nsConstructorFuncMapData kConstructorFuncMap[] =
{
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(Blob, DOMMultipartFileImpl::NewBlob)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(File, DOMMultipartFileImpl::NewFile)
NS_DEFINE_CONSTRUCTOR_FUNC_DATA(XSLTProcessor, XSLTProcessorCtor)
};
#undef NS_DEFINE_CONSTRUCTOR_FUNC_DATA
@ -783,6 +795,15 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMXPathNSResolver)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(Blob, nsIDOMBlob)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(File, nsIDOMFile)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMFile)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(MozSmsMessage, nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMMozSmsMessage)
DOM_CLASSINFO_MAP_END

View File

@ -43,6 +43,9 @@ DOMCI_CLASS(XSLTProcessor)
// DOM Level 3 XPath objects
DOMCI_CLASS(XPathNSResolver)
DOMCI_CLASS(Blob)
DOMCI_CLASS(File)
DOMCI_CLASS(MozSmsMessage)
DOMCI_CLASS(MozMmsMessage)
DOMCI_CLASS(MozMobileMessageThread)

View File

@ -48,11 +48,11 @@
#include "nsComputedDOMStyle.h"
#include "nsIPresShell.h"
#include "nsCSSProps.h"
#include "nsDOMFile.h"
#include "nsTArrayHelpers.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/DOMRect.h"
#include <algorithm>
@ -74,6 +74,7 @@
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/quota/PersistenceType.h"
#include "mozilla/dom/quota/QuotaManager.h"
#include "nsDOMBlobBuilder.h"
#include "nsPrintfCString.h"
#include "nsViewportInfo.h"
#include "nsIFormControl.h"
@ -2852,15 +2853,7 @@ nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_STATE(window);
nsPIDOMWindow* innerWindow = window->GetCurrentInnerWindow();
if (!innerWindow) {
return NS_ERROR_FAILURE;
}
nsRefPtr<File> file = File::CreateFromFile(innerWindow, aFile);
nsRefPtr<DOMFile> file = DOMFile::CreateFromFile(aFile);
file.forget(aDOMFile);
return NS_OK;
}

View File

@ -122,6 +122,7 @@
#include "nsAutoPtr.h"
#include "nsContentUtils.h"
#include "nsCSSProps.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h"
#include "nsIURIFixup.h"
#ifndef DEBUG
@ -7877,32 +7878,18 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data,
void* closure)
{
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
if (tag == SCTAG_DOM_BLOB) {
NS_ASSERTION(!data, "Data should be empty");
// What we get back from the reader is a FileImpl.
// From that we create a new File.
FileImpl* blobImpl;
if (JS_ReadBytes(reader, &blobImpl, sizeof(blobImpl))) {
MOZ_ASSERT(blobImpl);
// nsRefPtr<File> needs to go out of scope before toObjectOrNull() is
// called because the static analysis thinks dereferencing XPCOM objects
// can GC (because in some cases it can!), and a return statement with a
// JSObject* type means that JSObject* is on the stack as a raw pointer
// while destructors are running.
// What we get back from the reader is a DOMFileImpl.
// From that we create a new DOMFile.
nsISupports* supports;
if (JS_ReadBytes(reader, &supports, sizeof(supports))) {
nsCOMPtr<nsIDOMBlob> file = new DOMFile(static_cast<DOMFileImpl*>(supports));
JS::Rooted<JS::Value> val(cx);
{
nsRefPtr<File> blob = new File(scInfo->window, blobImpl);
if (!WrapNewBindingObject(cx, blob, &val)) {
return nullptr;
}
if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, file, &val))) {
return val.toObjectOrNull();
}
return &val.toObject();
}
}
@ -7937,19 +7924,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
// See if this is a File/Blob object.
{
File* blob = nullptr;
if (scInfo->subsumes && NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&
JS_WriteBytes(writer, &blobImpl, sizeof(blobImpl))) {
scInfo->event->StoreISupports(blobImpl);
return true;
}
}
}
nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -7957,6 +7931,13 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native();
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(supports);
if (blob && scInfo->subsumes) {
scTag = SCTAG_DOM_BLOB;
DOMFile* file = static_cast<DOMFile*>(blob.get());
supports = file->Impl();
}
nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list && scInfo->subsumes)
scTag = SCTAG_DOM_FILELIST;

View File

@ -1,7 +1,7 @@
this.EXPORTED_SYMBOLS = ['checkFromJSM'];
this.checkFromJSM = function checkFromJSM(ok, is) {
Components.utils.importGlobalProperties(['URL', 'Blob']);
Components.utils.importGlobalProperties(['URL']);
var url = new URL('http://www.example.com');
is(url.href, "http://www.example.com/", "JSM should have URL");

View File

@ -50,11 +50,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=677638
a.port1.onmessage = function(evt) {
ok(tests.length, "We are waiting for a message");
if (typeof(tests[0]) == 'object') {
is(typeof(tests[0]), typeof(evt.data), "Value ok: " + tests[0]);
} else {
is(tests[0], evt.data, "Value ok: " + tests[0]);
}
is(tests[0], evt.data, "Value ok: " + tests[0]);
tests.shift();
runTest();
}

View File

@ -136,10 +136,13 @@ DOMInterfaces = {
'headerFile': 'mozilla/dom/BarProps.h',
},
'Blob': {
'nativeType': 'mozilla::dom::File',
'headerFile': 'mozilla/dom/File.h',
'Blob': [
{
'headerFile': 'nsIDOMFile.h',
},
{
'workers': True,
}],
'BatteryManager': {
'nativeType': 'mozilla::dom::battery::BatteryManager',
@ -401,7 +404,8 @@ DOMInterfaces = {
},
'FileList': {
'headerFile': 'mozilla/dom/File.h',
'nativeType': 'nsDOMFileList',
'headerFile': 'nsDOMFile.h',
},
'FileReader': {
@ -1794,6 +1798,7 @@ addExternalIface('ApplicationCache', nativeType='nsIDOMOfflineResourceList')
addExternalIface('Counter')
addExternalIface('CSSRule')
addExternalIface('RTCDataChannel', nativeType='nsIDOMDataChannel')
addExternalIface('File')
addExternalIface('HitRegionOptions', nativeType='nsISupports')
addExternalIface('imgINotificationObserver', nativeType='imgINotificationObserver')
addExternalIface('imgIRequest', nativeType='imgIRequest', notflattened=True)
@ -1822,7 +1827,6 @@ addExternalIface('nsIDOMCrypto', nativeType='nsIDOMCrypto',
headerFile='Crypto.h')
addExternalIface('nsIInputStreamCallback', nativeType='nsIInputStreamCallback',
headerFile='nsIAsyncInputStream.h')
addExternalIface('nsIFile', nativeType='nsIFile', notflattened=True)
addExternalIface('nsIMessageBroadcaster', nativeType='nsIMessageBroadcaster',
headerFile='nsIMessageManager.h', notflattened=True)
addExternalIface('nsISelectionListener', nativeType='nsISelectionListener')

View File

@ -16,7 +16,6 @@
#include "mozilla/dom/BluetoothDiscoveryStateChangedEvent.h"
#include "mozilla/dom/BluetoothStatusChangedEvent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/LazyIdleThread.h"
@ -771,7 +770,7 @@ BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv)
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
File& aBlob, ErrorResult& aRv)
nsIDOMBlob* aBlob, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
@ -791,7 +790,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
if (XRE_GetProcessType() == GeckoProcessType_Default) {
// In-process transfer
bs->SendFile(aDeviceAddress, &aBlob, results);
bs->SendFile(aDeviceAddress, aBlob, results);
} else {
ContentChild *cc = ContentChild::GetSingleton();
if (!cc) {
@ -799,7 +798,7 @@ BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
return nullptr;
}
BlobChild* actor = cc->GetOrCreateActorForBlob(&aBlob);
BlobChild* actor = cc->GetOrCreateActorForBlob(aBlob);
if (!actor) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;

View File

@ -15,7 +15,6 @@
namespace mozilla {
namespace dom {
class File;
class DOMRequest;
struct MediaMetaData;
struct MediaPlayStatus;
@ -134,7 +133,7 @@ public:
GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv);
already_AddRefed<DOMRequest>
SendFile(const nsAString& aDeviceAddress, File& aBlob,
SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv);

View File

@ -15,7 +15,6 @@
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/dom/File.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
#include "mozilla/StaticPtr.h"
@ -23,6 +22,7 @@
#include "nsCExternalHandlerService.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMFile.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsIMIMEService.h"
@ -35,7 +35,6 @@
USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::ipc;
namespace {
@ -350,8 +349,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
return SendFile(aDeviceAddress, blob.get());
}

View File

@ -14,7 +14,6 @@
#include "ObexBase.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Services.h"
@ -23,6 +22,7 @@
#include "nsCExternalHandlerService.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIDOMFile.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
#include "nsIMIMEService.h"
@ -35,7 +35,6 @@
USING_BLUETOOTH_NAMESPACE
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::ipc;
using mozilla::TimeDuration;
using mozilla::TimeStamp;
@ -372,8 +371,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
{
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
nsCOMPtr<nsIDOMBlob> blob = aActor->GetBlob();
return SendFile(aDeviceAddress, blob.get());
}

View File

@ -580,8 +580,7 @@ BrowserElementParent.prototype = {
}
else {
debug("Got error in gotDOMRequestResult.");
Services.DOMRequest.fireErrorAsync(req,
Cu.cloneInto(data.json.errorMsg, this._window));
Services.DOMRequest.fireErrorAsync(req, data.json.errorMsg);
}
},

View File

@ -10,7 +10,6 @@
#include "nsThread.h"
#include "DeviceStorage.h"
#include "DeviceStorageFileDescriptor.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/MediaManager.h"
@ -21,6 +20,7 @@
#include "nsIDOMDeviceStorage.h"
#include "nsIDOMEventListener.h"
#include "nsIScriptSecurityManager.h"
#include "nsDOMFile.h"
#include "Navigator.h"
#include "nsXULAppAPI.h"
#include "DOMCameraManager.h"
@ -1437,7 +1437,7 @@ void
nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aPicture);
MOZ_ASSERT(aPicture != nullptr);
nsRefPtr<Promise> promise = mTakePicturePromise.forget();
if (promise) {
@ -1445,17 +1445,15 @@ nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
promise->MaybeResolve(picture);
}
nsRefPtr<File> blob = static_cast<File*>(aPicture);
nsRefPtr<CameraTakePictureCallback> cb = mTakePictureOnSuccessCb.forget();
mTakePictureOnErrorCb = nullptr;
if (cb) {
ErrorResult ignored;
cb->Call(*blob, ignored);
cb->Call(aPicture, ignored);
}
BlobEventInit eventInit;
eventInit.mData = blob;
eventInit.mData = aPicture;
nsRefPtr<BlobEvent> event = BlobEvent::Constructor(this,
NS_LITERAL_STRING("picture"),

View File

@ -4,11 +4,11 @@
#include "DOMCameraControlListener.h"
#include "nsThreadUtils.h"
#include "nsDOMFile.h"
#include "CameraCommon.h"
#include "DOMCameraControl.h"
#include "CameraPreviewMediaStream.h"
#include "mozilla/dom/CameraManagerBinding.h"
#include "mozilla/dom/File.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -348,10 +348,9 @@ DOMCameraControlListener::OnTakePictureComplete(uint8_t* aData, uint32_t aLength
RunCallback(nsDOMCameraControl* aDOMCameraControl) MOZ_OVERRIDE
{
nsCOMPtr<nsIDOMBlob> picture =
File::CreateMemoryFile(mDOMCameraControl,
static_cast<void*>(mData),
static_cast<uint64_t>(mLength),
mMimeType);
DOMFile::CreateMemoryFile(static_cast<void*>(mData),
static_cast<uint64_t>(mLength),
mMimeType);
aDOMCameraControl->OnTakePictureComplete(picture);
}

View File

@ -90,9 +90,8 @@ ContactManager.prototype = {
},
_convertContact: function(aContact) {
let contact = Cu.cloneInto(aContact, this._window);
let newContact = new this._window.mozContact(contact.properties);
newContact.setMetadata(contact.id, contact.published, contact.updated);
let newContact = new this._window.mozContact(aContact.properties);
newContact.setMetadata(aContact.id, aContact.published, aContact.updated);
return newContact;
},

View File

@ -88,14 +88,14 @@ var findResult1;
function verifyBlob(blob1, blob2, isLast)
{
is(blob1 instanceof Blob, true,
"blob1 is an instance of DOMBlob");
is(blob2 instanceof Blob, true,
"blob2 is an instance of DOMBlob");
isnot(blob1 instanceof File, true,
"blob1 is an instance of File");
isnot(blob2 instanceof File, true,
"blob2 is an instance of File");
is(blob1 instanceof SpecialPowers.Ci.nsIDOMBlob, true,
"blob1 is an instance of nsIDOMBlob");
is(blob2 instanceof SpecialPowers.Ci.nsIDOMBlob, true,
"blob2 is an instance of nsIDOMBlob");
isnot(blob1 instanceof SpecialPowers.Ci.nsIDOMFile, true,
"blob1 is an instance of nsIDOMFile");
isnot(blob2 instanceof SpecialPowers.Ci.nsIDOMFile, true,
"blob2 is an instance of nsIDOMFile");
ise(blob1.size, blob2.size, "Same size");
ise(blob1.type, blob2.type, "Same type");

View File

@ -7,7 +7,7 @@
#include "DeviceStorageRequestChild.h"
#include "DeviceStorageFileDescriptor.h"
#include "nsDeviceStorage.h"
#include "mozilla/dom/File.h"
#include "nsDOMFile.h"
#include "mozilla/dom/ipc/BlobChild.h"
namespace mozilla {
@ -103,15 +103,12 @@ DeviceStorageRequestChild::
{
BlobResponse r = aValue;
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
nsRefPtr<FileImpl> bloblImpl = actor->GetBlobImpl();
nsRefPtr<File> blob = new File(mRequest->GetParentObject(), bloblImpl);
nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(blob);
AutoJSContext cx;
JS::Rooted<JSObject*> obj(cx, blob->WrapObject(cx));
MOZ_ASSERT(obj);
JS::Rooted<JS::Value> result(cx, JS::ObjectValue(*obj));
JS::Rooted<JS::Value> result(cx,
InterfaceToJsval(window, file, &NS_GET_IID(nsIDOMFile)));
mRequest->FireSuccess(result);
break;
}

View File

@ -4,10 +4,10 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DeviceStorageRequestParent.h"
#include "nsDOMFile.h"
#include "nsIMIMEService.h"
#include "nsCExternalHandlerService.h"
#include "mozilla/unused.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "ContentParent.h"
#include "nsProxyRelease.h"
@ -44,10 +44,10 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
nsRefPtr<FileImpl> blobImpl = bp->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob();
nsCOMPtr<nsIInputStream> stream;
blobImpl->GetInternalStream(getter_AddRefs(stream));
blob->GetInternalStream(getter_AddRefs(stream));
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream,
DEVICE_STORAGE_REQUEST_CREATE);
@ -67,10 +67,10 @@ DeviceStorageRequestParent::Dispatch()
new DeviceStorageFile(p.type(), p.storageName(), p.relpath());
BlobParent* bp = static_cast<BlobParent*>(p.blobParent());
nsRefPtr<FileImpl> blobImpl = bp->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob();
nsCOMPtr<nsIInputStream> stream;
blobImpl->GetInternalStream(getter_AddRefs(stream));
blob->GetInternalStream(getter_AddRefs(stream));
nsRefPtr<CancelableRunnable> r = new WriteFileEvent(this, dsf, stream,
DEVICE_STORAGE_REQUEST_APPEND);
@ -522,9 +522,9 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
nsString fullPath;
mFile->GetFullPath(fullPath);
nsRefPtr<File> blob = new File(nullptr,
new FileImplFile(fullPath, mime, mLength, mFile->mFile,
mLastModificationDate));
nsCOMPtr<nsIDOMBlob> blob = new DOMFile(
new DOMFileImplFile(fullPath, mime, mLength, mFile->mFile,
mLastModificationDate));
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);

View File

@ -36,6 +36,8 @@
#include "nsIDirectoryEnumerator.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceDefs.h"
#include "nsIDOMFile.h"
#include "nsDOMBlobBuilder.h"
#include "nsNetUtil.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIPrincipal.h"
@ -1803,10 +1805,10 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
MOZ_ASSERT(aFile->mLength != UINT64_MAX);
MOZ_ASSERT(aFile->mLastModifiedDate != UINT64_MAX);
nsCOMPtr<nsIDOMBlob> blob = new File(aWindow,
new FileImplFile(fullPath, aFile->mMimeType,
aFile->mLength, aFile->mFile,
aFile->mLastModifiedDate));
nsCOMPtr<nsIDOMBlob> blob = new DOMFile(
new DOMFileImplFile(fullPath, aFile->mMimeType,
aFile->mLength, aFile->mFile,
aFile->mLastModifiedDate));
return InterfaceToJsval(aWindow, blob, &NS_GET_IID(nsIDOMBlob));
}
@ -2478,7 +2480,7 @@ private:
class WriteFileEvent : public nsRunnable
{
public:
WriteFileEvent(FileImpl* aBlobImpl,
WriteFileEvent(DOMFileImpl* aBlobImpl,
DeviceStorageFile *aFile,
already_AddRefed<DOMRequest> aRequest,
int32_t aRequestType)
@ -2544,7 +2546,7 @@ public:
}
private:
nsRefPtr<FileImpl> mBlobImpl;
nsRefPtr<DOMFileImpl> mBlobImpl;
nsRefPtr<DeviceStorageFile> mFile;
nsRefPtr<DOMRequest> mRequest;
int32_t mRequestType;
@ -2912,8 +2914,7 @@ public:
if (XRE_GetProcessType() != GeckoProcessType_Default) {
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(
static_cast<File*>(mBlob.get()));
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob);
if (!actor) {
return NS_ERROR_FAILURE;
}
@ -2931,7 +2932,7 @@ public:
return NS_OK;
}
File* blob = static_cast<File*>(mBlob.get());
DOMFile* blob = static_cast<DOMFile*>(mBlob.get());
r = new WriteFileEvent(blob->Impl(), mFile, mRequest.forget(),
mRequestType);
break;
@ -2958,8 +2959,7 @@ public:
if (XRE_GetProcessType() != GeckoProcessType_Default) {
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(
static_cast<File*>(mBlob.get()));
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(mBlob);
if (!actor) {
return NS_ERROR_FAILURE;
}
@ -2977,7 +2977,7 @@ public:
return NS_OK;
}
File* blob = static_cast<File*>(mBlob.get());
DOMFile* blob = static_cast<DOMFile*>(mBlob.get());
r = new WriteFileEvent(blob->Impl(), mFile, mRequest.forget(),
mRequestType);
break;

View File

@ -269,7 +269,7 @@ DataTransfer::GetMozUserCancelled(bool* aUserCancelled)
return NS_OK;
}
FileList*
nsDOMFileList*
DataTransfer::GetFiles(ErrorResult& aRv)
{
if (mEventType != NS_DRAGDROP_DROP && mEventType != NS_DRAGDROP_DRAGDROP &&
@ -278,7 +278,7 @@ DataTransfer::GetFiles(ErrorResult& aRv)
}
if (!mFiles) {
mFiles = new FileList(static_cast<nsIDOMDataTransfer*>(this));
mFiles = new nsDOMFileList(static_cast<nsIDOMDataTransfer*>(this));
uint32_t count = mItems.Length();
@ -303,7 +303,7 @@ DataTransfer::GetFiles(ErrorResult& aRv)
if (!file)
continue;
nsRefPtr<File> domFile = File::CreateFromFile(GetParentObject(), file);
nsRefPtr<DOMFile> domFile = DOMFile::CreateFromFile(file);
if (!mFiles->Append(domFile)) {
aRv.Throw(NS_ERROR_FAILURE);

View File

@ -16,8 +16,8 @@
#include "nsCycleCollectionParticipant.h"
#include "nsAutoPtr.h"
#include "nsDOMFile.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
class nsINode;
class nsITransferable;
@ -143,7 +143,7 @@ public:
ErrorResult& aRv);
void ClearData(const mozilla::dom::Optional<nsAString>& aFormat,
mozilla::ErrorResult& aRv);
FileList* GetFiles(mozilla::ErrorResult& aRv);
nsDOMFileList* GetFiles(mozilla::ErrorResult& aRv);
void AddElement(Element& aElement, mozilla::ErrorResult& aRv);
uint32_t MozItemCount()
{
@ -278,7 +278,7 @@ protected:
nsTArray<nsTArray<TransferItem> > mItems;
// array of files, containing only the files present in the dataTransfer
nsRefPtr<FileList> mFiles;
nsRefPtr<nsDOMFileList> mFiles;
// the target of the drag. The drag and dragend events will fire at this.
nsCOMPtr<mozilla::dom::Element> mDragTarget;

View File

@ -203,7 +203,7 @@ ok(!e.cancelable, "Event shouldn't be cancelable!");
document.dispatchEvent(e);
is(receivedEvent, e, "Wrong event!");
var blob = new Blob();
var blob = Blob();
e = new BlobEvent("hello", { bubbles: true, cancelable: true, data: blob });
is(e.type, "hello", "Wrong event type!");
ok(!e.isTrusted, "Event shouldn't be trusted!");

View File

@ -8,6 +8,7 @@
#include "nsIUnicodeDecoder.h"
#include "nsIURI.h"
#include "nsDOMFile.h"
#include "nsDOMString.h"
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
@ -16,7 +17,6 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/Headers.h"
#include "mozilla/dom/Fetch.h"
#include "mozilla/dom/Promise.h"
@ -24,6 +24,7 @@
#include "mozilla/dom/workers/bindings/URL.h"
// dom/workers
#include "File.h"
#include "WorkerPrivate.h"
namespace mozilla {
@ -357,17 +358,26 @@ Request::ConsumeBody(ConsumeType aType, ErrorResult& aRv)
// with worker wrapping.
uint32_t blobLen = buffer.Length();
void* blobData = moz_malloc(blobLen);
nsRefPtr<File> blob;
nsCOMPtr<nsIDOMBlob> blob;
if (blobData) {
memcpy(blobData, buffer.BeginReading(), blobLen);
blob = File::CreateMemoryFile(GetParentObject(), blobData, blobLen,
NS_ConvertUTF8toUTF16(mMimeType));
blob = DOMFile::CreateMemoryFile(blobData, blobLen,
NS_ConvertUTF8toUTF16(mMimeType));
} else {
aRv = NS_ERROR_OUT_OF_MEMORY;
return nullptr;
}
promise->MaybeResolve(blob);
JS::Rooted<JS::Value> jsBlob(cx);
if (NS_IsMainThread()) {
aRv = nsContentUtils::WrapNative(cx, blob, &jsBlob);
if (aRv.Failed()) {
return nullptr;
}
} else {
jsBlob.setObject(*workers::file::CreateBlob(cx, blob));
}
promise->MaybeResolve(cx, jsBlob);
return promise.forget();
}
case CONSUME_JSON: {

View File

@ -13,11 +13,11 @@
#include "FileStreamWrappers.h"
#include "MemoryStreams.h"
#include "mozilla/dom/EncodingUtils.h"
#include "mozilla/dom/File.h"
#include "MutableFile.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsIDOMFile.h"
#include "nsIEventTarget.h"
#include "nsISeekableStream.h"
#include "nsNetUtil.h"
@ -622,17 +622,17 @@ FileHandleBase::GetInputStream(const ArrayBuffer& aValue,
// static
already_AddRefed<nsIInputStream>
FileHandleBase::GetInputStream(const File& aValue, uint64_t* aInputLength,
FileHandleBase::GetInputStream(nsIDOMBlob* aValue, uint64_t* aInputLength,
ErrorResult& aRv)
{
File& file = const_cast<File&>(aValue);
uint64_t length = file.GetSize(aRv);
uint64_t length;
aRv = aValue->GetSize(&length);
if (aRv.Failed()) {
return nullptr;
}
nsCOMPtr<nsIInputStream> stream;
aRv = file.GetInternalStream(getter_AddRefs(stream));
aRv = aValue->GetInternalStream(getter_AddRefs(stream));
if (aRv.Failed()) {
return nullptr;
}

View File

@ -21,11 +21,11 @@
#include "nsTArray.h"
class nsAString;
class nsIDOMBlob;
namespace mozilla {
namespace dom {
class File;
class FileHelper;
class FileRequestBase;
class FileService;
@ -240,8 +240,7 @@ protected:
ErrorResult& aRv);
static already_AddRefed<nsIInputStream>
GetInputStream(const File& aValue, uint64_t* aInputLength,
ErrorResult& aRv);
GetInputStream(nsIDOMBlob* aValue, uint64_t* aInputLength, ErrorResult& aRv);
static already_AddRefed<nsIInputStream>
GetInputStream(const nsAString& aValue, uint64_t* aInputLength,

View File

@ -10,12 +10,12 @@
#include "DOMError.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemBase.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "nsDOMFile.h"
#include "nsIFile.h"
#include "nsNetUtil.h"
#include "nsStringGlue.h"
@ -27,7 +27,7 @@ uint32_t CreateFileTask::sOutputBufferSize = 0;
CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem,
const nsAString& aPath,
File* aBlobData,
nsIDOMBlob* aBlobData,
InfallibleTArray<uint8_t>& aArrayData,
bool replace,
ErrorResult& aRv)
@ -79,10 +79,9 @@ CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem,
}
BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data));
nsRefPtr<FileImpl> blobImpl = bp->GetBlobImpl();
MOZ_ASSERT(blobImpl, "blobData should not be null.");
nsresult rv = blobImpl->GetInternalStream(getter_AddRefs(mBlobStream));
nsCOMPtr<nsIDOMBlob> blobData = bp->GetBlob();
MOZ_ASSERT(blobData, "blobData should not be null.");
nsresult rv = blobData->GetInternalStream(getter_AddRefs(mBlobStream));
NS_WARN_IF(NS_FAILED(rv));
}
@ -127,8 +126,7 @@ FileSystemResponseValue
CreateFileTask::GetSuccessRequestResult() const
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
nsRefPtr<File> file = new File(mFileSystem->GetWindow(),
mTargetFileImpl);
nsRefPtr<DOMFile> file = new DOMFile(mTargetFileImpl);
BlobParent* actor = GetBlobParent(file);
if (!actor) {
return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR);
@ -144,7 +142,8 @@ CreateFileTask::SetSuccessRequestResult(const FileSystemResponseValue& aValue)
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
FileSystemFileResponse r = aValue;
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
mTargetFileImpl = actor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
mTargetFileImpl = static_cast<DOMFile*>(blob.get())->Impl();
}
nsresult
@ -261,7 +260,7 @@ CreateFileTask::Work()
return NS_ERROR_FAILURE;
}
mTargetFileImpl = new FileImplFile(file);
mTargetFileImpl = new DOMFileImplFile(file);
return NS_OK;
}
@ -280,7 +279,7 @@ CreateFileTask::Work()
return NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR;
}
mTargetFileImpl = new FileImplFile(file);
mTargetFileImpl = new DOMFileImplFile(file);
return NS_OK;
}
@ -303,7 +302,7 @@ CreateFileTask::HandlerCallback()
return;
}
nsCOMPtr<nsIDOMFile> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
nsCOMPtr<nsIDOMFile> file = new DOMFile(mTargetFileImpl);
mPromise->MaybeResolve(file);
mPromise = nullptr;
mBlobData = nullptr;

View File

@ -11,13 +11,13 @@
#include "nsAutoPtr.h"
#include "mozilla/ErrorResult.h"
class nsIDOMBlob;
class nsIInputStream;
namespace mozilla {
namespace dom {
class File;
class FileImpl;
class DOMFileImpl;
class Promise;
class CreateFileTask MOZ_FINAL
@ -26,7 +26,7 @@ class CreateFileTask MOZ_FINAL
public:
CreateFileTask(FileSystemBase* aFileSystem,
const nsAString& aPath,
File* aBlobData,
nsIDOMBlob* aBlobData,
InfallibleTArray<uint8_t>& aArrayData,
bool replace,
ErrorResult& aRv);
@ -68,15 +68,15 @@ private:
nsString mTargetRealPath;
// Not thread-safe and should be released on main thread.
nsRefPtr<File> mBlobData;
nsCOMPtr<nsIDOMBlob> mBlobData;
nsCOMPtr<nsIInputStream> mBlobStream;
InfallibleTArray<uint8_t> mArrayData;
bool mReplace;
// This cannot be a File because this object is created on a different
// thread and File is not thread-safe. Let's use the FileImpl instead.
nsRefPtr<FileImpl> mTargetFileImpl;
// This cannot be a DOMFile because this object is created on a different
// thread and DOMFile is not thread-safe. Let's use the DOMFileImpl instead.
nsRefPtr<DOMFileImpl> mTargetFileImpl;
};
} // namespace dom

View File

@ -9,11 +9,11 @@
#include "DeviceStorage.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Directory.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsDeviceStorage.h"
#include "nsDOMFile.h"
#include "nsIFile.h"
#include "nsPIDOMWindow.h"
@ -114,7 +114,7 @@ DeviceStorageFileSystem::GetLocalFile(const nsAString& aRealPath) const
}
bool
DeviceStorageFileSystem::GetRealPath(FileImpl* aFile, nsAString& aRealPath) const
DeviceStorageFileSystem::GetRealPath(DOMFileImpl* aFile, nsAString& aRealPath) const
{
MOZ_ASSERT(FileSystemUtils::IsParentProcess(),
"Should be on parent process!");
@ -123,9 +123,7 @@ DeviceStorageFileSystem::GetRealPath(FileImpl* aFile, nsAString& aRealPath) cons
aRealPath.Truncate();
nsAutoString filePath;
ErrorResult rv;
aFile->GetMozFullPathInternal(filePath, rv);
if (NS_WARN_IF(rv.Failed())) {
if (NS_FAILED(aFile->GetMozFullPathInternal(filePath))) {
return false;
}

View File

@ -37,7 +37,7 @@ public:
GetLocalFile(const nsAString& aRealPath) const MOZ_OVERRIDE;
virtual bool
GetRealPath(FileImpl* aFile, nsAString& aRealPath) const MOZ_OVERRIDE;
GetRealPath(DOMFileImpl* aFile, nsAString& aRealPath) const MOZ_OVERRIDE;
virtual const nsAString&
GetRootName() const MOZ_OVERRIDE;

View File

@ -101,7 +101,7 @@ Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
{
nsresult error = NS_OK;
nsString realPath;
nsRefPtr<File> blobData;
nsRefPtr<nsIDOMBlob> blobData;
InfallibleTArray<uint8_t> arrayData;
bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);
@ -129,8 +129,8 @@ Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
error = NS_ERROR_DOM_FILESYSTEM_INVALID_PATH_ERR;
}
nsRefPtr<CreateFileTask> task =
new CreateFileTask(mFileSystem, realPath, blobData, arrayData, replace, aRv);
nsRefPtr<CreateFileTask> task = new CreateFileTask(mFileSystem, realPath,
blobData, arrayData, replace, aRv);
if (aRv.Failed()) {
return nullptr;
}
@ -193,12 +193,12 @@ Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
{
nsresult error = NS_OK;
nsString realPath;
nsRefPtr<FileImpl> file;
nsRefPtr<DOMFileImpl> file;
// Check and get the target path.
if (aPath.IsFile()) {
file = aPath.GetAsFile().Impl();
file = static_cast<DOMFile*>(aPath.GetAsFile())->Impl();
goto parameters_check_done;
}

View File

@ -10,9 +10,9 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/File.h"
#include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsDOMFile.h"
#include "nsPIDOMWindow.h"
#include "nsWrapperCache.h"

View File

@ -16,7 +16,7 @@ namespace mozilla {
namespace dom {
class Directory;
class FileImpl;
class DOMFileImpl;
class FileSystemBase
{
@ -73,7 +73,7 @@ public:
* empty string.
*/
virtual bool
GetRealPath(FileImpl* aFile, nsAString& aRealPath) const = 0;
GetRealPath(DOMFileImpl* aFile, nsAString& aRealPath) const = 0;
/*
* Get the permission name required to access this file system.

View File

@ -8,7 +8,6 @@
#include "nsNetUtil.h" // Stream transport service.
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemBase.h"
#include "mozilla/dom/FileSystemRequestParent.h"
#include "mozilla/dom/FileSystemUtils.h"
@ -16,6 +15,7 @@
#include "mozilla/dom/PContent.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/unused.h"
#include "nsDOMFile.h"
namespace mozilla {
namespace dom {
@ -170,7 +170,7 @@ FileSystemTaskBase::GetBlobParent(nsIDOMFile* aFile) const
aFile->GetMozLastModifiedDate(&lastModifiedDate);
ContentParent* cp = static_cast<ContentParent*>(mRequestParent->Manager());
return cp->GetOrCreateActorForBlob(static_cast<File*>(aFile));
return cp->GetOrCreateActorForBlob(aFile);
}
void

View File

@ -8,13 +8,12 @@
#include "js/Value.h"
#include "mozilla/dom/Directory.h"
#include "mozilla/dom/DOMError.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemBase.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "nsDOMFile.h"
#include "nsIFile.h"
#include "nsStringGlue.h"
@ -82,7 +81,7 @@ GetFileOrDirectoryTask::GetSuccessRequestResult() const
return FileSystemDirectoryResponse(mTargetRealPath);
}
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
nsRefPtr<DOMFile> file = new DOMFile(mTargetFileImpl);
BlobParent* actor = GetBlobParent(file);
if (!actor) {
return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR);
@ -100,7 +99,8 @@ GetFileOrDirectoryTask::SetSuccessRequestResult(const FileSystemResponseValue& a
case FileSystemResponseValue::TFileSystemFileResponse: {
FileSystemFileResponse r = aValue;
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
mTargetFileImpl = actor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob();
mTargetFileImpl = static_cast<DOMFile*>(blob.get())->Impl();
mIsDirectory = false;
break;
}
@ -185,7 +185,7 @@ GetFileOrDirectoryTask::Work()
return NS_ERROR_DOM_SECURITY_ERR;
}
mTargetFileImpl = new FileImplFile(file);
mTargetFileImpl = new DOMFileImplFile(file);
return NS_OK;
}
@ -214,7 +214,7 @@ GetFileOrDirectoryTask::HandlerCallback()
return;
}
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
nsCOMPtr<nsIDOMFile> file = new DOMFile(mTargetFileImpl);
mPromise->MaybeResolve(file);
mPromise = nullptr;
}

View File

@ -14,7 +14,7 @@
namespace mozilla {
namespace dom {
class FileImpl;
class DOMFileImpl;
class GetFileOrDirectoryTask MOZ_FINAL
: public FileSystemTaskBase
@ -59,9 +59,9 @@ private:
// Whether we get a directory.
bool mIsDirectory;
// This cannot be a File bacause this object is created on a different
// thread and File is not thread-safe. Let's use the FileImpl instead.
nsRefPtr<FileImpl> mTargetFileImpl;
// This cannot be a DOMFile bacause this object is created on a different
// thread and DOMFile is not thread-safe. Let's use the DOMFileImpl instead.
nsRefPtr<DOMFileImpl> mTargetFileImpl;
};
} // namespace dom

View File

@ -7,12 +7,12 @@
#include "RemoveTask.h"
#include "DOMError.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/FileSystemBase.h"
#include "mozilla/dom/FileSystemUtils.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "nsDOMFile.h"
#include "nsIFile.h"
#include "nsStringGlue.h"
@ -21,7 +21,7 @@ namespace dom {
RemoveTask::RemoveTask(FileSystemBase* aFileSystem,
const nsAString& aDirPath,
FileImpl* aTargetFile,
DOMFileImpl* aTargetFile,
const nsAString& aTargetPath,
bool aRecursive,
ErrorResult& aRv)
@ -66,8 +66,9 @@ RemoveTask::RemoveTask(FileSystemBase* aFileSystem,
}
BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(target));
mTargetFileImpl = bp->GetBlobImpl();
MOZ_ASSERT(mTargetFileImpl);
nsCOMPtr<nsIDOMBlob> blob = bp->GetBlob();
MOZ_ASSERT(blob);
mTargetFileImpl = static_cast<DOMFile*>(blob.get())->Impl();
}
RemoveTask::~RemoveTask()
@ -92,7 +93,7 @@ RemoveTask::GetRequestParams(const nsString& aFileSystem) const
param.directory() = mDirRealPath;
param.recursive() = mRecursive;
if (mTargetFileImpl) {
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
nsRefPtr<DOMFile> file = new DOMFile(mTargetFileImpl);
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(file);
if (actor) {
@ -130,7 +131,7 @@ RemoveTask::Work()
return NS_ERROR_FAILURE;
}
// Get the DOM path if a File is passed as the target.
// Get the DOM path if a DOMFile is passed as the target.
if (mTargetFileImpl) {
if (!mFileSystem->GetRealPath(mTargetFileImpl, mTargetRealPath)) {
return NS_ERROR_DOM_SECURITY_ERR;

View File

@ -14,7 +14,7 @@
namespace mozilla {
namespace dom {
class FileImpl;
class DOMFileImpl;
class Promise;
class RemoveTask MOZ_FINAL
@ -23,7 +23,7 @@ class RemoveTask MOZ_FINAL
public:
RemoveTask(FileSystemBase* aFileSystem,
const nsAString& aDirPath,
FileImpl* aTargetFile,
DOMFileImpl* aTargetFile,
const nsAString& aTargetPath,
bool aRecursive,
ErrorResult& aRv);
@ -59,9 +59,9 @@ protected:
private:
nsRefPtr<Promise> mPromise;
nsString mDirRealPath;
// This cannot be a File because this object will be used on a different
// thread and File is not thread-safe. Let's use the FileImpl instead.
nsRefPtr<FileImpl> mTargetFileImpl;
// This cannot be a DOMFile because this object will be used on a different
// thread and DOMFile is not thread-safe. Let's use the DOMFileImpl instead.
nsRefPtr<DOMFileImpl> mTargetFileImpl;
nsString mTargetRealPath;
bool mRecursive;
bool mReturnValue;

Some files were not shown because too many files have changed in this diff Show More