diff --git a/mobile/shared/components/geckoview/ColorPickerDelegate.sys.mjs b/mobile/shared/components/geckoview/ColorPickerDelegate.sys.mjs index 81ebea0732a5..1a1c7c9e9a89 100644 --- a/mobile/shared/components/geckoview/ColorPickerDelegate.sys.mjs +++ b/mobile/shared/components/geckoview/ColorPickerDelegate.sys.mjs @@ -15,6 +15,7 @@ const { debug, warn } = GeckoViewUtils.initLogging("ColorPickerDelegate"); export class ColorPickerDelegate { // TODO(bug 1805397): Implement default colors init(aBrowsingContext, aTitle, aInitialColor, aDefaultColors) { + this._browsingContext = aBrowsingContext; this._prompt = new lazy.GeckoViewPrompter(aBrowsingContext); this._msg = { type: "color", @@ -25,6 +26,13 @@ export class ColorPickerDelegate { } open(aColorPickerShownCallback) { + if (!this._browsingContext.canOpenModalPicker) { + // Color pickers are not allowed to open, so we respond to the callback + // with returnCancel. + aColorPickerShownCallback.done(""); + return; + } + this._prompt.asyncShowPrompt(this._msg, result => { // OK: result // Cancel: !result diff --git a/widget/nsBaseColorPicker.cpp b/widget/nsBaseColorPicker.cpp index bb9d49e3d478..e6f10c8dfa6c 100644 --- a/widget/nsBaseColorPicker.cpp +++ b/widget/nsBaseColorPicker.cpp @@ -6,6 +6,7 @@ #include "nsBaseColorPicker.h" #include "mozilla/dom/BrowsingContext.h" +#include "mozilla/dom/CanonicalBrowsingContext.h" NS_IMETHODIMP nsBaseColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext, @@ -25,6 +26,10 @@ NS_IMETHODIMP nsBaseColorPicker::Open(nsIColorPickerShownCallback* aCallback) { MOZ_ASSERT(aCallback); + if (MaybeBlockColorPicker(aCallback)) { + return NS_OK; + } + if (mCallback) { // It means Open has already been called: this is not allowed NS_WARNING("mCallback is already set. Open called twice?"); @@ -34,3 +39,19 @@ nsBaseColorPicker::Open(nsIColorPickerShownCallback* aCallback) { return OpenNative(); } + +bool nsBaseColorPicker::MaybeBlockColorPicker( + nsIColorPickerShownCallback* aCallback) { + MOZ_ASSERT(mBrowsingContext); + + if (!mBrowsingContext->Canonical()->CanOpenModalPicker()) { + if (aCallback) { + // Color pickers are disabled, so we answer the callback with + // returnCancel. + aCallback->Done(EmptyString()); + } + return true; + } + + return false; +} diff --git a/widget/nsBaseColorPicker.h b/widget/nsBaseColorPicker.h index bdc2e2993787..3c02ba9006f7 100644 --- a/widget/nsBaseColorPicker.h +++ b/widget/nsBaseColorPicker.h @@ -30,6 +30,8 @@ class nsBaseColorPicker : public nsIColorPicker { virtual nsresult InitNative(const nsTArray& aDefaultColors) = 0; virtual nsresult OpenNative() = 0; + bool MaybeBlockColorPicker(nsIColorPickerShownCallback* aCallback); + RefPtr mBrowsingContext; nsString mTitle; nsString mInitialColor;