Bug 1163388 - patch 2 - get rid of nsIDOMFile, r=ehsan

--HG--
rename : dom/base/nsIDOMFile.idl => dom/base/nsIDOMBlob.idl
This commit is contained in:
Andrea Marchesini 2015-05-18 14:52:26 +01:00
parent 338c67e420
commit 3aa189b5ff
50 changed files with 162 additions and 195 deletions

View File

@ -1,6 +1,8 @@
const Cu = Components.utils; const Cu = Components.utils;
const Ci = Components.interfaces; const Ci = Components.interfaces;
Cu.importGlobalProperties(['File']);
const { Services } = Cu.import("resource://gre/modules/Services.jsm"); const { Services } = Cu.import("resource://gre/modules/Services.jsm");
// Load a duplicated copy of the jsm to prevent messing with the currently running one // Load a duplicated copy of the jsm to prevent messing with the currently running one
@ -25,7 +27,7 @@ function next() {
let steps = [ let steps = [
function getScreenshot() { function getScreenshot() {
let screenshot = Screenshot.get(); let screenshot = Screenshot.get();
assert.ok(screenshot instanceof Ci.nsIDOMFile, assert.ok(screenshot instanceof File,
"Screenshot.get() returns a File"); "Screenshot.get() returns a File");
next(); next();
}, },

View File

@ -14,6 +14,8 @@ Cu.import("resource://gre/modules/AppsUtils.jsm");
Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Promise.jsm");
Cu.import("resource://gre/modules/Webapps.jsm"); Cu.import("resource://gre/modules/Webapps.jsm");
Cu.importGlobalProperties(['File']);
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
"resource://gre/modules/FileUtils.jsm"); "resource://gre/modules/FileUtils.jsm");
@ -284,7 +286,7 @@ this.ImportExport = {
throw "NoBlobFound"; throw "NoBlobFound";
} }
let isFileBlob = aBlob instanceof Ci.nsIDOMFile; let isFileBlob = aBlob instanceof File;
// We can't QI the DOMFile to nsIFile, so we need to create one. // We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) { if (!isFileBlob) {
@ -498,7 +500,7 @@ this.ImportExport = {
throw "NoBlobFound"; throw "NoBlobFound";
} }
let isFileBlob = aBlob instanceof Ci.nsIDOMFile; let isFileBlob = aBlob instanceof File;
// We can't QI the DOMFile to nsIFile, so we need to create one. // We can't QI the DOMFile to nsIFile, so we need to create one.
let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile); let zipFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
if (!isFileBlob) { if (!isFileBlob) {

View File

@ -439,22 +439,6 @@ Blob::GetInternalStream(nsIInputStream** aStream)
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// mozilla::dom::File implementation // 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, BlobImpl* aImpl) File::File(nsISupports* aParent, BlobImpl* aImpl)
: Blob(aParent, aImpl) : Blob(aParent, aImpl)
{ {
@ -1282,9 +1266,9 @@ FileList::GetLength(uint32_t* aLength)
} }
NS_IMETHODIMP NS_IMETHODIMP
FileList::Item(uint32_t aIndex, nsIDOMFile **aFile) FileList::Item(uint32_t aIndex, nsISupports** aFile)
{ {
nsRefPtr<File> file = Item(aIndex); nsCOMPtr<nsIDOMBlob> file = Item(aIndex);
file.forget(aFile); file.forget(aFile);
return NS_OK; return NS_OK;
} }

View File

@ -20,7 +20,7 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIDOMFile.h" #include "nsIDOMBlob.h"
#include "nsIDOMFileList.h" #include "nsIDOMFileList.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIMutable.h" #include "nsIMutable.h"
@ -157,17 +157,10 @@ private:
}; };
class File final : public Blob class File final : public Blob
, public nsIDOMFile
{ {
friend class Blob; friend class Blob;
public: public:
NS_DECL_NSIDOMFILE
NS_FORWARD_NSIDOMBLOB(Blob::)
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(File, Blob);
// Note: BlobImpl must be a File in order to use this method. // Note: BlobImpl must be a File in order to use this method.
// Check impl->IsFile(). // Check impl->IsFile().
static File* static File*

View File

@ -9,7 +9,6 @@
#include "mozilla/DOMEventTargetHelper.h" #include "mozilla/DOMEventTargetHelper.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsITimer.h" #include "nsITimer.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIAsyncInputStream.h" #include "nsIAsyncInputStream.h"

View File

@ -11,10 +11,10 @@ XPIDL_SOURCES += [
'nsIContentPolicy.idl', 'nsIContentPolicy.idl',
'nsIContentPolicyBase.idl', 'nsIContentPolicyBase.idl',
'nsIDocumentEncoder.idl', 'nsIDocumentEncoder.idl',
'nsIDOMBlob.idl',
'nsIDOMDataChannel.idl', 'nsIDOMDataChannel.idl',
'nsIDOMDOMCursor.idl', 'nsIDOMDOMCursor.idl',
'nsIDOMDOMRequest.idl', 'nsIDOMDOMRequest.idl',
'nsIDOMFile.idl',
'nsIDOMFileList.idl', 'nsIDOMFileList.idl',
'nsIDOMFileReader.idl', 'nsIDOMFileReader.idl',
'nsIDOMFormData.idl', 'nsIDOMFormData.idl',

View File

@ -2593,7 +2593,7 @@ nsDOMWindowUtils::GetContainerElement(nsIDOMElement** aResult)
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile, nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
nsIDOMFile **aDOMFile) nsISupports **aDOMFile)
{ {
MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome()); MOZ_RELEASE_ASSERT(nsContentUtils::IsCallerChrome());
@ -2609,8 +2609,8 @@ nsDOMWindowUtils::WrapDOMFile(nsIFile *aFile,
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsRefPtr<File> file = File::CreateFromFile(innerWindow, aFile); nsCOMPtr<nsIDOMBlob> blob = File::CreateFromFile(innerWindow, aFile);
file.forget(aDOMFile); blob.forget(aDOMFile);
return NS_OK; return NS_OK;
} }

View File

@ -23,7 +23,6 @@
#include "nsIContentViewer.h" #include "nsIContentViewer.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDOMDocument.h" #include "nsIDOMDocument.h"
#include "nsIDOMFile.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsIWebNavigation.h" #include "nsIWebNavigation.h"
#include "nsIWebProgress.h" #include "nsIWebProgress.h"

View File

@ -53,14 +53,3 @@ interface nsIDOMBlob : nsISupports
// Return true if this blob is a memory file. // Return true if this blob is a memory file.
[notxpcom] bool isMemoryFile(); [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(26e292a6-f5aa-4560-b523-ae22a4c7dfca)]
interface nsIDOMFile : nsISupports
{
// Empty interface used by addons and some test to check if the object is a
// blob or file. This interface will be removed by bug 1163388
};

View File

@ -5,11 +5,10 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIDOMFile; [uuid(57128a85-34de-42db-a252-84dd57724a59)]
[uuid(283aa7b2-da81-4c72-aea2-9797b440fe34)]
interface nsIDOMFileList : nsISupports interface nsIDOMFileList : nsISupports
{ {
readonly attribute unsigned long length; readonly attribute unsigned long length;
nsIDOMFile item(in unsigned long index); // returns a DOM File object
nsISupports item(in unsigned long index);
}; };

View File

@ -172,7 +172,7 @@ ToJSValue(JSContext* aCx,
} }
// Accept objects that inherit from nsISupports but not nsWrapperCache (e.g. // Accept objects that inherit from nsISupports but not nsWrapperCache (e.g.
// nsIDOMFile). // DOM File).
template <class T> template <class T>
MOZ_WARN_UNUSED_RESULT MOZ_WARN_UNUSED_RESULT
typename EnableIf<!IsBaseOf<nsWrapperCache, T>::value && typename EnableIf<!IsBaseOf<nsWrapperCache, T>::value &&

