fix: file selection when disallowed on macOS (#38557)
This commit is contained in:
parent
905aad9cb6
commit
8d689c565a
1 changed files with 22 additions and 4 deletions
|
@ -281,11 +281,29 @@ void ReadDialogPathsWithBookmarks(NSOpenPanel* dialog,
|
|||
std::vector<base::FilePath>* paths,
|
||||
std::vector<std::string>* bookmarks) {
|
||||
NSArray* urls = [dialog URLs];
|
||||
for (NSURL* url in urls)
|
||||
if ([url isFileURL]) {
|
||||
paths->emplace_back(base::SysNSStringToUTF8([url path]));
|
||||
bookmarks->push_back(GetBookmarkDataFromNSURL(url));
|
||||
for (NSURL* url in urls) {
|
||||
if (![url isFileURL])
|
||||
continue;
|
||||
|
||||
NSString* path = [url path];
|
||||
|
||||
// There's a bug in macOS where despite a request to disallow file
|
||||
// selection, files/packages can be selected. If file selection
|
||||
// was disallowed, drop any files selected. See crbug.com/1357523.
|
||||
if (![dialog canChooseFiles]) {
|
||||
BOOL is_directory;
|
||||
BOOL exists =
|
||||
[[NSFileManager defaultManager] fileExistsAtPath:path
|
||||
isDirectory:&is_directory];
|
||||
BOOL is_package =
|
||||
[[NSWorkspace sharedWorkspace] isFilePackageAtPath:path];
|
||||
if (!exists || !is_directory || is_package)
|
||||
continue;
|
||||
}
|
||||
|
||||
paths->emplace_back(base::SysNSStringToUTF8(path));
|
||||
bookmarks->push_back(GetBookmarkDataFromNSURL(url));
|
||||
}
|
||||
}
|
||||
|
||||
void ReadDialogPaths(NSOpenPanel* dialog, std::vector<base::FilePath>* paths) {
|
||||
|
|
Loading…
Add table
Reference in a new issue