From 6fd66905f8b7bf5059b066335c902ecae990b862 Mon Sep 17 00:00:00 2001 From: Wes Kocher Date: Mon, 11 May 2015 14:54:02 -0700 Subject: [PATCH] Backed out 2 changesets (bug 1159401) for b2g build bustage Backed out changeset adfee1efb1e1 (bug 1159401) Backed out changeset 70c63c8546e3 (bug 1159401) --- dom/archivereader/ArchiveEvent.cpp | 4 +- dom/archivereader/ArchiveEvent.h | 2 +- dom/archivereader/ArchiveReader.cpp | 6 +- dom/archivereader/ArchiveReader.h | 11 +- dom/archivereader/ArchiveRequest.cpp | 30 +- dom/archivereader/ArchiveRequest.h | 9 +- dom/archivereader/ArchiveZipEvent.cpp | 8 +- dom/archivereader/ArchiveZipEvent.h | 3 +- dom/base/BlobSet.h | 2 +- dom/base/Console.cpp | 14 +- dom/base/File.cpp | 634 ++++++++---------- dom/base/File.h | 222 +++--- dom/base/ImageEncoder.cpp | 4 +- dom/base/ImageEncoder.h | 2 +- dom/base/MessagePort.cpp | 8 +- dom/base/MultipartFileImpl.cpp | 6 +- dom/base/MultipartFileImpl.h | 2 +- dom/base/Navigator.cpp | 2 +- dom/base/URL.cpp | 2 +- dom/base/URL.h | 4 +- dom/base/WebSocket.cpp | 2 +- dom/base/WebSocket.h | 4 +- dom/base/nsContentUtils.cpp | 6 +- dom/base/nsDOMDataChannel.cpp | 2 +- dom/base/nsDOMDataChannel.h | 4 +- dom/base/nsDOMFileReader.cpp | 64 +- dom/base/nsDOMFileReader.h | 25 +- dom/base/nsFormData.cpp | 40 +- dom/base/nsFormData.h | 17 +- dom/base/nsFrameMessageManager.cpp | 4 +- dom/base/nsGlobalWindow.cpp | 6 +- dom/base/nsIDOMFile.idl | 8 +- dom/base/nsXMLHttpRequest.cpp | 34 +- dom/base/nsXMLHttpRequest.h | 16 +- dom/bindings/Bindings.conf | 1 + .../bluedroid/BluetoothOppManager.cpp | 2 +- dom/bluetooth/bluetooth1/BluetoothAdapter.cpp | 2 +- dom/bluetooth/bluetooth1/BluetoothAdapter.h | 4 +- dom/bluetooth/bluetooth2/BluetoothAdapter.cpp | 2 +- dom/bluetooth/bluetooth2/BluetoothAdapter.h | 4 +- dom/broadcastchannel/BroadcastChannel.cpp | 4 +- .../BroadcastChannelChild.cpp | 10 +- dom/camera/DOMCameraControl.cpp | 2 +- dom/camera/DOMCameraControlListener.cpp | 2 +- dom/camera/TestGonkCameraHardware.cpp | 8 +- dom/devicestorage/DeviceStorage.h | 10 +- .../DeviceStorageRequestChild.cpp | 3 +- .../DeviceStorageRequestParent.cpp | 6 +- dom/devicestorage/nsDeviceStorage.cpp | 24 +- dom/devicestorage/nsDeviceStorage.h | 6 +- dom/events/DataTransfer.cpp | 6 +- dom/fetch/Fetch.cpp | 17 +- dom/filehandle/FileHandle.cpp | 4 +- dom/filehandle/FileHandle.h | 4 +- dom/filesystem/CreateFileTask.cpp | 10 +- dom/filesystem/CreateFileTask.h | 6 +- dom/filesystem/Directory.cpp | 2 +- dom/filesystem/FileSystemTaskBase.cpp | 22 +- dom/filesystem/FileSystemTaskBase.h | 5 +- dom/filesystem/GetFileOrDirectoryTask.cpp | 7 +- dom/filesystem/RemoveTask.cpp | 5 +- dom/html/HTMLCanvasElement.cpp | 6 +- dom/html/HTMLInputElement.cpp | 12 +- dom/html/nsFormSubmission.cpp | 43 +- dom/html/nsFormSubmission.h | 6 +- dom/indexedDB/ActorsChild.cpp | 4 +- dom/indexedDB/ActorsParent.cpp | 1 - dom/indexedDB/IDBDatabase.cpp | 4 +- dom/indexedDB/IDBDatabase.h | 6 +- dom/indexedDB/IDBMutableFile.cpp | 6 +- dom/indexedDB/IDBObjectStore.cpp | 44 +- dom/indexedDB/IndexedDatabase.h | 4 +- dom/indexedDB/IndexedDatabaseInlines.h | 2 +- dom/ipc/FilePickerParent.cpp | 7 +- dom/ipc/StructuredCloneUtils.cpp | 10 +- dom/ipc/StructuredCloneUtils.h | 2 +- dom/ipc/nsIContentChild.cpp | 13 +- dom/ipc/nsIContentChild.h | 6 +- dom/ipc/nsIContentParent.cpp | 13 +- dom/ipc/nsIContentParent.h | 6 +- dom/media/EncodedBufferCache.cpp | 10 +- dom/media/EncodedBufferCache.h | 4 +- dom/media/MediaRecorder.cpp | 2 +- dom/media/imagecapture/CaptureTask.cpp | 10 +- dom/media/imagecapture/CaptureTask.h | 4 +- dom/media/imagecapture/ImageCapture.cpp | 6 +- dom/media/imagecapture/ImageCapture.h | 4 +- dom/media/webrtc/MediaEngine.h | 5 +- .../webrtc/MediaEngineGonkVideoSource.cpp | 6 +- dom/mobilemessage/MmsMessage.cpp | 17 +- dom/mobilemessage/MmsMessage.h | 4 +- dom/mobilemessage/ipc/SmsParent.cpp | 4 +- dom/network/UDPSocket.cpp | 2 +- dom/workers/FileReaderSync.cpp | 8 +- dom/workers/FileReaderSync.h | 10 +- dom/workers/ServiceWorkerEvents.cpp | 2 +- dom/workers/ServiceWorkerEvents.h | 7 +- dom/workers/URL.cpp | 2 +- dom/workers/URL.h | 4 +- dom/workers/WorkerPrivate.cpp | 12 +- dom/workers/XMLHttpRequest.cpp | 2 +- dom/workers/XMLHttpRequest.h | 4 +- ipc/glue/BackgroundImpl.cpp | 2 +- js/xpconnect/src/ExportHelpers.cpp | 6 +- widget/nsFilePickerProxy.cpp | 9 +- 105 files changed, 769 insertions(+), 957 deletions(-) diff --git a/dom/archivereader/ArchiveEvent.cpp b/dom/archivereader/ArchiveEvent.cpp index dc2dc42c83f..c1831f21304 100644 --- a/dom/archivereader/ArchiveEvent.cpp +++ b/dom/archivereader/ArchiveEvent.cpp @@ -105,7 +105,7 @@ ArchiveReaderEvent::RunShare(nsresult aStatus) void ArchiveReaderEvent::ShareMainThread() { - nsTArray> fileList; + nsTArray > 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 file = item->GetFile(mArchiveReader); + nsRefPtr file = item->File(mArchiveReader); if (file) { fileList.AppendElement(file); } diff --git a/dom/archivereader/ArchiveEvent.h b/dom/archivereader/ArchiveEvent.h index 34d1aac61c1..ad9c0d4f6a5 100644 --- a/dom/archivereader/ArchiveEvent.h +++ b/dom/archivereader/ArchiveEvent.h @@ -36,7 +36,7 @@ public: virtual nsresult GetFilename(nsString& aFilename) = 0; // Generate a File - virtual already_AddRefed GetFile(ArchiveReader* aArchiveReader) = 0; + virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) = 0; protected: virtual ~ArchiveItem(); diff --git a/dom/archivereader/ArchiveReader.cpp b/dom/archivereader/ArchiveReader.cpp index e1e01ab3d8e..9de0595c9a0 100644 --- a/dom/archivereader/ArchiveReader.cpp +++ b/dom/archivereader/ArchiveReader.cpp @@ -24,7 +24,7 @@ USING_ARCHIVEREADER_NAMESPACE /* static */ already_AddRefed ArchiveReader::Constructor(const GlobalObject& aGlobal, - Blob& aBlob, + File& aBlob, const ArchiveReaderOptions& aOptions, ErrorResult& aError) { @@ -46,7 +46,7 @@ ArchiveReader::Constructor(const GlobalObject& aGlobal, return reader.forget(); } -ArchiveReader::ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow, +ArchiveReader::ArchiveReader(File& 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>& aFileList, +ArchiveReader::Ready(nsTArray >& aFileList, nsresult aStatus) { mStatus = READY; diff --git a/dom/archivereader/ArchiveReader.h b/dom/archivereader/ArchiveReader.h index 22896e412fd..a43b7fdba1a 100644 --- a/dom/archivereader/ArchiveReader.h +++ b/dom/archivereader/ArchiveReader.h @@ -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 - Constructor(const GlobalObject& aGlobal, Blob& aBlob, + Constructor(const GlobalObject& aGlobal, File& aBlob, const ArchiveReaderOptions& aOptions, ErrorResult& aError); - ArchiveReader(Blob& aBlob, nsPIDOMWindow* aWindow, + ArchiveReader(File& aBlob, nsPIDOMWindow* aWindow, const nsACString& aEncoding); nsIDOMWindow* GetParentObject() const @@ -69,7 +69,8 @@ public: // For events: return mFileImpl; } - void Ready(nsTArray>& aFileList, nsresult aStatus); + void Ready(nsTArray >& aFileList, + nsresult aStatus); private: ~ArchiveReader(); @@ -107,7 +108,7 @@ protected: // Everything related to the blobs and the status: struct { - nsTArray> fileList; + nsTArray > fileList; nsresult status; } mData; diff --git a/dom/archivereader/ArchiveRequest.cpp b/dom/archivereader/ArchiveRequest.cpp index 6a857a17a3d..fe7256c480c 100644 --- a/dom/archivereader/ArchiveRequest.cpp +++ b/dom/archivereader/ArchiveRequest.cpp @@ -122,7 +122,7 @@ ArchiveRequest::OpGetFiles() } nsresult -ArchiveRequest::ReaderReady(nsTArray>& aFileList, +ArchiveRequest::ReaderReady(nsTArray >& aFileList, nsresult aStatus) { if (NS_FAILED(aStatus)) { @@ -174,7 +174,7 @@ ArchiveRequest::ReaderReady(nsTArray>& aFileList, nsresult ArchiveRequest::GetFilenamesResult(JSContext* aCx, JS::Value* aValue, - nsTArray>& aFileList) + nsTArray >& aFileList) { JS::Rooted array(aCx, JS_NewArrayObject(aCx, aFileList.Length())); nsresult rv; @@ -185,7 +185,7 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx, JS::Rooted str(aCx); for (uint32_t i = 0; i < aFileList.Length(); ++i) { - nsRefPtr file = aFileList[i]; + nsCOMPtr file = aFileList[i]; nsString filename; rv = file->GetName(filename); @@ -211,21 +211,18 @@ ArchiveRequest::GetFilenamesResult(JSContext* aCx, nsresult ArchiveRequest::GetFileResult(JSContext* aCx, JS::MutableHandle aValue, - nsTArray>& aFileList) + nsTArray >& aFileList) { for (uint32_t i = 0; i < aFileList.Length(); ++i) { - nsRefPtr file = aFileList[i]; + nsCOMPtr file = aFileList[i]; nsString filename; nsresult rv = file->GetName(filename); NS_ENSURE_SUCCESS(rv, rv); if (filename == mFilename) { - if (!ToJSValue(aCx, file, aValue)) { - return NS_ERROR_FAILURE; - } - - return NS_OK; + return nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile), + aValue); } } @@ -235,7 +232,7 @@ ArchiveRequest::GetFileResult(JSContext* aCx, nsresult ArchiveRequest::GetFilesResult(JSContext* aCx, JS::MutableHandle aValue, - nsTArray>& aFileList) + nsTArray >& aFileList) { JS::Rooted array(aCx, JS_NewArrayObject(aCx, aFileList.Length())); if (!array) { @@ -243,14 +240,13 @@ ArchiveRequest::GetFilesResult(JSContext* aCx, } for (uint32_t i = 0; i < aFileList.Length(); ++i) { - nsRefPtr file = aFileList[i]; + nsCOMPtr file = aFileList[i]; JS::Rooted value(aCx); - if (!ToJSValue(aCx, file, &value)) { - return NS_ERROR_FAILURE; - } - - if (!JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) { + nsresult rv = nsContentUtils::WrapNative(aCx, file, &NS_GET_IID(nsIDOMFile), + &value); + if (NS_FAILED(rv) || + !JS_DefineElement(aCx, array, i, value, JSPROP_ENUMERATE)) { return NS_ERROR_FAILURE; } } diff --git a/dom/archivereader/ArchiveRequest.h b/dom/archivereader/ArchiveRequest.h index 67413b27994..690cb651147 100644 --- a/dom/archivereader/ArchiveRequest.h +++ b/dom/archivereader/ArchiveRequest.h @@ -49,7 +49,8 @@ public: void OpGetFile(const nsAString& aFilename); void OpGetFiles(); - nsresult ReaderReady(nsTArray>& aFileList, nsresult aStatus); + nsresult ReaderReady(nsTArray >& aFileList, + nsresult aStatus); public: // static static already_AddRefed Create(nsPIDOMWindow* aOwner, @@ -60,13 +61,13 @@ private: nsresult GetFilenamesResult(JSContext* aCx, JS::Value* aValue, - nsTArray>& aFileList); + nsTArray >& aFileList); nsresult GetFileResult(JSContext* aCx, JS::MutableHandle aValue, - nsTArray>& aFileList); + nsTArray >& aFileList); nsresult GetFilesResult(JSContext* aCx, JS::MutableHandle aValue, - nsTArray>& aFileList); + nsTArray >& aFileList); protected: // The reader: diff --git a/dom/archivereader/ArchiveZipEvent.cpp b/dom/archivereader/ArchiveZipEvent.cpp index ef3465aa67e..6968aff1bb3 100644 --- a/dom/archivereader/ArchiveZipEvent.cpp +++ b/dom/archivereader/ArchiveZipEvent.cpp @@ -75,8 +75,8 @@ ArchiveZipItem::GetFilename(nsString& aFilename) } // From zipItem to File: -already_AddRefed -ArchiveZipItem::GetFile(ArchiveReader* aArchiveReader) +nsIDOMFile* +ArchiveZipItem::File(ArchiveReader* aArchiveReader) { nsString filename; @@ -84,13 +84,11 @@ ArchiveZipItem::GetFile(ArchiveReader* aArchiveReader) return nullptr; } - nsRefPtr file = dom::File::Create(aArchiveReader, + return new dom::File(aArchiveReader, new ArchiveZipFileImpl(filename, NS_ConvertUTF8toUTF16(GetType()), StrToInt32(mCentralStruct.orglen), mCentralStruct, aArchiveReader->GetFileImpl())); - MOZ_ASSERT(file); - return file.forget(); } uint32_t diff --git a/dom/archivereader/ArchiveZipEvent.h b/dom/archivereader/ArchiveZipEvent.h index 2c25740f365..819f97b0509 100644 --- a/dom/archivereader/ArchiveZipEvent.h +++ b/dom/archivereader/ArchiveZipEvent.h @@ -31,8 +31,7 @@ public: nsresult GetFilename(nsString& aFilename) override; // From zipItem to File: - virtual already_AddRefed - GetFile(ArchiveReader* aArchiveReader) override; + virtual nsIDOMFile* File(ArchiveReader* aArchiveReader) override; public: // for the event static uint32_t StrToInt32(const uint8_t* aStr); diff --git a/dom/base/BlobSet.h b/dom/base/BlobSet.h index 86c1e28708c..b7d3825c3ed 100644 --- a/dom/base/BlobSet.h +++ b/dom/base/BlobSet.h @@ -31,7 +31,7 @@ public: nsTArray>& GetBlobImpls() { Flush(); return mBlobImpls; } - already_AddRefed GetBlobInternal(nsISupports* aParent, + already_AddRefed GetBlobInternal(nsISupports* aParent, const nsACString& aContentType); protected: diff --git a/dom/base/Console.cpp b/dom/base/Console.cpp index 5f0536a5c8a..29a1c0d6803 100644 --- a/dom/base/Console.cpp +++ b/dom/base/Console.cpp @@ -88,9 +88,9 @@ ConsoleStructuredCloneCallbacksRead(JSContext* aCx, JS::Rooted val(aCx); { - nsRefPtr blob = - Blob::Create(data->mParent, data->mFiles.ElementAt(aIndex)); - if (!ToJSValue(aCx, blob, &val)) { + nsRefPtr file = + new File(data->mParent, data->mFiles.ElementAt(aIndex)); + if (!GetOrCreateDOMReflector(aCx, file, &val)) { return nullptr; } } @@ -114,14 +114,14 @@ ConsoleStructuredCloneCallbacksWrite(JSContext* aCx, static_cast(aClosure); MOZ_ASSERT(data); - nsRefPtr blob; - if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) && - blob->Impl()->MayBeClonedToOtherThreads()) { + nsRefPtr file; + if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, file)) && + file->Impl()->MayBeClonedToOtherThreads()) { if (!JS_WriteUint32Pair(aWriter, CONSOLE_TAG_BLOB, data->mFiles.Length())) { return false; } - data->mFiles.AppendElement(blob->Impl()); + data->mFiles.AppendElement(file->Impl()); return true; } diff --git a/dom/base/File.cpp b/dom/base/File.cpp index 15c900de8de..8f0556f6cbb 100644 --- a/dom/base/File.cpp +++ b/dom/base/File.cpp @@ -124,351 +124,39 @@ nsresult DataOwnerAdapter::Create(DataOwner* aDataOwner, } //////////////////////////////////////////////////////////////////////////// -// mozilla::dom::Blob implementation +// mozilla::dom::File implementation -NS_IMPL_CYCLE_COLLECTION_CLASS(Blob) +NS_IMPL_CYCLE_COLLECTION_CLASS(File) -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Blob) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(File) 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(Blob) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(File) 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(Blob) +NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(File) NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER NS_IMPL_CYCLE_COLLECTION_TRACE_END -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Blob) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(File) // 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, nsIDOMBlob) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFile) 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(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::Create(nsISupports* aParent, const nsAString& aContentType, - uint64_t aLength) -{ - nsRefPtr blob = Blob::Create(aParent, - new FileImplBase(aContentType, aLength)); - MOZ_ASSERT(!blob->mImpl->IsFile()); - return blob.forget(); -} - -/* static */ already_AddRefed -Blob::Create(nsISupports* aParent, const nsAString& aContentType, - uint64_t aStart, uint64_t aLength) -{ - nsRefPtr blob = Blob::Create(aParent, - new FileImplBase(aContentType, aStart, aLength)); - MOZ_ASSERT(!blob->mImpl->IsFile()); - return blob.forget(); -} - -/* static */ already_AddRefed -Blob::CreateMemoryBlob(nsISupports* aParent, void* aMemoryBuffer, - uint64_t aLength, const nsAString& aContentType) -{ - nsRefPtr blob = Blob::Create(aParent, - new FileImplMemory(aMemoryBuffer, aLength, aContentType)); - MOZ_ASSERT(!blob->mImpl->IsFile()); - return blob.forget(); -} - -/* static */ already_AddRefed -Blob::CreateTemporaryBlob(nsISupports* aParent, PRFileDesc* aFD, - uint64_t aStartPos, uint64_t aLength, - const nsAString& aContentType) -{ - nsRefPtr 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 win = do_QueryInterface(aParent); - if (win) { - MOZ_ASSERT(win->IsInnerWindow()); - } - } -#endif -} - -bool -Blob::IsFile() const -{ - return mImpl->IsFile(); -} - -const nsTArray>* -Blob::GetSubBlobImpls() const -{ - return mImpl->GetSubBlobImpls(); -} - -already_AddRefed -Blob::ToFile() -{ - if (!mImpl->IsFile()) { - return nullptr; - } - - nsRefPtr file; - if (HasFileInterface()) { - file = static_cast(this); - } else { - file = new File(mParent, mImpl); - } - - return file.forget(); -} - -already_AddRefed -Blob::ToFile(const nsAString& aName) const -{ - nsAutoTArray, 1> blobImpls; - blobImpls.AppendElement(mImpl); - - nsAutoString contentType; - mImpl->GetType(contentType); - - nsRefPtr impl = - new MultipartFileImpl(blobImpls, aName, contentType); - - nsRefPtr file = new File(mParent, impl); - return file.forget(); -} - -already_AddRefed -Blob::CreateSlice(uint64_t aStart, uint64_t aLength, - const nsAString& aContentType, - ErrorResult& aRv) -{ - nsRefPtr impl = mImpl->CreateSlice(aStart, aLength, - aContentType, aRv); - if (aRv.Failed()) { - return nullptr; - } - - nsRefPtr 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 start; - if (aArgc > 0) { - start.Construct(aStart); - } - - Optional end; - if (aArgc > 1) { - end.Construct(aEnd); - } - - ErrorResult rv; - nsRefPtr blob = Slice(start, end, aContentType, rv); - if (rv.Failed()) { - return rv.StealNSResult(); - } - - blob.forget(aBlob); - return NS_OK; -} - -already_AddRefed -Blob::Slice(const Optional& aStart, - const Optional& aEnd, - const nsAString& aContentType, - ErrorResult& aRv) -{ - nsRefPtr impl = - mImpl->Slice(aStart, aEnd, aContentType, aRv); - if (aRv.Failed()) { - return nullptr; - } - - nsRefPtr 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 aGivenProto) -{ - return BlobBinding::Wrap(aCx, this, aGivenProto); -} - -/* static */ already_AddRefed -Blob::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv) -{ - nsRefPtr impl = new MultipartFileImpl(); - - impl->InitializeBlob(); - MOZ_ASSERT(!impl->IsFile()); - - nsRefPtr blob = Blob::Create(aGlobal.GetAsSupports(), impl); - return blob.forget(); -} - -/* static */ already_AddRefed -Blob::Constructor( - const GlobalObject& aGlobal, - const Sequence& aData, - const BlobPropertyBag& aBag, - ErrorResult& aRv) -{ - nsRefPtr 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::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); -} +NS_IMPL_CYCLE_COLLECTING_ADDREF(File) +NS_IMPL_CYCLE_COLLECTING_RELEASE(File) /* static */ already_AddRefed File::Create(nsISupports* aParent, const nsAString& aName, @@ -489,6 +177,24 @@ File::Create(nsISupports* aParent, const nsAString& aName, return file.forget(); } +/* static */ already_AddRefed +File::Create(nsISupports* aParent, const nsAString& aContentType, + uint64_t aLength) +{ + nsRefPtr file = new File(aParent, + new FileImplBase(aContentType, aLength)); + return file.forget(); +} + +/* static */ already_AddRefed +File::Create(nsISupports* aParent, const nsAString& aContentType, + uint64_t aStart, uint64_t aLength) +{ + nsRefPtr file = new File(aParent, + new FileImplBase(aContentType, aStart, aLength)); + return file.forget(); +} + /* static */ already_AddRefed File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength, const nsAString& aName, @@ -501,6 +207,25 @@ File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, return file.forget(); } +/* static */ already_AddRefed +File::CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, + uint64_t aLength, const nsAString& aContentType) +{ + nsRefPtr file = new File(aParent, + new FileImplMemory(aMemoryBuffer, aLength, aContentType)); + return file.forget(); +} + +/* static */ already_AddRefed +File::CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD, + uint64_t aStartPos, uint64_t aLength, + const nsAString& aContentType) +{ + nsRefPtr file = new File(aParent, + new FileImplTemporaryFileBlob(aFD, aStartPos, aLength, aContentType)); + return file.forget(); +} + /* static */ already_AddRefed File::CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary) { @@ -547,10 +272,59 @@ File::CreateFromFile(nsISupports* aParent, nsIFile* aFile, return file.forget(); } -JSObject* -File::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +File::File(nsISupports* aParent, FileImpl* aImpl) + : mImpl(aImpl) + , mParent(aParent) { - return FileBinding::Wrap(aCx, this, aGivenProto); + MOZ_ASSERT(mImpl); + +#ifdef DEBUG + { + nsCOMPtr win = do_QueryInterface(aParent); + if (win) { + MOZ_ASSERT(win->IsInnerWindow()); + } + } +#endif +} + +const nsTArray>* +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::CreateSlice(uint64_t aStart, uint64_t aLength, + const nsAString& aContentType, + ErrorResult& aRv) +{ + nsRefPtr impl = mImpl->CreateSlice(aStart, aLength, + aContentType, aRv); + if (aRv.Failed()) { + return nullptr; + } + + nsRefPtr file = new File(mParent, impl); + return file.forget(); } NS_IMETHODIMP @@ -566,23 +340,6 @@ File::GetPath(nsAString& aPath) return mImpl->GetPath(aPath); } -Date -File::GetLastModifiedDate(ErrorResult& aRv) -{ - int64_t value = GetLastModified(aRv); - if (aRv.Failed()) { - return Date(); - } - - return Date(value); -} - -int64_t -File::GetLastModified(ErrorResult& aRv) -{ - return mImpl->GetLastModified(aRv); -} - NS_IMETHODIMP File::GetLastModifiedDate(JSContext* aCx, JS::MutableHandle aDate) @@ -600,6 +357,23 @@ File::GetLastModifiedDate(JSContext* aCx, return NS_OK; } +Date +File::GetLastModifiedDate(ErrorResult& aRv) +{ + int64_t value = GetLastModified(aRv); + if (aRv.Failed()) { + return Date(); + } + + return Date(value); +} + +int64_t +File::GetLastModified(ErrorResult& aRv) +{ + return mImpl->GetLastModified(aRv); +} + NS_IMETHODIMP File::GetMozFullPath(nsAString& aFileName) { @@ -622,6 +396,29 @@ 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) { @@ -669,6 +466,137 @@ 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 start; + if (aArgc > 0) { + start.Construct(aStart); + } + + Optional end; + if (aArgc > 1) { + end.Construct(aEnd); + } + + ErrorResult rv; + nsRefPtr file = Slice(start, end, aContentType, rv); + if (rv.Failed()) { + return rv.StealNSResult(); + } + + file.forget(aBlob); + return NS_OK; +} + +already_AddRefed +File::Slice(const Optional& aStart, + const Optional& aEnd, + const nsAString& aContentType, + ErrorResult& aRv) +{ + nsRefPtr impl = + mImpl->Slice(aStart, aEnd, aContentType, aRv); + if (aRv.Failed()) { + return nullptr; + } + + nsRefPtr 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 aGivenProto) +{ + return IsFile() ? FileBinding::Wrap(aCx, this, aGivenProto) + : BlobBinding::Wrap(aCx, this, aGivenProto); +} + +/* static */ already_AddRefed +File::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv) +{ + nsRefPtr impl = new MultipartFileImpl(); + + impl->InitializeBlob(); + MOZ_ASSERT(!impl->IsFile()); + + nsRefPtr file = new File(aGlobal.GetAsSupports(), impl); + return file.forget(); +} + +/* static */ already_AddRefed +File::Constructor( + const GlobalObject& aGlobal, + const Sequence& aData, + const BlobPropertyBag& aBag, + ErrorResult& aRv) +{ + nsRefPtr 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 = new File(aGlobal.GetAsSupports(), impl); + return file.forget(); +} + /* static */ already_AddRefed File::Constructor( const GlobalObject& aGlobal, @@ -695,7 +623,7 @@ File::Constructor( /* static */ already_AddRefed File::Constructor(const GlobalObject& aGlobal, - Blob& aData, + File& aData, const ChromeFilePropertyBag& aBag, ErrorResult& aRv) { @@ -1263,14 +1191,14 @@ FileImplMemory::DataOwner::EnsureMemoryReporterRegistered() } //////////////////////////////////////////////////////////////////////////// -// FileImplTemporaryBlob implementation +// FileImplTemporaryFileBlob implementation -NS_IMPL_ISUPPORTS_INHERITED0(FileImplTemporaryBlob, FileImpl) +NS_IMPL_ISUPPORTS_INHERITED0(FileImplTemporaryFileBlob, FileImpl) already_AddRefed -FileImplTemporaryBlob::CreateSlice(uint64_t aStart, uint64_t aLength, - const nsAString& aContentType, - ErrorResult& aRv) +FileImplTemporaryFileBlob::CreateSlice(uint64_t aStart, uint64_t aLength, + const nsAString& aContentType, + ErrorResult& aRv) { if (aStart + aLength > mLength) { aRv.Throw(NS_ERROR_UNEXPECTED); @@ -1278,13 +1206,13 @@ FileImplTemporaryBlob::CreateSlice(uint64_t aStart, uint64_t aLength, } nsRefPtr impl = - new FileImplTemporaryBlob(this, aStart + mStartPos, - aLength, aContentType); + new FileImplTemporaryFileBlob(this, aStart + mStartPos, + aLength, aContentType); return impl.forget(); } nsresult -FileImplTemporaryBlob::GetInternalStream(nsIInputStream** aStream) +FileImplTemporaryFileBlob::GetInternalStream(nsIInputStream** aStream) { nsCOMPtr stream = new nsTemporaryFileInputStream(mFileDescOwner, mStartPos, mStartPos + mLength); @@ -1331,10 +1259,10 @@ FileList::Item(uint32_t aIndex, nsIDOMFile **aFile) //////////////////////////////////////////////////////////////////////////// // BlobSet implementation -already_AddRefed +already_AddRefed BlobSet::GetBlobInternal(nsISupports* aParent, const nsACString& aContentType) { - nsRefPtr blob = Blob::Create(aParent, + nsRefPtr blob = new File(aParent, new MultipartFileImpl(GetBlobImpls(), NS_ConvertASCIItoUTF16(aContentType))); return blob.forget(); diff --git a/dom/base/File.h b/dom/base/File.h index 0e84652ef53..4cc24a1cbc1 100644 --- a/dom/base/File.h +++ b/dom/base/File.h @@ -47,131 +47,23 @@ class FileInfo; struct BlobPropertyBag; struct ChromeFilePropertyBag; struct FilePropertyBag; -class File; class FileImpl; class OwningArrayBufferOrArrayBufferViewOrBlobOrString; -class Blob : public nsIDOMBlob - , public nsIXHRSendable - , public nsIMutable - , public nsSupportsWeakReference - , public nsWrapperCache +class File final : public nsIDOMFile + , 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(Blob, nsIDOMBlob) - - static Blob* - Create(nsISupports* aParent, FileImpl* aImpl); - - static already_AddRefed - Create(nsISupports* aParent, const nsAString& aContentType, - uint64_t aLength); - - static already_AddRefed - 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 - CreateMemoryBlob(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength, - const nsAString& aContentType); - - static already_AddRefed - CreateTemporaryBlob(nsISupports* aParent, PRFileDesc* aFD, - uint64_t aStartPos, uint64_t aLength, - const nsAString& aContentType); - - FileImpl* Impl() const - { - return mImpl; - } - - bool IsFile() const; - - const nsTArray>* 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 ToFile(); - - // This method creates a new File object with the given name and the same - // FileImpl. - already_AddRefed ToFile(const nsAString& aName) const; - - already_AddRefed - CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType, - ErrorResult& aRv); - - // WebIDL methods - nsISupports* GetParentObject() const - { - return mParent; - } - - // Blob constructor - static already_AddRefed - Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); - - // Blob constructor - static already_AddRefed - Constructor(const GlobalObject& aGlobal, - const Sequence& aData, - const BlobPropertyBag& aBag, - ErrorResult& aRv); - - virtual JSObject* WrapObject(JSContext* aCx, - JS::Handle aGivenProto) override; - - uint64_t GetSize(ErrorResult& aRv); - - // XPCOM GetType is OK - - already_AddRefed Slice(const Optional& aStart, - const Optional& 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 mImpl; - -private: - nsCOMPtr 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); + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(File, nsIDOMFile) static already_AddRefed Create(nsISupports* aParent, const nsAString& aName, @@ -182,6 +74,14 @@ public: Create(nsISupports* aParent, const nsAString& aName, const nsAString& aContentType, uint64_t aLength); + static already_AddRefed + Create(nsISupports* aParent, const nsAString& aContentType, + uint64_t aLength); + + static already_AddRefed + 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. @@ -190,6 +90,18 @@ 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 + CreateMemoryFile(nsISupports* aParent, void* aMemoryBuffer, uint64_t aLength, + const nsAString& aContentType); + + static already_AddRefed + CreateTemporaryFileBlob(nsISupports* aParent, PRFileDesc* aFD, + uint64_t aStartPos, uint64_t aLength, + const nsAString& aContentType); + static already_AddRefed CreateFromFile(nsISupports* aParent, nsIFile* aFile, bool aTemporary = false); @@ -211,10 +123,41 @@ public: CreateFromFile(nsISupports* aParent, nsIFile* aFile, const nsAString& aName, const nsAString& aContentType); - // WebIDL methods + File(nsISupports* aParent, FileImpl* aImpl); - virtual JSObject* WrapObject(JSContext *cx, - JS::Handle aGivenProto) override; + FileImpl* Impl() const + { + return mImpl; + } + + const nsTArray>* GetSubBlobImpls() const; + + bool IsSizeUnknown() const; + + bool IsDateUnknown() const; + + bool IsFile() const; + + already_AddRefed + CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType, + ErrorResult& aRv); + + // WebIDL methods + nsISupports* GetParentObject() const + { + return mParent; + } + + // Blob constructor + static already_AddRefed + Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); + + // Blob constructor + static already_AddRefed + Constructor(const GlobalObject& aGlobal, + const Sequence& aData, + const BlobPropertyBag& aBag, + ErrorResult& aRv); // File constructor static already_AddRefed @@ -227,7 +170,7 @@ public: // File constructor - ChromeOnly static already_AddRefed Constructor(const GlobalObject& aGlobal, - Blob& aData, + File& aData, const ChromeFilePropertyBag& aBag, ErrorResult& aRv); @@ -245,23 +188,35 @@ public: const ChromeFilePropertyBag& aBag, ErrorResult& aRv); + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle 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); -protected: - virtual bool HasFileInterface() const override { return true; } + already_AddRefed Slice(const Optional& aStart, + const Optional& aEnd, + const nsAString& aContentType, + ErrorResult& aRv); 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 mImpl; + + nsCOMPtr mParent; }; // This is the abstract class for any File backend. It must be nsISupports @@ -630,13 +585,13 @@ private: nsRefPtr mDataOwner; }; -class FileImplTemporaryBlob final : public FileImplBase +class FileImplTemporaryFileBlob final : public FileImplBase { public: NS_DECL_ISUPPORTS_INHERITED - FileImplTemporaryBlob(PRFileDesc* aFD, uint64_t aStartPos, - uint64_t aLength, const nsAString& aContentType) + FileImplTemporaryFileBlob(PRFileDesc* aFD, uint64_t aStartPos, + uint64_t aLength, const nsAString& aContentType) : FileImplBase(aContentType, aLength) , mStartPos(aStartPos) { @@ -650,15 +605,15 @@ public: const nsAString& aContentType, ErrorResult& aRv) override; private: - FileImplTemporaryBlob(const FileImplTemporaryBlob* aOther, - uint64_t aStart, uint64_t aLength, - const nsAString& aContentType) + FileImplTemporaryFileBlob(const FileImplTemporaryFileBlob* aOther, + uint64_t aStart, uint64_t aLength, + const nsAString& aContentType) : FileImplBase(aContentType, aLength) , mStartPos(aStart) , mFileDescOwner(aOther->mFileDescOwner) {} - ~FileImplTemporaryBlob() {} + ~FileImplTemporaryFileBlob() {} uint64_t mStartPos; nsRefPtr mFileDescOwner; @@ -868,8 +823,7 @@ public: NS_DECL_NSIDOMFILELIST - virtual JSObject* WrapObject(JSContext *cx, - JS::Handle aGivenProto) override; + virtual JSObject* WrapObject(JSContext *cx, JS::Handle aGivenProto) override; nsISupports* GetParentObject() { diff --git a/dom/base/ImageEncoder.cpp b/dom/base/ImageEncoder.cpp index 53abce2faf1..a95e186499a 100644 --- a/dom/base/ImageEncoder.cpp +++ b/dom/base/ImageEncoder.cpp @@ -90,8 +90,8 @@ public: if (!mFailed) { // The correct parentObject has to be set by the mEncodeCompleteCallback. - nsRefPtr blob = - Blob::CreateMemoryBlob(nullptr, mImgData, mImgSize, mType); + nsRefPtr blob = + File::CreateMemoryFile(nullptr, mImgData, mImgSize, mType); MOZ_ASSERT(blob); rv = mEncodeCompleteCallback->ReceiveBlob(blob.forget()); diff --git a/dom/base/ImageEncoder.h b/dom/base/ImageEncoder.h index e85336014ca..88216853e5b 100644 --- a/dom/base/ImageEncoder.h +++ b/dom/base/ImageEncoder.h @@ -116,7 +116,7 @@ class EncodeCompleteCallback public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(EncodeCompleteCallback) - virtual nsresult ReceiveBlob(already_AddRefed aBlob) = 0; + virtual nsresult ReceiveBlob(already_AddRefed aBlob) = 0; protected: virtual ~EncodeCompleteCallback() {} diff --git a/dom/base/MessagePort.cpp b/dom/base/MessagePort.cpp index 9ce23e14ff9..38a3e0f8544 100644 --- a/dom/base/MessagePort.cpp +++ b/dom/base/MessagePort.cpp @@ -124,9 +124,9 @@ PostMessageReadStructuredClone(JSContext* cx, // while destructors are running. JS::Rooted val(cx); { - nsRefPtr blob = Blob::Create(scInfo->mPort->GetParentObject(), - blobImpl); - if (!ToJSValue(cx, blob, &val)) { + nsRefPtr blob = new File(scInfo->mPort->GetParentObject(), + blobImpl); + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } @@ -168,7 +168,7 @@ PostMessageWriteStructuredClone(JSContext* cx, // See if this is a File/Blob object. { - Blob* blob = nullptr; + File* blob = nullptr; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) { FileImpl* blobImpl = blob->Impl(); if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) && diff --git a/dom/base/MultipartFileImpl.cpp b/dom/base/MultipartFileImpl.cpp index ebc6f16af89..94a163add52 100644 --- a/dom/base/MultipartFileImpl.cpp +++ b/dom/base/MultipartFileImpl.cpp @@ -145,8 +145,8 @@ MultipartFileImpl::InitializeBlob( const OwningArrayBufferOrArrayBufferViewOrBlobOrString& data = aData[i]; if (data.IsBlob()) { - nsRefPtr blob = data.GetAsBlob().get(); - blobSet.AppendBlobImpl(blob->Impl()); + nsRefPtr file = data.GetAsBlob().get(); + blobSet.AppendBlobImpl(file->Impl()); } else if (data.IsString()) { @@ -281,7 +281,7 @@ MultipartFileImpl::SetMutable(bool aMutable) } void -MultipartFileImpl::InitializeChromeFile(Blob& aBlob, +MultipartFileImpl::InitializeChromeFile(File& aBlob, const ChromeFilePropertyBag& aBag, ErrorResult& aRv) { diff --git a/dom/base/MultipartFileImpl.h b/dom/base/MultipartFileImpl.h index c88def80a6c..b062c3a0dc4 100644 --- a/dom/base/MultipartFileImpl.h +++ b/dom/base/MultipartFileImpl.h @@ -67,7 +67,7 @@ public: bool aNativeEOL, ErrorResult& aRv); - void InitializeChromeFile(Blob& aData, + void InitializeChromeFile(File& aData, const ChromeFilePropertyBag& aBag, ErrorResult& aRv); diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index d4bd0940783..bfecce47afd 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1213,7 +1213,7 @@ Navigator::SendBeacon(const nsAString& aUrl, in = strStream; } else if (aData.Value().IsBlob()) { - Blob& blob = aData.Value().GetAsBlob(); + File& blob = aData.Value().GetAsBlob(); rv = blob.GetInternalStream(getter_AddRefs(in)); if (NS_FAILED(rv)) { aRv.Throw(NS_ERROR_FAILURE); diff --git a/dom/base/URL.cpp b/dom/base/URL.cpp index 5dc76382c11..eb7d6602e18 100644 --- a/dom/base/URL.cpp +++ b/dom/base/URL.cpp @@ -112,7 +112,7 @@ URL::Constructor(const nsAString& aUrl, nsIURI* aBase, ErrorResult& aRv) void URL::CreateObjectURL(const GlobalObject& aGlobal, - Blob& aBlob, + File& aBlob, const objectURLOptions& aOptions, nsAString& aResult, ErrorResult& aError) diff --git a/dom/base/URL.h b/dom/base/URL.h index aa1ca15e996..9e28f92d457 100644 --- a/dom/base/URL.h +++ b/dom/base/URL.h @@ -22,7 +22,7 @@ class DOMMediaStream; namespace dom { -class Blob; +class File; 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, - Blob& aBlob, + File& aBlob, const objectURLOptions& aOptions, nsAString& aResult, ErrorResult& aError); diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index bb8569c090a..e571df07c09 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -2210,7 +2210,7 @@ WebSocket::Send(const nsAString& aData, } void -WebSocket::Send(Blob& aData, ErrorResult& aRv) +WebSocket::Send(File& aData, ErrorResult& aRv) { AssertIsOnTargetThread(); diff --git a/dom/base/WebSocket.h b/dom/base/WebSocket.h index 2b75a3493fa..954572469b9 100644 --- a/dom/base/WebSocket.h +++ b/dom/base/WebSocket.h @@ -28,7 +28,7 @@ class nsIInputStream; namespace mozilla { namespace dom { -class Blob; +class File; 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(Blob& aData, + void Send(File& aData, ErrorResult& aRv); void Send(const ArrayBuffer& aData, ErrorResult& aRv); diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 5745786c128..09b62335e37 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -6090,16 +6090,16 @@ nsContentUtils::CreateBlobBuffer(JSContext* aCx, { uint32_t blobLen = aData.Length(); void* blobData = malloc(blobLen); - nsRefPtr blob; + nsRefPtr blob; if (blobData) { memcpy(blobData, aData.BeginReading(), blobLen); - blob = mozilla::dom::Blob::CreateMemoryBlob(aParent, blobData, blobLen, + blob = mozilla::dom::File::CreateMemoryFile(aParent, blobData, blobLen, EmptyString()); } else { return NS_ERROR_OUT_OF_MEMORY; } - if (!ToJSValue(aCx, blob, aBlob)) { + if (!GetOrCreateDOMReflector(aCx, blob, aBlob)) { return NS_ERROR_FAILURE; } diff --git a/dom/base/nsDOMDataChannel.cpp b/dom/base/nsDOMDataChannel.cpp index 8ca5466e96b..525d05d9d23 100644 --- a/dom/base/nsDOMDataChannel.cpp +++ b/dom/base/nsDOMDataChannel.cpp @@ -267,7 +267,7 @@ nsDOMDataChannel::Send(const nsAString& aData, ErrorResult& aRv) } void -nsDOMDataChannel::Send(Blob& aData, ErrorResult& aRv) +nsDOMDataChannel::Send(File& aData, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread(), "Not running on main thread"); diff --git a/dom/base/nsDOMDataChannel.h b/dom/base/nsDOMDataChannel.h index ebe2054db5f..966e9c8035b 100644 --- a/dom/base/nsDOMDataChannel.h +++ b/dom/base/nsDOMDataChannel.h @@ -18,7 +18,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; } class DataChannel; @@ -70,7 +70,7 @@ public: static_cast(aType)); } void Send(const nsAString& aData, mozilla::ErrorResult& aRv); - void Send(mozilla::dom::Blob& aData, mozilla::ErrorResult& aRv); + void Send(mozilla::dom::File& aData, mozilla::ErrorResult& aRv); void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); void Send(const mozilla::dom::ArrayBufferView& aData, mozilla::ErrorResult& aRv); diff --git a/dom/base/nsDOMFileReader.cpp b/dom/base/nsDOMFileReader.cpp index 821f7dc5f45..2737e3391d8 100644 --- a/dom/base/nsDOMFileReader.cpp +++ b/dom/base/nsDOMFileReader.cpp @@ -43,13 +43,13 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMFileReader) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMFileReader, FileIOObject) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mBlob) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFile) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMFileReader, FileIOObject) tmp->mResultArrayBuffer = nullptr; - NS_IMPL_CYCLE_COLLECTION_UNLINK(mBlob) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mFile) NS_IMPL_CYCLE_COLLECTION_UNLINK_END @@ -183,43 +183,43 @@ nsDOMFileReader::GetError(nsISupports** aError) } NS_IMETHODIMP -nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aBlob, JSContext* aCx) +nsDOMFileReader::ReadAsArrayBuffer(nsIDOMBlob* aFile, JSContext* aCx) { - NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER); ErrorResult rv; - nsRefPtr blob = static_cast(aBlob); - ReadAsArrayBuffer(aCx, *blob, rv); + nsRefPtr file = static_cast(aFile); + ReadAsArrayBuffer(aCx, *file, rv); return rv.StealNSResult(); } NS_IMETHODIMP -nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aBlob) +nsDOMFileReader::ReadAsBinaryString(nsIDOMBlob* aFile) { - NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER); ErrorResult rv; - nsRefPtr blob = static_cast(aBlob); - ReadAsBinaryString(*blob, rv); + nsRefPtr file = static_cast(aFile); + ReadAsBinaryString(*file, rv); return rv.StealNSResult(); } NS_IMETHODIMP -nsDOMFileReader::ReadAsText(nsIDOMBlob* aBlob, +nsDOMFileReader::ReadAsText(nsIDOMBlob* aFile, const nsAString &aCharset) { - NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER); ErrorResult rv; - nsRefPtr blob = static_cast(aBlob); - ReadAsText(*blob, aCharset, rv); + nsRefPtr file = static_cast(aFile); + ReadAsText(*file, aCharset, rv); return rv.StealNSResult(); } NS_IMETHODIMP -nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aBlob) +nsDOMFileReader::ReadAsDataURL(nsIDOMBlob* aFile) { - NS_ENSURE_TRUE(aBlob, NS_ERROR_NULL_POINTER); + NS_ENSURE_TRUE(aFile, NS_ERROR_NULL_POINTER); ErrorResult rv; - nsRefPtr blob = static_cast(aBlob); - ReadAsDataURL(*blob, rv); + nsRefPtr file = static_cast(aFile); + ReadAsDataURL(*file, rv); return rv.StealNSResult(); } @@ -241,7 +241,7 @@ nsDOMFileReader::DoAbort(nsAString& aEvent) if (mAsyncStream) { mAsyncStream = nullptr; } - mBlob = nullptr; + mFile = 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 stream; mAsyncStream.swap(stream); - nsCOMPtr blob; - mBlob.swap(blob); + nsCOMPtr file; + mFile.swap(file); 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(blob, mCharset, "", mDataLen, mResult); + rv = GetAsText(file, mCharset, "", mDataLen, mResult); break; } - rv = GetAsText(blob, mCharset, mFileData, mDataLen, mResult); + rv = GetAsText(file, mCharset, mFileData, mDataLen, mResult); break; case FILE_AS_DATAURL: - rv = GetAsDataURL(blob, mFileData, mDataLen, mResult); + rv = GetAsDataURL(file, mFileData, mDataLen, mResult); break; } @@ -380,7 +380,7 @@ nsDOMFileReader::DoReadData(nsIAsyncInputStream* aStream, uint64_t aCount) // Helper methods void -nsDOMFileReader::ReadFileContent(Blob& aBlob, +nsDOMFileReader::ReadFileContent(File& aFile, const nsAString &aCharset, eDataFormat aDataFormat, ErrorResult& aRv) @@ -394,7 +394,7 @@ nsDOMFileReader::ReadFileContent(Blob& aBlob, mReadyState = nsIDOMFileReader::EMPTY; FreeFileData(); - mBlob = &aBlob; + mFile = &aFile; mDataFormat = aDataFormat; CopyUTF16toUTF8(aCharset, mCharset); @@ -408,7 +408,7 @@ nsDOMFileReader::ReadFileContent(Blob& aBlob, } nsCOMPtr stream; - rv = mBlob->GetInternalStream(getter_AddRefs(stream)); + rv = mFile->GetInternalStream(getter_AddRefs(stream)); if (NS_WARN_IF(NS_FAILED(rv))) { aRv.Throw(rv); return; @@ -440,7 +440,7 @@ nsDOMFileReader::ReadFileContent(Blob& aBlob, MOZ_ASSERT(mAsyncStream); mTotal = mozilla::dom::kUnknownSize; - mBlob->GetSize(&mTotal); + mFile->GetSize(&mTotal); rv = DoAsyncWait(mAsyncStream); if (NS_WARN_IF(NS_FAILED(rv))) { @@ -462,7 +462,7 @@ nsDOMFileReader::ReadFileContent(Blob& aBlob, } nsresult -nsDOMFileReader::GetAsText(nsIDOMBlob *aBlob, +nsDOMFileReader::GetAsText(nsIDOMBlob *aFile, const nsACString &aCharset, const char *aFileData, uint32_t aDataLen, @@ -480,7 +480,7 @@ nsDOMFileReader::GetAsText(nsIDOMBlob *aBlob, encoding)) { // API argument failed. Try the type property of the blob. nsAutoString type16; - aBlob->GetType(type16); + aFile->GetType(type16); NS_ConvertUTF16toUTF8 type(type16); nsAutoCString specifiedCharset; bool haveCharset; @@ -502,7 +502,7 @@ nsDOMFileReader::GetAsText(nsIDOMBlob *aBlob, } nsresult -nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aBlob, +nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aFile, const char *aFileData, uint32_t aDataLen, nsAString& aResult) @@ -511,7 +511,7 @@ nsDOMFileReader::GetAsDataURL(nsIDOMBlob *aBlob, nsresult rv; nsString contentType; - rv = aBlob->GetType(contentType); + rv = aFile->GetType(contentType); if (NS_SUCCEEDED(rv) && !contentType.IsEmpty()) { aResult.Append(contentType); } else { diff --git a/dom/base/nsDOMFileReader.h b/dom/base/nsDOMFileReader.h index dc18a97cd55..80531ffd1df 100644 --- a/dom/base/nsDOMFileReader.h +++ b/dom/base/nsDOMFileReader.h @@ -27,7 +27,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; } } @@ -38,8 +38,7 @@ class nsDOMFileReader final : public mozilla::dom::FileIOObject, { typedef mozilla::ErrorResult ErrorResult; typedef mozilla::dom::GlobalObject GlobalObject; - typedef mozilla::dom::Blob Blob; - + typedef mozilla::dom::File File; public: nsDOMFileReader(); @@ -69,17 +68,17 @@ public: // WebIDL static already_AddRefed Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); - void ReadAsArrayBuffer(JSContext* aCx, Blob& aBlob, ErrorResult& aRv) + void ReadAsArrayBuffer(JSContext* aCx, File& aBlob, ErrorResult& aRv) { ReadFileContent(aBlob, EmptyString(), FILE_AS_ARRAYBUFFER, aRv); } - void ReadAsText(Blob& aBlob, const nsAString& aLabel, ErrorResult& aRv) + void ReadAsText(File& aBlob, const nsAString& aLabel, ErrorResult& aRv) { ReadFileContent(aBlob, aLabel, FILE_AS_TEXT, aRv); } - void ReadAsDataURL(Blob& aBlob, ErrorResult& aRv) + void ReadAsDataURL(File& aBlob, ErrorResult& aRv) { ReadFileContent(aBlob, EmptyString(), FILE_AS_DATAURL, aRv); } @@ -103,7 +102,7 @@ public: using FileIOObject::SetOnerror; IMPL_EVENT_HANDLER(loadend) - void ReadAsBinaryString(Blob& aBlob, ErrorResult& aRv) + void ReadAsBinaryString(File& aBlob, ErrorResult& aRv) { ReadFileContent(aBlob, EmptyString(), FILE_AS_BINARY, aRv); } @@ -125,14 +124,12 @@ protected: FILE_AS_DATAURL }; - void ReadFileContent(Blob& aBlob, + void ReadFileContent(File& aBlob, const nsAString &aCharset, eDataFormat aDataFormat, ErrorResult& aRv); - 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); + 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); void FreeFileData() { free(mFileData); @@ -141,7 +138,7 @@ protected: } char *mFileData; - nsCOMPtr mBlob; + nsCOMPtr mFile; nsCString mCharset; uint32_t mDataLen; diff --git a/dom/base/nsFormData.cpp b/dom/base/nsFormData.cpp index 541aff1fe67..bca348b342d 100644 --- a/dom/base/nsFormData.cpp +++ b/dom/base/nsFormData.cpp @@ -22,10 +22,9 @@ nsFormData::nsFormData(nsISupports* aOwner) } namespace { - // Implements steps 3 and 4 of the "create an entry" algorithm of FormData. -already_AddRefed -CreateNewFileInstance(Blob& aBlob, const Optional& aFilename) +File* +CreateNewFileInstance(File& aBlob, const Optional& 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 @@ -36,20 +35,25 @@ CreateNewFileInstance(Blob& aBlob, const Optional& aFilename) nsAutoString filename; if (aFilename.WasPassed()) { filename = aFilename.Value(); - } else { + } else if (aBlob.IsFile()) { // If value is already a File and filename is not passed, the spec says not // to create a new instance. - nsRefPtr file = aBlob.ToFile(); - if (file) { - return file.forget(); - } - + return &aBlob; + } else { filename = NS_LITERAL_STRING("blob"); } - return aBlob.ToFile(filename); -} + nsAutoTArray, 1> blobImpls; + blobImpls.AppendElement(aBlob.Impl()); + nsAutoString contentType; + aBlob.GetType(contentType); + + nsRefPtr impl = + new MultipartFileImpl(blobImpls, filename, contentType); + + return new File(aBlob.GetParentObject(), impl); +} } // anonymous namespace // ------------------------------------------------------------------------- @@ -107,7 +111,7 @@ nsFormData::Append(const nsAString& aName, const nsAString& aValue) } void -nsFormData::Append(const nsAString& aName, Blob& aBlob, +nsFormData::Append(const nsAString& aName, File& aBlob, const Optional& aFilename) { nsRefPtr file = CreateNewFileInstance(aBlob, aFilename); @@ -175,14 +179,6 @@ 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) { @@ -206,7 +202,7 @@ nsFormData::RemoveAllOthersAndGetFirstFormDataTuple(const nsAString& aName) } void -nsFormData::Set(const nsAString& aName, Blob& aBlob, +nsFormData::Set(const nsAString& aName, File& aBlob, const Optional& aFilename) { FormDataTuple* tuple = RemoveAllOthersAndGetFirstFormDataTuple(aName); @@ -249,7 +245,7 @@ nsFormData::Append(const nsAString& aName, nsIVariant* aValue) free(iid); nsCOMPtr domBlob = do_QueryInterface(supports); - nsRefPtr blob = static_cast(domBlob.get()); + nsRefPtr blob = static_cast(domBlob.get()); if (domBlob) { Optional temp; Append(aName, *blob, temp); diff --git a/dom/base/nsFormData.h b/dom/base/nsFormData.h index 0d810da0000..10d57c7dbd5 100644 --- a/dom/base/nsFormData.h +++ b/dom/base/nsFormData.h @@ -35,9 +35,7 @@ class nsFormData final : public nsIDOMFormData, private: ~nsFormData() {} - typedef mozilla::dom::Blob Blob; typedef mozilla::dom::File File; - struct FormDataTuple { nsString name; @@ -63,11 +61,11 @@ private: void SetNameFilePair(FormDataTuple* aData, const nsAString& aName, - File* aFile) + File* aBlob) { MOZ_ASSERT(aData); aData->name = aName; - aData->fileValue = aFile; + aData->fileValue = aBlob; aData->valueIsFile = true; } @@ -97,13 +95,13 @@ public: const mozilla::dom::Optional >& aFormElement, mozilla::ErrorResult& aRv); void Append(const nsAString& aName, const nsAString& aValue); - void Append(const nsAString& aName, Blob& aBlob, + void Append(const nsAString& aName, File& aBlob, const mozilla::dom::Optional& aFilename); void Delete(const nsAString& aName); void Get(const nsAString& aName, mozilla::dom::Nullable& aOutValue); void GetAll(const nsAString& aName, nsTArray& aValues); bool Has(const nsAString& aName); - void Set(const nsAString& aName, Blob& aBlob, + void Set(const nsAString& aName, File& aBlob, const mozilla::dom::Optional& aFilename); void Set(const nsAString& aName, const nsAString& aValue); @@ -118,7 +116,12 @@ public: return NS_OK; } virtual nsresult AddNameFilePair(const nsAString& aName, - File* aFile) override; + File* aBlob) override + { + FormDataTuple* data = mFormData.AppendElement(); + SetNameFilePair(data, aName, aBlob); + return NS_OK; + } typedef bool (*FormDataEntryCallback)(const nsString& aName, bool aIsFile, const nsString& aValue, diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 9ed041e8383..b441bec95c0 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -212,7 +212,7 @@ BuildClonedMessageData(typename BlobTraits::ConcreteContentManagerType* SerializedStructuredCloneBuffer& buffer = aClonedData.data(); buffer.data = aData.mData; buffer.dataLength = aData.mDataLength; - const nsTArray>& blobs = aData.mClosure.mBlobs; + const nsTArray>& blobs = aData.mClosure.mBlobs; if (!blobs.IsEmpty()) { typedef typename BlobTraits::ProtocolType ProtocolType; InfallibleTArray& blobList = DataBlobs::Blobs(aClonedData); @@ -269,7 +269,7 @@ UnpackClonedMessageData(const ClonedMessageData& aData) // This object will be duplicated with a correct parent before being // exposed to JS. - nsRefPtr domBlob = Blob::Create(nullptr, blobImpl); + nsRefPtr domBlob = new File(nullptr, blobImpl); cloneData.mClosure.mBlobs.AppendElement(domBlob); } } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 86a45ef935c..b1699316ec1 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -8063,8 +8063,8 @@ PostMessageReadStructuredClone(JSContext* cx, // while destructors are running. JS::Rooted val(cx); { - nsRefPtr blob = Blob::Create(scInfo->window, blobImpl); - if (!ToJSValue(cx, blob, &val)) { + nsRefPtr blob = new File(scInfo->window, blobImpl); + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } @@ -8106,7 +8106,7 @@ PostMessageWriteStructuredClone(JSContext* cx, // See if this is a File/Blob object. { - Blob* blob = nullptr; + File* blob = nullptr; if (scInfo->subsumes && NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) { FileImpl* blobImpl = blob->Impl(); if (JS_WriteUint32Pair(writer, SCTAG_DOM_BLOB, 0) && diff --git a/dom/base/nsIDOMFile.idl b/dom/base/nsIDOMFile.idl index cc8507aa409..a01c9e78ed8 100644 --- a/dom/base/nsIDOMFile.idl +++ b/dom/base/nsIDOMFile.idl @@ -54,12 +54,8 @@ interface nsIDOMBlob : nsISupports [notxpcom] bool isMemoryFile(); }; -// 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 +[scriptable, builtinclass, uuid(74657f92-aa61-492b-8649-fd1cca62e255)] +interface nsIDOMFile : nsIDOMBlob { readonly attribute DOMString name; diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index 929bb48dc8a..dd26140f35f 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -428,7 +428,7 @@ nsXMLHttpRequest::ResetResponse() mResponseBody.Truncate(); mResponseText.Truncate(); mResponseBlob = nullptr; - mDOMBlob = nullptr; + mDOMFile = 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(mDOMBlob) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMFile) 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(mDOMBlob) + NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMFile) NS_IMPL_CYCLE_COLLECTION_UNLINK(mNotificationCallbacks) NS_IMPL_CYCLE_COLLECTION_UNLINK(mChannelEventSink) @@ -789,15 +789,15 @@ nsXMLHttpRequest::CreateResponseParsedJSON(JSContext* aCx) void nsXMLHttpRequest::CreatePartialBlob() { - if (mDOMBlob) { + if (mDOMFile) { // 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 = mDOMBlob; + mResponseBlob = mDOMFile; } else { ErrorResult rv; - mResponseBlob = mDOMBlob->CreateSlice(0, mDataAvailable, + mResponseBlob = mDOMFile->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->mDOMBlob) { + if (!xmlHttpRequest->mDOMFile) { if (!xmlHttpRequest->mBlobSet) { xmlHttpRequest->mBlobSet = new BlobSet(); } @@ -1899,7 +1899,7 @@ nsXMLHttpRequest::StreamReaderFunc(nsIInputStream* in, return rv; } -bool nsXMLHttpRequest::CreateDOMBlob(nsIRequest *request) +bool nsXMLHttpRequest::CreateDOMFile(nsIRequest *request) { nsCOMPtr file; nsCOMPtr fc = do_QueryInterface(request); @@ -1913,7 +1913,7 @@ bool nsXMLHttpRequest::CreateDOMBlob(nsIRequest *request) nsAutoCString contentType; mChannel->GetContentType(contentType); - mDOMBlob = File::CreateFromFile(GetOwner(), file, EmptyString(), + mDOMFile = 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) && !mDOMBlob) { - cancelable = CreateDOMBlob(request); + mResponseType == XML_HTTP_RESPONSE_TYPE_MOZ_BLOB) && !mDOMFile) { + cancelable = CreateDOMFile(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 - mDOMBlob->GetSize(&mDataAvailable); + mDOMFile->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 (!mDOMBlob) { - CreateDOMBlob(request); + if (!mDOMFile) { + CreateDOMFile(request); } - if (mDOMBlob) { - mResponseBlob = mDOMBlob; - mDOMBlob = nullptr; + if (mDOMFile) { + mResponseBlob = mDOMFile; + mDOMFile = nullptr; } else { // mBlobSet can be null if the channel is non-file non-cacheable // and if the response length is zero. diff --git a/dom/base/nsXMLHttpRequest.h b/dom/base/nsXMLHttpRequest.h index b4a3c289576..ce71cc7c44e 100644 --- a/dom/base/nsXMLHttpRequest.h +++ b/dom/base/nsXMLHttpRequest.h @@ -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::Blob& aBlob) : mType(Blob) + explicit RequestBody(mozilla::dom::File& 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::Blob* mBlob; + mozilla::dom::File* mBlob; nsIDocument* mDocument; const nsAString* mString; nsFormData* mFormData; @@ -450,7 +450,7 @@ public: { aRv = Send(RequestBody(&aArrayBufferView)); } - void Send(JSContext* /*aCx*/, mozilla::dom::Blob& aBlob, ErrorResult& aRv) + void Send(JSContext* /*aCx*/, mozilla::dom::File& aBlob, ErrorResult& aRv) { aRv = Send(RequestBody(aBlob)); } @@ -606,7 +606,7 @@ protected: uint32_t *writeCount); nsresult CreateResponseParsedJSON(JSContext* aCx); void CreatePartialBlob(); - bool CreateDOMBlob(nsIRequest *request); + bool CreateDOMFile(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 mResponseBlob; + nsRefPtr 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 mDOMBlob; + nsRefPtr mDOMFile; // We stream data to mBlobSet when response type is "blob" or "moz-blob" - // and mDOMBlob is null. + // and mDOMFile is null. nsAutoPtr mBlobSet; nsString mOverrideMimeType; diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index ce8ffef4caa..0120fafca01 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -138,6 +138,7 @@ DOMInterfaces = { }, 'Blob': { + 'nativeType': 'mozilla::dom::File', 'headerFile': 'mozilla/dom/File.h', }, diff --git a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp index a2cabbdede8..c02240a9401 100644 --- a/dom/bluetooth/bluedroid/BluetoothOppManager.cpp +++ b/dom/bluetooth/bluedroid/BluetoothOppManager.cpp @@ -413,7 +413,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress, MOZ_ASSERT(NS_IsMainThread()); nsRefPtr impl = aActor->GetBlobImpl(); - nsRefPtr blob = Blob::Create(nullptr, impl); + nsCOMPtr blob = new File(nullptr, impl); return SendFile(aDeviceAddress, blob.get()); } diff --git a/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp b/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp index 337d98c3610..3266a673dc6 100644 --- a/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp +++ b/dom/bluetooth/bluetooth1/BluetoothAdapter.cpp @@ -766,7 +766,7 @@ BluetoothAdapter::IsConnected(const uint16_t aServiceUuid, ErrorResult& aRv) already_AddRefed BluetoothAdapter::SendFile(const nsAString& aDeviceAddress, - Blob& aBlob, ErrorResult& aRv) + File& aBlob, ErrorResult& aRv) { nsCOMPtr win = GetOwner(); if (!win) { diff --git a/dom/bluetooth/bluetooth1/BluetoothAdapter.h b/dom/bluetooth/bluetooth1/BluetoothAdapter.h index c52396789ca..11dedb4ce27 100644 --- a/dom/bluetooth/bluetooth1/BluetoothAdapter.h +++ b/dom/bluetooth/bluetooth1/BluetoothAdapter.h @@ -15,7 +15,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; class DOMRequest; struct MediaMetaData; struct MediaPlayStatus; @@ -134,7 +134,7 @@ public: GetConnectedDevices(uint16_t aServiceUuid, ErrorResult& aRv); already_AddRefed - SendFile(const nsAString& aDeviceAddress, Blob& aBlob, + SendFile(const nsAString& aDeviceAddress, File& aBlob, ErrorResult& aRv); already_AddRefed StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv); diff --git a/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp b/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp index 96ac7835172..18e36fa11b6 100644 --- a/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp +++ b/dom/bluetooth/bluetooth2/BluetoothAdapter.cpp @@ -1261,7 +1261,7 @@ BluetoothAdapter::Disconnect(BluetoothDevice& aDevice, already_AddRefed BluetoothAdapter::SendFile(const nsAString& aDeviceAddress, - Blob& aBlob, ErrorResult& aRv) + File& aBlob, ErrorResult& aRv) { nsCOMPtr win = GetOwner(); if (!win) { diff --git a/dom/bluetooth/bluetooth2/BluetoothAdapter.h b/dom/bluetooth/bluetooth2/BluetoothAdapter.h index c7b84f8a186..986f6701ee8 100644 --- a/dom/bluetooth/bluetooth2/BluetoothAdapter.h +++ b/dom/bluetooth/bluetooth2/BluetoothAdapter.h @@ -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 SendFile(const nsAString& aDeviceAddress, - Blob& aBlob, + File& aBlob, ErrorResult& aRv); already_AddRefed StopSendingFile(const nsAString& aDeviceAddress, ErrorResult& aRv); diff --git a/dom/broadcastchannel/BroadcastChannel.cpp b/dom/broadcastchannel/BroadcastChannel.cpp index 325722cfcaa..8bd1a03091b 100644 --- a/dom/broadcastchannel/BroadcastChannel.cpp +++ b/dom/broadcastchannel/BroadcastChannel.cpp @@ -212,7 +212,7 @@ public: PBackgroundChild* backgroundManager = mActor->Manager(); MOZ_ASSERT(backgroundManager); - const nsTArray>& blobs = mData->mClosure.mBlobs; + const nsTArray>& blobs = mData->mClosure.mBlobs; if (!blobs.IsEmpty()) { message.blobsChild().SetCapacity(blobs.Length()); @@ -541,7 +541,7 @@ BroadcastChannel::PostMessageInternal(JSContext* aCx, return; } - const nsTArray>& blobs = data->mClosure.mBlobs; + const nsTArray>& 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); diff --git a/dom/broadcastchannel/BroadcastChannelChild.cpp b/dom/broadcastchannel/BroadcastChannelChild.cpp index 5d5d7753f19..d3b198fa1b8 100644 --- a/dom/broadcastchannel/BroadcastChannelChild.cpp +++ b/dom/broadcastchannel/BroadcastChannelChild.cpp @@ -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> blobs; + nsTArray> files; if (!aData.blobsChild().IsEmpty()) { - blobs.SetCapacity(aData.blobsChild().Length()); + files.SetCapacity(aData.blobsChild().Length()); for (uint32_t i = 0, len = aData.blobsChild().Length(); i < len; ++i) { nsRefPtr impl = static_cast(aData.blobsChild()[i])->GetBlobImpl(); - nsRefPtr blob = Blob::Create(mBC ? mBC->GetOwner() : nullptr, impl); - blobs.AppendElement(blob); + nsRefPtr file = new File(mBC ? mBC->GetOwner() : nullptr, impl); + files.AppendElement(file); } } @@ -92,7 +92,7 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData) StructuredCloneData cloneData; cloneData.mData = buffer.data; cloneData.mDataLength = buffer.dataLength; - cloneData.mClosure.mBlobs.SwapElements(blobs); + cloneData.mClosure.mBlobs.SwapElements(files); JS::Rooted value(cx, JS::NullValue()); if (cloneData.mDataLength && !ReadStructuredClone(cx, cloneData, &value)) { diff --git a/dom/camera/DOMCameraControl.cpp b/dom/camera/DOMCameraControl.cpp index b46770e6234..e62aa39edcd 100755 --- a/dom/camera/DOMCameraControl.cpp +++ b/dom/camera/DOMCameraControl.cpp @@ -1405,7 +1405,7 @@ nsDOMCameraControl::OnTakePictureComplete(nsIDOMBlob* aPicture) promise->MaybeResolve(picture); } - nsRefPtr blob = static_cast(aPicture); + nsRefPtr blob = static_cast(aPicture); BlobEventInit eventInit; eventInit.mData = blob; diff --git a/dom/camera/DOMCameraControlListener.cpp b/dom/camera/DOMCameraControlListener.cpp index 1e106e4bbee..25f2c6596f3 100644 --- a/dom/camera/DOMCameraControlListener.cpp +++ b/dom/camera/DOMCameraControlListener.cpp @@ -360,7 +360,7 @@ DOMCameraControlListener::OnTakePictureComplete(const uint8_t* aData, uint32_t a RunCallback(nsDOMCameraControl* aDOMCameraControl) override { nsCOMPtr picture = - Blob::CreateMemoryBlob(mDOMCameraControl.get(), + File::CreateMemoryFile(mDOMCameraControl.get(), static_cast(mData), static_cast(mLength), mMimeType); diff --git a/dom/camera/TestGonkCameraHardware.cpp b/dom/camera/TestGonkCameraHardware.cpp index 88b58b18ee5..34bac5f9675 100644 --- a/dom/camera/TestGonkCameraHardware.cpp +++ b/dom/camera/TestGonkCameraHardware.cpp @@ -106,19 +106,19 @@ TestGonkCameraHardwareListener::HandleEvent(nsIDOMEvent* aEvent) BlobEvent* event = aEvent->InternalDOMEvent()->AsBlobEvent(); if (!NS_WARN_IF(!event)) { - Blob* blob = event->GetData(); + File* file = event->GetData(); - if (blob) { + if (file) { static const uint64_t MAX_FILE_SIZE = 2147483647; uint64_t dataLength = 0; - nsresult rv = blob->GetSize(&dataLength); + nsresult rv = file->GetSize(&dataLength); if (NS_WARN_IF(NS_FAILED(rv) || dataLength > MAX_FILE_SIZE)) { return NS_OK; } nsCOMPtr inputStream; - rv = blob->GetInternalStream(getter_AddRefs(inputStream)); + rv = file->GetInternalStream(getter_AddRefs(inputStream)); if (NS_WARN_IF(NS_FAILED(rv))) { return NS_OK; } diff --git a/dom/devicestorage/DeviceStorage.h b/dom/devicestorage/DeviceStorage.h index c497adefa68..43d308e42b2 100644 --- a/dom/devicestorage/DeviceStorage.h +++ b/dom/devicestorage/DeviceStorage.h @@ -29,7 +29,6 @@ class nsIOutputStream; namespace mozilla { class EventListenerManager; namespace dom { -class Blob; struct DeviceStorageEnumerationParameters; class DOMCursor; class DOMRequest; @@ -223,16 +222,15 @@ public: IMPL_EVENT_HANDLER(change) already_AddRefed - Add(mozilla::dom::Blob* aBlob, ErrorResult& aRv); + Add(nsIDOMBlob* aBlob, ErrorResult& aRv); already_AddRefed - AddNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath, ErrorResult& aRv); + AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv); already_AddRefed - AppendNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath, - ErrorResult& aRv); + AppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv); already_AddRefed - AddOrAppendNamed(mozilla::dom::Blob* aBlob, const nsAString& aPath, + AddOrAppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath, const int32_t aRequestType, ErrorResult& aRv); already_AddRefed diff --git a/dom/devicestorage/DeviceStorageRequestChild.cpp b/dom/devicestorage/DeviceStorageRequestChild.cpp index 48e5790904a..dcc79d36cda 100644 --- a/dom/devicestorage/DeviceStorageRequestChild.cpp +++ b/dom/devicestorage/DeviceStorageRequestChild.cpp @@ -105,8 +105,7 @@ DeviceStorageRequestChild:: BlobResponse r = aValue; BlobChild* actor = static_cast(r.blobChild()); nsRefPtr bloblImpl = actor->GetBlobImpl(); - nsRefPtr blob = Blob::Create(mRequest->GetParentObject(), - bloblImpl); + nsRefPtr blob = new File(mRequest->GetParentObject(), bloblImpl); AutoJSContext cx; diff --git a/dom/devicestorage/DeviceStorageRequestParent.cpp b/dom/devicestorage/DeviceStorageRequestParent.cpp index acf0047099c..03042e7e88d 100644 --- a/dom/devicestorage/DeviceStorageRequestParent.cpp +++ b/dom/devicestorage/DeviceStorageRequestParent.cpp @@ -523,12 +523,12 @@ DeviceStorageRequestParent::PostBlobSuccessEvent::CancelableRun() { nsString fullPath; mFile->GetFullPath(fullPath); - nsRefPtr blob = + nsRefPtr blob = new File(nullptr, new FileImplFile(fullPath, mime, mLength, mFile->mFile, - mLastModificationDate); + mLastModificationDate)); ContentParent* cp = static_cast(mParent->Manager()); - BlobParent* actor = cp->GetOrCreateActorForFileImpl(blob); + BlobParent* actor = cp->GetOrCreateActorForBlob(blob); if (!actor) { ErrorResponse response(NS_LITERAL_STRING(POST_ERROR_EVENT_UNKNOWN)); unused << mParent->Send__delete__(mParent, response); diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index 18ed56d8288..9093107e701 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -274,7 +274,7 @@ DeviceStorageTypeChecker::InitFromBundle(nsIStringBundle* aBundle) bool -DeviceStorageTypeChecker::Check(const nsAString& aType, Blob* aBlob) +DeviceStorageTypeChecker::Check(const nsAString& aType, nsIDOMBlob* 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 blob = Blob::Create(aWindow, + nsCOMPtr blob = new File(aWindow, new FileImplFile(fullPath, aFile->mMimeType, aFile->mLength, aFile->mFile, aFile->mLastModifiedDate)); @@ -2876,7 +2876,7 @@ public: nsIPrincipal* aPrincipal, DeviceStorageFile* aFile, DOMRequest* aRequest, - Blob* aBlob = nullptr) + nsIDOMBlob* 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(mBlob.get())); + static_cast(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(mBlob.get())); + static_cast(mBlob.get())); if (!actor) { return NS_ERROR_FAILURE; } @@ -3331,7 +3331,7 @@ private: nsRefPtr mFile; nsRefPtr mRequest; - nsRefPtr mBlob; + nsCOMPtr mBlob; nsRefPtr mDeviceStorage; nsRefPtr mDSFileDescriptor; nsCOMPtr mRequester; @@ -3741,13 +3741,13 @@ NS_IMETHODIMP nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval) { ErrorResult rv; - nsRefPtr request = Add(static_cast(aBlob), rv); + nsRefPtr request = Add(aBlob, rv); request.forget(_retval); return rv.StealNSResult(); } already_AddRefed -nsDOMDeviceStorage::Add(Blob* aBlob, ErrorResult& aRv) +nsDOMDeviceStorage::Add(nsIDOMBlob* aBlob, ErrorResult& aRv) { if (!aBlob) { return nullptr; @@ -3790,13 +3790,13 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval) { ErrorResult rv; - nsRefPtr request = AddNamed(static_cast(aBlob), aPath, rv); + nsRefPtr request = AddNamed(aBlob, aPath, rv); request.forget(_retval); return rv.StealNSResult(); } already_AddRefed -nsDOMDeviceStorage::AddNamed(Blob* aBlob, const nsAString& aPath, +nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv) { return AddOrAppendNamed(aBlob, aPath, @@ -3804,7 +3804,7 @@ nsDOMDeviceStorage::AddNamed(Blob* aBlob, const nsAString& aPath, } already_AddRefed -nsDOMDeviceStorage::AppendNamed(Blob* aBlob, const nsAString& aPath, +nsDOMDeviceStorage::AppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv) { return AddOrAppendNamed(aBlob, aPath, @@ -3813,7 +3813,7 @@ nsDOMDeviceStorage::AppendNamed(Blob* aBlob, const nsAString& aPath, already_AddRefed -nsDOMDeviceStorage::AddOrAppendNamed(Blob* aBlob, const nsAString& aPath, +nsDOMDeviceStorage::AddOrAppendNamed(nsIDOMBlob* aBlob, const nsAString& aPath, const int32_t aRequestType, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); diff --git a/dom/devicestorage/nsDeviceStorage.h b/dom/devicestorage/nsDeviceStorage.h index 9409cdd1bbb..7c2b1c2578c 100644 --- a/dom/devicestorage/nsDeviceStorage.h +++ b/dom/devicestorage/nsDeviceStorage.h @@ -33,10 +33,6 @@ class nsPIDOMWindow; namespace mozilla { class ErrorResult; - -namespace dom { -class Blob; -} } // namespace mozilla #define POST_ERROR_EVENT_FILE_EXISTS "NoModificationAllowedError" @@ -161,7 +157,7 @@ public: void InitFromBundle(nsIStringBundle* aBundle); - bool Check(const nsAString& aType, mozilla::dom::Blob* aBlob); + bool Check(const nsAString& aType, nsIDOMBlob* aBlob); bool Check(const nsAString& aType, nsIFile* aFile); bool Check(const nsAString& aType, const nsString& aPath); void GetTypeFromFile(nsIFile* aFile, nsAString& aType); diff --git a/dom/events/DataTransfer.cpp b/dom/events/DataTransfer.cpp index 051cef121ed..c8c5b3fd234 100644 --- a/dom/events/DataTransfer.cpp +++ b/dom/events/DataTransfer.cpp @@ -308,11 +308,7 @@ DataTransfer::GetFiles(ErrorResult& aRv) if (!fileImpl) { continue; } - - MOZ_ASSERT(fileImpl->IsFile()); - - domFile = File::Create(GetParentObject(), fileImpl); - MOZ_ASSERT(domFile); + domFile = new File(GetParentObject(), static_cast(fileImpl.get())); } if (!mFiles->Append(domFile)) { diff --git a/dom/fetch/Fetch.cpp b/dom/fetch/Fetch.cpp index 86b4aa96e53..e0f8c7cdfff 100644 --- a/dom/fetch/Fetch.cpp +++ b/dom/fetch/Fetch.cpp @@ -446,10 +446,10 @@ ExtractFromArrayBufferView(const ArrayBufferView& aBuffer, } nsresult -ExtractFromBlob(const Blob& aBlob, nsIInputStream** aStream, +ExtractFromBlob(const File& aFile, nsIInputStream** aStream, nsCString& aContentType) { - nsRefPtr impl = aBlob.Impl(); + nsRefPtr impl = aFile.Impl(); nsresult rv = impl->GetInternalStream(aStream); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; @@ -773,7 +773,7 @@ private: } p = nullptr; - nsRefPtr file = + nsRefPtr file = File::CreateMemoryFile(mParentObject, reinterpret_cast(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 Blob& blob = aBodyInit.GetAsBlob(); + const File& 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 Blob& blob = aBodyInit.GetAsBlob(); + const File& blob = aBodyInit.GetAsBlob(); return ExtractFromBlob(blob, aStream, aContentType); } else if (aBodyInit.IsFormData()) { nsFormData& form = aBodyInit.GetAsFormData(); @@ -1507,10 +1507,9 @@ FetchBody::ContinueConsumeBody(nsresult aStatus, uint32_t aResultLength return; } case CONSUME_BLOB: { - nsRefPtr blob = - Blob::CreateMemoryBlob(DerivedClass()->GetParentObject(), - reinterpret_cast(aResult), aResultLength, - NS_ConvertUTF8toUTF16(mMimeType)); + nsRefPtr blob = + File::CreateMemoryFile(DerivedClass()->GetParentObject(), + reinterpret_cast(aResult), aResultLength, NS_ConvertUTF8toUTF16(mMimeType)); if (!blob) { localPromise->MaybeReject(NS_ERROR_DOM_UNKNOWN_ERR); diff --git a/dom/filehandle/FileHandle.cpp b/dom/filehandle/FileHandle.cpp index 405266646df..9b0662b3e9d 100644 --- a/dom/filehandle/FileHandle.cpp +++ b/dom/filehandle/FileHandle.cpp @@ -622,10 +622,10 @@ FileHandleBase::GetInputStream(const ArrayBuffer& aValue, // static already_AddRefed -FileHandleBase::GetInputStream(const Blob& aValue, uint64_t* aInputLength, +FileHandleBase::GetInputStream(const File& aValue, uint64_t* aInputLength, ErrorResult& aRv) { - Blob& file = const_cast(aValue); + File& file = const_cast(aValue); uint64_t length = file.GetSize(aRv); if (aRv.Failed()) { return nullptr; diff --git a/dom/filehandle/FileHandle.h b/dom/filehandle/FileHandle.h index a79ce43a3fb..1cce8f8c5d8 100644 --- a/dom/filehandle/FileHandle.h +++ b/dom/filehandle/FileHandle.h @@ -25,7 +25,7 @@ class nsAString; namespace mozilla { namespace dom { -class Blob; +class File; class FileHelper; class FileRequestBase; class FileService; @@ -240,7 +240,7 @@ protected: ErrorResult& aRv); static already_AddRefed - GetInputStream(const Blob& aValue, uint64_t* aInputLength, + GetInputStream(const File& aValue, uint64_t* aInputLength, ErrorResult& aRv); static already_AddRefed diff --git a/dom/filesystem/CreateFileTask.cpp b/dom/filesystem/CreateFileTask.cpp index 869f1c9067b..fef43bf0e79 100644 --- a/dom/filesystem/CreateFileTask.cpp +++ b/dom/filesystem/CreateFileTask.cpp @@ -27,7 +27,7 @@ uint32_t CreateFileTask::sOutputBufferSize = 0; CreateFileTask::CreateFileTask(FileSystemBase* aFileSystem, const nsAString& aPath, - Blob* aBlobData, + File* aBlobData, InfallibleTArray& aArrayData, bool replace, ErrorResult& aRv) @@ -127,7 +127,9 @@ FileSystemResponseValue CreateFileTask::GetSuccessRequestResult() const { MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); - BlobParent* actor = GetBlobParent(mTargetFileImpl); + nsRefPtr file = new File(mFileSystem->GetWindow(), + mTargetFileImpl); + BlobParent* actor = GetBlobParent(file); if (!actor) { return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR); } @@ -301,8 +303,8 @@ CreateFileTask::HandlerCallback() return; } - nsRefPtr blob = Blob::Create(mFileSystem->GetWindow(), mTargetFileImpl); - mPromise->MaybeResolve(blob); + nsCOMPtr file = new File(mFileSystem->GetWindow(), mTargetFileImpl); + mPromise->MaybeResolve(file); mPromise = nullptr; mBlobData = nullptr; } diff --git a/dom/filesystem/CreateFileTask.h b/dom/filesystem/CreateFileTask.h index ded39b18cd8..d33c46b7a1e 100644 --- a/dom/filesystem/CreateFileTask.h +++ b/dom/filesystem/CreateFileTask.h @@ -16,7 +16,7 @@ class nsIInputStream; namespace mozilla { namespace dom { -class Blob; +class File; class FileImpl; class Promise; @@ -26,7 +26,7 @@ class CreateFileTask final public: CreateFileTask(FileSystemBase* aFileSystem, const nsAString& aPath, - Blob* aBlobData, + File* aBlobData, InfallibleTArray& aArrayData, bool replace, ErrorResult& aRv); @@ -68,7 +68,7 @@ private: nsString mTargetRealPath; // Not thread-safe and should be released on main thread. - nsRefPtr mBlobData; + nsRefPtr mBlobData; nsCOMPtr mBlobStream; InfallibleTArray mArrayData; diff --git a/dom/filesystem/Directory.cpp b/dom/filesystem/Directory.cpp index be1eaa1d534..4034af9d4f4 100644 --- a/dom/filesystem/Directory.cpp +++ b/dom/filesystem/Directory.cpp @@ -100,7 +100,7 @@ Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions, { nsresult error = NS_OK; nsString realPath; - nsRefPtr blobData; + nsRefPtr blobData; InfallibleTArray arrayData; bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace); diff --git a/dom/filesystem/FileSystemTaskBase.cpp b/dom/filesystem/FileSystemTaskBase.cpp index 5eadc44fd11..674c24fd635 100644 --- a/dom/filesystem/FileSystemTaskBase.cpp +++ b/dom/filesystem/FileSystemTaskBase.cpp @@ -154,7 +154,7 @@ FileSystemTaskBase::Recv__delete__(const FileSystemResponseValue& aValue) } BlobParent* -FileSystemTaskBase::GetBlobParent(FileImpl* aFile) const +FileSystemTaskBase::GetBlobParent(nsIDOMFile* aFile) const { MOZ_ASSERT(FileSystemUtils::IsParentProcess(), "Only call from parent process!"); @@ -164,23 +164,13 @@ FileSystemTaskBase::GetBlobParent(FileImpl* aFile) const // Load the lazy dom file data from the parent before sending to the child. nsString mimeType; aFile->GetType(mimeType); - - // 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(); - } + uint64_t fileSize; + aFile->GetSize(&fileSize); + int64_t lastModifiedDate; + aFile->GetMozLastModifiedDate(&lastModifiedDate); ContentParent* cp = static_cast(mRequestParent->Manager()); - return cp->GetOrCreateActorForFileImpl(aFile); + return cp->GetOrCreateActorForBlob(static_cast(aFile)); } void diff --git a/dom/filesystem/FileSystemTaskBase.h b/dom/filesystem/FileSystemTaskBase.h index eaecbbc4deb..de2c63043fa 100644 --- a/dom/filesystem/FileSystemTaskBase.h +++ b/dom/filesystem/FileSystemTaskBase.h @@ -11,11 +11,12 @@ #include "mozilla/dom/FileSystemRequestParent.h" #include "mozilla/dom/PFileSystemRequestChild.h" +class nsIDOMFile; + namespace mozilla { namespace dom { class BlobParent; -class FileImpl; class FileSystemBase; class FileSystemParams; @@ -204,7 +205,7 @@ protected: Recv__delete__(const FileSystemResponseValue& value) override; BlobParent* - GetBlobParent(FileImpl* aFile) const; + GetBlobParent(nsIDOMFile* aFile) const; nsresult mErrorValue; diff --git a/dom/filesystem/GetFileOrDirectoryTask.cpp b/dom/filesystem/GetFileOrDirectoryTask.cpp index 9c34fc9eadf..4e88258b28d 100644 --- a/dom/filesystem/GetFileOrDirectoryTask.cpp +++ b/dom/filesystem/GetFileOrDirectoryTask.cpp @@ -82,7 +82,8 @@ GetFileOrDirectoryTask::GetSuccessRequestResult() const return FileSystemDirectoryResponse(mTargetRealPath); } - BlobParent* actor = GetBlobParent(mTargetFileImpl); + nsRefPtr file = new File(mFileSystem->GetWindow(), mTargetFileImpl); + BlobParent* actor = GetBlobParent(file); if (!actor) { return FileSystemErrorResponse(NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR); } @@ -213,8 +214,8 @@ GetFileOrDirectoryTask::HandlerCallback() return; } - nsRefPtr blob = Blob::Create(mFileSystem->GetWindow(), mTargetFileImpl); - mPromise->MaybeResolve(blob); + nsRefPtr file = new File(mFileSystem->GetWindow(), mTargetFileImpl); + mPromise->MaybeResolve(file); mPromise = nullptr; } diff --git a/dom/filesystem/RemoveTask.cpp b/dom/filesystem/RemoveTask.cpp index 82b71eef587..14fa7874da9 100644 --- a/dom/filesystem/RemoveTask.cpp +++ b/dom/filesystem/RemoveTask.cpp @@ -92,10 +92,9 @@ RemoveTask::GetRequestParams(const nsString& aFileSystem) const param.directory() = mDirRealPath; param.recursive() = mRecursive; if (mTargetFileImpl) { - nsRefPtr blob = Blob::Create(mFileSystem->GetWindow(), - mTargetFileImpl); + nsRefPtr file = new File(mFileSystem->GetWindow(), mTargetFileImpl); BlobChild* actor - = ContentChild::GetSingleton()->GetOrCreateActorForBlob(blob); + = ContentChild::GetSingleton()->GetOrCreateActorForBlob(file); if (actor) { param.target() = actor; } diff --git a/dom/html/HTMLCanvasElement.cpp b/dom/html/HTMLCanvasElement.cpp index 5e4a871de4a..8bfcccd39bd 100644 --- a/dom/html/HTMLCanvasElement.cpp +++ b/dom/html/HTMLCanvasElement.cpp @@ -555,9 +555,9 @@ HTMLCanvasElement::ToBlob(JSContext* aCx, , mFileCallback(aCallback) {} // This is called on main thread. - nsresult ReceiveBlob(already_AddRefed aBlob) + nsresult ReceiveBlob(already_AddRefed aBlob) { - nsRefPtr blob = aBlob; + nsRefPtr blob = aBlob; uint64_t size; nsresult rv = blob->GetSize(&size); if (NS_SUCCEEDED(rv)) { @@ -567,7 +567,7 @@ HTMLCanvasElement::ToBlob(JSContext* aCx, } } - nsRefPtr newBlob = Blob::Create(mGlobal, blob->Impl()); + nsRefPtr newBlob = new File(mGlobal, blob->Impl()); mozilla::ErrorResult error; mFileCallback->Call(*newBlob, error); diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index 20a376cadaa..d21f5820fa8 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -561,8 +561,7 @@ public: nsCOMPtr global = mInput->OwnerDoc()->GetScopeObject(); for (uint32_t i = 0; i < mFileList.Length(); ++i) { MOZ_ASSERT(!mFileList[i]->GetParentObject()); - mFileList[i] = File::Create(global, mFileList[i]->Impl()); - MOZ_ASSERT(mFileList[i]); + mFileList[i] = new File(global, mFileList[i]->Impl()); } // The text control frame (if there is one) isn't going to send a change @@ -2348,10 +2347,7 @@ HTMLInputElement::MozSetFileArray(const Sequence>& aFiles) } nsTArray> files; for (uint32_t i = 0; i < aFiles.Length(); ++i) { - nsRefPtr file = File::Create(global, aFiles[i].get()->Impl()); - MOZ_ASSERT(file); - - files.AppendElement(file); + files.AppendElement(new File(global, aFiles[i].get()->Impl())); } SetFiles(files, true); } @@ -6022,9 +6018,7 @@ HTMLInputElement::RestoreState(nsPresState* aState) nsTArray> files; for (uint32_t i = 0, len = fileImpls.Length(); i < len; ++i) { - nsRefPtr file = File::Create(global, fileImpls[i]); - MOZ_ASSERT(file); - + nsRefPtr file = new File(global, fileImpls[i]); files.AppendElement(file); } diff --git a/dom/html/nsFormSubmission.cpp b/dom/html/nsFormSubmission.cpp index 428d7e3456e..e24424bffca 100644 --- a/dom/html/nsFormSubmission.cpp +++ b/dom/html/nsFormSubmission.cpp @@ -77,12 +77,11 @@ public: } virtual nsresult AddNameValuePair(const nsAString& aName, - const nsAString& aValue) override; + const nsAString& aValue); virtual nsresult AddNameFilePair(const nsAString& aName, - File* aFile) override; + File* aBlob); virtual nsresult GetEncodedSubmission(nsIURI* aURI, - nsIInputStream** aPostDataStream) - override; + nsIInputStream** aPostDataStream); virtual bool SupportsIsindexSubmission() override { @@ -166,7 +165,7 @@ nsFSURLEncoded::AddIsindex(const nsAString& aValue) nsresult nsFSURLEncoded::AddNameFilePair(const nsAString& aName, - File* aFile) + File* aBlob) { if (!mWarnedFileControl) { SendJSWarning(mDocument, "ForgotFileEnctypeWarning", nullptr, 0); @@ -174,8 +173,8 @@ nsFSURLEncoded::AddNameFilePair(const nsAString& aName, } nsAutoString filename; - if (aFile) { - aFile->GetName(filename); + if (aBlob && aBlob->IsFile()) { + aBlob->GetName(filename); } return AddNameValuePair(aName, filename); @@ -440,7 +439,7 @@ nsFSMultipartFormData::AddNameValuePair(const nsAString& aName, nsresult nsFSMultipartFormData::AddNameFilePair(const nsAString& aName, - File* aFile) + File* aBlob) { // Encode the control name nsAutoCString nameStr; @@ -449,15 +448,18 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName, nsCString filename, contentType; nsCOMPtr fileStream; - if (aFile) { + 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()); nsAutoString filename16; - rv = aFile->GetName(filename16); + rv = aBlob->GetName(filename16); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } nsAutoString filepath16; - rv = aFile->GetPath(filepath16); + rv = aBlob->GetPath(filepath16); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -472,7 +474,7 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName, // Get content type nsAutoString contentType16; - rv = aFile->GetType(contentType16); + rv = aBlob->GetType(contentType16); if (NS_FAILED(rv) || contentType16.IsEmpty()) { contentType16.AssignLiteral("application/octet-stream"); } @@ -482,7 +484,7 @@ nsFSMultipartFormData::AddNameFilePair(const nsAString& aName, nsLinebreakConverter::eLinebreakSpace)); // Get input stream - rv = aFile->GetInternalStream(getter_AddRefs(fileStream)); + rv = aBlob->GetInternalStream(getter_AddRefs(fileStream)); NS_ENSURE_SUCCESS(rv, rv); if (fileStream) { // Create buffered stream (for efficiency) @@ -517,7 +519,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(aFile->GetSize(&size))) { + if (fileStream && NS_SUCCEEDED(aBlob->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(); @@ -585,12 +587,11 @@ public: } virtual nsresult AddNameValuePair(const nsAString& aName, - const nsAString& aValue) override; + const nsAString& aValue); virtual nsresult AddNameFilePair(const nsAString& aName, - File* aFile) override; + File* aBlob); virtual nsresult GetEncodedSubmission(nsIURI* aURI, - nsIInputStream** aPostDataStream) - override; + nsIInputStream** aPostDataStream); private: nsString mBody; @@ -611,11 +612,11 @@ nsFSTextPlain::AddNameValuePair(const nsAString& aName, nsresult nsFSTextPlain::AddNameFilePair(const nsAString& aName, - File* aFile) + File* aBlob) { nsAutoString filename; - if (aFile) { - aFile->GetName(filename); + if (aBlob && aBlob->IsFile()) { + aBlob->GetName(filename); } AddNameValuePair(aName, filename); diff --git a/dom/html/nsFormSubmission.h b/dom/html/nsFormSubmission.h index e95ee9107e5..2bede79b567 100644 --- a/dom/html/nsFormSubmission.h +++ b/dom/html/nsFormSubmission.h @@ -48,10 +48,10 @@ public: * Submit a name/file pair * * @param aName the name of the parameter - * @param aFile the file to submit. The file's name will be used + * @param aBlob the file to submit. The file's name will be used */ virtual nsresult AddNameFilePair(const nsAString& aName, - mozilla::dom::File* aFile) = 0; + mozilla::dom::File* aBlob) = 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* aFile) override; + mozilla::dom::File* aBlob) override; virtual nsresult GetEncodedSubmission(nsIURI* aURI, nsIInputStream** aPostDataStream) override; diff --git a/dom/indexedDB/ActorsChild.cpp b/dom/indexedDB/ActorsChild.cpp index 4f4f50791e2..d44b4fd026c 100644 --- a/dom/indexedDB/ActorsChild.cpp +++ b/dom/indexedDB/ActorsChild.cpp @@ -614,7 +614,7 @@ ConvertActorsToBlobs(IDBDatabase* aDatabase, nsRefPtr blobImpl = actor->GetBlobImpl(); MOZ_ASSERT(blobImpl); - nsRefPtr blob = Blob::Create(aDatabase->GetOwner(), blobImpl); + nsRefPtr blob = new File(aDatabase->GetOwner(), blobImpl); nsRefPtr fileInfo; if (!fileInfos.IsEmpty()) { @@ -631,7 +631,7 @@ ConvertActorsToBlobs(IDBDatabase* aDatabase, StructuredCloneFile* file = aFiles.AppendElement(); MOZ_ASSERT(file); - file->mBlob.swap(blob); + file->mFile.swap(blob); file->mFileInfo.swap(fileInfo); } } diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index c50cffb2520..9d3bd99d0f7 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -7718,7 +7718,6 @@ 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: diff --git a/dom/indexedDB/IDBDatabase.cpp b/dom/indexedDB/IDBDatabase.cpp index d88b94ddb18..f356e95526b 100644 --- a/dom/indexedDB/IDBDatabase.cpp +++ b/dom/indexedDB/IDBDatabase.cpp @@ -959,7 +959,7 @@ IDBDatabase::AbortTransactions(bool aShouldWarn) } PBackgroundIDBDatabaseFileChild* -IDBDatabase::GetOrCreateFileActorForBlob(Blob* aBlob) +IDBDatabase::GetOrCreateFileActorForBlob(File* aBlob) { AssertIsOnOwningThread(); MOZ_ASSERT(aBlob); @@ -1068,7 +1068,7 @@ IDBDatabase::NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild* aFileActor) } void -IDBDatabase::NoteReceivedBlob(Blob* aBlob) +IDBDatabase::NoteReceivedBlob(File* aBlob) { AssertIsOnOwningThread(); MOZ_ASSERT(aBlob); diff --git a/dom/indexedDB/IDBDatabase.h b/dom/indexedDB/IDBDatabase.h index 4aed0e3ea4b..33016ce1f73 100644 --- a/dom/indexedDB/IDBDatabase.h +++ b/dom/indexedDB/IDBDatabase.h @@ -28,7 +28,7 @@ class EventChainPostVisitor; namespace dom { -class Blob; +class File; class DOMStringList; struct IDBObjectStoreParameters; template class Optional; @@ -177,13 +177,13 @@ public: AbortTransactions(bool aShouldWarn); PBackgroundIDBDatabaseFileChild* - GetOrCreateFileActorForBlob(Blob* aBlob); + GetOrCreateFileActorForBlob(File* aBlob); void NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild* aFileActor); void - NoteReceivedBlob(Blob* aBlob); + NoteReceivedBlob(File* aBlob); void DelayedMaybeExpireFileActors(); diff --git a/dom/indexedDB/IDBMutableFile.cpp b/dom/indexedDB/IDBMutableFile.cpp index 0ae3a216154..2c9cad62f69 100644 --- a/dom/indexedDB/IDBMutableFile.cpp +++ b/dom/indexedDB/IDBMutableFile.cpp @@ -340,10 +340,8 @@ IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle, aFileHandle, mFileInfo); - nsRefPtr file = File::Create(GetOwner(), impl); - MOZ_ASSERT(file); - - return file.forget(); + nsCOMPtr fileSnapshot = new File(GetOwner(), impl); + return fileSnapshot.forget(); } already_AddRefed diff --git a/dom/indexedDB/IDBObjectStore.cpp b/dom/indexedDB/IDBObjectStore.cpp index abd2e053788..7fb06a9d634 100644 --- a/dom/indexedDB/IDBObjectStore.cpp +++ b/dom/indexedDB/IDBObjectStore.cpp @@ -62,7 +62,7 @@ struct IDBObjectStore::StructuredCloneWriteInfo { struct BlobOrFileInfo { - nsRefPtr mBlob; + nsRefPtr mBlob; nsRefPtr mFileInfo; bool @@ -300,7 +300,7 @@ StructuredCloneWriteCallback(JSContext* aCx, } { - Blob* blob = nullptr; + File* blob = nullptr; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) { uint64_t size; MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetSize(&size))); @@ -332,16 +332,15 @@ StructuredCloneWriteCallback(JSContext* aCx, return false; } - nsRefPtr file = blob->ToFile(); - if (file) { + if (blob->IsFile()) { int64_t lastModifiedDate; MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - file->GetMozLastModifiedDate(&lastModifiedDate))); + blob->GetMozLastModifiedDate(&lastModifiedDate))); lastModifiedDate = NativeEndian::swapToLittleEndian(lastModifiedDate); nsString name; - MOZ_ALWAYS_TRUE(NS_SUCCEEDED(file->GetName(name))); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(blob->GetName(name))); NS_ConvertUTF16toUTF8 convName(name); uint32_t convNameLength = @@ -403,11 +402,11 @@ GetAddInfoCallback(JSContext* aCx, void* aClosure) } BlobChild* -ActorFromRemoteFileImpl(FileImpl* aImpl) +ActorFromRemoteBlob(File* aBlob) { - MOZ_ASSERT(aImpl); + MOZ_ASSERT(aBlob); - nsCOMPtr remoteBlob = do_QueryInterface(aImpl); + nsCOMPtr remoteBlob = do_QueryInterface(aBlob->Impl()); if (remoteBlob) { BlobChild* actor = remoteBlob->GetBlobChild(); MOZ_ASSERT(actor); @@ -429,13 +428,13 @@ ActorFromRemoteFileImpl(FileImpl* aImpl) } bool -ResolveMysteryFile(FileImpl* aImpl, +ResolveMysteryFile(File* aBlob, const nsString& aName, const nsString& aContentType, uint64_t aSize, uint64_t aLastModifiedDate) { - BlobChild* actor = ActorFromRemoteFileImpl(aImpl); + BlobChild* actor = ActorFromRemoteBlob(aBlob); if (actor) { return actor->SetMysteryBlobInfo(aName, aContentType, aSize, aLastModifiedDate); @@ -444,11 +443,11 @@ ResolveMysteryFile(FileImpl* aImpl, } bool -ResolveMysteryBlob(FileImpl* aImpl, +ResolveMysteryBlob(File* aBlob, const nsString& aContentType, uint64_t aSize) { - BlobChild* actor = ActorFromRemoteFileImpl(aImpl); + BlobChild* actor = ActorFromRemoteBlob(aBlob); if (actor) { return actor->SetMysteryBlobInfo(aContentType, aSize); } @@ -606,7 +605,7 @@ public: MOZ_ASSERT(aData.tag == SCTAG_DOM_FILE || aData.tag == SCTAG_DOM_FILE_WITHOUT_LASTMODIFIEDDATE || aData.tag == SCTAG_DOM_BLOB); - MOZ_ASSERT(aFile.mBlob); + MOZ_ASSERT(aFile.mFile); // 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. @@ -628,18 +627,17 @@ public: } MOZ_ASSERT(parent); + nsRefPtr file = new File(parent, aFile.mFile->Impl()); if (aData.tag == SCTAG_DOM_BLOB) { - if (NS_WARN_IF(!ResolveMysteryBlob(aFile.mBlob->Impl(), + if (NS_WARN_IF(!ResolveMysteryBlob(aFile.mFile, aData.type, aData.size))) { return false; } - MOZ_ASSERT(!aFile.mBlob->IsFile()); - JS::Rooted wrappedBlob(aCx); - if (!ToJSValue(aCx, aFile.mBlob, &wrappedBlob)) { + if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedBlob)) { return false; } @@ -647,7 +645,9 @@ public: return true; } - if (NS_WARN_IF(!ResolveMysteryFile(aFile.mBlob->Impl(), + MOZ_ASSERT(aFile.mFile->IsFile()); + + if (NS_WARN_IF(!ResolveMysteryFile(aFile.mFile, aData.name, aData.type, aData.size, @@ -655,12 +655,8 @@ public: return false; } - MOZ_ASSERT(aFile.mBlob->IsFile()); - nsRefPtr file = aFile.mBlob->ToFile(); - MOZ_ASSERT(file); - JS::Rooted wrappedFile(aCx); - if (!ToJSValue(aCx, file, &wrappedFile)) { + if (!GetOrCreateDOMReflector(aCx, aFile.mFile, &wrappedFile)) { return false; } diff --git a/dom/indexedDB/IndexedDatabase.h b/dom/indexedDB/IndexedDatabase.h index 5144896f08a..9796b489012 100644 --- a/dom/indexedDB/IndexedDatabase.h +++ b/dom/indexedDB/IndexedDatabase.h @@ -15,7 +15,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; namespace indexedDB { @@ -25,7 +25,7 @@ class SerializedStructuredCloneReadInfo; struct StructuredCloneFile { - nsRefPtr mBlob; + nsRefPtr mFile; nsRefPtr mFileInfo; // In IndexedDatabaseInlines.h diff --git a/dom/indexedDB/IndexedDatabaseInlines.h b/dom/indexedDB/IndexedDatabaseInlines.h index 2845ff17da6..7e3f326b832 100644 --- a/dom/indexedDB/IndexedDatabaseInlines.h +++ b/dom/indexedDB/IndexedDatabaseInlines.h @@ -36,7 +36,7 @@ inline bool StructuredCloneFile::operator==(const StructuredCloneFile& aOther) const { - return this->mBlob == aOther.mBlob && + return this->mFile == aOther.mFile && this->mFileInfo == aOther.mFileInfo; } diff --git a/dom/ipc/FilePickerParent.cpp b/dom/ipc/FilePickerParent.cpp index dee62432538..107b3c109af 100644 --- a/dom/ipc/FilePickerParent.cpp +++ b/dom/ipc/FilePickerParent.cpp @@ -117,9 +117,10 @@ FilePickerParent::SendFiles(const nsTArray>& aFiles) InfallibleTArray files; for (unsigned i = 0; i < aFiles.Length(); i++) { - BlobParent* blobParent = parent->GetOrCreateActorForFileImpl(aFiles[i]); - if (blobParent) { - files.AppendElement(blobParent); + nsRefPtr file = new File(nullptr, aFiles[i]); + BlobParent* blob = parent->GetOrCreateActorForBlob(file); + if (blob) { + files.AppendElement(blob); } } diff --git a/dom/ipc/StructuredCloneUtils.cpp b/dom/ipc/StructuredCloneUtils.cpp index cba261c1f7a..81fdb8817a9 100644 --- a/dom/ipc/StructuredCloneUtils.cpp +++ b/dom/ipc/StructuredCloneUtils.cpp @@ -51,11 +51,11 @@ Read(JSContext* aCx, JSStructuredCloneReader* aReader, uint32_t aTag, JS::Rooted val(aCx); { MOZ_ASSERT(aData < closure->mBlobs.Length()); - nsRefPtr blob = closure->mBlobs[aData]; + nsRefPtr blob = closure->mBlobs[aData]; #ifdef DEBUG { - // Blob should not be mutable. + // File 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 newBlob = Blob::Create(global, blob->Impl()); - if (!ToJSValue(aCx, newBlob, &val)) { + nsRefPtr newBlob = new File(global, blob->Impl()); + if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) { return nullptr; } } @@ -89,7 +89,7 @@ Write(JSContext* aCx, JSStructuredCloneWriter* aWriter, // See if the wrapped native is a File/Blob. { - Blob* blob = nullptr; + File* blob = nullptr; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob)) && NS_SUCCEEDED(blob->SetMutable(false)) && JS_WriteUint32Pair(aWriter, SCTAG_DOM_BLOB, diff --git a/dom/ipc/StructuredCloneUtils.h b/dom/ipc/StructuredCloneUtils.h index b103d54a412..3f147a39635 100644 --- a/dom/ipc/StructuredCloneUtils.h +++ b/dom/ipc/StructuredCloneUtils.h @@ -19,7 +19,7 @@ namespace dom { struct StructuredCloneClosure { - nsTArray> mBlobs; + nsTArray> mBlobs; }; struct diff --git a/dom/ipc/nsIContentChild.cpp b/dom/ipc/nsIContentChild.cpp index 36f9f90b35a..99aa5c9a040 100644 --- a/dom/ipc/nsIContentChild.cpp +++ b/dom/ipc/nsIContentChild.cpp @@ -93,7 +93,7 @@ nsIContentChild::DeallocPBlobChild(PBlobChild* aActor) } BlobChild* -nsIContentChild::GetOrCreateActorForBlob(Blob* aBlob) +nsIContentChild::GetOrCreateActorForBlob(File* aBlob) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aBlob); @@ -101,16 +101,7 @@ nsIContentChild::GetOrCreateActorForBlob(Blob* aBlob) nsRefPtr blobImpl = aBlob->Impl(); MOZ_ASSERT(blobImpl); - return GetOrCreateActorForFileImpl(blobImpl); -} - -BlobChild* -nsIContentChild::GetOrCreateActorForFileImpl(FileImpl* aImpl) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aImpl); - - BlobChild* actor = BlobChild::GetOrCreate(this, aImpl); + BlobChild* actor = BlobChild::GetOrCreate(this, blobImpl); NS_ENSURE_TRUE(actor, nullptr); return actor; diff --git a/dom/ipc/nsIContentChild.h b/dom/ipc/nsIContentChild.h index 6869ea712cb..7e93da699d8 100644 --- a/dom/ipc/nsIContentChild.h +++ b/dom/ipc/nsIContentChild.h @@ -32,11 +32,10 @@ class CpowEntry; namespace dom { -class Blob; class BlobChild; class BlobConstructorParams; class ClonedMessageData; -class FileImpl; +class File; class IPCTabContext; class PBlobChild; class PBrowserChild; @@ -47,8 +46,7 @@ class nsIContentChild : public nsISupports public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENTCHILD_IID) - BlobChild* GetOrCreateActorForBlob(Blob* aBlob); - BlobChild* GetOrCreateActorForFileImpl(FileImpl* aImpl); + BlobChild* GetOrCreateActorForBlob(File* aBlob); virtual PBlobChild* SendPBlobConstructor( PBlobChild* aActor, diff --git a/dom/ipc/nsIContentParent.cpp b/dom/ipc/nsIContentParent.cpp index 59628b2746c..bbb61364227 100644 --- a/dom/ipc/nsIContentParent.cpp +++ b/dom/ipc/nsIContentParent.cpp @@ -159,7 +159,7 @@ nsIContentParent::DeallocPBlobParent(PBlobParent* aActor) } BlobParent* -nsIContentParent::GetOrCreateActorForBlob(Blob* aBlob) +nsIContentParent::GetOrCreateActorForBlob(File* aBlob) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aBlob); @@ -167,16 +167,7 @@ nsIContentParent::GetOrCreateActorForBlob(Blob* aBlob) nsRefPtr blobImpl = aBlob->Impl(); MOZ_ASSERT(blobImpl); - return GetOrCreateActorForFileImpl(blobImpl); -} - -BlobParent* -nsIContentParent::GetOrCreateActorForFileImpl(FileImpl* aImpl) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aImpl); - - BlobParent* actor = BlobParent::GetOrCreate(this, aImpl); + BlobParent* actor = BlobParent::GetOrCreate(this, blobImpl); NS_ENSURE_TRUE(actor, nullptr); return actor; diff --git a/dom/ipc/nsIContentParent.h b/dom/ipc/nsIContentParent.h index c46a82e5bd3..c4cd120dae5 100644 --- a/dom/ipc/nsIContentParent.h +++ b/dom/ipc/nsIContentParent.h @@ -33,11 +33,10 @@ class CpowEntry; namespace dom { -class Blob; class BlobConstructorParams; class BlobParent; class ContentParent; -class FileImpl; +class File; class IPCTabContext; class PBlobParent; class PBrowserParent; @@ -51,8 +50,7 @@ public: nsIContentParent(); - BlobParent* GetOrCreateActorForBlob(Blob* aBlob); - BlobParent* GetOrCreateActorForFileImpl(FileImpl* aImpl); + BlobParent* GetOrCreateActorForBlob(File* aBlob); virtual ContentParentId ChildID() = 0; virtual bool IsForApp() = 0; diff --git a/dom/media/EncodedBufferCache.cpp b/dom/media/EncodedBufferCache.cpp index d43d5924c21..283e5ef2bfa 100644 --- a/dom/media/EncodedBufferCache.cpp +++ b/dom/media/EncodedBufferCache.cpp @@ -39,16 +39,16 @@ EncodedBufferCache::AppendBuffer(nsTArray & aBuf) } -already_AddRefed +already_AddRefed EncodedBufferCache::ExtractBlob(nsISupports* aParent, const nsAString &aContentType) { MutexAutoLock lock(mMutex); - nsRefPtr blob; + nsRefPtr blob; if (mTempFileEnabled) { // generate new temporary file to write - blob = dom::Blob::CreateTemporaryBlob(aParent, mFD, 0, mDataSize, - aContentType); + blob = dom::File::CreateTemporaryFileBlob(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::Blob::CreateMemoryBlob(aParent, blobData, mDataSize, + blob = dom::File::CreateMemoryFile(aParent, blobData, mDataSize, aContentType); mEncodedBuffers.Clear(); } else diff --git a/dom/media/EncodedBufferCache.h b/dom/media/EncodedBufferCache.h index e0a921a823f..8b78efa9002 100644 --- a/dom/media/EncodedBufferCache.h +++ b/dom/media/EncodedBufferCache.h @@ -16,7 +16,7 @@ struct PRFileDesc; namespace mozilla { namespace dom { -class Blob; +class File; } /** @@ -41,7 +41,7 @@ public: // aBuf will append to mEncodedBuffers or temporary File, aBuf also be cleared void AppendBuffer(nsTArray & aBuf); // Read all buffer from memory or file System, also Remove the temporary file or clean the buffers in memory. - already_AddRefed ExtractBlob(nsISupports* aParent, const nsAString &aContentType); + already_AddRefed ExtractBlob(nsISupports* aParent, const nsAString &aContentType); private: //array for storing the encoded data. diff --git a/dom/media/MediaRecorder.cpp b/dom/media/MediaRecorder.cpp index 65bfc3821e9..7500a79b761 100644 --- a/dom/media/MediaRecorder.cpp +++ b/dom/media/MediaRecorder.cpp @@ -1017,7 +1017,7 @@ MediaRecorder::CreateAndDispatchBlobEvent(already_AddRefed&& aBlob) init.mCancelable = false; nsCOMPtr blob = aBlob; - init.mData = static_cast(blob.get()); + init.mData = static_cast(blob.get()); nsRefPtr event = BlobEvent::Constructor(this, diff --git a/dom/media/imagecapture/CaptureTask.cpp b/dom/media/imagecapture/CaptureTask.cpp index 7acfca9c61b..97cf3ea23df 100644 --- a/dom/media/imagecapture/CaptureTask.cpp +++ b/dom/media/imagecapture/CaptureTask.cpp @@ -15,18 +15,18 @@ namespace mozilla { nsresult -CaptureTask::TaskComplete(already_AddRefed aBlob, nsresult aRv) +CaptureTask::TaskComplete(already_AddRefed aBlob, nsresult aRv) { MOZ_ASSERT(NS_IsMainThread()); DetachStream(); nsresult rv; - nsRefPtr blob(aBlob); + nsRefPtr blob(aBlob); // We have to set the parent because the blob has been generated with a valid one. if (blob) { - blob = dom::Blob::Create(mImageCapture->GetParentObject(), blob->Impl()); + blob = new dom::File(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 aBlob) override + nsresult ReceiveBlob(already_AddRefed aBlob) override { - nsRefPtr blob(aBlob); + nsRefPtr blob(aBlob); mTask->TaskComplete(blob.forget(), NS_OK); mTask = nullptr; return NS_OK; diff --git a/dom/media/imagecapture/CaptureTask.h b/dom/media/imagecapture/CaptureTask.h index 47d344dfaf7..5bb7007c5b1 100644 --- a/dom/media/imagecapture/CaptureTask.h +++ b/dom/media/imagecapture/CaptureTask.h @@ -13,7 +13,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; class ImageCapture; } @@ -50,7 +50,7 @@ public: // // Note: // this function should be called on main thread. - nsresult TaskComplete(already_AddRefed aBlob, nsresult aRv); + nsresult TaskComplete(already_AddRefed aBlob, nsresult aRv); // Add listeners into MediaStream and PrincipalChangeObserver. It should be on // main thread only. diff --git a/dom/media/imagecapture/ImageCapture.cpp b/dom/media/imagecapture/ImageCapture.cpp index c9b631f60a0..dcc02535ecc 100644 --- a/dom/media/imagecapture/ImageCapture.cpp +++ b/dom/media/imagecapture/ImageCapture.cpp @@ -102,9 +102,9 @@ ImageCapture::TakePhotoByMediaEngine() mPrincipalChanged = true; } - nsresult PhotoComplete(already_AddRefed aBlob) override + nsresult PhotoComplete(already_AddRefed aBlob) override { - nsRefPtr blob = aBlob; + nsRefPtr blob = aBlob; if (mPrincipalChanged) { return PhotoError(NS_ERROR_DOM_SECURITY_ERR); @@ -172,7 +172,7 @@ ImageCapture::TakePhoto(ErrorResult& aResult) } nsresult -ImageCapture::PostBlobEvent(Blob* aBlob) +ImageCapture::PostBlobEvent(File* aBlob) { MOZ_ASSERT(NS_IsMainThread()); if (!CheckPrincipal()) { diff --git a/dom/media/imagecapture/ImageCapture.h b/dom/media/imagecapture/ImageCapture.h index 0025952aef7..1335f038252 100644 --- a/dom/media/imagecapture/ImageCapture.h +++ b/dom/media/imagecapture/ImageCapture.h @@ -30,7 +30,7 @@ PRLogModuleInfo* GetICLog(); namespace dom { -class Blob; +class File; class VideoStreamTrack; /** @@ -78,7 +78,7 @@ public: ImageCapture(VideoStreamTrack* aVideoStreamTrack, nsPIDOMWindow* aOwnerWindow); // Post a Blob event to script. - nsresult PostBlobEvent(Blob* aBlob); + nsresult PostBlobEvent(File* aBlob); // Post an error event to script. // aErrorCode should be one of error codes defined in ImageCaptureError.h. diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index 041c4e7c8f6..e805de018fb 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -6,6 +6,7 @@ #define MEDIAENGINE_H_ #include "mozilla/RefPtr.h" +#include "nsIDOMFile.h" #include "DOMMediaStream.h" #include "MediaStreamGraph.h" #include "mozilla/dom/MediaStreamTrackBinding.h" @@ -14,7 +15,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; } enum { @@ -129,7 +130,7 @@ public: // aBlob is the image captured by MediaEngineSource. It is // called on main thread. - virtual nsresult PhotoComplete(already_AddRefed aBlob) = 0; + virtual nsresult PhotoComplete(already_AddRefed aBlob) = 0; // It is called on main thread. aRv is the error code. virtual nsresult PhotoError(nsresult aRv) = 0; diff --git a/dom/media/webrtc/MediaEngineGonkVideoSource.cpp b/dom/media/webrtc/MediaEngineGonkVideoSource.cpp index b9363cb8e9c..141e60be2d0 100644 --- a/dom/media/webrtc/MediaEngineGonkVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineGonkVideoSource.cpp @@ -614,11 +614,11 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t NS_IMETHOD Run() { - nsRefPtr blob = - dom::Blob::CreateMemoryBlob(nullptr, mPhotoData, mPhotoDataLength, mMimeType); + nsRefPtr blob = + dom::File::CreateMemoryFile(nullptr, mPhotoData, mPhotoDataLength, mMimeType); uint32_t callbackCounts = mCallbacks.Length(); for (uint8_t i = 0; i < callbackCounts; i++) { - nsRefPtr tempBlob = blob; + nsRefPtr tempBlob = blob; mCallbacks[i]->PhotoComplete(tempBlob.forget()); } // PhotoCallback needs to dereference on main thread. diff --git a/dom/mobilemessage/MmsMessage.cpp b/dom/mobilemessage/MmsMessage.cpp index 643020556cd..3c09783276f 100644 --- a/dom/mobilemessage/MmsMessage.cpp +++ b/dom/mobilemessage/MmsMessage.cpp @@ -94,10 +94,10 @@ MmsMessage::MmsMessage(const mobilemessage::MmsMessageData& aData) // nullptr as parent. if (element.contentParent()) { nsRefPtr impl = static_cast(element.contentParent())->GetBlobImpl(); - att.mContent = Blob::Create(nullptr, impl); + att.mContent = new File(nullptr, impl); } else if (element.contentChild()) { nsRefPtr impl = static_cast(element.contentChild())->GetBlobImpl(); - att.mContent = Blob::Create(nullptr, impl); + att.mContent = new File(nullptr, impl); } else { NS_WARNING("MmsMessage: Unable to get attachment content."); } @@ -390,13 +390,10 @@ 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. - nsRefPtr impl = element.content->Impl(); - if (impl && impl->IsDateUnknown()) { - ErrorResult rv; - impl->GetLastModified(rv); - if (rv.Failed()) { + if (element.content->IsDateUnknown()) { + int64_t date; + if (NS_FAILED(element.content->GetMozLastModifiedDate(&date))) { NS_WARNING("Failed to get last modified date!"); - rv.SuppressException(); } } @@ -580,10 +577,10 @@ MmsMessage::GetAttachments(JSContext* aCx, JS::MutableHandle aAttachm // Duplicating the File with the correct parent object. nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aCx)); MOZ_ASSERT(global); - nsRefPtr newBlob = Blob::Create(global, attachment.content->Impl()); + nsRefPtr newBlob = new File(global, attachment.content->Impl()); JS::Rooted val(aCx); - if (!ToJSValue(aCx, newBlob, &val)) { + if (!GetOrCreateDOMReflector(aCx, newBlob, &val)) { return NS_ERROR_FAILURE; } diff --git a/dom/mobilemessage/MmsMessage.h b/dom/mobilemessage/MmsMessage.h index fac8dd50af8..a93b504cd3e 100644 --- a/dom/mobilemessage/MmsMessage.h +++ b/dom/mobilemessage/MmsMessage.h @@ -17,7 +17,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; namespace mobilemessage { class MmsMessageData; @@ -34,7 +34,7 @@ public: // If this is changed, change the WebIDL dictionary as well. struct Attachment final { - nsRefPtr content; + nsRefPtr content; nsString id; nsString location; diff --git a/dom/mobilemessage/ipc/SmsParent.cpp b/dom/mobilemessage/ipc/SmsParent.cpp index ed7e1c70f2f..7e41830c71b 100644 --- a/dom/mobilemessage/ipc/SmsParent.cpp +++ b/dom/mobilemessage/ipc/SmsParent.cpp @@ -65,8 +65,8 @@ MmsAttachmentDataToJSObject(JSContext* aContext, nsIGlobalObject *global = xpc::NativeGlobal(JS::CurrentGlobalOrNull(aContext)); MOZ_ASSERT(global); - nsRefPtr blob = Blob::Create(global, blobImpl); - if (!ToJSValue(aContext, blob, &content)) { + nsRefPtr blob = new File(global, blobImpl); + if (!GetOrCreateDOMReflector(aContext, blob, &content)) { return nullptr; } } diff --git a/dom/network/UDPSocket.cpp b/dom/network/UDPSocket.cpp index eed273c4ea4..8f755c9fc34 100644 --- a/dom/network/UDPSocket.cpp +++ b/dom/network/UDPSocket.cpp @@ -337,7 +337,7 @@ UDPSocket::Send(const StringOrBlobOrArrayBufferOrArrayBufferView& aData, nsCOMPtr stream; if (aData.IsBlob()) { - Blob& blob = aData.GetAsBlob(); + File& blob = aData.GetAsBlob(); aRv = blob.GetInternalStream(getter_AddRefs(stream)); if (NS_WARN_IF(aRv.Failed())) { diff --git a/dom/workers/FileReaderSync.cpp b/dom/workers/FileReaderSync.cpp index 9658114d6a1..c78a521eec2 100644 --- a/dom/workers/FileReaderSync.cpp +++ b/dom/workers/FileReaderSync.cpp @@ -52,7 +52,7 @@ FileReaderSync::WrapObject(JSContext* aCx, void FileReaderSync::ReadAsArrayBuffer(JSContext* aCx, JS::Handle aScopeObj, - Blob& aBlob, + File& aBlob, JS::MutableHandle aRetval, ErrorResult& aRv) { @@ -95,7 +95,7 @@ FileReaderSync::ReadAsArrayBuffer(JSContext* aCx, } void -FileReaderSync::ReadAsBinaryString(Blob& aBlob, +FileReaderSync::ReadAsBinaryString(File& aBlob, nsAString& aResult, ErrorResult& aRv) { @@ -125,7 +125,7 @@ FileReaderSync::ReadAsBinaryString(Blob& aBlob, } void -FileReaderSync::ReadAsText(Blob& aBlob, +FileReaderSync::ReadAsText(File& aBlob, const Optional& aEncoding, nsAString& aResult, ErrorResult& aRv) @@ -195,7 +195,7 @@ FileReaderSync::ReadAsText(Blob& aBlob, } void -FileReaderSync::ReadAsDataURL(Blob& aBlob, nsAString& aResult, +FileReaderSync::ReadAsDataURL(File& aBlob, nsAString& aResult, ErrorResult& aRv) { nsAutoString scratchResult; diff --git a/dom/workers/FileReaderSync.h b/dom/workers/FileReaderSync.h index 49be76bdd60..0bb82a22e94 100644 --- a/dom/workers/FileReaderSync.h +++ b/dom/workers/FileReaderSync.h @@ -15,7 +15,7 @@ namespace mozilla { class ErrorResult; namespace dom { -class Blob; +class File; class GlobalObject; template class Optional; } @@ -43,12 +43,12 @@ public: bool WrapObject(JSContext* aCx, JS::Handle aGivenProto, JS::MutableHandle aReflector); void ReadAsArrayBuffer(JSContext* aCx, JS::Handle aScopeObj, - Blob& aBlob, JS::MutableHandle aRetval, + File& aBlob, JS::MutableHandle aRetval, ErrorResult& aRv); - void ReadAsBinaryString(Blob& aBlob, nsAString& aResult, ErrorResult& aRv); - void ReadAsText(Blob& aBlob, const Optional& aEncoding, + void ReadAsBinaryString(File& aBlob, nsAString& aResult, ErrorResult& aRv); + void ReadAsText(File& aBlob, const Optional& aEncoding, nsAString& aResult, ErrorResult& aRv); - void ReadAsDataURL(Blob& aBlob, nsAString& aResult, ErrorResult& aRv); + void ReadAsDataURL(File& aBlob, nsAString& aResult, ErrorResult& aRv); }; END_WORKERS_NAMESPACE diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 694173b0e9f..6654f70aca8 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -412,7 +412,7 @@ PushMessageData::ArrayBuffer(JSContext* cx, JS::MutableHandle aRetval NS_ABORT(); } -mozilla::dom::Blob* +mozilla::dom::File* PushMessageData::Blob() { //todo bug 1149195. Don't be lazy. diff --git a/dom/workers/ServiceWorkerEvents.h b/dom/workers/ServiceWorkerEvents.h index a2e06fbcf04..7af8e190505 100644 --- a/dom/workers/ServiceWorkerEvents.h +++ b/dom/workers/ServiceWorkerEvents.h @@ -25,9 +25,8 @@ class nsIInterceptedChannel; namespace mozilla { namespace dom { -class Blob; -class Request; -class ResponseOrPromise; + class Request; + class ResponseOrPromise; } // namespace dom } // namespace mozilla @@ -177,7 +176,7 @@ public: void Json(JSContext* cx, JS::MutableHandle aRetval); void Text(nsAString& aData); void ArrayBuffer(JSContext* cx, JS::MutableHandle aRetval); - mozilla::dom::Blob* Blob(); + mozilla::dom::File* Blob(); explicit PushMessageData(const nsAString& aData); private: diff --git a/dom/workers/URL.cpp b/dom/workers/URL.cpp index 8810f53a5b8..d1c24c87022 100644 --- a/dom/workers/URL.cpp +++ b/dom/workers/URL.cpp @@ -880,7 +880,7 @@ URL::SetHash(const nsAString& aHash, ErrorResult& aRv) // static void -URL::CreateObjectURL(const GlobalObject& aGlobal, Blob& aBlob, +URL::CreateObjectURL(const GlobalObject& aGlobal, File& aBlob, const mozilla::dom::objectURLOptions& aOptions, nsAString& aResult, mozilla::ErrorResult& aRv) { diff --git a/dom/workers/URL.h b/dom/workers/URL.h index e51166e5a93..0a7661c8b62 100644 --- a/dom/workers/URL.h +++ b/dom/workers/URL.h @@ -15,7 +15,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; struct objectURLOptions; } } @@ -61,7 +61,7 @@ public: static void CreateObjectURL(const GlobalObject& aGlobal, - Blob& aArg, const objectURLOptions& aOptions, + File& aArg, const objectURLOptions& aOptions, nsAString& aResult, ErrorResult& aRv); static void diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index b6618c45018..f363e91fc8f 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -397,7 +397,7 @@ EnsureBlobForBackgroundManager(FileImpl* aBlobImpl, return blobImpl.forget(); } -already_AddRefed +already_AddRefed ReadBlobOrFileNoWrap(JSContext* aCx, JSStructuredCloneReader* aReader, bool aIsMainThread) @@ -436,7 +436,7 @@ ReadBlobOrFileNoWrap(JSContext* aCx, parent = do_QueryObject(globalScope); } - nsRefPtr blob = Blob::Create(parent, blobImpl); + nsRefPtr blob = new File(parent, blobImpl); return blob.forget(); } @@ -446,7 +446,7 @@ ReadBlobOrFile(JSContext* aCx, bool aIsMainThread, JS::MutableHandle aBlobOrFile) { - nsRefPtr blob = ReadBlobOrFileNoWrap(aCx, aReader, aIsMainThread); + nsRefPtr blob = ReadBlobOrFileNoWrap(aCx, aReader, aIsMainThread); aBlobOrFile.set(blob->WrapObject(aCx, JS::NullPtr())); } @@ -495,7 +495,7 @@ ReadFormData(JSContext* aCx, if (isFile) { // Read out the tag since the blob reader isn't expecting it. MOZ_ALWAYS_TRUE(JS_ReadUint32Pair(aReader, &dummy, &dummy)); - nsRefPtr blob = ReadBlobOrFileNoWrap(aCx, aReader, aIsMainThread); + nsRefPtr blob = ReadBlobOrFileNoWrap(aCx, aReader, aIsMainThread); MOZ_ASSERT(blob); formData->Append(name, *blob, thirdArg); } else { @@ -646,7 +646,7 @@ struct WorkerStructuredCloneCallbacks // See if this is a Blob/File object. { - nsRefPtr blob; + nsRefPtr blob; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) { FileImpl* blobImpl = blob->Impl(); MOZ_ASSERT(blobImpl); @@ -738,7 +738,7 @@ struct MainThreadWorkerStructuredCloneCallbacks // See if this is a Blob/File object. { - nsRefPtr blob; + nsRefPtr blob; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, aObj, blob))) { FileImpl* blobImpl = blob->Impl(); MOZ_ASSERT(blobImpl); diff --git a/dom/workers/XMLHttpRequest.cpp b/dom/workers/XMLHttpRequest.cpp index 5ab704f2b10..bf829e1d539 100644 --- a/dom/workers/XMLHttpRequest.cpp +++ b/dom/workers/XMLHttpRequest.cpp @@ -2156,7 +2156,7 @@ XMLHttpRequest::Send(JS::Handle aBody, ErrorResult& aRv) } void -XMLHttpRequest::Send(Blob& aBody, ErrorResult& aRv) +XMLHttpRequest::Send(File& aBody, ErrorResult& aRv) { mWorkerPrivate->AssertIsOnWorkerThread(); JSContext* cx = mWorkerPrivate->GetJSContext(); diff --git a/dom/workers/XMLHttpRequest.h b/dom/workers/XMLHttpRequest.h index 9475d9ad330..6dbbf12b9fe 100644 --- a/dom/workers/XMLHttpRequest.h +++ b/dom/workers/XMLHttpRequest.h @@ -19,7 +19,7 @@ namespace mozilla { namespace dom { -class Blob; +class File; } } @@ -171,7 +171,7 @@ public: Send(JS::Handle aBody, ErrorResult& aRv); void - Send(Blob& aBody, ErrorResult& aRv); + Send(File& aBody, ErrorResult& aRv); void Send(nsFormData& aBody, ErrorResult& aRv); diff --git a/ipc/glue/BackgroundImpl.cpp b/ipc/glue/BackgroundImpl.cpp index 4e3a0973eaa..0fb3ed37b3c 100644 --- a/ipc/glue/BackgroundImpl.cpp +++ b/ipc/glue/BackgroundImpl.cpp @@ -921,7 +921,7 @@ BackgroundChild::GetOrCreateActorForBlob(PBackgroundChild* aBackgroundActor, MOZ_ASSERT(aBackgroundActor == GetForCurrentThread(), "BackgroundChild is bound to a different thread!"); - nsRefPtr blobImpl = static_cast(aBlob)->Impl(); + nsRefPtr blobImpl = static_cast(aBlob)->Impl(); MOZ_ASSERT(blobImpl); BlobChild* actor = BlobChild::GetOrCreate(aBackgroundActor, blobImpl); diff --git a/js/xpconnect/src/ExportHelpers.cpp b/js/xpconnect/src/ExportHelpers.cpp index a25c85ab1e7..39be4915338 100644 --- a/js/xpconnect/src/ExportHelpers.cpp +++ b/js/xpconnect/src/ExportHelpers.cpp @@ -116,8 +116,8 @@ StackScopedCloneRead(JSContext* cx, JSStructuredCloneReader* reader, uint32_t ta // otherwise the static analysis thinks it can gc the JSObject via the stack. JS::Rooted val(cx); { - nsRefPtr blob = Blob::Create(global, cloneData->mBlobImpls[idx]); - if (!ToJSValue(cx, blob, &val)) { + nsRefPtr blob = new File(global, cloneData->mBlobImpls[idx]); + if (!GetOrCreateDOMReflector(cx, blob, &val)) { return nullptr; } } @@ -178,7 +178,7 @@ StackScopedCloneWrite(JSContext* cx, JSStructuredCloneWriter* writer, StackScopedCloneData* cloneData = static_cast(closure); { - Blob* blob = nullptr; + File* blob = nullptr; if (NS_SUCCEEDED(UNWRAP_OBJECT(Blob, obj, blob))) { FileImpl* blobImpl = blob->Impl(); MOZ_ASSERT(blobImpl); diff --git a/widget/nsFilePickerProxy.cpp b/widget/nsFilePickerProxy.cpp index e4aadda2b3d..61a158d9b3b 100644 --- a/widget/nsFilePickerProxy.cpp +++ b/widget/nsFilePickerProxy.cpp @@ -158,12 +158,9 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles, nsRefPtr blobImpl = actor->GetBlobImpl(); NS_ENSURE_TRUE(blobImpl, true); - if (!blobImpl->IsFile()) { - return true; - } - - nsRefPtr file = File::Create(mParent, blobImpl); - MOZ_ASSERT(file); + nsCOMPtr blob = new File(mParent, blobImpl); + nsCOMPtr file(do_QueryInterface(blob)); + NS_ENSURE_TRUE(file, true); mDomfiles.AppendObject(file); }