Bug 1159401 - Split Blob and File classes, r=bz

This commit is contained in:
Andrea Marchesini 2015-05-12 13:09:51 +01:00
Родитель b679e52953
Коммит 368a198972
106 изменённых файлов: 959 добавлений и 771 удалений

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

@ -105,7 +105,7 @@ ArchiveReaderEvent::RunShare(nsresult aStatus)
void
ArchiveReaderEvent::ShareMainThread()
{
nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
nsTArray<nsRefPtr<File>> fileList;
if (!NS_FAILED(mStatus)) {
// This extra step must run in the main thread:
@ -131,7 +131,7 @@ ArchiveReaderEvent::ShareMainThread()
}
// This is a File:
nsRefPtr<nsIDOMFile> file = item->File(mArchiveReader);
nsRefPtr<File> file = item->GetFile(mArchiveReader);
if (file) {
fileList.AppendElement(file);
}

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

@ -36,7 +36,7 @@ public:
virtual nsresult GetFilename(nsString& aFilename) = 0;
// Generate a File
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) = 0;
virtual already_AddRefed<File> GetFile(ArchiveReader* aArchiveReader) = 0;
protected:
virtual ~ArchiveItem();

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

@ -24,7 +24,7 @@ USING_ARCHIVEREADER_NAMESPACE
/* static */ already_AddRefed<ArchiveReader>
ArchiveReader::Constructor(const GlobalObject& aGlobal,
File& aBlob,
Blob& aBlob,
const ArchiveReaderOptions& aOptions,
ErrorResult& aError)
{
@ -46,7 +46,7 @@ ArchiveReader::Constructor(const GlobalObject& aGlobal,
return reader.forget();
}
ArchiveReader::ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader::ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding)
: mFileImpl(aBlob.Impl())
, mWindow(aWindow)
@ -136,7 +136,7 @@ ArchiveReader::OpenArchive()
// Data received from the dispatched event:
void
ArchiveReader::Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
ArchiveReader::Ready(nsTArray<nsRefPtr<File>>& aFileList,
nsresult aStatus)
{
mStatus = READY;

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

@ -13,12 +13,12 @@
#include "nsCOMArray.h"
#include "nsIChannel.h"
#include "nsIDOMFile.h"
#include "mozilla/Attributes.h"
namespace mozilla {
namespace dom {
struct ArchiveReaderOptions;
class Blob;
class File;
class FileImpl;
class GlobalObject;
@ -40,10 +40,10 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ArchiveReader)
static already_AddRefed<ArchiveReader>
Constructor(const GlobalObject& aGlobal, File& aBlob,
Constructor(const GlobalObject& aGlobal, Blob& aBlob,
const ArchiveReaderOptions& aOptions, ErrorResult& aError);
ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow,
ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow,
const nsACString& aEncoding);
nsIDOMWindow* GetParentObject() const
@ -69,8 +69,7 @@ public: // For events:
return mFileImpl;
}
void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult aStatus);
void Ready(nsTArray<nsRefPtr<File>>& aFileList, nsresult aStatus);
private:
~ArchiveReader();
@ -108,7 +107,7 @@ protected:
// Everything related to the blobs and the status:
struct {
nsTArray<nsCOMPtr<nsIDOMFile> > fileList;
nsTArray<nsRefPtr<File>> fileList;
nsresult status;
} mData;

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

@ -122,7 +122,7 @@ ArchiveRequest::OpGetFiles()
}
nsresult
ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
ArchiveRequest::ReaderReady(nsTArray<nsRefPtr<File>>& aFileList,
nsresult aStatus)
{
if (NS_FAILED(aStatus)) {
@ -174,7 +174,7 @@ ArchiveRequest::ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult
ArchiveRequest::GetFilenamesResult(JSContext* aCx,
JS::Value* aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length()));
nsresult rv;
@ -185,7 +185,7 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,
JS::Rooted<JSString*> str(aCx);
for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];
nsString filename;
rv = file->GetName(filename);
@ -211,18 +211,21 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx,
nsresult
ArchiveRequest::GetFileResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];
nsString filename;
nsresult rv = file->GetName(filename);
NS_ENSURE_SUCCESS(rv, rv);
if (filename == mFilename) {
return nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile),
aValue);
if (!ToJSValue(aCx, file, aValue)) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
}
@ -232,7 +235,7 @@ ArchiveRequest::GetFileResult(JSContext* aCx,
nsresult
ArchiveRequest::GetFilesResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList)
nsTArray<nsRefPtr<File>>& aFileList)
{
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, aFileList.Length()));
if (!array) {
@ -240,13 +243,14 @@ ArchiveRequest::GetFilesResult(JSContext* aCx,
}
for (uint32_t i = 0; i < aFileList.Length(); ++i) {
nsCOMPtr<nsIDOMFile> file = aFileList[i];
nsRefPtr<File> file = aFileList[i];
JS::Rooted<JS::Value> value(aCx);
nsresult rv = nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile),
&value);
if (NS_FAILED(rv) ||
!JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) {
if (!ToJSValue(aCx, file, &value)) {
return NS_ERROR_FAILURE;
}
if (!JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
}

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

@ -49,8 +49,7 @@ public:
void OpGetFile(const nsAString& aFilename);
void OpGetFiles();
nsresult ReaderReady(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
nsresult aStatus);
nsresult ReaderReady(nsTArray<nsRefPtr<File>>& aFileList, nsresult aStatus);
public: // static
static already_AddRefed<ArchiveRequest> Create(nsPIDOMWindow* aOwner,
@ -61,13 +60,13 @@ private:
nsresult GetFilenamesResult(JSContext* aCx,
JS::Value* aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);
nsresult GetFileResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);
nsresult GetFilesResult(JSContext* aCx,
JS::MutableHandle<JS::Value> aValue,
nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList);
nsTArray<nsRefPtr<File>>& aFileList);
protected:
// The reader:

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

@ -75,8 +75,8 @@ ArchiveZipItem::GetFilename(nsString& aFilename)
}
// From zipItem to File:
nsIDOMFile*
ArchiveZipItem::File(ArchiveReader* aArchiveReader)
already_AddRefed<File>
ArchiveZipItem::GetFile(ArchiveReader* aArchiveReader)
{
nsString filename;
@ -84,11 +84,13 @@ ArchiveZipItem::File(ArchiveReader* aArchiveReader)
return nullptr;
}
return new dom::File(aArchiveReader,
nsRefPtr<dom::File> file = dom::File::Create(aArchiveReader,
new ArchiveZipFileImpl(filename,
NS_ConvertUTF8toUTF16(GetType()),
StrToInt32(mCentralStruct.orglen),
mCentralStruct, aArchiveReader->GetFileImpl()));
MOZ_ASSERT(file);
return file.forget();
}
uint32_t

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

@ -31,7 +31,8 @@ public:
nsresult GetFilename(nsString& aFilename) override;
// From zipItem to File:
virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) override;
virtual already_AddRefed<File>
GetFile(ArchiveReader* aArchiveReader) override;
public: // for the event
static uint32_t StrToInt32(const uint8_t* aStr);

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

@ -31,7 +31,7 @@ public:
nsTArray<nsRefPtr<FileImpl>>& GetBlobImpls() { Flush(); return mBlobImpls; }
already_AddRefed<File> GetBlobInternal(nsISupports* aParent,
already_AddRefed<Blob> GetBlobInternal(nsISupports* aParent,
const nsACString& aContentType);
protected:

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

@ -88,9 +88,9 @@ ConsoleStructuredCloneCallbacksRead(JSContext* aCx,
JS::Rooted<JS::Value> val(aCx);
{
nsRefPtr<File> file =
new File(data->mParent, data->mFiles.ElementAt(aIndex));
if (!GetOrCreateDOMReflector(aCx, file, &val)) {
nsRefPtr<Blob> blob =
Blob::Create(data->mParent, data->mFiles.ElementAt(aIndex));
if (!ToJSValue(aCx, blob, &val)) {
return nullptr;
}
}
@ -114,14 +114,14 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx,
static_cast<ConsoleStructuredCloneData*>(aClosure);
MOZ_ASSERT(data);
nsRefPtr<File> file;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, file)) &&
file->Impl()->MayBeClonedToOtherThreads()) {
nsRefPtr<Blob> blob;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
blob->Impl()->MayBeClonedToOtherThreads()) {
if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB, data->mFiles.Length())) {
return false;
}
data->mFiles.AppendElement(file->Impl());
data->mFiles.AppendElement(blob->Impl());
return true;
}

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

