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
Родитель 227cb189b8
Коммит cd3e8a6f73
180 изменённых файлов: 3915 добавлений и 3417 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -3,7 +3,7 @@
Cu.import("resource://gre/modules/NetUtil.jsm"); Cu.import("resource://gre/modules/NetUtil.jsm");
function test() { 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 url = URL.createObjectURL(file);
var channel = NetUtil.newChannel(url); var channel = NetUtil.newChannel(url);

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

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

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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));
}

Просмотреть файл

@ -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

Просмотреть файл

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

Просмотреть файл

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

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -5,8 +5,7 @@
#include "nsFormData.h" #include "nsFormData.h"
#include "nsIVariant.h" #include "nsIVariant.h"
#include "nsIInputStream.h" #include "nsIInputStream.h"
#include "mozilla/dom/File.h" #include "nsIDOMFile.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/HTMLFormElement.h" #include "mozilla/dom/HTMLFormElement.h"
#include "mozilla/dom/FormDataBinding.h" #include "mozilla/dom/FormDataBinding.h"
@ -22,34 +21,9 @@ nsFormData::nsFormData(nsISupports* aOwner)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// nsISupports // nsISupports
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormData) NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsFormData, mOwner)
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_COLLECTING_ADDREF(nsFormData) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFormData)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFormData)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFormData)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIDOMFormData) NS_INTERFACE_MAP_ENTRY(nsIDOMFormData)
@ -74,7 +48,7 @@ nsFormData::Append(const nsAString& aName, const nsAString& aValue)
} }
void void
nsFormData::Append(const nsAString& aName, File& aBlob, nsFormData::Append(const nsAString& aName, nsIDOMBlob* aBlob,
const Optional<nsAString>& aFilename) const Optional<nsAString>& aFilename)
{ {
nsString filename; nsString filename;
@ -83,7 +57,7 @@ nsFormData::Append(const nsAString& aName, File& aBlob,
} else { } else {
filename.SetIsVoid(true); 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); nsMemory::Free(iid);
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports); nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
nsRefPtr<File> blob = static_cast<File*>(domBlob.get());
if (domBlob) { if (domBlob) {
Optional<nsAString> temp; Optional<nsAString> temp;
Append(aName, *blob, temp); Append(aName, domBlob, temp);
return NS_OK; return NS_OK;
} }
} }

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -33,13 +33,13 @@ function createFileWithData(fileData) {
return testFile; 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 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.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, file.path, "mozFullPath returns path if created with nsIFile"); 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.mozFullPathInternal, undefined, "mozFullPathInternal is undefined from js");
is(f.mozFullPath, "", "mozFullPath returns blank if created with a string"); is(f.mozFullPath, "", "mozFullPath returns blank if created with a string");
</script> </script>

Просмотреть файл

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

Просмотреть файл

