Fix for bug 734505 (Add new DOM binding for FileList). r=jst.

--HG--
extra : rebase_source : 7a563b1af70c24f9117b813016b7a37612e92431
This commit is contained in:
Peter Van der Beken 2011-08-22 11:14:13 +02:00
parent 4d875e976f
commit c2e7269a78
7 changed files with 90 additions and 16 deletions

View File

@ -59,6 +59,8 @@
#include "mozilla/dom/indexedDB/FileInfo.h"
#include "mozilla/dom/indexedDB/FileManager.h"
#include "mozilla/dom/indexedDB/IndexedDatabaseManager.h"
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
class nsIFile;
class nsIInputStream;
@ -326,22 +328,38 @@ protected:
nsRefPtr<DataOwner> mDataOwner;
};
class nsDOMFileList : public nsIDOMFileList
class nsDOMFileList MOZ_FINAL : public nsIDOMFileList,
public nsWrapperCache
{
public:
NS_DECL_ISUPPORTS
nsDOMFileList(nsISupports *aParent) : mParent(aParent)
{
SetIsProxy();
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMFileList)
NS_DECL_NSIDOMFILELIST
virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap);
nsISupports* GetParentObject()
{
return mParent;
}
void Disconnect()
{
mParent = nsnull;
}
bool Append(nsIDOMFile *aFile) { return mFiles.AppendObject(aFile); }
bool Remove(PRUint32 aIndex) { return mFiles.RemoveObjectAt(aIndex); }
void Clear() { return mFiles.Clear(); }
nsIDOMFile* GetItemAt(PRUint32 aIndex)
{
return mFiles.SafeObjectAt(aIndex);
}
static nsDOMFileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
@ -361,6 +379,7 @@ public:
private:
nsCOMArray<nsIDOMFile> mFiles;
nsISupports *mParent;
};
class NS_STACK_CLASS nsDOMFileInternalUrlHolder {

View File

@ -43,5 +43,6 @@ interface nsIDOMFile;
interface nsIDOMFileList : nsISupports
{
readonly attribute unsigned long length;
nsIDOMFile item(in unsigned long index);
[getter,forward(getItemAt)] nsIDOMFile item(in unsigned long index);
[noscript,notxpcom,nostdcall] nsIDOMFile getItemAt(in unsigned long index);
};

View File

@ -67,6 +67,7 @@
#include "plbase64.h"
#include "prmem.h"
#include "dombindings.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -607,14 +608,39 @@ nsDOMMemoryFile::GetInternalStream(nsIInputStream **aStream)
DOMCI_DATA(FileList, nsDOMFileList)
NS_INTERFACE_MAP_BEGIN(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMFileList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFileList)
NS_INTERFACE_MAP_ENTRY(nsIDOMFileList)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(FileList)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMFileList)
NS_IMPL_RELEASE(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMFileList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMFileList)
JSObject*
nsDOMFileList::WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
bool *triedToWrap)
{
return mozilla::dom::binding::FileList::create(cx, scope, this, triedToWrap);
}
nsIDOMFile*
nsDOMFileList::GetItemAt(PRUint32 aIndex)
{
return mFiles.SafeObjectAt(aIndex);
}
NS_IMETHODIMP
nsDOMFileList::GetLength(PRUint32* aLength)
@ -627,7 +653,7 @@ nsDOMFileList::GetLength(PRUint32* aLength)
NS_IMETHODIMP
nsDOMFileList::Item(PRUint32 aIndex, nsIDOMFile **aFile)
{
NS_IF_ADDREF(*aFile = GetItemAt(aIndex));
NS_IF_ADDREF(*aFile = nsDOMFileList::GetItemAt(aIndex));
return NS_OK;
}

View File

@ -58,7 +58,20 @@
using namespace mozilla;
NS_IMPL_CYCLE_COLLECTION_2(nsDOMDataTransfer, mDragTarget, mDragImage)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMDataTransfer)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMDataTransfer)
if (tmp->mFiles) {
tmp->mFiles->Disconnect();
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFiles)
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragTarget)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDragImage)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMDataTransfer)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFiles)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragTarget)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDragImage)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMDataTransfer)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMDataTransfer)
@ -235,7 +248,7 @@ nsDOMDataTransfer::GetFiles(nsIDOMFileList** aFileList)
return NS_OK;
if (!mFiles) {
mFiles = new nsDOMFileList();
mFiles = new nsDOMFileList(static_cast<nsIDOMDataTransfer*>(this));
NS_ENSURE_TRUE(mFiles, NS_ERROR_OUT_OF_MEMORY);
PRUint32 count = mItems.Length();

View File

@ -105,6 +105,13 @@ protected:
PRUint32 aDragImageX,
PRUint32 aDragImageY);
~nsDOMDataTransfer()
{
if (mFiles) {
mFiles->Disconnect();
}
}
static const char sEffects[8][9];
public:

View File

@ -587,6 +587,9 @@ nsHTMLInputElement::nsHTMLInputElement(already_AddRefed<nsINodeInfo> aNodeInfo,
nsHTMLInputElement::~nsHTMLInputElement()
{
if (mFileList) {
mFileList->Disconnect();
}
DestroyImageLoadingContent();
FreeData();
}
@ -634,7 +637,10 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLInputElement,
nsGenericHTMLFormElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mControllers)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mFiles)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mFileList);
if (tmp->mFileList) {
tmp->mFileList->Disconnect();
tmp->mFileList = nsnull;
}
//XXX should unlink more?
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
@ -2773,7 +2779,7 @@ nsHTMLInputElement::GetFiles(nsIDOMFileList** aFileList)
}
if (!mFileList) {
mFileList = new nsDOMFileList();
mFileList = new nsDOMFileList(static_cast<nsIContent*>(this));
if (!mFileList) return NS_ERROR_OUT_OF_MEMORY;
UpdateFileList();

View File

@ -9,6 +9,7 @@ prefableClasses = {
'ClientRectList': 'nsClientRectList',
'PaintRequestList': 'nsPaintRequestList',
'TouchList': 'nsDOMTouchList',
'FileList': 'nsDOMFileList',
}
irregularFilenames = {
@ -18,6 +19,7 @@ irregularFilenames = {
'nsIDOMTouch': 'nsIDOMTouchEvent',
'nsIDOMTouchList': 'nsIDOMTouchEvent',
'nsDOMTouchList': 'nsDOMTouchEvent',
'nsDOMFileList': 'nsDOMFile',
}
customInheritance = {