Bug 1185381 - Make FileList clonable - patch 1 - move code into FileList.h/.cpp, r=smaug

This commit is contained in:
Andrea Marchesini 2015-07-22 17:03:07 +01:00
Родитель 3fafd87671
Коммит 367d4612a6
11 изменённых файлов: 156 добавлений и 115 удалений

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

@ -41,8 +41,6 @@
#include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerPrivate.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "mozilla/dom/FileListBinding.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -1232,42 +1230,6 @@ BlobImplTemporaryBlob::GetInternalStream(nsIInputStream** aStream,
stream.forget(aStream); stream.forget(aStream);
} }
////////////////////////////////////////////////////////////////////////////
// FileList implementation
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileList, mFiles, mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFileList)
NS_INTERFACE_MAP_ENTRY(nsIDOMFileList)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileList)
JSObject*
FileList::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto)
{
return mozilla::dom::FileListBinding::Wrap(cx, this, aGivenProto);
}
NS_IMETHODIMP
FileList::GetLength(uint32_t* aLength)
{
*aLength = Length();
return NS_OK;
}
NS_IMETHODIMP
FileList::Item(uint32_t aIndex, nsISupports** aFile)
{
nsCOMPtr<nsIDOMBlob> file = Item(aIndex);
file.forget(aFile);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// BlobSet implementation // BlobSet implementation

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

@ -21,7 +21,6 @@
#include "nsCycleCollectionParticipant.h" #include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIDOMBlob.h" #include "nsIDOMBlob.h"
#include "nsIDOMFileList.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsIMutable.h" #include "nsIMutable.h"
#include "nsIXMLHttpRequest.h" #include "nsIXMLHttpRequest.h"
@ -976,78 +975,6 @@ private:
bool mIsTemporary; bool mIsTemporary;
}; };
class FileList final : public nsIDOMFileList,
public nsWrapperCache
{
~FileList() {}
public:
explicit FileList(nsISupports *aParent) : mParent(aParent)
{
}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList)
NS_DECL_NSIDOMFILELIST
virtual JSObject* WrapObject(JSContext *cx,
JS::Handle<JSObject*> aGivenProto) override;
nsISupports* GetParentObject()
{
return mParent;
}
bool Append(File *aFile) { return mFiles.AppendElement(aFile); }
bool Remove(uint32_t aIndex) {
if (aIndex < mFiles.Length()) {
mFiles.RemoveElementAt(aIndex);
return true;
}
return false;
}
void Clear() { return mFiles.Clear(); }
static FileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMFileList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMFileList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == static_cast<nsIDOMFileList*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<FileList*>(aSupports);
}
File* Item(uint32_t aIndex)
{
return mFiles.SafeElementAt(aIndex);
}
File* IndexedGetter(uint32_t aIndex, bool& aFound)
{
aFound = aIndex < mFiles.Length();
return aFound ? mFiles.ElementAt(aIndex) : nullptr;
}
uint32_t Length()
{
return mFiles.Length();
}
private:
nsTArray<nsRefPtr<File>> mFiles;
nsCOMPtr<nsISupports> mParent;
};
} // namespace dom } // namespace dom
} // namespace mozilla } // namespace mozilla

