Bug 1238515 - nsIFilePicker methods should clearly say when they return directories and files, r=smaug

This commit is contained in:
Andrea Marchesini 2016-01-12 10:23:13 +00:00
Родитель d89b7c6795
Коммит 923de404a2
11 изменённых файлов: 55 добавлений и 49 удалений

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

@ -71,11 +71,12 @@ FilePicker.prototype = {
/* readonly attribute nsISimpleEnumerator files - not implemented; */
/* readonly attribute nsIURI fileURL - not implemented; */
get domfiles() {
get domFileOrDirectoryEnumerator() {
return this.mFilesEnumerator;
},
get domfile() {
// We don't support directory selection yet.
get domFileOrDirectory() {
return this.mFilesEnumerator ? this.mFilesEnumerator.mFiles[0] : null;
},

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

@ -386,7 +386,8 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
nsTArray<RefPtr<File>> newFiles;
if (mode == static_cast<int16_t>(nsIFilePicker::modeOpenMultiple)) {
nsCOMPtr<nsISimpleEnumerator> iter;
nsresult rv = mFilePicker->GetDomfiles(getter_AddRefs(iter));
nsresult rv =
mFilePicker->GetDomFileOrDirectoryEnumerator(getter_AddRefs(iter));
NS_ENSURE_SUCCESS(rv, rv);
if (!iter) {
@ -409,7 +410,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
MOZ_ASSERT(mode == static_cast<int16_t>(nsIFilePicker::modeOpen) ||
mode == static_cast<int16_t>(nsIFilePicker::modeGetFolder));
nsCOMPtr<nsISupports> tmp;
nsresult rv = mFilePicker->GetDomfile(getter_AddRefs(tmp));
nsresult rv = mFilePicker->GetDomFileOrDirectory(getter_AddRefs(tmp));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMBlob> blob = do_QueryInterface(tmp);

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

@ -140,7 +140,8 @@ FilePicker.prototype = {
});
},
get domfile() {
// We don't support directory selection yet.
get domFileOrDirectory() {
let f = this.file;
if (!f) {
return null;
@ -155,7 +156,7 @@ FilePicker.prototype = {
return new File(f);
},
get domfiles() {
get domFileOrDirectoryEnumerator() {
let win = this._domWin;
return this.getEnumerator([this.file], function(file) {
if (win) {

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

@ -31,14 +31,15 @@ add_test(function filepicker_open() {
is(file.path, "/mnt/sdcard/my-favorite-martian.png", "Retrieve the right martian file from array!");
}
do_print("DOMFile: " + fp.domfile.mozFullPath);
is(fp.domfile.mozFullPath, "/mnt/sdcard/my-favorite-martian.png", "Retrieve the right martian domfile!");
let file = fp.domFileOrDirectory;
do_print("DOMFile: " + file.mozFullPath);
is(file.mozFullPath, "/mnt/sdcard/my-favorite-martian.png", "Retrieve the right martian DOM File!");
let domfiles = fp.domfiles;
while (domfiles.hasMoreElements()) {
let domfile = domfiles.getNext();
do_print("DOMFile: " + domfile.mozFullPath);
is(domfile.mozFullPath, "/mnt/sdcard/my-favorite-martian.png", "Retrieve the right martian file from domfile array!");
let enum = fp.domFileOrDirectoryEnumerator;
while (enum.hasMoreElements()) {
let file = enum.getNext();
do_print("DOMFile: " + file.mozFullPath);
is(file.mozFullPath, "/mnt/sdcard/my-favorite-martian.png", "Retrieve the right martian file from domFileOrDirectoryEnumerator array!");
}
do_test_finished();

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

@ -146,7 +146,9 @@ MockFilePickerInstance.prototype = {
return null;
},
get domfile() {
// We don't support directories here.
get domFileOrDirectory() {
if (MockFilePicker.returnFiles.length >= 1) {
// window.File does not implement nsIFile
if (!MockFilePicker.isNsIFile(MockFilePicker.returnFiles[0])) {
@ -184,7 +186,7 @@ MockFilePickerInstance.prototype = {
}
};
},
get domfiles() {
get domFileOrDirectoryEnumerator() {
let utils = this.parent.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
return {

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

@ -93,14 +93,14 @@ nsFilePicker.prototype = {
/* readonly attribute nsISimpleEnumerator files; */
get files() { return this.mFilesEnumerator; },
/* readonly attribute DOM File domfile; */
get domfile() {
let enumerator = this.domfiles;
/* we don't support directories, yet */
get domFileOrDirectory() {
let enumerator = this.domFileOrDirectoryEnumerator;
return enumerator ? enumerator.mFiles[0] : null;
},
/* readonly attribute nsISimpleEnumerator domfiles; */
get domfiles() {
/* readonly attribute nsISimpleEnumerator domFileOrDirectoryEnumerator; */
get domFileOrDirectoryEnumerator() {
if (!this.mFilesEnumerator) {
return null;
}

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

@ -337,25 +337,25 @@ nsBaseFilePicker::GetMode(int16_t* aMode)
}
NS_IMETHODIMP
nsBaseFilePicker::GetDomfile(nsISupports** aDomfile)
nsBaseFilePicker::GetDomFileOrDirectory(nsISupports** aValue)
{
nsCOMPtr<nsIFile> localFile;
nsresult rv = GetFile(getter_AddRefs(localFile));
NS_ENSURE_SUCCESS(rv, rv);
if (!localFile) {
*aDomfile = nullptr;
*aValue = nullptr;
return NS_OK;
}
RefPtr<File> domFile = File::CreateFromFile(mParent, localFile);
domFile->Impl()->SetIsDirectory(mMode == nsIFilePicker::modeGetFolder);
nsCOMPtr<nsIDOMBlob>(domFile).forget(aDomfile);
nsCOMPtr<nsIDOMBlob>(domFile).forget(aValue);
return NS_OK;
}
NS_IMETHODIMP
nsBaseFilePicker::GetDomfiles(nsISimpleEnumerator** aDomfiles)
nsBaseFilePicker::GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aValue)
{
nsCOMPtr<nsISimpleEnumerator> iter;
nsresult rv = GetFiles(getter_AddRefs(iter));
@ -364,7 +364,7 @@ nsBaseFilePicker::GetDomfiles(nsISimpleEnumerator** aDomfiles)
RefPtr<nsBaseFilePickerEnumerator> retIter =
new nsBaseFilePickerEnumerator(mParent, iter, mMode);
retIter.forget(aDomfiles);
retIter.forget(aValue);
return NS_OK;
}

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

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

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

@ -102,21 +102,21 @@ nsFilePickerProxy::SetFilterIndex(int32_t aFilterIndex)
NS_IMETHODIMP
nsFilePickerProxy::GetFile(nsIFile** aFile)
{
MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomfile");
MOZ_ASSERT(false, "GetFile is unimplemented; use GetDomFileOrDirectory");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsFilePickerProxy::GetFileURL(nsIURI** aFileURL)
{
MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomfile");
MOZ_ASSERT(false, "GetFileURL is unimplemented; use GetDomFileOrDirectory");
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsFilePickerProxy::GetFiles(nsISimpleEnumerator** aFiles)
{
MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomfiles");
MOZ_ASSERT(false, "GetFiles is unimplemented; use GetDomFileOrDirectoryEnumerator");
return NS_ERROR_FAILURE;
}
@ -161,7 +161,7 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
RefPtr<File> file = File::Create(mParent, blobImpl);
MOZ_ASSERT(file);
mDomfiles.AppendElement(file);
mFilesOrDirectories.AppendElement(file);
}
}
@ -174,16 +174,16 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputFiles& aFiles,
}
NS_IMETHODIMP
nsFilePickerProxy::GetDomfile(nsISupports** aDomfile)
nsFilePickerProxy::GetDomFileOrDirectory(nsISupports** aValue)
{
*aDomfile = nullptr;
if (mDomfiles.IsEmpty()) {
*aValue = nullptr;
if (mFilesOrDirectories.IsEmpty()) {
return NS_OK;
}
MOZ_ASSERT(mDomfiles.Length() == 1);
nsCOMPtr<nsIDOMBlob> blob = mDomfiles[0].get();
blob.forget(aDomfile);
MOZ_ASSERT(mFilesOrDirectories.Length() == 1);
nsCOMPtr<nsIDOMBlob> blob = mFilesOrDirectories[0].get();
blob.forget(aValue);
return NS_OK;
}
@ -230,9 +230,9 @@ NS_IMPL_ISUPPORTS(SimpleEnumerator, nsISimpleEnumerator)
} // namespace
NS_IMETHODIMP
nsFilePickerProxy::GetDomfiles(nsISimpleEnumerator** aDomfiles)
nsFilePickerProxy::GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aDomfiles)
{
RefPtr<SimpleEnumerator> enumerator = new SimpleEnumerator(mDomfiles);
RefPtr<SimpleEnumerator> enumerator = new SimpleEnumerator(mFilesOrDirectories);
enumerator.forget(aDomfiles);
return NS_OK;
}

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

@ -51,8 +51,8 @@ public:
NS_IMETHODIMP GetFileURL(nsIURI** aFileURL) override;
NS_IMETHODIMP GetFiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP GetDomfile(nsISupports** aFile) override;
NS_IMETHODIMP GetDomfiles(nsISimpleEnumerator** aFiles) override;
NS_IMETHODIMP GetDomFileOrDirectory(nsISupports** aValue) override;
NS_IMETHODIMP GetDomFileOrDirectoryEnumerator(nsISimpleEnumerator** aValue) override;
NS_IMETHODIMP Show(int16_t* aReturn) override;
NS_IMETHODIMP Open(nsIFilePickerShownCallback* aCallback) override;
@ -65,7 +65,7 @@ private:
~nsFilePickerProxy();
void InitNative(nsIWidget*, const nsAString&) override;
nsTArray<RefPtr<mozilla::dom::File>> mDomfiles;
nsTArray<RefPtr<mozilla::dom::File>> mFilesOrDirectories;
nsCOMPtr<nsIFilePickerShownCallback> mCallback;
int16_t mSelectedType;

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

@ -23,7 +23,7 @@ interface nsIFilePickerShownCallback : nsISupports
void done(in short aResult);
};
[scriptable, uuid(9840d564-42c8-4d78-9a4d-71002343c918)]
[scriptable, uuid(2a74ba0d-ffdd-4dad-b78a-98635e525a38)]
interface nsIFilePicker : nsISupports
{
const short modeOpen = 0; // Load a file or directory
@ -142,19 +142,19 @@ interface nsIFilePicker : nsISupports
readonly attribute nsISimpleEnumerator files;
/**
* Get the DOM File for the file.
* Get the DOM File or the DOM Directory
*
* @return Returns the file currently selected as File
* @return Returns the file or directory currently selected DOM object.
*/
readonly attribute nsISupports domfile;
readonly attribute nsISupports domFileOrDirectory;
/**
* Get the enumerator for the selected files
* Get the enumerator for the selected files or directories
* only works in the modeOpenMultiple mode
*
* @return Returns the files currently selected as Files
* @return Returns the files/directories currently selected as DOM object.
*/
readonly attribute nsISimpleEnumerator domfiles;
readonly attribute nsISimpleEnumerator domFileOrDirectoryEnumerator;
/**
* Controls whether the chosen file(s) should be added to the system's recent