Bug 660586 - Prevent hangs when selecting a large number of files in MacOS X file picker. r=joshmoz

This commit is contained in:
Mounir Lamouri 2011-06-03 00:36:11 +02:00
parent 42d1a4c2b4
commit 271cf17825

View File

@ -399,15 +399,24 @@ nsFilePicker::GetLocalFiles(const nsString& inTitle, PRBool inAllowMultiple, nsC
if (result == NSFileHandlingPanelCancelButton)
return retVal;
// append each chosen file to our list
for (unsigned int i = 0; i < [[thePanel URLs] count]; i++) {
NSURL *theURL = [[thePanel URLs] objectAtIndex:i];
if (theURL) {
nsCOMPtr<nsILocalFile> localFile;
NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(localFile);
if (macLocalFile && NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)theURL)))
outFiles.AppendObject(localFile);
// Converts data from a NSArray of NSURL to the returned format.
// We should be careful to not call [thePanel URLs] more than once given that
// it creates a new array each time.
// TODO: we should use Fast Enumeration as soon as Obj-C 2.0 is allowed in
// our code.
NSArray* urls = [thePanel URLs];
for (unsigned int i = 0; i < [urls count]; ++i) {
NSURL* url = [urls objectAtIndex:i];
if (!url) {
continue;
}
nsCOMPtr<nsILocalFile> localFile;
NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
nsCOMPtr<nsILocalFileMac> macLocalFile = do_QueryInterface(localFile);
if (macLocalFile && NS_SUCCEEDED(macLocalFile->InitWithCFURL((CFURLRef)url))) {
outFiles.AppendObject(localFile);
}
}