View File

@ -72,14 +72,14 @@ BEGIN_BLUETOOTH_NAMESPACE
class BluetoothOppManager::SendFileBatch final class BluetoothOppManager::SendFileBatch final
{ {
public: public:
SendFileBatch(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob) SendFileBatch(const nsAString& aDeviceAddress, Blob* aBlob)
: mDeviceAddress(aDeviceAddress) : mDeviceAddress(aDeviceAddress)
{ {
mBlobs.AppendElement(aBlob); mBlobs.AppendElement(aBlob);
} }
nsString mDeviceAddress; nsString mDeviceAddress;
nsCOMArray<nsIDOMBlob> mBlobs; nsTArray<nsRefPtr<Blob>> mBlobs;
}; };
NS_IMETHODIMP NS_IMETHODIMP
@ -420,7 +420,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
bool bool
BluetoothOppManager::SendFile(const nsAString& aDeviceAddress, BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob) Blob* aBlob)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -434,7 +434,7 @@ BluetoothOppManager::SendFile(const nsAString& aDeviceAddress,
void void
BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress, BluetoothOppManager::AppendBlobToSend(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob) Blob* aBlob)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
@ -794,7 +794,7 @@ BluetoothOppManager::RetrieveSentFileName()
{ {
mFileName.Truncate(); mFileName.Truncate();
nsRefPtr<File> file = static_cast<Blob*>(mBlob.get()).ToFile(); nsRefPtr<File> file = static_cast<Blob*>(mBlob.get())->ToFile();
if (file) { if (file) {
file->GetName(mFileName); file->GetName(mFileName);
} }

View File

@ -14,13 +14,13 @@
#include "mozilla/ipc/SocketBase.h" #include "mozilla/ipc/SocketBase.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
class nsIDOMBlob;
class nsIOutputStream; class nsIOutputStream;
class nsIInputStream; class nsIInputStream;
class nsIVolumeMountLock; class nsIVolumeMountLock;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Blob;
class BlobParent; class BlobParent;
} }
} }
@ -55,7 +55,7 @@ public:
bool Listen(); bool Listen();
bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor); bool SendFile(const nsAString& aDeviceAddress, BlobParent* aActor);
bool SendFile(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob); bool SendFile(const nsAString& aDeviceAddress, Blob* aBlob);
bool StopSendingFile(); bool StopSendingFile();
bool ConfirmReceivingFile(bool aConfirm); bool ConfirmReceivingFile(bool aConfirm);
@ -102,7 +102,7 @@ private:
void NotifyAboutFileChange(); void NotifyAboutFileChange();
bool AcquireSdcardMountLock(); bool AcquireSdcardMountLock();
void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize); void SendObexData(uint8_t* aData, uint8_t aOpcode, int aSize);
void AppendBlobToSend(const nsAString& aDeviceAddress, nsIDOMBlob* aBlob); void AppendBlobToSend(const nsAString& aDeviceAddress, Blob* aBlob);
void DiscardBlobsToSend(); void DiscardBlobsToSend();
bool ProcessNextBatch(); bool ProcessNextBatch();
void ConnectInternal(const nsAString& aDeviceAddress); void ConnectInternal(const nsAString& aDeviceAddress);
@ -199,7 +199,7 @@ private:
nsAutoArrayPtr<uint8_t> mReceivedDataBuffer; nsAutoArrayPtr<uint8_t> mReceivedDataBuffer;
int mCurrentBlobIndex; int mCurrentBlobIndex;
nsCOMPtr<nsIDOMBlob> mBlob; nsRefPtr<Blob> mBlob;
nsTArray<SendFileBatch> mBatches; nsTArray<SendFileBatch> mBatches;
/** /**

View File

@ -1827,7 +1827,7 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
void void
BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress, BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, Blob* aBlob,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());

View File

@ -130,7 +130,7 @@ public:
virtual void virtual void
SendFile(const nsAString& aDeviceAddress, SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, Blob* aBlob,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void
@ -435,7 +435,7 @@ public:
virtual void virtual void
SendFile(const nsAString& aDeviceAddress, SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, Blob* aBlob,
BluetoothReplyRunnable* aRunnable); BluetoothReplyRunnable* aRunnable);
virtual void virtual void

View File

@ -12,15 +12,13 @@
#include "BluetoothProfileManagerBase.h" #include "BluetoothProfileManagerBase.h"
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsClassHashtable.h" #include "nsClassHashtable.h"
#include "nsIDOMFile.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsTObserverArray.h" #include "nsTObserverArray.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
class nsIDOMBlob;
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
class Blob;
class BlobChild; class BlobChild;
class BlobParent; class BlobParent;
} }
@ -295,7 +293,7 @@ public:
virtual void virtual void
SendFile(const nsAString& aDeviceAddress, SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, Blob* aBlob,
BluetoothReplyRunnable* aRunnable) = 0; BluetoothReplyRunnable* aRunnable) = 0;
virtual void virtual void

View File

@ -316,7 +316,7 @@ BluetoothServiceChildProcess::SendFile(
void void
BluetoothServiceChildProcess::SendFile( BluetoothServiceChildProcess::SendFile(
const nsAString& aDeviceAddress, const nsAString& aDeviceAddress,
nsIDOMBlob* aBlobChild, Blob* aBlobChild,
BluetoothReplyRunnable* aRunnable) BluetoothReplyRunnable* aRunnable)
{ {
// Parent-process-only method // Parent-process-only method

View File

@ -140,7 +140,7 @@ public:
virtual void virtual void
SendFile(const nsAString& aDeviceAddress, SendFile(const nsAString& aDeviceAddress,
nsIDOMBlob* aBlob, Blob* aBlob,
BluetoothReplyRunnable* aRunnable) override; BluetoothReplyRunnable* aRunnable) override;
virtual void virtual void

View File

@ -6,8 +6,6 @@
#include "InternalResponse.h" #include "InternalResponse.h"
#include "nsIDOMFile.h"
#include "mozilla/dom/InternalHeaders.h" #include "mozilla/dom/InternalHeaders.h"
#include "nsStreamUtils.h" #include "nsStreamUtils.h"
#include "nsSerializationHelper.h" #include "nsSerializationHelper.h"

View File

@ -647,16 +647,22 @@ HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType, const nsAString& aType,
ErrorResult& aRv) ErrorResult& aRv)
{ {
nsCOMPtr<nsIDOMFile> file; nsCOMPtr<nsISupports> file;
aRv = MozGetAsFile(aName, aType, getter_AddRefs(file)); aRv = MozGetAsFile(aName, aType, getter_AddRefs(file));
nsRefPtr<File> tmp = static_cast<File*>(file.get()); if (NS_WARN_IF(aRv.Failed())) {
return tmp.forget(); return nullptr;
}
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(file);
nsRefPtr<Blob> domBlob = static_cast<Blob*>(blob.get());
MOZ_ASSERT(domBlob->IsFile());
return domBlob->ToFile();
} }
NS_IMETHODIMP NS_IMETHODIMP
HTMLCanvasElement::MozGetAsFile(const nsAString& aName, HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
const nsAString& aType, const nsAString& aType,
nsIDOMFile** aResult) nsISupports** aResult)
{ {
OwnerDoc()->WarnOnceAbout(nsIDocument::eMozGetAsFile); OwnerDoc()->WarnOnceAbout(nsIDocument::eMozGetAsFile);
@ -672,7 +678,7 @@ HTMLCanvasElement::MozGetAsFile(const nsAString& aName,
nsresult nsresult
HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName, HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
const nsAString& aType, const nsAString& aType,
nsIDOMFile** aResult) nsISupports** aResult)
{ {
nsCOMPtr<nsIInputStream> stream; nsCOMPtr<nsIInputStream> stream;
nsAutoString type(aType); nsAutoString type(aType);
@ -696,7 +702,7 @@ HTMLCanvasElement::MozGetAsBlobImpl(const nsAString& aName,
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScopeObject()); nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(OwnerDoc()->GetScopeObject());
// The File takes ownership of the buffer // The File takes ownership of the buffer
nsRefPtr<File> file = nsCOMPtr<nsIDOMBlob> file =
File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type, File::CreateMemoryFile(win, imgData, (uint32_t)imgSize, aName, type,
PR_Now()); PR_Now());

View File

@ -237,7 +237,7 @@ protected:
nsAString& aDataURL); nsAString& aDataURL);
nsresult MozGetAsBlobImpl(const nsAString& aName, nsresult MozGetAsBlobImpl(const nsAString& aName,
const nsAString& aType, const nsAString& aType,
nsIDOMFile** aResult); nsISupports** aResult);
void CallPrintCallback(); void CallPrintCallback();
CanvasContextType mCurrentContextType; CanvasContextType mCurrentContextType;

View File

@ -405,7 +405,9 @@ public:
MOZ_ASSERT(blobImpl); MOZ_ASSERT(blobImpl);
blobImpl->SetPath(Substring(path, 0, uint32_t(length))); blobImpl->SetPath(Substring(path, 0, uint32_t(length)));
} }
*aResult = domFile.forget().downcast<nsIDOMFile>().take();
nsCOMPtr<nsIDOMBlob> blob = domFile.get();
blob.forget(aResult);
LookupAndCacheNext(); LookupAndCacheNext();
return NS_OK; return NS_OK;
} }
@ -488,7 +490,7 @@ NS_IMPL_ISUPPORTS(DirPickerRecursiveFileEnumerator, nsISimpleEnumerator)
/** /**
* This may return nullptr if aDomFile's implementation of * This may return nullptr if aDomFile's implementation of
* nsIDOMFile::mozFullPathInternal does not successfully return a non-empty * File::mozFullPathInternal does not successfully return a non-empty
* string that is a valid path. This can happen on Firefox OS, for example, * string that is a valid path. This can happen on Firefox OS, for example,
* where the file picker can create Blobs. * where the file picker can create Blobs.
*/ */
@ -537,9 +539,9 @@ public:
nsCOMPtr<nsISupports> tmp; nsCOMPtr<nsISupports> tmp;
while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) { while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) {
iter->GetNext(getter_AddRefs(tmp)); iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp); nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(tmp);
MOZ_ASSERT(domFile); MOZ_ASSERT(domBlob);
mFileList.AppendElement(static_cast<File*>(domFile.get())); mFileList.AppendElement(static_cast<File*>(domBlob.get()));
mFileListLength = mFileList.Length(); mFileListLength = mFileList.Length();
if (mCanceled) { if (mCanceled) {
MOZ_ASSERT(!mInput, "This is bad - how did this happen?"); MOZ_ASSERT(!mInput, "This is bad - how did this happen?");
@ -696,20 +698,23 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) { while (NS_SUCCEEDED(iter->HasMoreElements(&hasMore)) && hasMore) {
iter->GetNext(getter_AddRefs(tmp)); iter->GetNext(getter_AddRefs(tmp));
nsCOMPtr<nsIDOMFile> domFile = do_QueryInterface(tmp); nsCOMPtr<nsIDOMBlob> domBlob = do_QueryInterface(tmp);
NS_WARN_IF_FALSE(domFile, NS_WARN_IF_FALSE(domBlob,
"Null file object from FilePicker's file enumerator?"); "Null file object from FilePicker's file enumerator?");
if (domFile) { if (domBlob) {
newFiles.AppendElement(static_cast<File*>(domFile.get())); newFiles.AppendElement(static_cast<File*>(domBlob.get()));
} }
} }
} else { } else {
MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen)); MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen));
nsCOMPtr<nsIDOMFile> domFile; nsCOMPtr<nsISupports> tmp;
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(domFile)); nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (domFile) {
newFiles.AppendElement(static_cast<File*>(domFile.get())); nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(tmp);
if (blob) {
nsRefPtr<File> file = static_cast<Blob*>(blob.get())->ToFile();
newFiles.AppendElement(file);
} }
} }