@ -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> <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=403852">Mozilla Bug 403852</a>
<p id="display"> <p id="display">
<input id="fileList" type="file"></input> <input id="fileList" type="file"></input>
<canvas id="canvas"></canvas>
</p> </p>
<div id="content" style="display: none"> <div id="content" style="display: none">
</div> </div>
@ -36,14 +37,10 @@ ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
var d = new Date(testFile.lastModifiedTime); var d = new Date(testFile.lastModifiedTime);
ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same."); ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same.");
var cf = document.getElementById("canvas").mozGetAsFile("canvFile");
var x = new Date(); var x = new Date();
var y = cf.lastModifiedDate;
// 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 z = new Date(); 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"); ok((x.getTime() <= y.getTime()) && (y.getTime() <= z.getTime()), "lastModifiedDate of file which does not have last modified date should be current time");

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -52,11 +52,11 @@ function runTest() {
fd.append("empty", blob); fd.append("empty", blob);
fd.append("explicit", blob, "explicit-file-name"); fd.append("explicit", blob, "explicit-file-name");
fd.append("explicit-empty", blob, ""); 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); 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); 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"); fd.append("file-name-overwrite", file, "overwrite");
xhr.responseType = 'json'; xhr.responseType = 'json';
xhr.send(fd); xhr.send(fd);
@ -65,4 +65,4 @@ function runTest() {
runTest() runTest()
</script> </script>
</body> </body>
</html> </html>

Просмотреть файл

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

Просмотреть файл

@ -16,10 +16,6 @@ class nsIDOMBlob;
namespace mozilla { namespace mozilla {
namespace dom {
class File;
}
class ReentrantMonitor; class ReentrantMonitor;
/** /**
* Data is moved into a temporary file when it grows beyond * 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 // aBuf will append to mEncodedBuffers or temporary File, aBuf also be cleared
void AppendBuffer(nsTArray<uint8_t> & aBuf); 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. // 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: private:
//array for storing the encoded data. //array for storing the encoded data.

Просмотреть файл

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

Просмотреть файл

@ -15,20 +15,14 @@
namespace mozilla { namespace mozilla {
nsresult nsresult
CaptureTask::TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv) CaptureTask::TaskComplete(already_AddRefed<dom::DOMFile> aBlob, nsresult aRv)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
DetachStream(); DetachStream();
nsresult rv; nsresult rv;
nsRefPtr<dom::File> blob(aBlob); nsRefPtr<dom::DOMFile> 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());
}
if (mPrincipalChanged) { if (mPrincipalChanged) {
aRv = NS_ERROR_DOM_SECURITY_ERR; aRv = NS_ERROR_DOM_SECURITY_ERR;
IC_LOG("MediaStream principal should not change during TakePhoto()."); IC_LOG("MediaStream principal should not change during TakePhoto().");
@ -104,9 +98,9 @@ CaptureTask::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
public: public:
explicit EncodeComplete(CaptureTask* aTask) : mTask(aTask) {} 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->TaskComplete(blob.forget(), NS_OK);
mTask = nullptr; mTask = nullptr;
return NS_OK; return NS_OK;

Просмотреть файл

@ -13,8 +13,8 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class File;
class ImageCapture; class ImageCapture;
class DOMFile;
} }
/** /**
@ -51,7 +51,7 @@ public:
// //
// Note: // Note:
// this function should be called on main thread. // 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 // Add listeners into MediaStream and PrincipalChangeObserver. It should be on
// main thread only. // main thread only.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -5,9 +5,7 @@
#include "MessagePort.h" #include "MessagePort.h"
#include "MessageEvent.h" #include "MessageEvent.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/Event.h" #include "mozilla/dom/Event.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MessageChannel.h" #include "mozilla/dom/MessageChannel.h"
#include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/MessagePortList.h" #include "mozilla/dom/MessagePortList.h"
@ -18,6 +16,7 @@
#include "ScriptSettings.h" #include "ScriptSettings.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h" #include "nsIDOMFileList.h"
#include "nsIPresShell.h" #include "nsIPresShell.h"
@ -104,37 +103,7 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data, uint32_t data,
void* closure) void* closure)
{ {
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure); if (tag == SCTAG_DOM_BLOB || tag == SCTAG_DOM_FILELIST) {
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) {
NS_ASSERTION(!data, "Data should be empty"); NS_ASSERTION(!data, "Data should be empty");
nsISupports* supports; nsISupports* supports;
@ -165,19 +134,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure); StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!"); 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; nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()-> nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative)); GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -185,6 +141,11 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0; uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native(); nsISupports* supports = wrappedNative->Native();
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(supports);
if (blob) {
scTag = SCTAG_DOM_BLOB;
}
nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports); nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list) { if (list) {
scTag = SCTAG_DOM_FILELIST; scTag = SCTAG_DOM_FILELIST;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -122,6 +122,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsCSSProps.h" #include "nsCSSProps.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h" #include "nsIDOMFileList.h"
#include "nsIURIFixup.h" #include "nsIURIFixup.h"
#ifndef DEBUG #ifndef DEBUG
@ -7877,32 +7878,18 @@ PostMessageReadStructuredClone(JSContext* cx,
uint32_t data, uint32_t data,
void* closure) void* closure)
{ {
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!");
if (tag == SCTAG_DOM_BLOB) { if (tag == SCTAG_DOM_BLOB) {
NS_ASSERTION(!data, "Data should be empty"); NS_ASSERTION(!data, "Data should be empty");
// What we get back from the reader is a FileImpl. // What we get back from the reader is a DOMFileImpl.
// From that we create a new File. // From that we create a new DOMFile.
FileImpl* blobImpl; nsISupports* supports;
if (JS_ReadBytes(reader, &blobImpl, sizeof(blobImpl))) { if (JS_ReadBytes(reader, &supports, sizeof(supports))) {
MOZ_ASSERT(blobImpl); nsCOMPtr<nsIDOMBlob> file = new DOMFile(static_cast<DOMFileImpl*>(supports));
// 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); JS::Rooted<JS::Value> val(cx);
{ if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, file, &val))) {
nsRefPtr<File> blob = new File(scInfo->window, blobImpl); return val.toObjectOrNull();
if (!WrapNewBindingObject(cx, blob, &val)) {
return nullptr;
}
} }
return &val.toObject();
} }
} }
@ -7937,19 +7924,6 @@ PostMessageWriteStructuredClone(JSContext* cx,
StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure); StructuredCloneInfo* scInfo = static_cast<StructuredCloneInfo*>(closure);
NS_ASSERTION(scInfo, "Must have scInfo!"); 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; nsCOMPtr<nsIXPConnectWrappedNative> wrappedNative;
nsContentUtils::XPConnect()-> nsContentUtils::XPConnect()->
GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative)); GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative));
@ -7957,6 +7931,13 @@ PostMessageWriteStructuredClone(JSContext* cx,
uint32_t scTag = 0; uint32_t scTag = 0;
nsISupports* supports = wrappedNative->Native(); 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); nsCOMPtr<nsIDOMFileList> list = do_QueryInterface(supports);
if (list && scInfo->subsumes) if (list && scInfo->subsumes)
scTag = SCTAG_DOM_FILELIST; scTag = SCTAG_DOM_FILELIST;

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -16,7 +16,7 @@ namespace mozilla {
namespace dom { namespace dom {
class Directory; class Directory;
class FileImpl; class DOMFileImpl;
class FileSystemBase class FileSystemBase
{ {
@ -73,7 +73,7 @@ public:
* empty string. * empty string.
*/ */
virtual bool 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. * Get the permission name required to access this file system.

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше