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
This commit is contained in:
Edgar Chen
2025-03-15 19:52:58 +00:00
parent 16a06d0983
commit d44e0b7046
2 changed files with 14 additions and 4 deletions

View File

@@ -7,6 +7,7 @@
#include "mozilla/dom/BrowsingContext.h" #include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/CanonicalBrowsingContext.h" #include "mozilla/dom/CanonicalBrowsingContext.h"
#include "nsThreadUtils.h"
NS_IMETHODIMP NS_IMETHODIMP
nsBaseColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext, nsBaseColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext,
@@ -47,8 +48,10 @@ bool nsBaseColorPicker::MaybeBlockColorPicker(
if (!mBrowsingContext->Canonical()->CanOpenModalPicker()) { if (!mBrowsingContext->Canonical()->CanOpenModalPicker()) {
if (aCallback) { if (aCallback) {
// Color pickers are disabled, so we answer the callback with // Color pickers are disabled, so we answer the callback with
// returnCancel. // empty string.
aCallback->Done(EmptyString()); NS_DispatchToCurrentThread(mozilla::NewRunnableMethod<const nsAString&>(
"nsBaseColorPicker::CallbackWithEmptyString", aCallback,
&nsIColorPickerShownCallback::Done, EmptyString()));
} }
return true; return true;
} }

View File

@@ -26,6 +26,7 @@
#include "WidgetUtils.h" #include "WidgetUtils.h"
#include "nsSimpleEnumerator.h" #include "nsSimpleEnumerator.h"
#include "nsContentUtils.h" #include "nsContentUtils.h"
#include "nsThreadUtils.h"
#include "nsBaseFilePicker.h" #include "nsBaseFilePicker.h"
@@ -351,7 +352,10 @@ bool nsBaseFilePicker::MaybeBlockFilePicker(
if (mozilla::StaticPrefs::widget_disable_file_pickers()) { if (mozilla::StaticPrefs::widget_disable_file_pickers()) {
if (aCallback) { if (aCallback) {
// File pickers are disabled, so we answer the callback with returnCancel. // File pickers are disabled, so we answer the callback with returnCancel.
aCallback->Done(nsIFilePicker::returnCancel); NS_DispatchToCurrentThread(
mozilla::NewRunnableMethod<nsIFilePicker::ResultCode>(
"nsBaseFilePicker::CallbackWithCancelResult", aCallback,
&nsIFilePickerShownCallback::Done, nsIFilePicker::returnCancel));
} }
RefPtr<Element> topFrameElement = mBrowsingContext->GetTopFrameElement(); RefPtr<Element> topFrameElement = mBrowsingContext->GetTopFrameElement();
@@ -372,7 +376,10 @@ bool nsBaseFilePicker::MaybeBlockFilePicker(
if (aCallback) { if (aCallback) {
// File pickers are not allowed to open, so we respond to the callback with // File pickers are not allowed to open, so we respond to the callback with
// returnCancel. // returnCancel.
aCallback->Done(nsIFilePicker::returnCancel); NS_DispatchToCurrentThread(
mozilla::NewRunnableMethod<nsIFilePicker::ResultCode>(
"nsBaseFilePicker::CallbackWithCancelResult", aCallback,
&nsIFilePickerShownCallback::Done, nsIFilePicker::returnCancel));
} }
return true; return true;