47
dom/base/FileList.cpp Normal file
Просмотреть файл

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/FileList.h"
#include "mozilla/dom/FileListBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FileList, mFiles, mParent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FileList)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMFileList)
NS_INTERFACE_MAP_ENTRY(nsIDOMFileList)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(FileList)
NS_IMPL_CYCLE_COLLECTING_RELEASE(FileList)
JSObject*
FileList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return mozilla::dom::FileListBinding::Wrap(aCx, this, aGivenProto);
}
NS_IMETHODIMP
FileList::GetLength(uint32_t* aLength)
{
*aLength = Length();
return NS_OK;
}
NS_IMETHODIMP
FileList::Item(uint32_t aIndex, nsISupports** aFile)
{
nsCOMPtr<nsIDOMBlob> file = Item(aIndex);
file.forget(aFile);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

102
dom/base/FileList.h Normal file
Просмотреть файл

@ -0,0 +1,102 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_FileList_h
#define mozilla_dom_FileList_h
#include "nsIDOMFileList.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
class File;
class FileList final : public nsIDOMFileList,
public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FileList)
NS_DECL_NSIDOMFILELIST
explicit FileList(nsISupports* aParent)
: mParent(aParent)
{}
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsISupports* GetParentObject()
{
return mParent;
}
bool Append(File* aFile)
{
return mFiles.AppendElement(aFile);
}
bool Remove(uint32_t aIndex)
{
if (aIndex < mFiles.Length()) {
mFiles.RemoveElementAt(aIndex);
return true;
}
return false;
}
void Clear()
{
return mFiles.Clear();
}
static FileList* FromSupports(nsISupports* aSupports)
{
#ifdef DEBUG
{
nsCOMPtr<nsIDOMFileList> list_qi = do_QueryInterface(aSupports);
// If this assertion fires the QI implementation for the object in
// question doesn't use the nsIDOMFileList pointer as the nsISupports
// pointer. That must be fixed, or we'll crash...
NS_ASSERTION(list_qi == static_cast<nsIDOMFileList*>(aSupports),
"Uh, fix QI!");
}
#endif
return static_cast<FileList*>(aSupports);
}
File* Item(uint32_t aIndex)
{
return mFiles.SafeElementAt(aIndex);
}
File* IndexedGetter(uint32_t aIndex, bool& aFound)
{
aFound = aIndex < mFiles.Length();
return aFound ? mFiles.ElementAt(aIndex) : nullptr;
}
uint32_t Length()
{
return mFiles.Length();
}
private:
~FileList() {}
nsTArray<nsRefPtr<File>> mFiles;
nsCOMPtr<nsISupports> mParent;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_FileList_h

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

@ -8,6 +8,7 @@
#include "MessageEvent.h" #include "MessageEvent.h"
#include "mozilla/dom/BlobBinding.h" #include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/FileList.h"
#include "mozilla/dom/MessagePort.h" #include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/MessagePortBinding.h"
#include "mozilla/dom/PMessagePort.h" #include "mozilla/dom/PMessagePort.h"

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

@ -175,6 +175,7 @@ EXPORTS.mozilla.dom += [
'ElementInlines.h', 'ElementInlines.h',
'EventSource.h', 'EventSource.h',
'File.h', 'File.h',
'FileList.h',
'FragmentOrElement.h', 'FragmentOrElement.h',
'FromParser.h', 'FromParser.h',
'ImageEncoder.h', 'ImageEncoder.h',
@ -233,6 +234,7 @@ UNIFIED_SOURCES += [
'EventSource.cpp', 'EventSource.cpp',
'File.cpp', 'File.cpp',
'FileIOObject.cpp', 'FileIOObject.cpp',
'FileList.cpp',
'FragmentOrElement.cpp', 'FragmentOrElement.cpp',
'ImageEncoder.cpp', 'ImageEncoder.cpp',
'ImportManager.cpp', 'ImportManager.cpp',

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

@ -18,6 +18,7 @@
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsINode.h" #include "nsINode.h"
#include "nsIDOMWindow.h" #include "nsIDOMWindow.h"
#include "nsIURI.h"
NS_IMPL_ISUPPORTS(nsDataDocumentContentPolicy, nsIContentPolicy) NS_IMPL_ISUPPORTS(nsDataDocumentContentPolicy, nsIContentPolicy)

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

@ -481,10 +481,6 @@ DOMInterfaces = {
}, },
}, },
'FileList': {
'headerFile': 'mozilla/dom/File.h',
},
'FileReader': { 'FileReader': {
'nativeType': 'nsDOMFileReader', 'nativeType': 'nsDOMFileReader',
'implicitJSContext': [ 'readAsArrayBuffer' ], 'implicitJSContext': [ 'readAsArrayBuffer' ],

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

@ -28,6 +28,7 @@
#include "mozilla/dom/DataTransferBinding.h" #include "mozilla/dom/DataTransferBinding.h"
#include "mozilla/dom/Directory.h" #include "mozilla/dom/Directory.h"
#include "mozilla/dom/Element.h" #include "mozilla/dom/Element.h"
#include "mozilla/dom/FileList.h"
#include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/OSFileSystem.h" #include "mozilla/dom/OSFileSystem.h"

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

@ -34,6 +34,7 @@ namespace dom {
class DOMStringList; class DOMStringList;
class Element; class Element;
class FileList;
template<typename T> class Optional; template<typename T> class Optional;
/** /**

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

@ -80,6 +80,7 @@
// input type=file // input type=file
#include "mozilla/dom/File.h" #include "mozilla/dom/File.h"
#include "mozilla/dom/FileList.h"
#include "nsIFile.h" #include "nsIFile.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"