fix: getAsFileSystemHandle failure when drag-dropping two directories (#45234)

fix: drag-dropping two directories
This commit is contained in:
Shelley Vohr 2025-01-20 09:54:12 +01:00 committed by GitHub
parent 6953f5505f
commit 0e5fe3fa60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 11 deletions

View file

@ -588,7 +588,7 @@ void FileSystemAccessPermissionContext::ConfirmSensitiveEntryAccess(
content::GlobalRenderFrameHostId frame_id, content::GlobalRenderFrameHostId frame_id,
base::OnceCallback<void(SensitiveEntryResult)> callback) { base::OnceCallback<void(SensitiveEntryResult)> callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
callback_ = std::move(callback); callback_map_[path_info.path] = std::move(callback);
auto after_blocklist_check_callback = base::BindOnce( auto after_blocklist_check_callback = base::BindOnce(
&FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist, &FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist,
@ -632,16 +632,18 @@ void FileSystemAccessPermissionContext::PerformAfterWriteChecks(
} }
void FileSystemAccessPermissionContext::RunRestrictedPathCallback( void FileSystemAccessPermissionContext::RunRestrictedPathCallback(
const base::FilePath& file_path,
SensitiveEntryResult result) { SensitiveEntryResult result) {
if (callback_) if (base::Contains(callback_map_, file_path))
std::move(callback_).Run(result); std::move(callback_map_[file_path]).Run(result);
} }
void FileSystemAccessPermissionContext::OnRestrictedPathResult( void FileSystemAccessPermissionContext::OnRestrictedPathResult(
const base::FilePath& file_path,
gin::Arguments* args) { gin::Arguments* args) {
SensitiveEntryResult result = SensitiveEntryResult::kAbort; SensitiveEntryResult result = SensitiveEntryResult::kAbort;
args->GetNext(&result); args->GetNext(&result);
RunRestrictedPathCallback(result); RunRestrictedPathCallback(file_path, result);
} }
void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist( void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist(
@ -654,8 +656,9 @@ void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (user_action == UserAction::kNone) { if (user_action == UserAction::kNone) {
RunRestrictedPathCallback(should_block ? SensitiveEntryResult::kAbort auto result = should_block ? SensitiveEntryResult::kAbort
: SensitiveEntryResult::kAllowed); : SensitiveEntryResult::kAllowed;
RunRestrictedPathCallback(path_info.path, result);
return; return;
} }
@ -674,11 +677,11 @@ void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist(
"file-system-access-restricted", details, "file-system-access-restricted", details,
base::BindRepeating( base::BindRepeating(
&FileSystemAccessPermissionContext::OnRestrictedPathResult, &FileSystemAccessPermissionContext::OnRestrictedPathResult,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr(), path_info.path));
return; return;
} }
RunRestrictedPathCallback(SensitiveEntryResult::kAllowed); RunRestrictedPathCallback(path_info.path, SensitiveEntryResult::kAllowed);
} }
void FileSystemAccessPermissionContext::MaybeEvictEntries( void FileSystemAccessPermissionContext::MaybeEvictEntries(

View file

@ -144,9 +144,11 @@ class FileSystemAccessPermissionContext
content::GlobalRenderFrameHostId frame_id, content::GlobalRenderFrameHostId frame_id,
bool should_block); bool should_block);
void RunRestrictedPathCallback(SensitiveEntryResult result); void RunRestrictedPathCallback(const base::FilePath& file_path,
SensitiveEntryResult result);
void OnRestrictedPathResult(gin::Arguments* args); void OnRestrictedPathResult(const base::FilePath& file_path,
gin::Arguments* args);
void MaybeEvictEntries(base::Value::Dict& dict); void MaybeEvictEntries(base::Value::Dict& dict);
@ -170,7 +172,8 @@ class FileSystemAccessPermissionContext
std::map<url::Origin, base::Value::Dict> id_pathinfo_map_; std::map<url::Origin, base::Value::Dict> id_pathinfo_map_;
base::OnceCallback<void(SensitiveEntryResult)> callback_; std::map<base::FilePath, base::OnceCallback<void(SensitiveEntryResult)>>
callback_map_;
base::WeakPtrFactory<FileSystemAccessPermissionContext> weak_factory_{this}; base::WeakPtrFactory<FileSystemAccessPermissionContext> weak_factory_{this};
}; };