@ -124,39 +124,351 @@ nsresult DataOwnerAdapter::Create(DataOwner* aDataOwner,
}
////////////////////////////////////////////////////////////////////////////
// mozilla::dom::File implementation
// mozilla::dom::Blob implementation
NS_IMPL_CYCLE_COLLECTION_CLASS(File)
NS_IMPL_CYCLE_COLLECTION_CLASS(Blob)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(File)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Blob)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(File)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Blob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(File)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(Blob)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(File)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Blob)
// This class should not receive any nsIRemoteBlob QI!
MOZ_ASSERT(!aIID.Equals(NS_GET_IID(nsIRemoteBlob)));
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMBlob)
NS_INTERFACE_MAP_ENTRY(nsIDOMBlob)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMFile, IsFile())
NS_INTERFACE_MAP_ENTRY(nsIXHRSendable)
NS_INTERFACE_MAP_ENTRY(nsIMutable)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(File)
NS_IMPL_CYCLE_COLLECTING_RELEASE(File)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Blob)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Blob)
/* static */ Blob*
Blob::Create(nsISupports* aParent, FileImpl* aImpl)
{
MOZ_ASSERT(aImpl);
return aImpl->IsFile() ? new File(aParent, aImpl)
: new Blob(aParent, aImpl);
}
/* static */ already_AddRefed<Blob>
Blob::Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength)
{
nsRefPtr<Blob> blob = Blob::Create(aParent,
new FileImplBase(aContentType, aLength));
MOZ_ASSERT(!blob->mImpl->IsFile());
return blob.forget();
}
/* static */ already_AddRefed<Blob>
Blob::Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aStart, uint64_t aLength)
{
nsRefPtr<Blob> blob = Blob::Create(aParent,
new FileImplBase(aContentType, aStart, aLength));
MOZ_ASSERT(!blob->mImpl->IsFile());
return blob.forget();
}
/* static */ already_AddRefed<Blob>
Blob::CreateMemoryBlob(nsISupports* aParent, void* aMemoryBuffer,
uint64_t aLength, const nsAString& aContentType)
{
nsRefPtr<Blob> blob = Blob::Create(aParent,
new FileImplMemory(aMemoryBuffer, aLength, aContentType));
MOZ_ASSERT(!blob->mImpl->IsFile());
return blob.forget();
}
/* static */ already_AddRefed<Blob>
Blob::CreateTemporaryBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
const nsAString& aContentType)
{
nsRefPtr<Blob> blob = Blob::Create(aParent,
new FileImplTemporaryBlob(aFD, aStartPos, aLength, aContentType));
MOZ_ASSERT(!blob->mImpl->IsFile());
return blob.forget();
}
Blob::Blob(nsISupports* aParent, FileImpl* aImpl)
: mImpl(aImpl)
, mParent(aParent)
{
MOZ_ASSERT(mImpl);
#ifdef DEBUG
{
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aParent);
if (win) {
MOZ_ASSERT(win->IsInnerWindow());
}
}
#endif
}
bool
Blob::IsFile() const
{
return mImpl->IsFile();
}
const nsTArray<nsRefPtr<FileImpl>>*
Blob::GetSubBlobImpls() const
{
return mImpl->GetSubBlobImpls();
}
already_AddRefed<File>
Blob::ToFile()
{
if (!mImpl->IsFile()) {
return nullptr;
}
nsRefPtr<File> file;
if (HasFileInterface()) {
file = static_cast<File*>(this);
} else {
file = new File(mParent, mImpl);
}
return file.forget();
}
already_AddRefed<File>
Blob::ToFile(const nsAString& aName) const
{
nsAutoTArray<nsRefPtr<FileImpl>, 1> blobImpls;
blobImpls.AppendElement(mImpl);
nsAutoString contentType;
mImpl->GetType(contentType);
nsRefPtr<MultipartFileImpl> impl =
new MultipartFileImpl(blobImpls, aName, contentType);
nsRefPtr<File> file = new File(mParent, impl);
return file.forget();
}
already_AddRefed<Blob>
Blob::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
nsRefPtr<FileImpl> impl = mImpl->CreateSlice(aStart, aLength,
aContentType, aRv);
if (aRv.Failed()) {
return nullptr;
}
nsRefPtr<Blob> blob = Blob::Create(mParent, impl);
return blob.forget();
}
NS_IMETHODIMP
Blob::GetSize(uint64_t* aSize)
{
MOZ_ASSERT(aSize);
ErrorResult rv;
*aSize = GetSize(rv);
return rv.StealNSResult();
}
uint64_t
Blob::GetSize(ErrorResult& aRv)
{
return mImpl->GetSize(aRv);
}
NS_IMETHODIMP
Blob::GetType(nsAString &aType)
{
mImpl->GetType(aType);
return NS_OK;
}
NS_IMETHODIMP
Blob::Slice(int64_t aStart, int64_t aEnd,
const nsAString& aContentType, uint8_t aArgc,
nsIDOMBlob **aBlob)
{
Optional<int64_t> start;
if (aArgc > 0) {
start.Construct(aStart);
}
Optional<int64_t> end;
if (aArgc > 1) {
end.Construct(aEnd);
}
ErrorResult rv;
nsRefPtr<Blob> blob = Slice(start, end, aContentType, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
blob.forget(aBlob);
return NS_OK;
}
already_AddRefed<Blob>
Blob::Slice(const Optional<int64_t>& aStart,
const Optional<int64_t>& aEnd,
const nsAString& aContentType,
ErrorResult& aRv)
{
nsRefPtr<FileImpl> impl =
mImpl->Slice(aStart, aEnd, aContentType, aRv);
if (aRv.Failed()) {
return nullptr;
}
nsRefPtr<Blob> blob = Blob::Create(mParent, impl);
return blob.forget();
}
NS_IMETHODIMP
Blob::GetSendInfo(nsIInputStream** aBody,
uint64_t* aContentLength,
nsACString& aContentType,
nsACString& aCharset)
{
return mImpl->GetSendInfo(aBody, aContentLength, aContentType, aCharset);
}
NS_IMETHODIMP
Blob::GetMutable(bool* aMutable)
{
return mImpl->GetMutable(aMutable);
}
NS_IMETHODIMP
Blob::SetMutable(bool aMutable)
{
return mImpl->SetMutable(aMutable);
}
JSObject*
Blob::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return BlobBinding::Wrap(aCx, this, aGivenProto);
}
/* static */ already_AddRefed<Blob>
Blob::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl();
impl->InitializeBlob();
MOZ_ASSERT(!impl->IsFile());
nsRefPtr<Blob> blob = Blob::Create(aGlobal.GetAsSupports(), impl);
return blob.forget();
}
/* static */ already_AddRefed<Blob>
Blob::Constructor(
const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv)
{
nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl();
impl->InitializeBlob(aGlobal.Context(), aData, aBag.mType,
aBag.mEndings == EndingTypes::Native, aRv);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(!impl->IsFile());
nsRefPtr<Blob> blob = Blob::Create(aGlobal.GetAsSupports(), impl);
return blob.forget();
}
NS_IMETHODIMP_(int64_t)
Blob::GetFileId()
{
return mImpl->GetFileId();
}
NS_IMETHODIMP_(void)
Blob::AddFileInfo(indexedDB::FileInfo* aFileInfo)
{
mImpl->AddFileInfo(aFileInfo);
}
indexedDB::FileInfo*
Blob::GetFileInfo(indexedDB::FileManager* aFileManager)
{
return mImpl->GetFileInfo(aFileManager);
}
NS_IMETHODIMP_(bool)
Blob::IsMemoryFile()
{
return mImpl->IsMemoryFile();
}
NS_IMETHODIMP
Blob::GetInternalStream(nsIInputStream** aStream)
{
return mImpl->GetInternalStream(aStream);
}
////////////////////////////////////////////////////////////////////////////
// mozilla::dom::File implementation
NS_IMPL_CYCLE_COLLECTION_CLASS(File)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(File, Blob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(File, Blob)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(File)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile)
NS_INTERFACE_MAP_ENTRY(nsIDOMFile)
NS_INTERFACE_MAP_END_INHERITING(Blob)
NS_IMPL_ADDREF_INHERITED(File, Blob)
NS_IMPL_RELEASE_INHERITED(File, Blob)
File::File(nsISupports* aParent, FileImpl* aImpl)
: Blob(aParent, aImpl)
{
MOZ_ASSERT(aImpl->IsFile());
}
/* static */ File*
File::Create(nsISupports* aParent, FileImpl* aImpl)
{
MOZ_ASSERT(aImpl);
MOZ_ASSERT(aImpl->IsFile());
return new File(aParent, aImpl);
}
/* static */ already_AddRefed<File>
File::Create(nsISupports* aParent, const nsAString& aName,
@ -177,24 +489,6 @@ File::Create(nsISupports* aParent, const nsAString& aName,
return file.forget();
}
/* static */ already_AddRefed<File>
File::Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength)
{
nsRefPtr<File> file = new File(aParent,
new FileImplBase(aContentType, aLength));
return file.forget();
}
/* static */ already_AddRefed<File>
File::Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aStart, uint64_t aLength)
{
nsRefPtr<File> file = new File(aParent,
new FileImplBase(aContentType, aStart, aLength));
return file.forget();
}
/* static */ already_AddRefed<File>
File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer,
uint64_t aLength, const nsAString& aName,
@ -207,25 +501,6 @@ File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer,
return file.forget();
}
/* static */ already_AddRefed<File>
File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer,
uint64_t aLength, const nsAString& aContentType)
{
nsRefPtr<File> file = new File(aParent,
new FileImplMemory(aMemoryBuffer, aLength, aContentType));
return file.forget();
}
/* static */ already_AddRefed<File>
File::CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
const nsAString& aContentType)
{
nsRefPtr<File> file = new File(aParent,
new FileImplTemporaryFileBlob(aFD, aStartPos, aLength, aContentType));
return file.forget();
}
/* static */ already_AddRefed<File>
File::CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary)
{
@ -272,59 +547,10 @@ File::CreateFromFile(nsISupports* aParent, nsIFile* aFile,
return file.forget();
}
File::File(nsISupports* aParent, FileImpl* aImpl)
: mImpl(aImpl)
, mParent(aParent)
JSObject*
File::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
MOZ_ASSERT(mImpl);
#ifdef DEBUG
{
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aParent);
if (win) {
MOZ_ASSERT(win->IsInnerWindow());
}
}
#endif
}
const nsTArray<nsRefPtr<FileImpl>>*
File::GetSubBlobImpls() const
{
return mImpl->GetSubBlobImpls();
}
bool
File::IsSizeUnknown() const
{
return mImpl->IsSizeUnknown();
}
bool
File::IsDateUnknown() const
{
return mImpl->IsDateUnknown();
}
bool
File::IsFile() const
{
return mImpl->IsFile();
}
already_AddRefed<File>
File::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
nsRefPtr<FileImpl> impl = mImpl->CreateSlice(aStart, aLength,
aContentType, aRv);
if (aRv.Failed()) {
return nullptr;
}
nsRefPtr<File> file = new File(mParent, impl);
return file.forget();
return FileBinding::Wrap(aCx, this, aGivenProto);
}
NS_IMETHODIMP
@ -340,23 +566,6 @@ File::GetPath(nsAString& aPath)
return mImpl->GetPath(aPath);
}
NS_IMETHODIMP
File::GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate)
{
ErrorResult rv;
Date value = GetLastModifiedDate(rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
if (!value.ToDateObject(aCx, aDate)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
Date
File::GetLastModifiedDate(ErrorResult& aRv)
{
@ -374,6 +583,23 @@ File::GetLastModified(ErrorResult& aRv)
return mImpl->GetLastModified(aRv);
}
NS_IMETHODIMP
File::GetLastModifiedDate(JSContext* aCx,
JS::MutableHandle<JS::Value> aDate)
{
ErrorResult rv;
Date value = GetLastModifiedDate(rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
if (!value.ToDateObject(aCx, aDate)) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
File::GetMozFullPath(nsAString& aFileName)
{
@ -396,29 +622,6 @@ File::GetMozFullPathInternal(nsAString& aFileName)
return rv.StealNSResult();
}
NS_IMETHODIMP
File::GetSize(uint64_t* aSize)
{
MOZ_ASSERT(aSize);
ErrorResult rv;
*aSize = GetSize(rv);
return rv.StealNSResult();
}
uint64_t
File::GetSize(ErrorResult& aRv)
{
return mImpl->GetSize(aRv);
}
NS_IMETHODIMP
File::GetType(nsAString &aType)
{
mImpl->GetType(aType);
return NS_OK;
}
NS_IMETHODIMP
File::GetMozLastModifiedDate(int64_t* aDate)
{
@ -466,137 +669,6 @@ ParseSize(int64_t aSize, int64_t& aStart, int64_t& aEnd)
}
}
NS_IMETHODIMP
File::Slice(int64_t aStart, int64_t aEnd,
const nsAString& aContentType, uint8_t aArgc,
nsIDOMBlob **aBlob)
{
Optional<int64_t> start;
if (aArgc > 0) {
start.Construct(aStart);
}
Optional<int64_t> end;
if (aArgc > 1) {
end.Construct(aEnd);
}
ErrorResult rv;
nsRefPtr<File> file = Slice(start, end, aContentType, rv);
if (rv.Failed()) {
return rv.StealNSResult();
}
file.forget(aBlob);
return NS_OK;
}
already_AddRefed<File>
File::Slice(const Optional<int64_t>& aStart,
const Optional<int64_t>& aEnd,
const nsAString& aContentType,
ErrorResult& aRv)
{
nsRefPtr<FileImpl> impl =
mImpl->Slice(aStart, aEnd, aContentType, aRv);
if (aRv.Failed()) {
return nullptr;
}
nsRefPtr<File> file = new File(mParent, impl);
return file.forget();
}
NS_IMETHODIMP
File::GetInternalStream(nsIInputStream** aStream)
{
return mImpl->GetInternalStream(aStream);
}
NS_IMETHODIMP_(int64_t)
File::GetFileId()
{
return mImpl->GetFileId();
}
NS_IMETHODIMP_(void)
File::AddFileInfo(indexedDB::FileInfo* aFileInfo)
{
mImpl->AddFileInfo(aFileInfo);
}
indexedDB::FileInfo*
File::GetFileInfo(indexedDB::FileManager* aFileManager)
{
return mImpl->GetFileInfo(aFileManager);
}
NS_IMETHODIMP
File::GetSendInfo(nsIInputStream** aBody,
uint64_t* aContentLength,
nsACString& aContentType,
nsACString& aCharset)
{
return mImpl->GetSendInfo(aBody, aContentLength, aContentType, aCharset);
}
NS_IMETHODIMP
File::GetMutable(bool* aMutable)
{
return mImpl->GetMutable(aMutable);
}
NS_IMETHODIMP
File::SetMutable(bool aMutable)
{
return mImpl->SetMutable(aMutable);
}
NS_IMETHODIMP_(bool)
File::IsMemoryFile()
{
return mImpl->IsMemoryFile();
}
JSObject*
File::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return IsFile() ? FileBinding::Wrap(aCx, this, aGivenProto)
: BlobBinding::Wrap(aCx, this, aGivenProto);
}
/* static */ already_AddRefed<File>
File::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
{
nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl();
impl->InitializeBlob();
MOZ_ASSERT(!impl->IsFile());
nsRefPtr<File> file = new File(aGlobal.GetAsSupports(), impl);
return file.forget();
}
/* static */ already_AddRefed<File>
File::Constructor(
const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv)
{
nsRefPtr<MultipartFileImpl> impl = new MultipartFileImpl();
impl->InitializeBlob(aGlobal.Context(), aData, aBag.mType,
aBag.mEndings == EndingTypes::Native, aRv);
if (aRv.Failed()) {
return nullptr;
}
MOZ_ASSERT(!impl->IsFile());
nsRefPtr<File> file = new File(aGlobal.GetAsSupports(), impl);
return file.forget();
}
/* static */ already_AddRefed<File>
File::Constructor(
const GlobalObject& aGlobal,
@ -623,7 +695,7 @@ File::Constructor(
/* static */ already_AddRefed<File>
File::Constructor(const GlobalObject& aGlobal,
File& aData,
Blob& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{
@ -1191,14 +1263,14 @@ FileImplMemory::DataOwner::EnsureMemoryReporterRegistered()
}
////////////////////////////////////////////////////////////////////////////
// FileImplTemporaryFileBlob implementation
// FileImplTemporaryBlob implementation
NS_IMPL_ISUPPORTS_INHERITED0(FileImplTemporaryFileBlob, FileImpl)
NS_IMPL_ISUPPORTS_INHERITED0(FileImplTemporaryBlob, FileImpl)
already_AddRefed<FileImpl>
FileImplTemporaryFileBlob::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
FileImplTemporaryBlob::CreateSlice(uint64_t aStart, uint64_t aLength,
const nsAString& aContentType,
ErrorResult& aRv)
{
if (aStart + aLength > mLength) {
aRv.Throw(NS_ERROR_UNEXPECTED);
@ -1206,13 +1278,13 @@ FileImplTemporaryFileBlob::CreateSlice(uint64_t aStart, uint64_t aLength,
}
nsRefPtr<FileImpl> impl =
new FileImplTemporaryFileBlob(this, aStart + mStartPos,
aLength, aContentType);
new FileImplTemporaryBlob(this, aStart + mStartPos,
aLength, aContentType);
return impl.forget();
}
nsresult
FileImplTemporaryFileBlob::GetInternalStream(nsIInputStream** aStream)
FileImplTemporaryBlob::GetInternalStream(nsIInputStream** aStream)
{
nsCOMPtr<nsIInputStream> stream =
new nsTemporaryFileInputStream(mFileDescOwner, mStartPos, mStartPos + mLength);
@ -1259,10 +1331,10 @@ FileList::Item(uint32_t aIndex, nsIDOMFile **aFile)
////////////////////////////////////////////////////////////////////////////
// BlobSet implementation
already_AddRefed<File>
already_AddRefed<Blob>
BlobSet::GetBlobInternal(nsISupports* aParent, const nsACString& aContentType)
{
nsRefPtr<File> blob = new File(aParent,
nsRefPtr<Blob> blob = Blob::Create(aParent,
new MultipartFileImpl(GetBlobImpls(),
NS_ConvertASCIItoUTF16(aContentType)));
return blob.forget();

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

@ -47,23 +47,131 @@ class FileInfo;
struct BlobPropertyBag;
struct ChromeFilePropertyBag;
struct FilePropertyBag;
class File;
class FileImpl;
class OwningArrayBufferOrArrayBufferViewOrBlobOrString;
class File final : public nsIDOMFile
, public nsIXHRSendable
, public nsIMutable
, public nsSupportsWeakReference
, public nsWrapperCache
class Blob : public nsIDOMBlob
, public nsIXHRSendable
, public nsIMutable
, public nsSupportsWeakReference
, public nsWrapperCache
{
public:
NS_DECL_NSIDOMBLOB
NS_DECL_NSIDOMFILE
NS_DECL_NSIXHRSENDABLE
NS_DECL_NSIMUTABLE
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(File, nsIDOMFile)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Blob, nsIDOMBlob)
static Blob*
Create(nsISupports* aParent, FileImpl* aImpl);
static already_AddRefed<Blob>
Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength);
static already_AddRefed<Blob>
Create(nsISupports* aParent, const nsAString& aContentType, uint64_t aStart,
uint64_t aLength);
// The returned Blob takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by free so it must be allocated by malloc or something
// compatible with it.
static already_AddRefed<Blob>
CreateMemoryBlob(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<Blob>
CreateTemporaryBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
const nsAString& aContentType);
FileImpl* Impl() const
{
return mImpl;
}
bool IsFile() const;
const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const;
// This method returns null if this Blob is not a File; it returns
// the same object in case this Blob already implements the File interface;
// otherwise it returns a new File object with the same FileImpl.
already_AddRefed<File> ToFile();
// This method creates a new File object with the given name and the same
// FileImpl.
already_AddRefed<File> ToFile(const nsAString& aName) const;
already_AddRefed<Blob>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv);
// WebIDL methods
nsISupports* GetParentObject() const
{
return mParent;
}
// Blob constructor
static already_AddRefed<Blob>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
// Blob constructor
static already_AddRefed<Blob>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
uint64_t GetSize(ErrorResult& aRv);
// XPCOM GetType is OK
already_AddRefed<Blob> Slice(const Optional<int64_t>& aStart,
const Optional<int64_t>& aEnd,
const nsAString& aContentType,
ErrorResult& aRv);
protected:
// File constructor should never be used directly. Use Blob::Create instead.
Blob(nsISupports* aParent, FileImpl* aImpl);
virtual ~Blob() {};
virtual bool HasFileInterface() const { return false; }
// The member is the real backend implementation of this File/Blob.
// It's thread-safe and not CC-able and it's the only element that is moved
// between threads.
// Note: we should not store any other state in this class!
nsRefPtr<FileImpl> mImpl;
private:
nsCOMPtr<nsISupports> mParent;
};
class File final : public Blob
, public nsIDOMFile
{
friend class Blob;
public:
NS_DECL_NSIDOMFILE
NS_FORWARD_NSIDOMBLOB(Blob::)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(File, Blob);
// Note: FileImpl must be a File in order to use this method.
// Check impl->IsFile().
static File*
Create(nsISupports* aParent, FileImpl* aImpl);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aName,
@ -74,14 +182,6 @@ public:
Create(nsISupports* aParent, const nsAString& aName,
const nsAString& aContentType, uint64_t aLength);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType,
uint64_t aLength);
static already_AddRefed<File>
Create(nsISupports* aParent, const nsAString& aContentType, uint64_t aStart,
uint64_t aLength);
// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by free so it must be allocated by malloc or something
// compatible with it.
@ -90,18 +190,6 @@ public:
const nsAString& aName, const nsAString& aContentType,
int64_t aLastModifiedDate);
// The returned File takes ownership of aMemoryBuffer. aMemoryBuffer will be
// freed by free so it must be allocated by malloc or something
// compatible with it.
static already_AddRefed<File>
CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<File>
CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD,
uint64_t aStartPos, uint64_t aLength,
const nsAString& aContentType);
static already_AddRefed<File>
CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary = false);
@ -123,41 +211,10 @@ public:
CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName,
const nsAString& aContentType);
File(nsISupports* aParent, FileImpl* aImpl);
FileImpl* Impl() const
{
return mImpl;
}
const nsTArray<nsRefPtr<FileImpl>>* GetSubBlobImpls() const;
bool IsSizeUnknown() const;
bool IsDateUnknown() const;
bool IsFile() const;
already_AddRefed<File>
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
ErrorResult& aRv);
// WebIDL methods
nsISupports* GetParentObject() const
{
return mParent;
}
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
// Blob constructor
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
const Sequence<OwningArrayBufferOrArrayBufferViewOrBlobOrString>& aData,
const BlobPropertyBag& aBag,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext *cx,
JS::Handle<JSObject*> aGivenProto) override;
// File constructor
static already_AddRefed<File>
@ -170,7 +227,7 @@ public:
// File constructor - ChromeOnly
static already_AddRefed<File>
Constructor(const GlobalObject& aGlobal,
File& aData,
Blob& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
@ -188,35 +245,23 @@ public:
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) 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);
protected:
virtual bool HasFileInterface() const override { return true; }
private:
// File constructor should never be used directly. Use Blob::Create or
// File::Create.
File(nsISupports* aParent, FileImpl* aImpl);
~File() {};
// The member is the real backend implementation of this File/Blob.
// It's thread-safe and not CC-able and it's the only element that is moved
// between threads.
// Note: we should not store any other state in this class!
nsRefPtr<FileImpl> mImpl;
nsCOMPtr<nsISupports> mParent;
};
// This is the abstract class for any File backend. It must be nsISupports
@ -585,13 +630,13 @@ private:
nsRefPtr<DataOwner> mDataOwner;
};
class FileImplTemporaryFileBlob final : public FileImplBase
class FileImplTemporaryBlob final : public FileImplBase
{
public:
NS_DECL_ISUPPORTS_INHERITED
FileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength, const nsAString& aContentType)
FileImplTemporaryBlob(PRFileDesc* aFD, uint64_t aStartPos,
uint64_t aLength, const nsAString& aContentType)
: FileImplBase(aContentType, aLength)
, mStartPos(aStartPos)
{
@ -605,15 +650,15 @@ public:
const nsAString& aContentType, ErrorResult& aRv) override;
private:
FileImplTemporaryFileBlob(const FileImplTemporaryFileBlob* aOther,
uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
FileImplTemporaryBlob(const FileImplTemporaryBlob* aOther,
uint64_t aStart, uint64_t aLength,
const nsAString& aContentType)
: FileImplBase(aContentType, aLength)
, mStartPos(aStart)
, mFileDescOwner(aOther->mFileDescOwner)
{}
~FileImplTemporaryFileBlob() {}
~FileImplTemporaryBlob() {}
uint64_t mStartPos;
nsRefPtr<nsTemporaryFileInputStream::FileDescOwner> mFileDescOwner;
@ -823,7 +868,8 @@ public:
NS_DECL_NSIDOMFILELIST
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
virtual JSObject* WrapObject(JSContext *cx,
JS::Handle<JSObject*> aGivenProto) override;
nsISupports* GetParentObject()
{

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

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

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

@ -116,7 +116,7 @@ class EncodeCompleteCallback
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodeCompleteCallback)
virtual nsresult ReceiveBlob(already_AddRefed<File> aBlob) = 0;
virtual nsresult ReceiveBlob(already_AddRefed<Blob> aBlob) = 0;
protected:
virtual ~EncodeCompleteCallback() {}

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

@ -124,9 +124,9 @@ PostMessageReadStructuredClone(JSContext* cx,
// while destructors are running.
JS::Rooted<JS::Value> val(cx);
{
nsRefPtr<File> blob = new File(scInfo->mPort->GetParentObject(),
blobImpl);
if (!GetOrCreateDOMReflector(cx, blob, &val)) {
nsRefPtr<Blob> blob = Blob::Create(scInfo->mPort->GetParentObject(),
blobImpl);
if (!ToJSValue(cx, blob, &val)) {
return nullptr;
}
}
@ -168,7 +168,7 @@ PostMessageWriteStructuredClone(JSContext* cx,
// See if this is a File/Blob object.
{
File* blob = nullptr;
Blob* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&

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

@ -145,8 +145,8 @@ MultipartFileImpl::InitializeBlob(
const OwningArrayBufferOrArrayBufferViewOrBlobOrString& data = aData[i];
if (data.IsBlob()) {
nsRefPtr<File> file = data.GetAsBlob().get();
blobSet.AppendBlobImpl(file->Impl());
nsRefPtr<Blob> blob = data.GetAsBlob().get();
blobSet.AppendBlobImpl(blob->Impl());
}
else if (data.IsString()) {
@ -281,7 +281,7 @@ MultipartFileImpl::SetMutable(bool aMutable)
}
void
MultipartFileImpl::InitializeChromeFile(File& aBlob,
MultipartFileImpl::InitializeChromeFile(Blob& aBlob,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv)
{

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

@ -67,7 +67,7 @@ public:
bool aNativeEOL,
ErrorResult& aRv);
void InitializeChromeFile(File& aData,
void InitializeChromeFile(Blob& aData,
const ChromeFilePropertyBag& aBag,
ErrorResult& aRv);

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

@ -1213,7 +1213,7 @@ Navigator::SendBeacon(const nsAString& aUrl,
in = strStream;
} else if (aData.Value().IsBlob()) {
File& blob = aData.Value().GetAsBlob();
Blob& blob = aData.Value().GetAsBlob();
rv = blob.GetInternalStream(getter_AddRefs(in));
if (NS_FAILED(rv)) {
aRv.Throw(NS_ERROR_FAILURE);

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

@ -112,7 +112,7 @@ URL::Constructor(const nsAString& aUrl, nsIURI* aBase, ErrorResult& aRv)
void
URL::CreateObjectURL(const GlobalObject& aGlobal,
File& aBlob,
Blob& aBlob,
const objectURLOptions& aOptions,
nsAString& aResult,
ErrorResult& aError)

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

@ -22,7 +22,7 @@ class DOMMediaStream;
namespace dom {
class File;
class Blob;
class MediaSource;
class GlobalObject;
struct objectURLOptions;
@ -61,7 +61,7 @@ public:
Constructor(const nsAString& aUrl, nsIURI* aBase, ErrorResult& aRv);
static void CreateObjectURL(const GlobalObject& aGlobal,
File& aBlob,
Blob& aBlob,
const objectURLOptions& aOptions,
nsAString& aResult,
ErrorResult& aError);

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

@ -2210,7 +2210,7 @@ WebSocket::Send(const nsAString& aData,
}
void
WebSocket::Send(File& aData, ErrorResult& aRv)
WebSocket::Send(Blob& aData, ErrorResult& aRv)
{
AssertIsOnTargetThread();

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

@ -28,7 +28,7 @@ class nsIInputStream;
namespace mozilla {
namespace dom {
class File;
class Blob;
class WebSocketImpl;
@ -121,7 +121,7 @@ public: // WebIDL interface:
// webIDL: void send(DOMString|Blob|ArrayBufferView data);
void Send(const nsAString& aData,
ErrorResult& aRv);
void Send(File& aData,
void Send(Blob& aData,
ErrorResult& aRv);
void Send(const ArrayBuffer& aData,
ErrorResult& aRv);

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

@ -6090,16 +6090,16 @@ nsContentUtils::CreateBlobBuffer(JSContext* aCx,
{
uint32_t blobLen = aData.Length();
void* blobData = malloc(blobLen);
nsRefPtr<File> blob;
nsRefPtr<Blob> blob;
if (blobData) {
memcpy(blobData, aData.BeginReading(), blobLen);
blob = mozilla::dom::File::CreateMemoryFile(aParent, blobData, blobLen,
blob = mozilla::dom::Blob::CreateMemoryBlob(aParent, blobData, blobLen,
EmptyString());
} else {
return NS_ERROR_OUT_OF_MEMORY;
}
if (!GetOrCreateDOMReflector(aCx, blob, aBlob)) {
if (!ToJSValue(aCx, blob, aBlob)) {
return NS_ERROR_FAILURE;
}

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

@ -267,7 +267,7 @@ nsDOMDataChannel::Send(const nsAString& aData, ErrorResult& aRv)
}
void
nsDOMDataChannel::Send(File& aData, ErrorResult& aRv)
nsDOMDataChannel::Send(Blob& aData, ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread");

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

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

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

@ -43,13 +43,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMFileReader)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMFileReader,
FileIOObject)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFile)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBlob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMFileReader,
FileIOObject)
tmp->mResultArrayBuffer = nullptr;
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFile)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mBlob)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -183,43 +183,43 @@ nsDOMFileReader::GetError(nsISupports** aError)
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aFile, JSContext* aCx)
nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aBlob, JSContext* aCx)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsArrayBuffer(aCx, *file, rv);
nsRefPtr<Blob> blob = static_cast<Blob*>(aBlob);
ReadAsArrayBuffer(aCx, *blob, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aFile)
nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aBlob)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsBinaryString(*file, rv);
nsRefPtr<Blob> blob = static_cast<Blob*>(aBlob);
ReadAsBinaryString(*blob, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsText(nsIDOMBlob* aFile,
nsDOMFileReader::ReadAsText(nsIDOMBlob* aBlob,
const nsAString &aCharset)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsText(*file, aCharset, rv);
nsRefPtr<Blob> blob = static_cast<Blob*>(aBlob);
ReadAsText(*blob, aCharset, rv);
return rv.StealNSResult();
}
NS_IMETHODIMP
nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile)
nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aBlob)
{
NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER);
NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER);
ErrorResult rv;
nsRefPtr<File> file = static_cast<File*>(aFile);
ReadAsDataURL(*file, rv);
nsRefPtr<Blob> blob = static_cast<Blob*>(aBlob);
ReadAsDataURL(*blob, rv);
return rv.StealNSResult();
}
@ -241,7 +241,7 @@ nsDOMFileReader::DoAbort(nsAString& aEvent)
if (mAsyncStream) {
mAsyncStream = nullptr;
}
mFile = nullptr;
mBlob = nullptr;
//Clean up memory buffer
FreeFileData();
@ -281,8 +281,8 @@ nsDOMFileReader::DoOnLoadEnd(nsresult aStatus,
// Make sure we drop all the objects that could hold files open now.
nsCOMPtr<nsIAsyncInputStream> stream;
mAsyncStream.swap(stream);
nsCOMPtr<nsIDOMBlob> file;
mFile.swap(file);
nsCOMPtr<nsIDOMBlob> blob;
mBlob.swap(blob);
aSuccessEvent = NS_LITERAL_STRING(LOAD_STR);
aTerminationEvent = NS_LITERAL_STRING(LOADEND_STR);
@ -319,13 +319,13 @@ nsDOMFileReader::DoOnLoadEnd(nsresult aStatus,
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
rv = GetAsText(file, mCharset, "", mDataLen, mResult);
rv = GetAsText(blob, mCharset, "", mDataLen, mResult);
break;
}
rv = GetAsText(file, mCharset, mFileData, mDataLen, mResult);
rv = GetAsText(blob, mCharset, mFileData, mDataLen, mResult);
break;
case FILE_AS_DATAURL:
rv = GetAsDataURL(file, mFileData, mDataLen, mResult);
rv = GetAsDataURL(blob, mFileData, mDataLen, mResult);
break;
}
@ -380,7 +380,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount)
// Helper methods
void
nsDOMFileReader::ReadFileContent(File& aFile,
nsDOMFileReader::ReadFileContent(Blob& aBlob,
const nsAString &aCharset,
eDataFormat aDataFormat,
ErrorResult& aRv)
@ -394,7 +394,7 @@ nsDOMFileReader::ReadFileContent(File& aFile,
mReadyState = nsIDOMFileReader::EMPTY;
FreeFileData();
mFile = &aFile;
mBlob = &aBlob;
mDataFormat = aDataFormat;
CopyUTF16toUTF8(aCharset, mCharset);
@ -408,7 +408,7 @@ nsDOMFileReader::ReadFileContent(File& aFile,
}
nsCOMPtr<nsIInputStream> stream;
rv = mFile->GetInternalStream(getter_AddRefs(stream));
rv = mBlob->GetInternalStream(getter_AddRefs(stream));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return;
@ -440,7 +440,7 @@ nsDOMFileReader::ReadFileContent(File& aFile,
MOZ_ASSERT(mAsyncStream);
mTotal = mozilla::dom::kUnknownSize;
mFile->GetSize(&mTotal);
mBlob->GetSize(&mTotal);
rv = DoAsyncWait(mAsyncStream);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -462,7 +462,7 @@ nsDOMFileReader::ReadFileContent(File& aFile,
}
nsresult
nsDOMFileReader::GetAsText(nsIDOMBlob *aFile,
nsDOMFileReader::GetAsText(nsIDOMBlob *aBlob,
const nsACString &aCharset,
const char *aFileData,
uint32_t aDataLen,
@ -480,7 +480,7 @@ nsDOMFileReader::GetAsText(nsIDOMBlob *aFile,
encoding)) {
// API argument failed. Try the type property of the blob.
nsAutoString type16;
aFile->GetType(type16);
aBlob->GetType(type16);
NS_ConvertUTF16toUTF8 type(type16);
nsAutoCString specifiedCharset;
bool haveCharset;
@ -502,7 +502,7 @@ nsDOMFileReader::GetAsText(nsIDOMBlob *aFile,
}
nsresult
nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aFile,
nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aBlob,
const char *aFileData,
uint32_t aDataLen,
nsAString& aResult)
@ -511,7 +511,7 @@ nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aFile,
nsresult rv;
nsString contentType;
rv = aFile->GetType(contentType);
rv = aBlob->GetType(contentType);
if (NS_SUCCEEDED(rv) && !contentType.IsEmpty()) {
aResult.Append(contentType);
} else {

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

@ -27,7 +27,7 @@
namespace mozilla {
namespace dom {
class File;
class Blob;
}
}
@ -38,7 +38,8 @@ class nsDOMFileReader final : public mozilla::dom::FileIOObject,
{
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::GlobalObject GlobalObject;
typedef mozilla::dom::File File;
typedef mozilla::dom::Blob Blob;
public:
nsDOMFileReader();
@ -68,17 +69,17 @@ public:
// WebIDL
static already_AddRefed<nsDOMFileReader>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
void ReadAsArrayBuffer(JSContext* aCx, File& aBlob, ErrorResult& aRv)
void ReadAsArrayBuffer(JSContext* aCx, Blob& aBlob, ErrorResult& aRv)
{
ReadFileContent(aBlob, EmptyString(), FILE_AS_ARRAYBUFFER, aRv);
}
void ReadAsText(File& aBlob, const nsAString& aLabel, ErrorResult& aRv)
void ReadAsText(Blob& aBlob, const nsAString& aLabel, ErrorResult& aRv)
{
ReadFileContent(aBlob, aLabel, FILE_AS_TEXT, aRv);
}
void ReadAsDataURL(File& aBlob, ErrorResult& aRv)
void ReadAsDataURL(Blob& aBlob, ErrorResult& aRv)
{
ReadFileContent(aBlob, EmptyString(), FILE_AS_DATAURL, aRv);
}
@ -102,7 +103,7 @@ public:
using FileIOObject::SetOnerror;
IMPL_EVENT_HANDLER(loadend)
void ReadAsBinaryString(File& aBlob, ErrorResult& aRv)
void ReadAsBinaryString(Blob& aBlob, ErrorResult& aRv)
{
ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv);
}
@ -124,12 +125,14 @@ protected:
FILE_AS_DATAURL
};
void ReadFileContent(File& aBlob,
void ReadFileContent(Blob& aBlob,
const nsAString &aCharset, eDataFormat aDataFormat,
ErrorResult& aRv);
nsresult GetAsText(nsIDOMBlob *aFile, const nsACString &aCharset,
const char *aFileData, uint32_t aDataLen, nsAString &aResult);
nsresult GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, uint32_t aDataLen, nsAString &aResult);
nsresult GetAsText(nsIDOMBlob *aBlob, const nsACString &aCharset,
const char *aFileData, uint32_t aDataLen,
nsAString &aResult);
nsresult GetAsDataURL(nsIDOMBlob *aBlob, const char *aFileData,
uint32_t aDataLen, nsAString &aResult);
void FreeFileData() {
free(mFileData);
@ -138,7 +141,7 @@ protected:
}
char *mFileData;
nsCOMPtr<nsIDOMBlob> mFile;
nsCOMPtr<nsIDOMBlob> mBlob;
nsCString mCharset;
uint32_t mDataLen;

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

@ -22,9 +22,10 @@ nsFormData::nsFormData(nsISupports* aOwner)
}
namespace {
// Implements steps 3 and 4 of the "create an entry" algorithm of FormData.
File*
CreateNewFileInstance(File& aBlob, const Optional<nsAString>& aFilename)
already_AddRefed<File>
CreateNewFileInstance(Blob& aBlob, const Optional<nsAString>& aFilename)
{
// Step 3 "If value is a Blob object and not a File object, set value to
// a new File object, representing the same bytes, whose name attribute value
@ -35,25 +36,20 @@ CreateNewFileInstance(File& aBlob, const Optional<nsAString>& aFilename)
nsAutoString filename;
if (aFilename.WasPassed()) {
filename = aFilename.Value();
} else if (aBlob.IsFile()) {
} else {
// If value is already a File and filename is not passed, the spec says not
// to create a new instance.
return &aBlob;
} else {
nsRefPtr<File> file = aBlob.ToFile();
if (file) {
return file.forget();
}
filename = NS_LITERAL_STRING("blob");
}
nsAutoTArray<nsRefPtr<FileImpl>, 1> blobImpls;
blobImpls.AppendElement(aBlob.Impl());
nsAutoString contentType;
aBlob.GetType(contentType);
nsRefPtr<MultipartFileImpl> impl =
new MultipartFileImpl(blobImpls, filename, contentType);
return new File(aBlob.GetParentObject(), impl);
return aBlob.ToFile(filename);
}
} // anonymous namespace
// -------------------------------------------------------------------------
@ -111,7 +107,7 @@ nsFormData::Append(const nsAString& aName, const nsAString& aValue)
}
void
nsFormData::Append(const nsAString& aName, File& aBlob,
nsFormData::Append(const nsAString& aName, Blob& aBlob,
const Optional<nsAString>& aFilename)
{
nsRefPtr<File> file = CreateNewFileInstance(aBlob, aFilename);
@ -179,6 +175,14 @@ nsFormData::Has(const nsAString& aName)
return false;
}
nsresult
nsFormData::AddNameFilePair(const nsAString& aName, File* aFile)
{
FormDataTuple* data = mFormData.AppendElement();
SetNameFilePair(data, aName, aFile);
return NS_OK;
}
nsFormData::FormDataTuple*
nsFormData::RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName)
{
@ -202,7 +206,7 @@ nsFormData::RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName)
}
void
nsFormData::Set(const nsAString& aName, File& aBlob,
nsFormData::Set(const nsAString& aName, Blob& aBlob,
const Optional<nsAString>& aFilename)
{
FormDataTuple* tuple = RemoveAllOthersAndGetFirstFormDataTuple(aName);
@ -245,7 +249,7 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue)
free(iid);
nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(supports);
nsRefPtr<File> blob = static_cast<File*>(domBlob.get());
nsRefPtr<Blob> blob = static_cast<Blob*>(domBlob.get());
if (domBlob) {
Optional<nsAString> temp;
Append(aName, *blob, temp);

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

@ -35,7 +35,9 @@ class nsFormData final : public nsIDOMFormData,
private:
~nsFormData() {}
typedef mozilla::dom::Blob Blob;
typedef mozilla::dom::File File;
struct FormDataTuple
{
nsString name;
@ -61,11 +63,11 @@ private:
void SetNameFilePair(FormDataTuple* aData,
const nsAString& aName,
File* aBlob)
File* aFile)
{
MOZ_ASSERT(aData);
aData->name = aName;
aData->fileValue = aBlob;
aData->fileValue = aFile;
aData->valueIsFile = true;
}
@ -95,13 +97,13 @@ public:
const mozilla::dom::Optional<mozilla::dom::NonNull<mozilla::dom::HTMLFormElement> >& aFormElement,
mozilla::ErrorResult& aRv);
void Append(const nsAString& aName, const nsAString& aValue);
void Append(const nsAString& aName, File& aBlob,
void Append(const nsAString& aName, Blob& aBlob,
const mozilla::dom::Optional<nsAString>& aFilename);
void Delete(const nsAString& aName);
void Get(const nsAString& aName, mozilla::dom::Nullable<mozilla::dom::OwningFileOrUSVString>& aOutValue);
void GetAll(const nsAString& aName, nsTArray<mozilla::dom::OwningFileOrUSVString>& aValues);
bool Has(const nsAString& aName);
void Set(const nsAString& aName, File& aBlob,
void Set(const nsAString& aName, Blob& aBlob,
const mozilla::dom::Optional<nsAString>& aFilename);
void Set(const nsAString& aName, const nsAString& aValue);
@ -116,12 +118,7 @@ public:
return NS_OK;
}
virtual nsresult AddNameFilePair(const nsAString& aName,
File* aBlob) override
{
FormDataTuple* data = mFormData.AppendElement();
SetNameFilePair(data, aName, aBlob);
return NS_OK;
}
File* aFile) override;
typedef bool (*FormDataEntryCallback)(const nsString& aName, bool aIsFile,
const nsString& aValue,

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

@ -277,7 +277,7 @@ BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType*
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsRefPtr<File>>& blobs = aData.mClosure.mBlobs;
const nsTArray<nsRefPtr<Blob>>& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
@ -334,7 +334,7 @@ UnpackClonedMessageData(const ClonedMessageData& aData)
// This object will be duplicated with a correct parent before being
// exposed to JS.
nsRefPtr<File> domBlob = new File(nullptr, blobImpl);
nsRefPtr<Blob> domBlob = Blob::Create(nullptr, blobImpl);
cloneData.mClosure.mBlobs.AppendElement(domBlob);
}
}

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

@ -8063,8 +8063,8 @@ PostMessageReadStructuredClone(JSContext* cx,
// while destructors are running.
JS::Rooted<JS::Value> val(cx);
{
nsRefPtr<File> blob = new File(scInfo->window, blobImpl);
if (!GetOrCreateDOMReflector(cx, blob, &val)) {
nsRefPtr<Blob> blob = Blob::Create(scInfo->window, blobImpl);
if (!ToJSValue(cx, blob, &val)) {
return nullptr;
}
}
@ -8106,7 +8106,7 @@ PostMessageWriteStructuredClone(JSContext* cx,
// See if this is a File/Blob object.
{
File* blob = nullptr;
Blob* blob = nullptr;
if (scInfo->subsumes && NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) {
FileImpl* blobImpl = blob->Impl();
if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) &&

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

@ -54,8 +54,12 @@ interface nsIDOMBlob : nsISupports
[notxpcom] bool isMemoryFile();
};
[scriptable, builtinclass, uuid(74657f92-aa61-492b-8649-fd1cca62e255)]
interface nsIDOMFile : nsIDOMBlob
// We want to avoid multiple inheritance of nsIDOMBlob so we can downcast from
// nsIDOMBlob to Blob safely. Our chain is:
// - Blob -> nsIDOMBlob
// - File -> nsIDOMFile and Blob
[scriptable, builtinclass, uuid(cc28cf12-f1d4-44ff-843f-9289aa14613b)]
interface nsIDOMFile : nsISupports
{
readonly attribute DOMString name;

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

@ -428,7 +428,7 @@ nsXMLHttpRequest::ResetResponse()
mResponseBody.Truncate();
mResponseText.Truncate();
mResponseBlob = nullptr;
mDOMFile = nullptr;
mDOMBlob = nullptr;
mBlobSet = nullptr;
mResultArrayBuffer = nullptr;
mArrayBufferBuilder.reset();
@ -479,7 +479,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLHttpRequest,
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mXMLParserStreamListener)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mResponseBlob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMFile)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMBlob)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNotificationCallbacks)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannelEventSink)
@ -501,7 +501,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsXMLHttpRequest,
NS_IMPL_CYCLE_COLLECTION_UNLINK(mXMLParserStreamListener)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mResponseBlob)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMFile)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMBlob)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNotificationCallbacks)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChannelEventSink)
@ -789,15 +789,15 @@ nsXMLHttpRequest::CreateResponseParsedJSON(JSContext* aCx)
void
nsXMLHttpRequest::CreatePartialBlob()
{
if (mDOMFile) {
if (mDOMBlob) {
// Use progress info to determine whether load is complete, but use
// mDataAvailable to ensure a slice is created based on the uncompressed
// data count.
if (mLoadTotal == mLoadTransferred) {
mResponseBlob = mDOMFile;
mResponseBlob = mDOMBlob;
} else {
ErrorResult rv;
mResponseBlob = mDOMFile->CreateSlice(0, mDataAvailable,
mResponseBlob = mDOMBlob->CreateSlice(0, mDataAvailable,
EmptyString(), rv);
}
return;
@ -1829,7 +1829,7 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
if (xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
xmlHttpRequest->mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) {
if (!xmlHttpRequest->mDOMFile) {
if (!xmlHttpRequest->mDOMBlob) {
if (!xmlHttpRequest->mBlobSet) {
xmlHttpRequest->mBlobSet = new BlobSet();
}
@ -1899,7 +1899,7 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in,
return rv;
}
bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request)
bool nsXMLHttpRequest::CreateDOMBlob(nsIRequest *request)
{
nsCOMPtr<nsIFile> file;
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(request);
@ -1913,7 +1913,7 @@ bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request)
nsAutoCString contentType;
mChannel->GetContentType(contentType);
mDOMFile = File::CreateFromFile(GetOwner(), file, EmptyString(),
mDOMBlob = File::CreateFromFile(GetOwner(), file, EmptyString(),
NS_ConvertASCIItoUTF16(contentType));
mBlobSet = nullptr;
@ -1936,8 +1936,8 @@ nsXMLHttpRequest::OnDataAvailable(nsIRequest *request,
bool cancelable = false;
if ((mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) && !mDOMFile) {
cancelable = CreateDOMFile(request);
mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) && !mDOMBlob) {
cancelable = CreateDOMBlob(request);
// The nsIStreamListener contract mandates us
// to read from the stream before returning.
}
@ -1949,7 +1949,7 @@ nsXMLHttpRequest::OnDataAvailable(nsIRequest *request,
if (cancelable) {
// We don't have to read from the local file for the blob response
mDOMFile->GetSize(&mDataAvailable);
mDOMBlob->GetSize(&mDataAvailable);
ChangeState(XML_HTTP_REQUEST_LOADING);
return request->Cancel(NS_OK);
}
@ -2246,12 +2246,12 @@ nsXMLHttpRequest::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult
if (NS_SUCCEEDED(status) &&
(mResponseType == XML_HTTP_RESPONSE_TYPE_BLOB ||
mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB)) {
if (!mDOMFile) {
CreateDOMFile(request);
if (!mDOMBlob) {
CreateDOMBlob(request);
}
if (mDOMFile) {
mResponseBlob = mDOMFile;
mDOMFile = nullptr;
if (mDOMBlob) {
mResponseBlob = mDOMBlob;
mDOMBlob = nullptr;
} else {
// mBlobSet can be null if the channel is non-file non-cacheable
// and if the response length is zero.

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

@ -51,8 +51,8 @@ class nsIJSID;
namespace mozilla {
namespace dom {
class Blob;
class BlobSet;
class File;
}
// A helper for building up an ArrayBuffer object's data
@ -352,7 +352,7 @@ private:
{
mValue.mArrayBufferView = aArrayBufferView;
}
explicit RequestBody(mozilla::dom::File& aBlob) : mType(Blob)
explicit RequestBody(mozilla::dom::Blob& aBlob) : mType(Blob)
{
mValue.mBlob = &aBlob;
}
@ -386,7 +386,7 @@ private:
union Value {
const mozilla::dom::ArrayBuffer* mArrayBuffer;
const mozilla::dom::ArrayBufferView* mArrayBufferView;
mozilla::dom::File* mBlob;
mozilla::dom::Blob* mBlob;
nsIDocument* mDocument;
const nsAString* mString;
nsFormData* mFormData;
@ -450,7 +450,7 @@ public:
{
aRv = Send(RequestBody(&aArrayBufferView));
}
void Send(JSContext* /*aCx*/, mozilla::dom::File& aBlob, ErrorResult& aRv)
void Send(JSContext* /*aCx*/, mozilla::dom::Blob& aBlob, ErrorResult& aRv)
{
aRv = Send(RequestBody(aBlob));
}
@ -606,7 +606,7 @@ protected:
uint32_t *writeCount);
nsresult CreateResponseParsedJSON(JSContext* aCx);
void CreatePartialBlob();
bool CreateDOMFile(nsIRequest *request);
bool CreateDOMBlob(nsIRequest *request);
// Change the state of the object with this. The broadcast argument
// determines if the onreadystatechange listener should be called.
nsresult ChangeState(uint32_t aState, bool aBroadcast = true);
@ -708,12 +708,12 @@ protected:
// It is either a cached blob-response from the last call to GetResponse,
// but is also explicitly set in OnStopRequest.
nsRefPtr<mozilla::dom::File> mResponseBlob;
nsRefPtr<mozilla::dom::Blob> mResponseBlob;
// Non-null only when we are able to get a os-file representation of the
// response, i.e. when loading from a file.
nsRefPtr<mozilla::dom::File> mDOMFile;
nsRefPtr<mozilla::dom::Blob> mDOMBlob;
// We stream data to mBlobSet when response type is "blob" or "moz-blob"
// and mDOMFile is null.
// and mDOMBlob is null.
nsAutoPtr<mozilla::dom::BlobSet> mBlobSet;
nsString mOverrideMimeType;

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

@ -138,7 +138,6 @@ DOMInterfaces = {
},
'Blob': {
'nativeType': 'mozilla::dom::File',
'headerFile': 'mozilla/dom/File.h',
},

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

@ -413,7 +413,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
nsRefPtr<Blob> blob = Blob::Create(nullptr, impl);
return SendFile(aDeviceAddress, blob.get());
}

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

@ -766,7 +766,7 @@ BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv)
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
File& aBlob, ErrorResult& aRv)
Blob& aBlob, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {

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

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

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

@ -1261,7 +1261,7 @@ BluetoothAdapter::Disconnect(BluetoothDevice& aDevice,
already_AddRefed<DOMRequest>
BluetoothAdapter::SendFile(const nsAString& aDeviceAddress,
File& aBlob, ErrorResult& aRv)
Blob& aBlob, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {

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

@ -17,8 +17,8 @@
namespace mozilla {
namespace dom {
class Blob;
class DOMRequest;
class File;
struct MediaMetaData;
struct MediaPlayStatus;
}
@ -132,7 +132,7 @@ public:
// OPP file transfer related methods
already_AddRefed<DOMRequest> SendFile(const nsAString& aDeviceAddress,
File& aBlob,
Blob& aBlob,
ErrorResult& aRv);
already_AddRefed<DOMRequest> StopSendingFile(const nsAString& aDeviceAddress,
ErrorResult& aRv);

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

@ -385,7 +385,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
MOZ_ASSERT(NS_IsMainThread());
nsRefPtr<FileImpl> impl = aActor->GetBlobImpl();
nsCOMPtr<nsIDOMBlob> blob = new File(nullptr, impl);
nsCOMPtr<nsIDOMBlob> blob = Blob::Create(nullptr, impl);
return SendFile(aDeviceAddress, blob.get());
}

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

@ -212,7 +212,7 @@ public:
PBackgroundChild* backgroundManager = mActor->Manager();
MOZ_ASSERT(backgroundManager);
const nsTArray<nsRefPtr<File>>& blobs = mData->mClosure.mBlobs;
const nsTArray<nsRefPtr<Blob>>& blobs = mData->mClosure.mBlobs;
if (!blobs.IsEmpty()) {
message.blobsChild().SetCapacity(blobs.Length());
@ -541,7 +541,7 @@ BroadcastChannel::PostMessageInternal(JSContext* aCx,
return;
}
const nsTArray<nsRefPtr<File>>& blobs = data->mClosure.mBlobs;
const nsTArray<nsRefPtr<Blob>>& blobs = data->mClosure.mBlobs;
for (uint32_t i = 0, len = blobs.Length(); i < len; ++i) {
if (!blobs[i]->Impl()->MayBeClonedToOtherThreads()) {
aRv.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);

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

@ -42,16 +42,16 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
{
// Make sure to retrieve all blobs from the message before returning to avoid
// leaking their actors.
nsTArray<nsRefPtr<File>> files;
nsTArray<nsRefPtr<Blob>> blobs;
if (!aData.blobsChild().IsEmpty()) {
files.SetCapacity(aData.blobsChild().Length());
blobs.SetCapacity(aData.blobsChild().Length());
for (uint32_t i = 0, len = aData.blobsChild().Length(); i < len; ++i) {
nsRefPtr<FileImpl> impl =
static_cast<BlobChild*>(aData.blobsChild()[i])->GetBlobImpl();
nsRefPtr<File> file = new File(mBC ? mBC->GetOwner() : nullptr, impl);
files.AppendElement(file);
nsRefPtr<Blob> blob = Blob::Create(mBC ? mBC->GetOwner() : nullptr, impl);
blobs.AppendElement(blob);
}
}
@ -92,7 +92,7 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
StructuredCloneData cloneData;
cloneData.mData = buffer.data;
cloneData.mDataLength = buffer.dataLength;
cloneData.mClosure.mBlobs.SwapElements(files);
cloneData.mClosure.mBlobs.SwapElements(blobs);
JS::Rooted<JS::Value> value(cx, JS::NullValue());
if (cloneData.mDataLength && !ReadStructuredClone(cx, cloneData, &value)) {

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

@ -1405,7 +1405,7 @@ nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture)
promise->MaybeResolve(picture);
}
nsRefPtr<File> blob = static_cast<File*>(aPicture);
nsRefPtr<Blob> blob = static_cast<Blob*>(aPicture);
BlobEventInit eventInit;
eventInit.mData = blob;

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

@ -360,7 +360,7 @@ DOMCameraControlListener::OnTakePictureComplete(const uint8_t* aData, uint32_t a
RunCallback(nsDOMCameraControl* aDOMCameraControl) override
{
nsCOMPtr<nsIDOMBlob> picture =
File::CreateMemoryFile(mDOMCameraControl.get(),
Blob::CreateMemoryBlob(mDOMCameraControl.get(),
static_cast<void*>(mData),
static_cast<uint64_t>(mLength),
mMimeType);

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

@ -106,19 +106,19 @@ TestGonkCameraHardwareListener::HandleEvent(nsIDOMEvent* aEvent)
BlobEvent* event = aEvent->InternalDOMEvent()->AsBlobEvent();
if (!NS_WARN_IF(!event)) {
File* file = event->GetData();
Blob* blob = event->GetData();
if (file) {
if (blob) {
static const uint64_t MAX_FILE_SIZE = 2147483647;
uint64_t dataLength = 0;
nsresult rv = file->GetSize(&dataLength);
nsresult rv = blob->GetSize(&dataLength);
if (NS_WARN_IF(NS_FAILED(rv) || dataLength > MAX_FILE_SIZE)) {
return NS_OK;
}
nsCOMPtr<nsIInputStream> inputStream;
rv = file->GetInternalStream(getter_AddRefs(inputStream));
rv = blob->GetInternalStream(getter_AddRefs(inputStream));
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_OK;
}

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

@ -29,6 +29,7 @@ class nsIOutputStream;
namespace mozilla {
class EventListenerManager;
namespace dom {
class Blob;
struct DeviceStorageEnumerationParameters;
class DOMCursor;
class DOMRequest;
@ -222,15 +223,16 @@ public:
IMPL_EVENT_HANDLER(change)
already_AddRefed<DOMRequest>
Add(nsIDOMBlob* aBlob, ErrorResult& aRv);
Add(mozilla::dom::Blob* aBlob, ErrorResult& aRv);
already_AddRefed<DOMRequest>
AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv);
AddNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath, ErrorResult& aRv);
already_AddRefed<DOMRequest>
AppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv);
AppendNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath,
ErrorResult& aRv);
already_AddRefed<DOMRequest>
AddOrAppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
AddOrAppendNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath,
const int32_t aRequestType, ErrorResult& aRv);
already_AddRefed<DOMRequest>

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

@ -105,7 +105,8 @@ DeviceStorageRequestChild::
BlobResponse r = aValue;
BlobChild* actor = static_cast<BlobChild*>(r.blobChild());
nsRefPtr<FileImpl> bloblImpl = actor->GetBlobImpl();
nsRefPtr<File> blob = new File(mRequest->GetParentObject(), bloblImpl);
nsRefPtr<Blob> blob = Blob::Create(mRequest->GetParentObject(),
bloblImpl);
AutoJSContext cx;

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

@ -523,12 +523,12 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() {
nsString fullPath;
mFile->GetFullPath(fullPath);
nsRefPtr<File> blob = new File(nullptr,
nsRefPtr<FileImpl> blob =
new FileImplFile(fullPath, mime, mLength, mFile->mFile,
mLastModificationDate));
mLastModificationDate);
ContentParent* cp = static_cast<ContentParent*>(mParent->Manager());
BlobParent* actor = cp->GetOrCreateActorForBlob(blob);
BlobParent* actor = cp->GetOrCreateActorForFileImpl(blob);
if (!actor) {
ErrorResponse response(NS_LITERAL_STRING(POST_ERROR_EVENT_UNKNOWN));
unused << mParent->Send__delete__(mParent, response);

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

@ -274,7 +274,7 @@ DeviceStorageTypeChecker::InitFromBundle(nsIStringBundle* aBundle)
bool
DeviceStorageTypeChecker::Check(const nsAString& aType, nsIDOMBlob* aBlob)
DeviceStorageTypeChecker::Check(const nsAString& aType, Blob* aBlob)
{
MOZ_ASSERT(aBlob);
@ -1924,7 +1924,7 @@ nsIFileToJsval(nsPIDOMWindow* aWindow, DeviceStorageFile* aFile)
MOZ_ASSERT(aFile->mLength != UINT64_MAX);
MOZ_ASSERT(aFile->mLastModifiedDate != UINT64_MAX);
nsCOMPtr<nsIDOMBlob> blob = new File(aWindow,
nsCOMPtr<nsIDOMBlob> blob = Blob::Create(aWindow,
new FileImplFile(fullPath, aFile->mMimeType,
aFile->mLength, aFile->mFile,
aFile->mLastModifiedDate));
@ -2876,7 +2876,7 @@ public:
nsIPrincipal* aPrincipal,
DeviceStorageFile* aFile,
DOMRequest* aRequest,
nsIDOMBlob* aBlob = nullptr)
Blob* aBlob = nullptr)
: mRequestType(aRequestType)
, mWindow(aWindow)
, mPrincipal(aPrincipal)
@ -3048,7 +3048,7 @@ public:
if (XRE_GetProcessType() != GeckoProcessType_Default) {
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(
static_cast<File*>(mBlob.get()));
static_cast<Blob*>(mBlob.get()));
if (!actor) {
return NS_ERROR_FAILURE;
}
@ -3094,7 +3094,7 @@ public:
if (XRE_GetProcessType() != GeckoProcessType_Default) {
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(
static_cast<File*>(mBlob.get()));
static_cast<Blob*>(mBlob.get()));
if (!actor) {
return NS_ERROR_FAILURE;
}
@ -3331,7 +3331,7 @@ private:
nsRefPtr<DeviceStorageFile> mFile;
nsRefPtr<DOMRequest> mRequest;
nsCOMPtr<nsIDOMBlob> mBlob;
nsRefPtr<Blob> mBlob;
nsRefPtr<nsDOMDeviceStorage> mDeviceStorage;
nsRefPtr<DeviceStorageFileDescriptor> mDSFileDescriptor;
nsCOMPtr<nsIContentPermissionRequester> mRequester;
@ -3741,13 +3741,13 @@ NS_IMETHODIMP
nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = Add(aBlob, rv);
nsRefPtr<DOMRequest> request = Add(static_cast<Blob*>(aBlob), rv);
request.forget(_retval);
return rv.StealNSResult();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::Add(nsIDOMBlob* aBlob, ErrorResult& aRv)
nsDOMDeviceStorage::Add(Blob* aBlob, ErrorResult& aRv)
{
if (!aBlob) {
return nullptr;
@ -3790,13 +3790,13 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
nsIDOMDOMRequest * *_retval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = AddNamed(aBlob, aPath, rv);
nsRefPtr<DOMRequest> request = AddNamed(static_cast<Blob*>(aBlob), aPath, rv);
request.forget(_retval);
return rv.StealNSResult();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
nsDOMDeviceStorage::AddNamed(Blob* aBlob, const nsAString& aPath,
ErrorResult& aRv)
{
return AddOrAppendNamed(aBlob, aPath,
@ -3804,7 +3804,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::AppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
nsDOMDeviceStorage::AppendNamed(Blob* aBlob, const nsAString& aPath,
ErrorResult& aRv)
{
return AddOrAppendNamed(aBlob, aPath,
@ -3813,7 +3813,7 @@ nsDOMDeviceStorage::AppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::AddOrAppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
nsDOMDeviceStorage::AddOrAppendNamed(Blob* aBlob, const nsAString& aPath,
const int32_t aRequestType, ErrorResult& aRv)
{
MOZ_ASSERT(NS_IsMainThread());

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

@ -33,6 +33,10 @@ class nsPIDOMWindow;
namespace mozilla {
class ErrorResult;
namespace dom {
class Blob;
}
} // namespace mozilla
#define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError"
@ -157,7 +161,7 @@ public:
void InitFromBundle(nsIStringBundle* aBundle);
bool Check(const nsAString& aType, nsIDOMBlob* aBlob);
bool Check(const nsAString& aType, mozilla::dom::Blob* aBlob);
bool Check(const nsAString& aType, nsIFile* aFile);
bool Check(const nsAString& aType, const nsString& aPath);
void GetTypeFromFile(nsIFile* aFile, nsAString& aType);

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

@ -308,7 +308,11 @@ DataTransfer::GetFiles(ErrorResult& aRv)
if (!fileImpl) {
continue;
}
domFile = new File(GetParentObject(), static_cast<FileImpl*>(fileImpl.get()));
MOZ_ASSERT(fileImpl->IsFile());
domFile = File::Create(GetParentObject(), fileImpl);
MOZ_ASSERT(domFile);
}
if (!mFiles->Append(domFile)) {

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

@ -446,10 +446,10 @@ ExtractFromArrayBufferView(const ArrayBufferView& aBuffer,
}
nsresult
ExtractFromBlob(const File& aFile, nsIInputStream** aStream,
ExtractFromBlob(const Blob& aBlob, nsIInputStream** aStream,
nsCString& aContentType)
{
nsRefPtr<FileImpl> impl = aFile.Impl();
nsRefPtr<FileImpl> impl = aBlob.Impl();
nsresult rv = impl->GetInternalStream(aStream);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
@ -773,7 +773,7 @@ private:
}
p = nullptr;
nsRefPtr<File> file =
nsRefPtr<Blob> file =
File::CreateMemoryFile(mParentObject,
reinterpret_cast<void *>(copy), body.Length(),
NS_ConvertUTF8toUTF16(mFilename),
@ -910,7 +910,7 @@ ExtractByteStreamFromBody(const OwningArrayBufferOrArrayBufferViewOrBlobOrFormDa
const ArrayBufferView& buf = aBodyInit.GetAsArrayBufferView();
return ExtractFromArrayBufferView(buf, aStream);
} else if (aBodyInit.IsBlob()) {
const File& blob = aBodyInit.GetAsBlob();
const Blob& blob = aBodyInit.GetAsBlob();
return ExtractFromBlob(blob, aStream, aContentType);
} else if (aBodyInit.IsFormData()) {
nsFormData& form = aBodyInit.GetAsFormData();
@ -942,7 +942,7 @@ ExtractByteStreamFromBody(const ArrayBufferOrArrayBufferViewOrBlobOrFormDataOrUS
const ArrayBufferView& buf = aBodyInit.GetAsArrayBufferView();
return ExtractFromArrayBufferView(buf, aStream);
} else if (aBodyInit.IsBlob()) {
const File& blob = aBodyInit.GetAsBlob();
const Blob& blob = aBodyInit.GetAsBlob();
return ExtractFromBlob(blob, aStream, aContentType);
} else if (aBodyInit.IsFormData()) {
nsFormData& form = aBodyInit.GetAsFormData();
@ -1507,9 +1507,10 @@ FetchBody<Derived>::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength
return;
}
case CONSUME_BLOB: {
nsRefPtr<File> blob =
File::CreateMemoryFile(DerivedClass()->GetParentObject(),
reinterpret_cast<void *>(aResult), aResultLength, NS_ConvertUTF8toUTF16(mMimeType));
nsRefPtr<dom::Blob> blob =
Blob::CreateMemoryBlob(DerivedClass()->GetParentObject(),
reinterpret_cast<void *>(aResult), aResultLength,
NS_ConvertUTF8toUTF16(mMimeType));
if (!blob) {
localPromise->MaybeReject(NS_ERROR_DOM_UNKNOWN_ERR);

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

@ -622,10 +622,10 @@ FileHandleBase::GetInputStream(const ArrayBuffer& aValue,
// static
already_AddRefed<nsIInputStream>
FileHandleBase::GetInputStream(const File& aValue, uint64_t* aInputLength,
FileHandleBase::GetInputStream(const Blob& aValue, uint64_t* aInputLength,
ErrorResult& aRv)
{
File& file = const_cast<File&>(aValue);
Blob& file = const_cast<Blob&>(aValue);
uint64_t length = file.GetSize(aRv);
if (aRv.Failed()) {
return nullptr;

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

@ -25,7 +25,7 @@ class nsAString;
namespace mozilla {
namespace dom {
class File;
class Blob;
class FileHelper;
class FileRequestBase;
class FileService;
@ -240,7 +240,7 @@ protected:
ErrorResult& aRv);
static already_AddRefed<nsIInputStream>
GetInputStream(const File& aValue, uint64_t* aInputLength,
GetInputStream(const Blob& aValue, uint64_t* aInputLength,
ErrorResult& aRv);
static already_AddRefed<nsIInputStream>

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

@ -27,7 +27,7 @@ uint32_t CreateFileTask::sOutputBufferSize = 0;
CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem,
const nsAString& aPath,
File* aBlobData,
Blob* aBlobData,
InfallibleTArray<uint8_t>& aArrayData,
bool replace,
ErrorResult& aRv)
@ -127,9 +127,7 @@ FileSystemResponseValue
CreateFileTask::GetSuccessRequestResult() const
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
nsRefPtr<File> file = new File(mFileSystem->GetWindow(),
mTargetFileImpl);
BlobParent* actor = GetBlobParent(file);
BlobParent* actor = GetBlobParent(mTargetFileImpl);
if (!actor) {
return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR);
}
@ -303,8 +301,8 @@ CreateFileTask::HandlerCallback()
return;
}
nsCOMPtr<nsIDOMFile> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
mPromise->MaybeResolve(file);
nsRefPtr<Blob> blob = Blob::Create(mFileSystem->GetWindow(), mTargetFileImpl);
mPromise->MaybeResolve(blob);
mPromise = nullptr;
mBlobData = nullptr;
}

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

@ -16,7 +16,7 @@ class nsIInputStream;
namespace mozilla {
namespace dom {
class File;
class Blob;
class FileImpl;
class Promise;
@ -26,7 +26,7 @@ class CreateFileTask final
public:
CreateFileTask(FileSystemBase* aFileSystem,
const nsAString& aPath,
File* aBlobData,
Blob* aBlobData,
InfallibleTArray<uint8_t>& aArrayData,
bool replace,
ErrorResult& aRv);
@ -68,7 +68,7 @@ private:
nsString mTargetRealPath;
// Not thread-safe and should be released on main thread.
nsRefPtr<File> mBlobData;
nsRefPtr<Blob> mBlobData;
nsCOMPtr<nsIInputStream> mBlobStream;
InfallibleTArray<uint8_t> mArrayData;

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

@ -100,7 +100,7 @@ Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
{
nsresult error = NS_OK;
nsString realPath;
nsRefPtr<File> blobData;
nsRefPtr<Blob> blobData;
InfallibleTArray<uint8_t> arrayData;
bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);

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

@ -154,7 +154,7 @@ FileSystemTaskBase::Recv__delete__(const FileSystemResponseValue& aValue)
}
BlobParent*
FileSystemTaskBase::GetBlobParent(nsIDOMFile* aFile) const
FileSystemTaskBase::GetBlobParent(FileImpl* aFile) const
{
MOZ_ASSERT(FileSystemUtils::IsParentProcess(),
"Only call from parent process!");
@ -164,13 +164,23 @@ FileSystemTaskBase::GetBlobParent(nsIDOMFile* aFile) const
// Load the lazy dom file data from the parent before sending to the child.
nsString mimeType;
aFile->GetType(mimeType);
uint64_t fileSize;
aFile->GetSize(&fileSize);
int64_t lastModifiedDate;
aFile->GetMozLastModifiedDate(&lastModifiedDate);
// We call GetSize and GetLastModified to prepopulate the value in the
// FileImpl.
{
ErrorResult rv;
aFile->GetSize(rv);
rv.SuppressException();
}
{
ErrorResult rv;
aFile->GetLastModified(rv);
rv.SuppressException();
}
ContentParent* cp = static_cast<ContentParent*>(mRequestParent->Manager());
return cp->GetOrCreateActorForBlob(static_cast<File*>(aFile));
return cp->GetOrCreateActorForFileImpl(aFile);
}
void

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

@ -11,12 +11,11 @@
#include "mozilla/dom/FileSystemRequestParent.h"
#include "mozilla/dom/PFileSystemRequestChild.h"
class nsIDOMFile;
namespace mozilla {
namespace dom {
class BlobParent;
class FileImpl;
class FileSystemBase;
class FileSystemParams;
@ -205,7 +204,7 @@ protected:
Recv__delete__(const FileSystemResponseValue& value) override;
BlobParent*
GetBlobParent(nsIDOMFile* aFile) const;
GetBlobParent(FileImpl* aFile) const;
nsresult mErrorValue;

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

@ -82,8 +82,7 @@ GetFileOrDirectoryTask::GetSuccessRequestResult() const
return FileSystemDirectoryResponse(mTargetRealPath);
}
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
BlobParent* actor = GetBlobParent(file);
BlobParent* actor = GetBlobParent(mTargetFileImpl);
if (!actor) {
return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR);
}
@ -214,8 +213,8 @@ GetFileOrDirectoryTask::HandlerCallback()
return;
}
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
mPromise->MaybeResolve(file);
nsRefPtr<Blob> blob = Blob::Create(mFileSystem->GetWindow(), mTargetFileImpl);
mPromise->MaybeResolve(blob);
mPromise = nullptr;
}

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

@ -92,9 +92,10 @@ RemoveTask::GetRequestParams(const nsString& aFileSystem) const
param.directory() = mDirRealPath;
param.recursive() = mRecursive;
if (mTargetFileImpl) {
nsRefPtr<File> file = new File(mFileSystem->GetWindow(), mTargetFileImpl);
nsRefPtr<Blob> blob = Blob::Create(mFileSystem->GetWindow(),
mTargetFileImpl);
BlobChild* actor
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(file);
= ContentChild::GetSingleton()->GetOrCreateActorForBlob(blob);
if (actor) {
param.target() = actor;
}

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

@ -555,9 +555,9 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
, mFileCallback(aCallback) {}
// This is called on main thread.
nsresult ReceiveBlob(already_AddRefed<File> aBlob)
nsresult ReceiveBlob(already_AddRefed<Blob> aBlob)
{
nsRefPtr<File> blob = aBlob;
nsRefPtr<Blob> blob = aBlob;
uint64_t size;
nsresult rv = blob->GetSize(&size);
if (NS_SUCCEEDED(rv)) {
@ -567,7 +567,7 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
}
}
nsRefPtr<File> newBlob = new File(mGlobal, blob->Impl());
nsRefPtr<Blob> newBlob = Blob::Create(mGlobal, blob->Impl());
mozilla::ErrorResult error;
mFileCallback->Call(*newBlob, error);

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

@ -561,7 +561,8 @@ public:
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());
mFileList[i] = File::Create(global, mFileList[i]->Impl());
MOZ_ASSERT(mFileList[i]);
}
// The text control frame (if there is one) isn't going to send a change
@ -2347,7 +2348,10 @@ HTMLInputElement::MozSetFileArray(const Sequence<OwningNonNull<File>>& aFiles)
}
nsTArray<nsRefPtr<File>> files;
for (uint32_t i = 0; i < aFiles.Length(); ++i) {
files.AppendElement(new File(global, aFiles[i].get()->Impl()));
nsRefPtr<File> file = File::Create(global, aFiles[i].get()->Impl());
MOZ_ASSERT(file);
files.AppendElement(file);
}
SetFiles(files, true);
}
@ -6018,7 +6022,9 @@ HTMLInputElement::RestoreState(nsPresState* aState)
nsTArray<nsRefPtr<File>> files;
for (uint32_t i = 0, len = fileImpls.Length(); i < len; ++i) {
nsRefPtr<File> file = new File(global, fileImpls[i]);
nsRefPtr<File> file = File::Create(global, fileImpls[i]);
MOZ_ASSERT(file);
files.AppendElement(file);
}

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

@ -77,18 +77,19 @@ public:
}
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue);
const nsAString& aValue) override;
virtual nsresult AddNameFilePair(const nsAString& aName,
File* aBlob);
File* aFile) override;
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
nsIInputStream** aPostDataStream);
nsIInputStream** aPostDataStream)
override;
virtual bool SupportsIsindexSubmission()
virtual bool SupportsIsindexSubmission() override
{
return true;
}
virtual nsresult AddIsindex(const nsAString& aValue);
virtual nsresult AddIsindex(const nsAString& aValue) override;
protected:
@ -165,7 +166,7 @@ nsFSURLEncoded::AddIsindex(const nsAString& aValue)
nsresult
nsFSURLEncoded::AddNameFilePair(const nsAString& aName,
File* aBlob)
File* aFile)
{
if (!mWarnedFileControl) {
SendJSWarning(mDocument, "ForgotFileEnctypeWarning", nullptr, 0);
@ -173,8 +174,8 @@ nsFSURLEncoded::AddNameFilePair(const nsAString& aName,
}
nsAutoString filename;
if (aBlob && aBlob->IsFile()) {
aBlob->GetName(filename);
if (aFile) {
aFile->GetName(filename);
}
return AddNameValuePair(aName, filename);
@ -439,7 +440,7 @@ nsFSMultipartFormData::AddNameValuePair(const nsAString& aName,
nsresult
nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
File* aBlob)
File* aFile)
{
// Encode the control name
nsAutoCString nameStr;
@ -448,18 +449,15 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
nsCString filename, contentType;
nsCOMPtr<nsIInputStream> fileStream;
if (aBlob) {
// Since Bug 1127150, any Blob received from FormData must be a File
// instance with a valid name (possibly "blob").
MOZ_ASSERT(aBlob->IsFile());
if (aFile) {
nsAutoString filename16;
rv = aBlob->GetName(filename16);
rv = aFile->GetName(filename16);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsAutoString filepath16;
rv = aBlob->GetPath(filepath16);
rv = aFile->GetPath(filepath16);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -474,7 +472,7 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
// Get content type
nsAutoString contentType16;
rv = aBlob->GetType(contentType16);
rv = aFile->GetType(contentType16);
if (NS_FAILED(rv) || contentType16.IsEmpty()) {
contentType16.AssignLiteral("application/octet-stream");
}
@ -484,7 +482,7 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
nsLinebreakConverter::eLinebreakSpace));
// Get input stream
rv = aBlob->GetInternalStream(getter_AddRefs(fileStream));
rv = aFile->GetInternalStream(getter_AddRefs(fileStream));
NS_ENSURE_SUCCESS(rv, rv);
if (fileStream) {
// Create buffered stream (for efficiency)
@ -519,7 +517,7 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName,
// We should not try to append an invalid stream. That will happen for example
// if we try to update a file that actually do not exist.
uint64_t size;
if (fileStream && NS_SUCCEEDED(aBlob->GetSize(&size))) {
if (fileStream && NS_SUCCEEDED(aFile->GetSize(&size))) {
// We need to dump the data up to this point into the POST data stream here,
// since we're about to add the file input stream
AddPostDataStream();
@ -587,11 +585,12 @@ public:
}
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue);
const nsAString& aValue) override;
virtual nsresult AddNameFilePair(const nsAString& aName,
File* aBlob);
File* aFile) override;
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
nsIInputStream** aPostDataStream);
nsIInputStream** aPostDataStream)
override;
private:
nsString mBody;
@ -612,11 +611,11 @@ nsFSTextPlain::AddNameValuePair(const nsAString& aName,
nsresult
nsFSTextPlain::AddNameFilePair(const nsAString& aName,
File* aBlob)
File* aFile)
{
nsAutoString filename;
if (aBlob && aBlob->IsFile()) {
aBlob->GetName(filename);
if (aFile) {
aFile->GetName(filename);
}
AddNameValuePair(aName, filename);

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

@ -48,10 +48,10 @@ public:
* Submit a name/file pair
*
* @param aName the name of the parameter
* @param aBlob the file to submit. The file's name will be used
* @param aFile the file to submit. The file's name will be used
*/
virtual nsresult AddNameFilePair(const nsAString& aName,
mozilla::dom::File* aBlob) = 0;
mozilla::dom::File* aFile) = 0;
/**
* Reports whether the instance supports AddIsindex().
@ -160,7 +160,7 @@ public:
virtual nsresult AddNameValuePair(const nsAString& aName,
const nsAString& aValue) override;
virtual nsresult AddNameFilePair(const nsAString& aName,
mozilla::dom::File* aBlob) override;
mozilla::dom::File* aFile) override;
virtual nsresult GetEncodedSubmission(nsIURI* aURI,
nsIInputStream** aPostDataStream) override;

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

@ -614,7 +614,7 @@ ConvertActorsToBlobs(IDBDatabase* aDatabase,
nsRefPtr<FileImpl> blobImpl = actor->GetBlobImpl();
MOZ_ASSERT(blobImpl);
nsRefPtr<File> blob = new File(aDatabase->GetOwner(), blobImpl);
nsRefPtr<Blob> blob = Blob::Create(aDatabase->GetOwner(), blobImpl);
nsRefPtr<FileInfo> fileInfo;
if (!fileInfos.IsEmpty()) {
@ -631,7 +631,7 @@ ConvertActorsToBlobs(IDBDatabase* aDatabase,
StructuredCloneFile* file = aFiles.AppendElement();
MOZ_ASSERT(file);
file->mFile.swap(blob);
file->mBlob.swap(blob);
file->mFileInfo.swap(fileInfo);
}
}

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

@ -7718,6 +7718,7 @@ public:
// So, this is a hack to keep the nsExternalHelperAppService out of the
// picture entirely. Eventually we should probably fix this some other way.
mContentType.Truncate();
mIsFile = false;
}
private:

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

@ -959,7 +959,7 @@ IDBDatabase::AbortTransactions(bool aShouldWarn)
}
PBackgroundIDBDatabaseFileChild*
IDBDatabase::GetOrCreateFileActorForBlob(File* aBlob)
IDBDatabase::GetOrCreateFileActorForBlob(Blob* aBlob)
{
AssertIsOnOwningThread();
MOZ_ASSERT(aBlob);
@ -1068,7 +1068,7 @@ IDBDatabase::NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild* aFileActor)
}
void
IDBDatabase::NoteReceivedBlob(File* aBlob)
IDBDatabase::NoteReceivedBlob(Blob* aBlob)
{
AssertIsOnOwningThread();
MOZ_ASSERT(aBlob);

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

@ -28,7 +28,7 @@ class EventChainPostVisitor;
namespace dom {
class File;
class Blob;
class DOMStringList;
struct IDBObjectStoreParameters;
template <class> class Optional;
@ -177,13 +177,13 @@ public:
AbortTransactions(bool aShouldWarn);
PBackgroundIDBDatabaseFileChild*
GetOrCreateFileActorForBlob(File* aBlob);
GetOrCreateFileActorForBlob(Blob* aBlob);
void
NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild* aFileActor);
void
NoteReceivedBlob(File* aBlob);
NoteReceivedBlob(Blob* aBlob);
void
DelayedMaybeExpireFileActors();

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

@ -340,8 +340,10 @@ IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle,
aFileHandle,
mFileInfo);
nsCOMPtr<nsIDOMFile> fileSnapshot = new File(GetOwner(), impl);
return fileSnapshot.forget();
nsRefPtr<File> file = File::Create(GetOwner(), impl);
MOZ_ASSERT(file);
return file.forget();
}
already_AddRefed<DOMRequest>

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

@ -62,7 +62,7 @@ struct IDBObjectStore::StructuredCloneWriteInfo
{
struct BlobOrFileInfo
{
nsRefPtr<File> mBlob;
nsRefPtr<Blob> mBlob;
nsRefPtr<FileInfo> mFileInfo;
bool
@ -300,7 +300,7 @@ StructuredCloneWriteCallback(JSContext* aCx,
}
{
File* blob = nullptr;
Blob* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) {
uint64_t size;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetSize(&size)));
@ -332,15 +332,16 @@ StructuredCloneWriteCallback(JSContext* aCx,
return false;
}
if (blob->IsFile()) {
nsRefPtr<File> file = blob->ToFile();
if (file) {
int64_t lastModifiedDate;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
blob->GetMozLastModifiedDate(&lastModifiedDate)));
file->GetMozLastModifiedDate(&lastModifiedDate)));
lastModifiedDate = NativeEndian::swapToLittleEndian(lastModifiedDate);
nsString name;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetName(name)));
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(file->GetName(name)));
NS_ConvertUTF16toUTF8 convName(name);
uint32_t convNameLength =
@ -402,11 +403,11 @@ GetAddInfoCallback(JSContext* aCx, void* aClosure)
}
BlobChild*
ActorFromRemoteBlob(File* aBlob)
ActorFromRemoteFileImpl(FileImpl* aImpl)
{
MOZ_ASSERT(aBlob);
MOZ_ASSERT(aImpl);
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob->Impl());
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aImpl);
if (remoteBlob) {
BlobChild* actor = remoteBlob->GetBlobChild();
MOZ_ASSERT(actor);
@ -428,13 +429,13 @@ ActorFromRemoteBlob(File* aBlob)
}
bool
ResolveMysteryFile(File* aBlob,
ResolveMysteryFile(FileImpl* aImpl,
const nsString& aName,
const nsString& aContentType,
uint64_t aSize,
uint64_t aLastModifiedDate)
{
BlobChild* actor = ActorFromRemoteBlob(aBlob);
BlobChild* actor = ActorFromRemoteFileImpl(aImpl);
if (actor) {
return actor->SetMysteryBlobInfo(aName, aContentType,
aSize, aLastModifiedDate);
@ -443,11 +444,11 @@ ResolveMysteryFile(File* aBlob,
}
bool
ResolveMysteryBlob(File* aBlob,
ResolveMysteryBlob(FileImpl* aImpl,
const nsString& aContentType,
uint64_t aSize)
{
BlobChild* actor = ActorFromRemoteBlob(aBlob);
BlobChild* actor = ActorFromRemoteFileImpl(aImpl);
if (actor) {
return actor->SetMysteryBlobInfo(aContentType, aSize);
}
@ -605,7 +606,7 @@ public:
MOZ_ASSERT(aData.tag == SCTAG_DOM_FILE ||
aData.tag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE ||
aData.tag == SCTAG_DOM_BLOB);
MOZ_ASSERT(aFile.mFile);
MOZ_ASSERT(aFile.mBlob);
// It can happen that this IDB is chrome code, so there is no parent, but
// still we want to set a correct parent for the new File object.
@ -627,17 +628,18 @@ public:
}
MOZ_ASSERT(parent);
nsRefPtr<File> file = new File(parent, aFile.mFile->Impl());
if (aData.tag == SCTAG_DOM_BLOB) {
if (NS_WARN_IF(!ResolveMysteryBlob(aFile.mFile,
if (NS_WARN_IF(!ResolveMysteryBlob(aFile.mBlob->Impl(),
aData.type,
aData.size))) {
return false;
}
MOZ_ASSERT(!aFile.mBlob->IsFile());
JS::Rooted<JS::Value> wrappedBlob(aCx);
if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedBlob)) {
if (!ToJSValue(aCx, aFile.mBlob, &wrappedBlob)) {
return false;
}
@ -645,9 +647,7 @@ public:
return true;
}
MOZ_ASSERT(aFile.mFile->IsFile());
if (NS_WARN_IF(!ResolveMysteryFile(aFile.mFile,
if (NS_WARN_IF(!ResolveMysteryFile(aFile.mBlob->Impl(),
aData.name,
aData.type,
aData.size,
@ -655,8 +655,12 @@ public:
return false;
}
MOZ_ASSERT(aFile.mBlob->IsFile());
nsRefPtr<File> file = aFile.mBlob->ToFile();
MOZ_ASSERT(file);
JS::Rooted<JS::Value> wrappedFile(aCx);
if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedFile)) {
if (!ToJSValue(aCx, file, &wrappedFile)) {
return false;
}

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

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
class File;
class Blob;
namespace indexedDB {
@ -25,7 +25,7 @@ class SerializedStructuredCloneReadInfo;
struct StructuredCloneFile
{
nsRefPtr<File> mFile;
nsRefPtr<Blob> mBlob;
nsRefPtr<FileInfo> mFileInfo;
// In IndexedDatabaseInlines.h

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

@ -36,7 +36,7 @@ inline
bool
StructuredCloneFile::operator==(const StructuredCloneFile& aOther) const
{
return this->mFile == aOther.mFile &&
return this->mBlob == aOther.mBlob &&
this->mFileInfo == aOther.mFileInfo;
}

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

@ -117,10 +117,9 @@ FilePickerParent::SendFiles(const nsTArray<nsRefPtr<FileImpl>>& aFiles)
InfallibleTArray<PBlobParent*> files;
for (unsigned i = 0; i < aFiles.Length(); i++) {
nsRefPtr<File> file = new File(nullptr, aFiles[i]);
BlobParent* blob = parent->GetOrCreateActorForBlob(file);
if (blob) {
files.AppendElement(blob);
BlobParent* blobParent = parent->GetOrCreateActorForFileImpl(aFiles[i]);
if (blobParent) {
files.AppendElement(blobParent);
}
}

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

@ -51,11 +51,11 @@ Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
JS::Rooted<JS::Value> val(aCx);
{
MOZ_ASSERT(aData < closure->mBlobs.Length());
nsRefPtr<File> blob = closure->mBlobs[aData];
nsRefPtr<Blob> blob = closure->mBlobs[aData];
#ifdef DEBUG
{
// File should not be mutable.
// Blob should not be mutable.
bool isMutable;
MOZ_ASSERT(NS_SUCCEEDED(blob->GetMutable(&isMutable)));
MOZ_ASSERT(!isMutable);
@ -66,8 +66,8 @@ Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag,
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
MOZ_ASSERT(global);
nsRefPtr<File> newBlob = new File(global, blob->Impl());
if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) {
nsRefPtr<Blob> newBlob = Blob::Create(global, blob->Impl());
if (!ToJSValue(aCx, newBlob, &val)) {
return nullptr;
}
}
@ -89,7 +89,7 @@ Write(JSContext* aCx, JSStructuredCloneWriter* aWriter,
// See if the wrapped native is a File/Blob.
{
File* blob = nullptr;
Blob* blob = nullptr;
if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) &&
NS_SUCCEEDED(blob->SetMutable(false)) &&
JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB,

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

@ -19,7 +19,7 @@ namespace dom {
struct
StructuredCloneClosure
{
nsTArray<nsRefPtr<File>> mBlobs;
nsTArray<nsRefPtr<Blob>> mBlobs;
};
struct

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

@ -93,7 +93,7 @@ nsIContentChild::DeallocPBlobChild(PBlobChild* aActor)
}
BlobChild*
nsIContentChild::GetOrCreateActorForBlob(File* aBlob)
nsIContentChild::GetOrCreateActorForBlob(Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aBlob);
@ -101,7 +101,16 @@ nsIContentChild::GetOrCreateActorForBlob(File* aBlob)
nsRefPtr<FileImpl> blobImpl = aBlob->Impl();
MOZ_ASSERT(blobImpl);
BlobChild* actor = BlobChild::GetOrCreate(this, blobImpl);
return GetOrCreateActorForFileImpl(blobImpl);
}
BlobChild*
nsIContentChild::GetOrCreateActorForFileImpl(FileImpl* aImpl)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aImpl);
BlobChild* actor = BlobChild::GetOrCreate(this, aImpl);
NS_ENSURE_TRUE(actor, nullptr);
return actor;

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

@ -32,10 +32,11 @@ class CpowEntry;
namespace dom {
class Blob;
class BlobChild;
class BlobConstructorParams;
class ClonedMessageData;
class File;
class FileImpl;
class IPCTabContext;
class PBlobChild;
class PBrowserChild;
@ -46,7 +47,8 @@ class nsIContentChild : public nsISupports
public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENTCHILD_IID)
BlobChild* GetOrCreateActorForBlob(File* aBlob);
BlobChild* GetOrCreateActorForBlob(Blob* aBlob);
BlobChild* GetOrCreateActorForFileImpl(FileImpl* aImpl);
virtual PBlobChild* SendPBlobConstructor(
PBlobChild* aActor,

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

@ -159,7 +159,7 @@ nsIContentParent::DeallocPBlobParent(PBlobParent* aActor)
}
BlobParent*
nsIContentParent::GetOrCreateActorForBlob(File* aBlob)
nsIContentParent::GetOrCreateActorForBlob(Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aBlob);
@ -167,7 +167,16 @@ nsIContentParent::GetOrCreateActorForBlob(File* aBlob)
nsRefPtr<FileImpl> blobImpl = aBlob->Impl();
MOZ_ASSERT(blobImpl);
BlobParent* actor = BlobParent::GetOrCreate(this, blobImpl);
return GetOrCreateActorForFileImpl(blobImpl);
}
BlobParent*
nsIContentParent::GetOrCreateActorForFileImpl(FileImpl* aImpl)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aImpl);
BlobParent* actor = BlobParent::GetOrCreate(this, aImpl);
NS_ENSURE_TRUE(actor, nullptr);
return actor;

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

@ -33,10 +33,11 @@ class CpowEntry;
namespace dom {
class Blob;
class BlobConstructorParams;
class BlobParent;
class ContentParent;
class File;
class FileImpl;
class IPCTabContext;
class PBlobParent;
class PBrowserParent;
@ -52,7 +53,8 @@ public:
nsIContentParent();
BlobParent* GetOrCreateActorForBlob(File* aBlob);
BlobParent* GetOrCreateActorForBlob(Blob* aBlob);
BlobParent* GetOrCreateActorForFileImpl(FileImpl* aImpl);
virtual ContentParentId ChildID() = 0;
virtual bool IsForApp() = 0;

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

@ -39,16 +39,16 @@ EncodedBufferCache::AppendBuffer(nsTArray<uint8_t> & aBuf)
}
already_AddRefed<dom::File>
already_AddRefed<dom::Blob>
EncodedBufferCache::ExtractBlob(nsISupports* aParent,
const nsAString &aContentType)
{
MutexAutoLock lock(mMutex);
nsRefPtr<dom::File> blob;
nsRefPtr<dom::Blob> blob;
if (mTempFileEnabled) {
// generate new temporary file to write
blob = dom::File::CreateTemporaryFileBlob(aParent, mFD, 0, mDataSize,
aContentType);
blob = dom::Blob::CreateTemporaryBlob(aParent, mFD, 0, mDataSize,
aContentType);
// fallback to memory blob
mTempFileEnabled = false;
mDataSize = 0;
@ -63,7 +63,7 @@ EncodedBufferCache::ExtractBlob(nsISupports* aParent,
mEncodedBuffers.ElementAt(i).Length());
offset += mEncodedBuffers.ElementAt(i).Length();
}
blob = dom::File::CreateMemoryFile(aParent, blobData, mDataSize,
blob = dom::Blob::CreateMemoryBlob(aParent, blobData, mDataSize,
aContentType);
mEncodedBuffers.Clear();
} else

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

@ -16,7 +16,7 @@ struct PRFileDesc;
namespace mozilla {
namespace dom {
class File;
class Blob;
}
/**
@ -41,7 +41,7 @@ public:
// aBuf will append to mEncodedBuffers or temporary File, aBuf also be cleared
void AppendBuffer(nsTArray<uint8_t> & aBuf);
// Read all buffer from memory or file System, also Remove the temporary file or clean the buffers in memory.
already_AddRefed<dom::File> ExtractBlob(nsISupports* aParent, const nsAString &aContentType);
already_AddRefed<dom::Blob> ExtractBlob(nsISupports* aParent, const nsAString &aContentType);
private:
//array for storing the encoded data.

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

@ -1017,7 +1017,7 @@ MediaRecorder::CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob)
init.mCancelable = false;
nsCOMPtr<nsIDOMBlob> blob = aBlob;
init.mData = static_cast<File*>(blob.get());
init.mData = static_cast<Blob*>(blob.get());
nsRefPtr<BlobEvent> event =
BlobEvent::Constructor(this,

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

@ -15,18 +15,18 @@
namespace mozilla {
nsresult
CaptureTask::TaskComplete(already_AddRefed<dom::File> aBlob, nsresult aRv)
CaptureTask::TaskComplete(already_AddRefed<dom::Blob> aBlob, nsresult aRv)
{
MOZ_ASSERT(NS_IsMainThread());
DetachStream();
nsresult rv;
nsRefPtr<dom::File> blob(aBlob);
nsRefPtr<dom::Blob> 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());
blob = dom::Blob::Create(mImageCapture->GetParentObject(), blob->Impl());
}
if (mPrincipalChanged) {
@ -103,9 +103,9 @@ CaptureTask::NotifyQueuedTrackChanges(MediaStreamGraph* aGraph, TrackID aID,
public:
explicit EncodeComplete(CaptureTask* aTask) : mTask(aTask) {}
nsresult ReceiveBlob(already_AddRefed<dom::File> aBlob) override
nsresult ReceiveBlob(already_AddRefed<dom::Blob> aBlob) override
{
nsRefPtr<dom::File> blob(aBlob);
nsRefPtr<dom::Blob> blob(aBlob);
mTask->TaskComplete(blob.forget(), NS_OK);
mTask = nullptr;
return NS_OK;

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

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

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

@ -102,9 +102,9 @@ ImageCapture::TakePhotoByMediaEngine()
mPrincipalChanged = true;
}
nsresult PhotoComplete(already_AddRefed<File> aBlob) override
nsresult PhotoComplete(already_AddRefed<Blob> aBlob) override
{
nsRefPtr<File> blob = aBlob;
nsRefPtr<Blob> blob = aBlob;
if (mPrincipalChanged) {
return PhotoError(NS_ERROR_DOM_SECURITY_ERR);
@ -172,7 +172,7 @@ ImageCapture::TakePhoto(ErrorResult& aResult)
}
nsresult
ImageCapture::PostBlobEvent(File* aBlob)
ImageCapture::PostBlobEvent(Blob* aBlob)
{
MOZ_ASSERT(NS_IsMainThread());
if (!CheckPrincipal()) {

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

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

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

@ -6,7 +6,6 @@
#define MEDIAENGINE_H_
#include "mozilla/RefPtr.h"
#include "nsIDOMFile.h"
#include "DOMMediaStream.h"
#include "MediaStreamGraph.h"
#include "mozilla/dom/MediaStreamTrackBinding.h"
@ -15,7 +14,7 @@
namespace mozilla {
namespace dom {
class File;
class Blob;
}
enum {
@ -130,7 +129,7 @@ public:
// aBlob is the image captured by MediaEngineSource. It is
// called on main thread.
virtual nsresult PhotoComplete(already_AddRefed<dom::File> aBlob) = 0;
virtual nsresult PhotoComplete(already_AddRefed<dom::Blob> aBlob) = 0;
// It is called on main thread. aRv is the error code.
virtual nsresult PhotoError(nsresult aRv) = 0;

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

@ -614,11 +614,11 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t
NS_IMETHOD Run()
{
nsRefPtr<dom::File> blob =
dom::File::CreateMemoryFile(nullptr, mPhotoData, mPhotoDataLength, mMimeType);
nsRefPtr<dom::Blob> blob =
dom::Blob::CreateMemoryBlob(nullptr, mPhotoData, mPhotoDataLength, mMimeType);
uint32_t callbackCounts = mCallbacks.Length();
for (uint8_t i = 0; i < callbackCounts; i++) {
nsRefPtr<dom::File> tempBlob = blob;
nsRefPtr<dom::Blob> tempBlob = blob;
mCallbacks[i]->PhotoComplete(tempBlob.forget());
}
// PhotoCallback needs to dereference on main thread.

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

@ -94,10 +94,10 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData)
// nullptr as parent.
if (element.contentParent()) {
nsRefPtr<FileImpl> impl = static_cast<BlobParent*>(element.contentParent())->GetBlobImpl();
att.mContent = new File(nullptr, impl);
att.mContent = Blob::Create(nullptr, impl);
} else if (element.contentChild()) {
nsRefPtr<FileImpl> impl = static_cast<BlobChild*>(element.contentChild())->GetBlobImpl();
att.mContent = new File(nullptr, impl);
att.mContent = Blob::Create(nullptr, impl);
} else {
NS_WARNING("MmsMessage: Unable to get attachment content.");
}
@ -390,10 +390,13 @@ MmsMessage::GetData(ContentParent* aParent,
// doesn't have a valid last modified date, making the ContentParent
// send a "Mystery Blob" to the ContentChild. Attempting to get the
// last modified date of blob can force that value to be initialized.
if (element.content->IsDateUnknown()) {
int64_t date;
if (NS_FAILED(element.content->GetMozLastModifiedDate(&date))) {
nsRefPtr<FileImpl> impl = element.content->Impl();
if (impl && impl->IsDateUnknown()) {
ErrorResult rv;
impl->GetLastModified(rv);
if (rv.Failed()) {
NS_WARNING("Failed to get last modified date!");
rv.SuppressException();
}
}
@ -577,10 +580,10 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle<JS::Value> aAttachm
// Duplicating the File with the correct parent object.
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx));
MOZ_ASSERT(global);
nsRefPtr<File> newBlob = new File(global, attachment.content->Impl());
nsRefPtr<Blob> newBlob = Blob::Create(global, attachment.content->Impl());
JS::Rooted<JS::Value> val(aCx);
if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) {
if (!ToJSValue(aCx, newBlob, &val)) {
return NS_ERROR_FAILURE;
}

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

@ -17,7 +17,7 @@
namespace mozilla {
namespace dom {
class File;
class Blob;
namespace mobilemessage {
class MmsMessageData;
@ -34,7 +34,7 @@ public:
// If this is changed, change the WebIDL dictionary as well.
struct Attachment final
{
nsRefPtr<File> content;
nsRefPtr<Blob> content;
nsString id;
nsString location;

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

@ -65,8 +65,8 @@ MmsAttachmentDataToJSObject(JSContext* aContext,
nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext));
MOZ_ASSERT(global);
nsRefPtr<File> blob = new File(global, blobImpl);
if (!GetOrCreateDOMReflector(aContext, blob, &content)) {
nsRefPtr<Blob> blob = Blob::Create(global, blobImpl);
if (!ToJSValue(aContext, blob, &content)) {
return nullptr;
}
}

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

@ -337,7 +337,7 @@ UDPSocket::Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData,
nsCOMPtr<nsIInputStream> stream;
if (aData.IsBlob()) {
File& blob = aData.GetAsBlob();
Blob& blob = aData.GetAsBlob();
aRv = blob.GetInternalStream(getter_AddRefs(stream));
if (NS_WARN_IF(aRv.Failed())) {

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

@ -52,7 +52,7 @@ FileReaderSync::WrapObject(JSContext* aCx,
void
FileReaderSync::ReadAsArrayBuffer(JSContext* aCx,
JS::Handle<JSObject*> aScopeObj,
File& aBlob,
Blob& aBlob,
JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv)
{
@ -95,7 +95,7 @@ FileReaderSync::ReadAsArrayBuffer(JSContext* aCx,
}
void
FileReaderSync::ReadAsBinaryString(File& aBlob,
FileReaderSync::ReadAsBinaryString(Blob& aBlob,
nsAString& aResult,
ErrorResult& aRv)
{
@ -125,7 +125,7 @@ FileReaderSync::ReadAsBinaryString(File& aBlob,
}
void
FileReaderSync::ReadAsText(File& aBlob,
FileReaderSync::ReadAsText(Blob& aBlob,
const Optional<nsAString>& aEncoding,
nsAString& aResult,
ErrorResult& aRv)
@ -195,7 +195,7 @@ FileReaderSync::ReadAsText(File& aBlob,
}
void
FileReaderSync::ReadAsDataURL(File& aBlob, nsAString& aResult,
FileReaderSync::ReadAsDataURL(Blob& aBlob, nsAString& aResult,
ErrorResult& aRv)
{
nsAutoString scratchResult;

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

@ -15,7 +15,7 @@ namespace mozilla {
class ErrorResult;
namespace dom {
class File;
class Blob;
class GlobalObject;
template<typename> class Optional;
}
@ -43,12 +43,12 @@ public:
bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector);
void ReadAsArrayBuffer(JSContext* aCx, JS::Handle<JSObject*> aScopeObj,
File& aBlob, JS::MutableHandle<JSObject*> aRetval,
Blob& aBlob, JS::MutableHandle<JSObject*> aRetval,
ErrorResult& aRv);
void ReadAsBinaryString(File& aBlob, nsAString& aResult, ErrorResult& aRv);
void ReadAsText(File& aBlob, const Optional<nsAString>& aEncoding,
void ReadAsBinaryString(Blob& aBlob, nsAString& aResult, ErrorResult& aRv);
void ReadAsText(Blob& aBlob, const Optional<nsAString>& aEncoding,
nsAString& aResult, ErrorResult& aRv);
void ReadAsDataURL(File& aBlob, nsAString& aResult, ErrorResult& aRv);
void ReadAsDataURL(Blob& aBlob, nsAString& aResult, ErrorResult& aRv);
};
END_WORKERS_NAMESPACE

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

@ -412,7 +412,7 @@ PushMessageData::ArrayBuffer(JSContext* cx, JS::MutableHandle<JSObject*> aRetval
NS_ABORT();
}
mozilla::dom::File*
mozilla::dom::Blob*
PushMessageData::Blob()
{
//todo bug 1149195. Don't be lazy.

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

@ -25,8 +25,9 @@ class nsIInterceptedChannel;
namespace mozilla {
namespace dom {
class Request;
class ResponseOrPromise;
class Blob;
class Request;
class ResponseOrPromise;
} // namespace dom
} // namespace mozilla
@ -176,7 +177,7 @@ public:
void Json(JSContext* cx, JS::MutableHandle<JSObject*> aRetval);
void Text(nsAString& aData);
void ArrayBuffer(JSContext* cx, JS::MutableHandle<JSObject*> aRetval);
mozilla::dom::File* Blob();
mozilla::dom::Blob* Blob();
explicit PushMessageData(const nsAString& aData);
private:

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

@ -880,7 +880,7 @@ URL::SetHash(const nsAString& aHash, ErrorResult& aRv)
// static
void
URL::CreateObjectURL(const GlobalObject& aGlobal, File& aBlob,
URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob,
const mozilla::dom::objectURLOptions& aOptions,
nsAString& aResult, mozilla::ErrorResult& aRv)
{

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

@ -15,7 +15,7 @@
namespace mozilla {
namespace dom {
class File;
class Blob;
struct objectURLOptions;
}
}
@ -61,7 +61,7 @@ public:
static void
CreateObjectURL(const GlobalObject& aGlobal,
File& aArg, const objectURLOptions& aOptions,
Blob& aArg, const objectURLOptions& aOptions,
nsAString& aResult, ErrorResult& aRv);
static void

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