mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1185381 - Make FileList clonable - patch 1 - move code into FileList.h/.cpp, r=smaug
This commit is contained in:
parent
40ecfa670a
commit
37c7484608
@ -41,8 +41,6 @@
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "mozilla/dom/FileListBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@ -1232,42 +1230,6 @@ BlobImplTemporaryBlob::GetInternalStream(nsIInputStream** 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
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDOMBlob.h"
|
||||
#include "nsIDOMFileList.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsIMutable.h"
|
||||
#include "nsIXMLHttpRequest.h"
|
||||
@ -976,78 +975,6 @@ private:
|
||||
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 mozilla
|
||||
|
||||
|
47
dom/base/FileList.cpp
Normal file
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
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 "mozilla/dom/BlobBinding.h"
|
||||
#include "mozilla/dom/FileList.h"
|
||||
#include "mozilla/dom/MessagePort.h"
|
||||
#include "mozilla/dom/MessagePortBinding.h"
|
||||
#include "mozilla/dom/PMessagePort.h"
|
||||
|
@ -175,6 +175,7 @@ EXPORTS.mozilla.dom += [
|
||||
'ElementInlines.h',
|
||||
'EventSource.h',
|
||||
'File.h',
|
||||
'FileList.h',
|
||||
'FragmentOrElement.h',
|
||||
'FromParser.h',
|
||||
'ImageEncoder.h',
|
||||
@ -233,6 +234,7 @@ UNIFIED_SOURCES += [
|
||||
'EventSource.cpp',
|
||||
'File.cpp',
|
||||
'FileIOObject.cpp',
|
||||
'FileList.cpp',
|
||||
'FragmentOrElement.cpp',
|
||||
'ImageEncoder.cpp',
|
||||
'ImportManager.cpp',
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINode.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsDataDocumentContentPolicy, nsIContentPolicy)
|
||||
|
||||
|
@ -481,10 +481,6 @@ DOMInterfaces = {
|
||||
},
|
||||
},
|
||||
|
||||
'FileList': {
|
||||
'headerFile': 'mozilla/dom/File.h',
|
||||
},
|
||||
|
||||
'FileReader': {
|
||||
'nativeType': 'nsDOMFileReader',
|
||||
'implicitJSContext': [ 'readAsArrayBuffer' ],
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "mozilla/dom/DataTransferBinding.h"
|
||||
#include "mozilla/dom/Directory.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "mozilla/dom/FileList.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/OSFileSystem.h"
|
||||
|
||||
|
@ -34,6 +34,7 @@ namespace dom {
|
||||
|
||||
class DOMStringList;
|
||||
class Element;
|
||||
class FileList;
|
||||
template<typename T> class Optional;
|
||||
|
||||
/**
|
||||
|
@ -80,6 +80,7 @@
|
||||
|
||||
// input type=file
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/FileList.h"
|
||||
#include "nsIFile.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
Loading…
Reference in New Issue
Block a user