Skip to content

Commit

Permalink
M101: Prevent multiple SelectFileDialog in BookmarksIOFunction
Browse files Browse the repository at this point in the history
Similar to crrev.com/c/3546821

(cherry picked from commit 0a6b033)

Bug: 1309583
Change-Id: I61c852d2dc44720d4a47677a2725dc58c7b9627d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3577755
Auto-Submit: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: Ben Wells <benwells@chromium.org>
Commit-Queue: Ben Wells <benwells@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#991345}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3586522
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/branch-heads/4951@{#1058}
Cr-Branched-From: 27de622-refs/heads/main@{#982481}
  • Loading branch information
Luciano Pacheco authored and Chromium LUCI CQ committed Apr 26, 2022
1 parent ec78aae commit 4ffea64
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chrome/browser/extensions/api/bookmarks/bookmarks_api.cc
Expand Up @@ -723,6 +723,10 @@ void BookmarksIOFunction::ShowSelectFileDialog(
if (!dispatcher())
return; // Extension was unloaded.

// Early return if the select file dialog is already active.
if (select_file_dialog_)
return;

DCHECK_CURRENTLY_ON(content::BrowserThread::UI);

// Balanced in one of the three callbacks of SelectFileDialog:
Expand All @@ -748,11 +752,13 @@ void BookmarksIOFunction::ShowSelectFileDialog(
}

void BookmarksIOFunction::FileSelectionCanceled(void* params) {
select_file_dialog_.reset();
Release(); // Balanced in BookmarksIOFunction::SelectFile()
}

void BookmarksIOFunction::MultiFilesSelected(
const std::vector<base::FilePath>& files, void* params) {
select_file_dialog_.reset();
Release(); // Balanced in BookmarsIOFunction::SelectFile()
NOTREACHED() << "Should not be able to select multiple files";
}
Expand Down Expand Up @@ -784,6 +790,7 @@ void BookmarksImportFunction::FileSelected(const base::FilePath& path,

importer::LogImporterUseToMetrics("BookmarksAPI",
importer::TYPE_BOOKMARKS_FILE);
select_file_dialog_.reset();
Release(); // Balanced in BookmarksIOFunction::SelectFile()
}

Expand All @@ -810,6 +817,7 @@ void BookmarksExportFunction::FileSelected(const base::FilePath& path,
int index,
void* params) {
bookmark_html_writer::WriteBookmarks(GetProfile(), path, nullptr);
select_file_dialog_.reset();
Release(); // Balanced in BookmarksIOFunction::SelectFile()
}

Expand Down

0 comments on commit 4ffea64

Please sign in to comment.