From 973c344f1b179a942a1ce73853646632a6ce545c Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:39:09 -0600 Subject: [PATCH] fix: `getAsFileSystemHandle` failure when drag-dropping two directories (#45258) fix: drag-dropping two directories Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr --- .../file_system_access_permission_context.cc | 19 +++++++++++-------- .../file_system_access_permission_context.h | 9 ++++++--- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/shell/browser/file_system_access/file_system_access_permission_context.cc b/shell/browser/file_system_access/file_system_access_permission_context.cc index 756aae63e5ed..5e8364210210 100644 --- a/shell/browser/file_system_access/file_system_access_permission_context.cc +++ b/shell/browser/file_system_access/file_system_access_permission_context.cc @@ -592,7 +592,7 @@ void FileSystemAccessPermissionContext::ConfirmSensitiveEntryAccess( content::GlobalRenderFrameHostId frame_id, base::OnceCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - callback_ = std::move(callback); + callback_map_.try_emplace(path_info.path, std::move(callback)); auto after_blocklist_check_callback = base::BindOnce( &FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist, @@ -636,16 +636,18 @@ void FileSystemAccessPermissionContext::PerformAfterWriteChecks( } void FileSystemAccessPermissionContext::RunRestrictedPathCallback( + const base::FilePath& file_path, SensitiveEntryResult result) { - if (callback_) - std::move(callback_).Run(result); + if (auto val = callback_map_.extract(file_path)) + std::move(val.mapped()).Run(result); } void FileSystemAccessPermissionContext::OnRestrictedPathResult( + const base::FilePath& file_path, gin::Arguments* args) { SensitiveEntryResult result = SensitiveEntryResult::kAbort; args->GetNext(&result); - RunRestrictedPathCallback(result); + RunRestrictedPathCallback(file_path, result); } void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist( @@ -658,8 +660,9 @@ void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist( DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (user_action == UserAction::kNone) { - RunRestrictedPathCallback(should_block ? SensitiveEntryResult::kAbort - : SensitiveEntryResult::kAllowed); + auto result = should_block ? SensitiveEntryResult::kAbort + : SensitiveEntryResult::kAllowed; + RunRestrictedPathCallback(path_info.path, result); return; } @@ -678,11 +681,11 @@ void FileSystemAccessPermissionContext::DidCheckPathAgainstBlocklist( "file-system-access-restricted", details, base::BindRepeating( &FileSystemAccessPermissionContext::OnRestrictedPathResult, - weak_factory_.GetWeakPtr())); + weak_factory_.GetWeakPtr(), path_info.path)); return; } - RunRestrictedPathCallback(SensitiveEntryResult::kAllowed); + RunRestrictedPathCallback(path_info.path, SensitiveEntryResult::kAllowed); } void FileSystemAccessPermissionContext::MaybeEvictEntries( diff --git a/shell/browser/file_system_access/file_system_access_permission_context.h b/shell/browser/file_system_access/file_system_access_permission_context.h index 9fe2f38807c9..db60e43210a9 100644 --- a/shell/browser/file_system_access/file_system_access_permission_context.h +++ b/shell/browser/file_system_access/file_system_access_permission_context.h @@ -144,9 +144,11 @@ class FileSystemAccessPermissionContext content::GlobalRenderFrameHostId frame_id, 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); @@ -170,7 +172,8 @@ class FileSystemAccessPermissionContext std::map id_pathinfo_map_; - base::OnceCallback callback_; + std::map> + callback_map_; base::WeakPtrFactory weak_factory_{this}; };