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

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