Bug 1837963 - Disallow opening color pickers from background tabs; r=geckoview-reviewers,emilio,m_kato
Differential Revision: https://phabricator.services.mozilla.com/D230089
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class nsBaseColorPicker : public nsIColorPicker {
|
||||
virtual nsresult InitNative(const nsTArray<nsString>& aDefaultColors) = 0;
|
||||
virtual nsresult OpenNative() = 0;
|
||||
|
||||
bool MaybeBlockColorPicker(nsIColorPickerShownCallback* aCallback);
|
||||
|
||||
RefPtr<mozilla::dom::BrowsingContext> mBrowsingContext;
|
||||
nsString mTitle;
|
||||
nsString mInitialColor;
|
||||
|
||||
Reference in New Issue
Block a user