View File

@ -18,7 +18,6 @@
#include "nsAttrValueInlines.h" #include "nsAttrValueInlines.h"
#include "nsISaveAsCharset.h" #include "nsISaveAsCharset.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIDOMFile.h"
#include "nsDirectoryServiceDefs.h" #include "nsDirectoryServiceDefs.h"
#include "nsStringStream.h" #include "nsStringStream.h"
#include "nsIURI.h" #include "nsIURI.h"

View File

@ -27,7 +27,6 @@
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsDebug.h" #include "nsDebug.h"
#include "nsError.h" #include "nsError.h"
#include "nsIDOMFile.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
namespace mozilla { namespace mozilla {
@ -328,7 +327,7 @@ IDBMutableFile::GetFileId() const
return mFileInfo->Id(); return mFileInfo->Id();
} }
already_AddRefed<nsIDOMFile> already_AddRefed<File>
IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle, IDBMutableFile::CreateFileObject(IDBFileHandle* aFileHandle,
MetadataParameters* aMetadataParams) MetadataParameters* aMetadataParams)
{ {
@ -393,12 +392,10 @@ GetFileHelper::GetSuccessResult(JSContext* aCx,
auto fileHandle = static_cast<IDBFileHandle*>(mFileHandle.get()); auto fileHandle = static_cast<IDBFileHandle*>(mFileHandle.get());
nsCOMPtr<nsIDOMFile> domFile = nsRefPtr<File> domFile =
mMutableFile->CreateFileObject(fileHandle, mParams); mMutableFile->CreateFileObject(fileHandle, mParams);
nsresult rv = if (!ToJSValue(aCx, domFile, aVal)) {
nsContentUtils::WrapNative(aCx, domFile, &NS_GET_IID(nsIDOMFile), aVal);
if (NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR; return NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR;
} }

View File

@ -18,7 +18,6 @@
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
class nsIDOMFile;
class nsPIDOMWindow; class nsPIDOMWindow;
namespace mozilla { namespace mozilla {
@ -28,6 +27,7 @@ class ErrorResult;
namespace dom { namespace dom {
class DOMRequest; class DOMRequest;
class File;
class MetadataParameters; class MetadataParameters;
namespace indexedDB { namespace indexedDB {
@ -83,7 +83,7 @@ public:
return mFileInfo; return mFileInfo;
} }
already_AddRefed<nsIDOMFile> already_AddRefed<File>
CreateFileObject(IDBFileHandle* aFileHandle, CreateFileObject(IDBFileHandle* aFileHandle,
MetadataParameters* aMetadataParams); MetadataParameters* aMetadataParams);

View File

@ -17,7 +17,6 @@
#include "mozilla/dom/DOMStringList.h" #include "mozilla/dom/DOMStringList.h"
#include "mozilla/ipc/BackgroundChild.h" #include "mozilla/ipc/BackgroundChild.h"
#include "nsIAppShell.h" #include "nsIAppShell.h"
#include "nsIDOMFile.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"

View File

@ -94,12 +94,11 @@ function verifyBlob(blob1, blob2, fileId, blobReadHandler)
{ {
is(blob1 instanceof Components.interfaces.nsIDOMBlob, true, is(blob1 instanceof Components.interfaces.nsIDOMBlob, true,
"Instance of nsIDOMBlob"); "Instance of nsIDOMBlob");
is(blob1 instanceof Components.interfaces.nsIDOMFile, is(blob1 instanceof File, blob2 instanceof File,
blob2 instanceof Components.interfaces.nsIDOMFile, "Instance of DOM File");
"Instance of nsIDOMFile");
is(blob1.size, blob2.size, "Correct size"); is(blob1.size, blob2.size, "Correct size");
is(blob1.type, blob2.type, "Correct type"); is(blob1.type, blob2.type, "Correct type");
if (blob2 instanceof Components.interfaces.nsIDOMFile) { if (blob2 instanceof File) {
is(blob1.name, blob2.name, "Correct name"); is(blob1.name, blob2.name, "Correct name");
} }
is(utils.getFileId(blob1), fileId, "Correct file id"); is(utils.getFileId(blob1), fileId, "Correct file id");

View File

@ -39,8 +39,6 @@ interface nsIDOMStyleSheet;
interface nsITransferable; interface nsITransferable;
interface nsIQueryContentEventResult; interface nsIQueryContentEventResult;
interface nsIDOMWindow; interface nsIDOMWindow;
interface nsIDOMBlob;
interface nsIDOMFile;
interface nsIFile; interface nsIFile;
interface nsIDOMClientRect; interface nsIDOMClientRect;
interface nsIURI; interface nsIURI;
@ -51,7 +49,7 @@ interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest; interface nsIContentPermissionRequest;
interface nsIObserver; interface nsIObserver;
[scriptable, uuid(1a75c351-d115-4d51-94df-731dd1723a1f)] [scriptable, uuid(34a42cdc-7a04-4e71-8a5c-63e092fba58e)]
interface nsIDOMWindowUtils : nsISupports { interface nsIDOMWindowUtils : nsISupports {
/** /**
@ -1445,9 +1443,10 @@ interface nsIDOMWindowUtils : nsISupports {
in AString value2); in AString value2);
/** /**
* Wrap an nsIFile in an nsIDOMFile * Wrap an nsIFile in an DOM File
* Returns a File object.
*/ */
nsIDOMFile wrapDOMFile(in nsIFile aFile); nsISupports wrapDOMFile(in nsIFile aFile);
/** /**
* Get the type of the currently focused html input, if any. * Get the type of the currently focused html input, if any.

View File

@ -16,11 +16,10 @@
*/ */
interface nsIDOMBlob; interface nsIDOMBlob;
interface nsIDOMFile;
interface nsIVariant; interface nsIVariant;
interface nsIInputStreamCallback; interface nsIInputStreamCallback;
[uuid(8978d1c5-2981-4678-a1c3-b0b7bae04fbc)] [uuid(2c984658-2e7c-4774-8ac5-cf1b39f8bec3)]
interface nsIDOMHTMLCanvasElement : nsISupports interface nsIDOMHTMLCanvasElement : nsISupports
{ {
attribute unsigned long width; attribute unsigned long width;
@ -38,7 +37,8 @@ interface nsIDOMHTMLCanvasElement : nsISupports
// Valid calls are // Valid calls are
// mozGetAsFile(name); -- defaults to image/png // mozGetAsFile(name); -- defaults to image/png
// mozGetAsFile(name, type); -- uses given type // mozGetAsFile(name, type); -- uses given type
nsIDOMFile mozGetAsFile(in DOMString name, [optional] in DOMString type); // The return value is a File object.
nsISupports mozGetAsFile(in DOMString name, [optional] in DOMString type);
// A Mozilla-only extension to get a canvas context backed by double-buffered // A Mozilla-only extension to get a canvas context backed by double-buffered
// shared memory. Only privileged callers can call this. // shared memory. Only privileged callers can call this.

View File

@ -8,7 +8,6 @@
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDOMFile.h"
#include "nsIDOMWindow.h" #include "nsIDOMWindow.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsISimpleEnumerator.h" #include "nsISimpleEnumerator.h"

View File

@ -7,7 +7,6 @@
#ifndef mozilla_dom_FilePickerParent_h #ifndef mozilla_dom_FilePickerParent_h
#define mozilla_dom_FilePickerParent_h #define mozilla_dom_FilePickerParent_h
#include "nsIDOMFile.h"
#include "nsIEventTarget.h" #include "nsIEventTarget.h"
#include "nsIFilePicker.h" #include "nsIFilePicker.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"

View File

@ -113,6 +113,7 @@ GetMediaManagerLog()
} }
#define LOG(msg) PR_LOG(GetMediaManagerLog(), PR_LOG_DEBUG, msg) #define LOG(msg) PR_LOG(GetMediaManagerLog(), PR_LOG_DEBUG, msg)
using dom::File;
using dom::MediaStreamConstraints; using dom::MediaStreamConstraints;
using dom::MediaTrackConstraintSet; using dom::MediaTrackConstraintSet;
using dom::MediaTrackConstraints; using dom::MediaTrackConstraints;
@ -264,53 +265,6 @@ private:
nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
}; };
/**
* Invoke the "onSuccess" callback in content. The callback will take a
* DOMBlob in the case of {picture:true}, and a MediaStream in the case of
* {audio:true} or {video:true}. There is a constructor available for each
* form. Do this only on the main thread.
*/
class SuccessCallbackRunnable : public nsRunnable
{
public:
SuccessCallbackRunnable(
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback>& aOnSuccess,
nsCOMPtr<nsIDOMGetUserMediaErrorCallback>& aOnFailure,
nsIDOMFile* aFile, uint64_t aWindowID)
: mFile(aFile)
, mWindowID(aWindowID)
, mManager(MediaManager::GetInstance())
{
mOnSuccess.swap(aOnSuccess);
mOnFailure.swap(aOnFailure);
}
NS_IMETHOD
Run()
{
// Only run if the window is still active.
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onSuccess = mOnSuccess.forget();
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onFailure = mOnFailure.forget();
if (!(mManager->IsWindowStillActive(mWindowID))) {
return NS_OK;
}
// This is safe since we're on main-thread, and the windowlist can only
// be invalidated from the main-thread (see OnNavigation)
onSuccess->OnSuccess(mFile);
return NS_OK;
}
private:
nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
nsCOMPtr<nsIDOMFile> mFile;
uint64_t mWindowID;
nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
};
/** /**
* Invoke the GetUserMediaDevices success callback. Wrapped in a runnable * Invoke the GetUserMediaDevices success callback. Wrapped in a runnable
* so that it may be called on the main thread. The error callback is also * so that it may be called on the main thread. The error callback is also

View File

@ -112,7 +112,7 @@ protected:
mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling
// This is only modified on MainThread (AllocImpl and DeallocImpl) // This is only modified on MainThread (AllocImpl and DeallocImpl)
nsRefPtr<ICameraControl> mCameraControl; nsRefPtr<ICameraControl> mCameraControl;
nsCOMPtr<nsIDOMFile> mLastCapture; nsRefPtr<dom::File> mLastCapture;
android::sp<android::GonkCameraSource> mCameraSource; android::sp<android::GonkCameraSource> mCameraSource;

View File

@ -210,7 +210,7 @@ interface nsINfcContentHelper : nsISupports
* *
* @param blob * @param blob
* Raw data of the file to be sent. This object represents a file-like * Raw data of the file to be sent. This object represents a file-like
* (nsIDOMFile) object of immutable, raw data. The blob data needs * (DOM File) object of immutable, raw data. The blob data needs
* to be 'object wrapped' before calling this interface. * to be 'object wrapped' before calling this interface.
* *
* @param sessionToken * @param sessionToken

View File

@ -8,7 +8,7 @@ let Cc = Components.classes;
let Ci = Components.interfaces; let Ci = Components.interfaces;
let Cu = Components.utils; let Cu = Components.utils;
Cu.importGlobalProperties(['Blob']); Cu.importGlobalProperties(['Blob', 'File']);
Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Services.jsm");
this.EXPORTED_SYMBOLS = ["SettingsDB", "SETTINGSDB_NAME", "SETTINGSSTORE_NAME"]; this.EXPORTED_SYMBOLS = ["SettingsDB", "SETTINGSDB_NAME", "SETTINGSSTORE_NAME"];
@ -209,7 +209,7 @@ SettingsDB.prototype = {
return "primitive"; return "primitive";
} else if (Array.isArray(aObject)) { } else if (Array.isArray(aObject)) {
return "array"; return "array";
} else if (aObject instanceof Ci.nsIDOMFile) { } else if (aObject instanceof File) {
return "file"; return "file";
} else if (aObject instanceof Ci.nsIDOMBlob) { } else if (aObject instanceof Ci.nsIDOMBlob) {
return "blob"; return "blob";

View File

@ -8,6 +8,8 @@ const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
Cu.importGlobalProperties(['File']);
this.EXPORTED_SYMBOLS = ["SettingsRequestManager"]; this.EXPORTED_SYMBOLS = ["SettingsRequestManager"];
Cu.import("resource://gre/modules/SettingsDB.jsm"); Cu.import("resource://gre/modules/SettingsDB.jsm");
@ -245,7 +247,7 @@ let SettingsRequestManager = {
if (!aValue || !aValue.constructor) { if (!aValue || !aValue.constructor) {
return false; return false;
} }
return (aValue.constructor.name == "Date") || (aValue instanceof Ci.nsIDOMFile) || return (aValue.constructor.name == "Date") || (aValue instanceof File) ||
(aValue instanceof Ci.nsIDOMBlob); (aValue instanceof Ci.nsIDOMBlob);
} }
// We need to serialize settings objects, otherwise they can change between // We need to serialize settings objects, otherwise they can change between

View File

@ -18,7 +18,7 @@
#include "cert.h" #include "cert.h"
#include "certdb.h" #include "certdb.h"
#include "CryptoTask.h" #include "CryptoTask.h"
#include "nsIDOMFile.h" #include "nsIDOMBlob.h"
#include "nsIWifiService.h" #include "nsIWifiService.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"

View File

@ -28,7 +28,6 @@
#include "mozilla/dom/StructuredCloneTags.h" #include "mozilla/dom/StructuredCloneTags.h"
#include "mozilla/dom/WindowBinding.h" #include "mozilla/dom/WindowBinding.h"
#include "nsZipArchive.h" #include "nsZipArchive.h"
#include "nsIDOMFile.h"
#include "nsIDOMFileList.h" #include "nsIDOMFileList.h"
#include "nsWindowMemoryReporter.h" #include "nsWindowMemoryReporter.h"
#include "nsDOMClassInfo.h" #include "nsDOMClassInfo.h"

View File

@ -49,7 +49,7 @@
if (Array.isArray(a)) if (Array.isArray(a))
return 'array'; return 'array';
if (a instanceof Ci.nsIDOMFile) if (a instanceof File)
return 'file'; return 'file';
if (a instanceof Ci.nsIDOMBlob) if (a instanceof Ci.nsIDOMBlob)

View File

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.importGlobalProperties(['Blob']); Components.utils.importGlobalProperties(['Blob', 'File']);
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -31,7 +31,7 @@ BlobComponent.prototype =
// do some tests // do some tests
do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); do_check_true(!(f1 instanceof File), "Should not be a DOM File");
do_check_true(f1.type == "text/xml", "Wrong type"); do_check_true(f1.type == "text/xml", "Wrong type");

View File

@ -36,8 +36,8 @@ FileComponent.prototype =
var f2 = new File(file); var f2 = new File(file);
// do some tests // do some tests
do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File"); do_check_true(f1 instanceof File, "Should be a DOM File");
do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File"); do_check_true(f2 instanceof File, "Should be a DOM File");
do_check_true(f1.name == "xpcshell.ini", "Should be the right file"); do_check_true(f1.name == "xpcshell.ini", "Should be the right file");
do_check_true(f2.name == "xpcshell.ini", "Should be the right file"); do_check_true(f2.name == "xpcshell.ini", "Should be the right file");

View File

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.importGlobalProperties(['Blob']); Components.utils.importGlobalProperties(['Blob', 'File']);
const Ci = Components.interfaces; const Ci = Components.interfaces;
@ -15,7 +15,7 @@ function run_test() {
// do some tests // do some tests
do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob"); do_check_true(f1 instanceof Ci.nsIDOMBlob, "Should be a DOM Blob");
do_check_true(!(f1 instanceof Ci.nsIDOMFile), "Should not be a DOM File"); do_check_true(!(f1 instanceof File), "Should not be a DOM File");
do_check_true(f1.type == "text/xml", "Wrong type"); do_check_true(f1.type == "text/xml", "Wrong type");

View File

@ -21,8 +21,8 @@ function run_test() {
var f2 = new File(file); var f2 = new File(file);
// do some tests // do some tests
do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File"); do_check_true(f1 instanceof File, "Should be a DOM File");
do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File"); do_check_true(f2 instanceof File, "Should be a DOM File");
do_check_true(f1.name == "xpcshell.ini", "Should be the right file"); do_check_true(f1.name == "xpcshell.ini", "Should be the right file");
do_check_true(f2.name == "xpcshell.ini", "Should be the right file"); do_check_true(f2.name == "xpcshell.ini", "Should be the right file");

View File

@ -93,7 +93,7 @@ nsFilePicker.prototype = {
/* readonly attribute nsISimpleEnumerator files; */ /* readonly attribute nsISimpleEnumerator files; */
get files() { return this.mFilesEnumerator; }, get files() { return this.mFilesEnumerator; },
/* readonly attribute nsIDOMFile domfile; */ /* readonly attribute DOM File domfile; */
get domfile() { get domfile() {
let enumerator = this.domfiles; let enumerator = this.domfiles;
return enumerator ? enumerator.mFiles[0] : null; return enumerator ? enumerator.mFiles[0] : null;

View File

@ -83,7 +83,7 @@ this.PropertyListUtils = Object.freeze({
* The reaon for failure is reported to the Error Console. * The reaon for failure is reported to the Error Console.
*/ */
read: function PLU_read(aFile, aCallback) { read: function PLU_read(aFile, aCallback) {
if (!(aFile instanceof Ci.nsILocalFile || aFile instanceof Ci.nsIDOMFile)) if (!(aFile instanceof Ci.nsILocalFile || aFile instanceof File))
throw new Error("aFile is not a file object"); throw new Error("aFile is not a file object");
if (typeof(aCallback) != "function") if (typeof(aCallback) != "function")
throw new Error("Invalid value for aCallback"); throw new Error("Invalid value for aCallback");

View File

@ -96,7 +96,7 @@ public:
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIDOMFile> domFile = File::CreateFromFile(mParent, localFile); nsCOMPtr<nsIDOMBlob> domFile = File::CreateFromFile(mParent, localFile);
domFile.forget(aResult); domFile.forget(aResult);
return NS_OK; return NS_OK;
} }
@ -311,7 +311,7 @@ nsBaseFilePicker::GetMode(int16_t* aMode)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsBaseFilePicker::GetDomfile(nsIDOMFile** aDomfile) nsBaseFilePicker::GetDomfile(nsISupports** aDomfile)
{ {
nsCOMPtr<nsIFile> localFile; nsCOMPtr<nsIFile> localFile;
nsresult rv = GetFile(getter_AddRefs(localFile)); nsresult rv = GetFile(getter_AddRefs(localFile));
@ -322,7 +322,7 @@ nsBaseFilePicker::GetDomfile(nsIDOMFile** aDomfile)
return NS_OK; return NS_OK;
} }
nsRefPtr<File> domFile = File::CreateFromFile(mParent, localFile); nsCOMPtr<nsIDOMBlob> domFile = File::CreateFromFile(mParent, localFile);
domFile.forget(aDomfile); domFile.forget(aDomfile);
return NS_OK; return NS_OK;
} }

View File

@ -37,7 +37,7 @@ public:
NS_IMETHOD SetAddToRecentDocs(bool aFlag); NS_IMETHOD SetAddToRecentDocs(bool aFlag);
NS_IMETHOD GetMode(int16_t *aMode); NS_IMETHOD GetMode(int16_t *aMode);
NS_IMETHOD GetDomfile(nsIDOMFile** aDomfile); NS_IMETHOD GetDomfile(nsISupports** aDomfile);
NS_IMETHOD GetDomfiles(nsISimpleEnumerator** aDomfiles); NS_IMETHOD GetDomfiles(nsISimpleEnumerator** aDomfiles);
protected: protected:

View File

@ -165,7 +165,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
nsRefPtr<File> file = File::Create(mParent, blobImpl); nsRefPtr<File> file = File::Create(mParent, blobImpl);
MOZ_ASSERT(file); MOZ_ASSERT(file);
mDomfiles.AppendObject(file); mDomfiles.AppendElement(file);
} }
} }
@ -178,7 +178,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile) nsFilePickerProxy::GetDomfile(nsISupports** aDomfile)
{ {
*aDomfile = nullptr; *aDomfile = nullptr;
if (mDomfiles.IsEmpty()) { if (mDomfiles.IsEmpty()) {
@ -186,13 +186,55 @@ nsFilePickerProxy::GetDomfile(nsIDOMFile** aDomfile)
} }
MOZ_ASSERT(mDomfiles.Length() == 1); MOZ_ASSERT(mDomfiles.Length() == 1);
nsCOMPtr<nsIDOMFile> domfile = mDomfiles[0]; nsCOMPtr<nsIDOMBlob> blob = mDomfiles[0].get();
domfile.forget(aDomfile); blob.forget(aDomfile);
return NS_OK; return NS_OK;
} }
namespace {
class SimpleEnumerator final : public nsISimpleEnumerator
{
public:
NS_DECL_ISUPPORTS
explicit SimpleEnumerator(const nsTArray<nsRefPtr<File>>& aFiles)
: mFiles(aFiles)
, mIndex(0)
{}
NS_IMETHOD
HasMoreElements(bool* aRetvalue) override
{
MOZ_ASSERT(aRetvalue);
*aRetvalue = mFiles.Length() >= mIndex;
return NS_OK;
}
NS_IMETHOD
GetNext(nsISupports** aSupports) override
{
nsCOMPtr<nsIDOMBlob> blob = mFiles[mIndex++].get();
blob.forget(aSupports);
return NS_OK;
}
private:
~SimpleEnumerator()
{}
nsTArray<nsRefPtr<File>> mFiles;
uint32_t mIndex;
};
NS_IMPL_ISUPPORTS(SimpleEnumerator, nsISimpleEnumerator)
} // anonymous namespace
NS_IMETHODIMP NS_IMETHODIMP
nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles) nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
{ {
return NS_NewArrayEnumerator(aDomfiles, mDomfiles); nsRefPtr<SimpleEnumerator> enumerator = new SimpleEnumerator(mDomfiles);
enumerator.forget(aDomfiles);
return NS_OK;
} }

View File

@ -18,6 +18,12 @@ class nsIWidget;
class nsIFile; class nsIFile;
class nsPIDOMWindow; class nsPIDOMWindow;
namespace mozilla {
namespace dom {
class File;
}
}
/** /**
This class creates a proxy file picker to be used in content processes. This class creates a proxy file picker to be used in content processes.
The file picker just collects the initialization data and when Show() is The file picker just collects the initialization data and when Show() is
@ -45,7 +51,7 @@ public:
NS_IMETHODIMP GetFileURL(nsIURI** aFileURL) override; NS_IMETHODIMP GetFileURL(nsIURI** aFileURL) override;
NS_IMETHODIMP GetFiles(nsISimpleEnumerator** aFiles) override; NS_IMETHODIMP GetFiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP GetDomfile(nsIDOMFile** aFile) override; NS_IMETHODIMP GetDomfile(nsISupports** aFile) override;
NS_IMETHODIMP GetDomfiles(nsISimpleEnumerator** aFiles) override; NS_IMETHODIMP GetDomfiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP Show(int16_t* aReturn) override; NS_IMETHODIMP Show(int16_t* aReturn) override;
@ -59,7 +65,7 @@ private:
~nsFilePickerProxy(); ~nsFilePickerProxy();
void InitNative(nsIWidget*, const nsAString&) override; void InitNative(nsIWidget*, const nsAString&) override;
nsCOMArray<nsIDOMFile> mDomfiles; nsTArray<nsRefPtr<mozilla::dom::File>> mDomfiles;
nsCOMPtr<nsIFilePickerShownCallback> mCallback; nsCOMPtr<nsIFilePickerShownCallback> mCallback;
int16_t mSelectedType; int16_t mSelectedType;

View File

@ -8,7 +8,6 @@
interface nsIFile; interface nsIFile;
interface nsIURI; interface nsIURI;
interface nsIDOMFile;
interface nsIDOMWindow; interface nsIDOMWindow;
interface nsISimpleEnumerator; interface nsISimpleEnumerator;
@ -24,7 +23,7 @@ interface nsIFilePickerShownCallback : nsISupports
void done(in short aResult); void done(in short aResult);
}; };
[scriptable, uuid(f93509a0-0434-11e3-8ffd-0800200c9a66)] [scriptable, uuid(9840d564-42c8-4d78-9a4d-71002343c918)]
interface nsIFilePicker : nsISupports interface nsIFilePicker : nsISupports
{ {
const short modeOpen = 0; // Load a file or directory const short modeOpen = 0; // Load a file or directory
@ -143,11 +142,11 @@ interface nsIFilePicker : nsISupports
readonly attribute nsISimpleEnumerator files; readonly attribute nsISimpleEnumerator files;
/** /**
* Get the nsIDOMFile for the file. * Get the DOM File for the file.
* *
* @return Returns the file currently selected as File * @return Returns the file currently selected as File
*/ */
readonly attribute nsIDOMFile domfile; readonly attribute nsISupports domfile;
/** /**
* Get the enumerator for the selected files * Get the enumerator for the selected files