From d44e0b70462df3cdda9d4d89c39b4c2e2d89cb6d Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Sat, 15 Mar 2025 19:52:58 +0000 Subject: [PATCH] Bug 1952343 - Notify nsI{Color|File}PickerShownCallback asynchronously when picker is blocked; r=emilio Otherwise, the HTMLInputElement doesn't handle the mPickerRunning flag right if it is in parent process. There is no such problem on content process because the IPC is async. Differential Revision: https://phabricator.services.mozilla.com/D241440 --- widget/nsBaseColorPicker.cpp | 7 +++++-- widget/nsBaseFilePicker.cpp | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/widget/nsBaseColorPicker.cpp b/widget/nsBaseColorPicker.cpp index e6f10c8dfa6c..5c13bbe3c38c 100644 --- a/widget/nsBaseColorPicker.cpp +++ b/widget/nsBaseColorPicker.cpp @@ -7,6 +7,7 @@ #include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/CanonicalBrowsingContext.h" +#include "nsThreadUtils.h" NS_IMETHODIMP nsBaseColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext, @@ -47,8 +48,10 @@ bool nsBaseColorPicker::MaybeBlockColorPicker( if (!mBrowsingContext->Canonical()->CanOpenModalPicker()) { if (aCallback) { // Color pickers are disabled, so we answer the callback with - // returnCancel. - aCallback->Done(EmptyString()); + // empty string. + NS_DispatchToCurrentThread(mozilla::NewRunnableMethod( + "nsBaseColorPicker::CallbackWithEmptyString", aCallback, + &nsIColorPickerShownCallback::Done, EmptyString())); } return true; } diff --git a/widget/nsBaseFilePicker.cpp b/widget/nsBaseFilePicker.cpp index bed69bffc73b..7de814a376f0 100644 --- a/widget/nsBaseFilePicker.cpp +++ b/widget/nsBaseFilePicker.cpp @@ -26,6 +26,7 @@ #include "WidgetUtils.h" #include "nsSimpleEnumerator.h" #include "nsContentUtils.h" +#include "nsThreadUtils.h" #include "nsBaseFilePicker.h" @@ -351,7 +352,10 @@ bool nsBaseFilePicker::MaybeBlockFilePicker( if (mozilla::StaticPrefs::widget_disable_file_pickers()) { if (aCallback) { // File pickers are disabled, so we answer the callback with returnCancel. - aCallback->Done(nsIFilePicker::returnCancel); + NS_DispatchToCurrentThread( + mozilla::NewRunnableMethod( + "nsBaseFilePicker::CallbackWithCancelResult", aCallback, + &nsIFilePickerShownCallback::Done, nsIFilePicker::returnCancel)); } RefPtr topFrameElement = mBrowsingContext->GetTopFrameElement(); @@ -372,7 +376,10 @@ bool nsBaseFilePicker::MaybeBlockFilePicker( if (aCallback) { // File pickers are not allowed to open, so we respond to the callback with // returnCancel. - aCallback->Done(nsIFilePicker::returnCancel); + NS_DispatchToCurrentThread( + mozilla::NewRunnableMethod( + "nsBaseFilePicker::CallbackWithCancelResult", aCallback, + &nsIFilePickerShownCallback::Done, nsIFilePicker::returnCancel)); } return true;