mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
fix: file selection when disallowed on macOS (#38557)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user