Backed out 4 changesets (bug 1837963) for causing build bustages on nsColorPicker.cpp

Backed out changeset 6465dbafe002 (bug 1837963)
Backed out changeset 5ed6d107133f (bug 1837963)
Backed out changeset 90114d0e72d1 (bug 1837963)
Backed out changeset 36f4b96eb15b (bug 1837963)
This commit is contained in:
Norisz Fay
2025-01-14 15:23:14 +02:00
parent aeb5eb62f5
commit f8452b2129
17 changed files with 65 additions and 207 deletions

View File

@@ -3233,32 +3233,6 @@ CanonicalBrowsingContext::GetBounceTrackingState() {
return mWebProgress->GetBounceTrackingState();
}
bool CanonicalBrowsingContext::CanOpenModalPicker() {
if (!mozilla::StaticPrefs::browser_disable_pickers_background_tabs()) {
return true;
}
// Alway allows to open picker from chrome.
if (IsChrome()) {
return true;
}
if (!IsActive()) {
return false;
}
RefPtr<Document> chromeDoc = TopCrossChromeBoundary()->GetExtantDocument();
if (!chromeDoc || !chromeDoc->HasFocus(mozilla::IgnoreErrors())) {
return false;
}
// Only allow web content to open a picker when it has focus. For example, if
// the focus is on the URL bar, web content cannot open a picker, even if it
// is the foreground tab.
mozilla::dom::Element* topFrameElement = GetTopFrameElement();
return !topFrameElement || topFrameElement == chromeDoc->GetActiveElement();
}
NS_IMPL_CYCLE_COLLECTION_CLASS(CanonicalBrowsingContext)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CanonicalBrowsingContext,

View File

@@ -413,8 +413,6 @@ class CanonicalBrowsingContext final : public BrowsingContext {
already_AddRefed<BounceTrackingState> GetBounceTrackingState();
bool CanOpenModalPicker();
protected:
// Called when the browsing context is being discarded.
void CanonicalDiscard();

View File

@@ -441,11 +441,6 @@ interface CanonicalBrowsingContext : BrowsingContext {
* visibility, or no frame.
*/
readonly attribute boolean isUnderHiddenEmbedderElement;
/**
* Indicates whether opening a modal picker is permitted.
*/
readonly attribute boolean canOpenModalPicker;
};
[Exposed=Window, ChromeOnly]

View File

@@ -15,7 +15,6 @@ 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",
@@ -26,13 +25,6 @@ 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

View File

@@ -22,7 +22,6 @@ export class FilePickerDelegate {
) {
throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
}
this._browsingContext = aBrowsingContext;
this._prompt = new lazy.GeckoViewPrompter(aBrowsingContext);
this._msg = {
type: "file",
@@ -42,14 +41,11 @@ export class FilePickerDelegate {
this._mimeTypes.push(aFilter);
}
open(aFilePickerShownCallback) {
if (!this._browsingContext.canOpenModalPicker) {
// File pickers are not allowed to open, so we respond to the callback
// with returnCancel.
aFilePickerShownCallback.done(Ci.nsIFilePicker.returnCancel);
return;
show() {
throw Components.Exception("", Cr.NS_ERROR_NOT_IMPLEMENTED);
}
open(aFilePickerShownCallback) {
this._msg.mimeTypes = this._mimeTypes;
this._msg.capture = this._capture;
this._prompt.asyncShowPrompt(this._msg, result => {

View File

@@ -1966,12 +1966,6 @@
value: @IS_NOT_ANDROID@
mirror: always
# Whether we block opening pickers from background tabs.
- name: browser.disable_pickers_background_tabs
type: RelaxedAtomicBool
value: true
mirror: always
#---------------------------------------------------------------------------
# Prefs starting with "channelclassifier."
#---------------------------------------------------------------------------

View File

@@ -7,7 +7,7 @@
#ifndef nsColorPicker_h_
#define nsColorPicker_h_
#include "nsBaseColorPicker.h"
#include "nsIColorPicker.h"
#include "nsString.h"
#include "nsCOMPtr.h"
@@ -16,9 +16,10 @@ class mozIDOMWindowProxy;
@class NSColorPanelWrapper;
@class NSColor;
class nsColorPicker final : public nsBaseColorPicker {
class nsColorPicker final : public nsIColorPicker {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOLORPICKER
// For NSColorPanelWrapper.
void Update(NSColor* aColor);
@@ -27,14 +28,14 @@ class nsColorPicker final : public nsBaseColorPicker {
private:
~nsColorPicker();
// nsBaseColorPicker
nsresult InitNative(const nsTArray<nsString>& aDefaultColors) override;
nsresult OpenNative() override;
static NSColor* GetNSColorFromHexString(const nsAString& aColor);
static void GetHexStringFromNSColor(NSColor* aColor, nsAString& aResult);
NSColorPanelWrapper* mColorPanelWrapper;
nsString mTitle;
nsString mColor;
nsCOMPtr<nsIColorPickerShownCallback> mCallback;
};
#endif // nsColorPicker_h_

View File

@@ -95,9 +95,14 @@ nsColorPicker::~nsColorPicker() {
}
// TODO(bug 1805397): Implement default colors
nsresult nsColorPicker::InitNative(const nsTArray<nsString>& aDefaultColors) {
NS_IMETHODIMP
nsColorPicker::Init(dom::BrowsingContext* aBrowsingContext,
const nsAString& aTitle, const nsAString& aInitialColor,
const nsTArray<nsString>& aDefaultColors) {
MOZ_ASSERT(NS_IsMainThread(),
"Color pickers can only be opened from main thread currently");
mTitle = aTitle;
mColor = aInitialColor;
mColorPanelWrapper = [[NSColorPanelWrapper alloc] initWithPicker:this];
return NS_OK;
}
@@ -133,8 +138,12 @@ nsresult nsColorPicker::InitNative(const nsTArray<nsString>& aDefaultColors) {
aResult);
}
nsresult nsColorPicker::OpenNative() {
[mColorPanelWrapper open:GetNSColorFromHexString(mInitialColor)
NS_IMETHODIMP
nsColorPicker::Open(nsIColorPickerShownCallback* aCallback) {
MOZ_ASSERT(aCallback);
mCallback = aCallback;
[mColorPanelWrapper open:GetNSColorFromHexString(mColor)
title:nsCocoaUtils::ToNSString(mTitle)];
NS_ADDREF_THIS();
@@ -143,8 +152,8 @@ nsresult nsColorPicker::OpenNative() {
}
void nsColorPicker::Update(NSColor* aColor) {
GetHexStringFromNSColor(aColor, mInitialColor);
mCallback->Update(mInitialColor);
GetHexStringFromNSColor(aColor, mColor);
mCallback->Update(mColor);
}
void nsColorPicker::Done() {

View File

@@ -111,10 +111,6 @@ class nsFilePicker::AsyncShowFilePicker : public mozilla::Runnable {
NS_ASSERTION(NS_IsMainThread(),
"AsyncShowFilePicker should be on the main thread!");
if (mFilePicker->MaybeBlockFilePicker(mCallback)) {
return NS_OK;
}
// macOS requires require GUI operations to be on the main thread, so that's
// why we're not dispatching to another thread and calling back to the main
// after it's done.

View File

@@ -68,16 +68,22 @@ GtkColorSelection* nsColorPicker::WidgetGetColorSelection(GtkWidget* widget) {
}
#endif
NS_IMETHODIMP nsColorPicker::InitNative(
const nsTArray<nsString>& aDefaultColors) {
NS_IMETHODIMP nsColorPicker::Init(
mozilla::dom::BrowsingContext* aBrowsingContext, const nsAString& title,
const nsAString& initialColor, const nsTArray<nsString>& aDefaultColors) {
MOZ_ASSERT(aBrowsingContext, "Null browsingContext passed to color picker!");
mParentWidget =
mBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
aBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
mTitle = title;
mInitialColor = initialColor;
mDefaultColors.Assign(aDefaultColors);
return NS_OK;
}
NS_IMETHODIMP nsColorPicker::OpenNative() {
NS_IMETHODIMP nsColorPicker::Open(
nsIColorPickerShownCallback* aColorPickerShownCallback) {
// Don't attempt to open a real color-picker in headless mode.
if (gfxPlatform::IsHeadless()) {
return NS_ERROR_NOT_AVAILABLE;

View File

@@ -8,8 +8,8 @@
#include <gtk/gtk.h>
#include "nsBaseColorPicker.h"
#include "nsCOMPtr.h"
#include "nsIColorPicker.h"
#include "nsString.h"
// Enable Gtk3 system color picker.
@@ -17,19 +17,16 @@
class nsIWidget;
class nsColorPicker final : public nsBaseColorPicker {
class nsColorPicker final : public nsIColorPicker {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICOLORPICKER
nsColorPicker() = default;
private:
~nsColorPicker() = default;
// nsBaseColorPicker
nsresult InitNative(const nsTArray<nsString>& aDefaultColors) override;
nsresult OpenNative() override;
static nsString ToHexString(int n);
static void OnResponse(GtkWidget* dialog, gint response_id,
@@ -64,7 +61,10 @@ class nsColorPicker final : public nsBaseColorPicker {
void Done(GtkWidget* dialog, gint response_id);
nsCOMPtr<nsIWidget> mParentWidget;
nsCOMPtr<nsIColorPickerShownCallback> mCallback;
nsString mTitle;
nsString mColor;
nsString mInitialColor;
nsTArray<nsString> mDefaultColors;
};

View File

@@ -154,7 +154,6 @@ EXPORTS += [
"InputData.h",
"nsBaseAppShell.h",
"nsBaseClipboard.h",
"nsBaseColorPicker.h",
"nsBaseDragService.h",
"nsBaseFilePicker.h",
"nsBaseWidget.h",
@@ -333,11 +332,6 @@ if toolkit in {"gtk", "cocoa", "windows", "android", "uikit"}:
"nsBaseFilePicker.cpp",
]
if toolkit in {"gtk", "cocoa", "windows"}:
UNIFIED_SOURCES += [
"nsBaseColorPicker.cpp",
]
if toolkit in ("gtk", "windows", "cocoa", "uikit", "android"):
UNIFIED_SOURCES += [
"nsNativeTheme.cpp",

View File

@@ -1,48 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsBaseColorPicker.h"
NS_IMETHODIMP
nsBaseColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext,
const nsAString& aTitle, const nsAString& aInitialColor,
const nsTArray<nsString>& aDefaultColors) {
MOZ_ASSERT(
aBrowsingContext,
"Null browsingContext passed to colorpicker, no color picker for you!");
mBrowsingContext = aBrowsingContext;
mTitle = aTitle;
mInitialColor = aInitialColor;
return InitNative(aDefaultColors);
}
NS_IMETHODIMP
nsBaseColorPicker::Open(nsIColorPickerShownCallback* aCallback) {
MOZ_ASSERT(aCallback);
if (MaybeBlockColorPicker(aCallback)) {
return NS_OK;
}
mCallback = 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;
}

View File

@@ -1,41 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsBaseColorPicker_h_
#define nsBaseColorPicker_h_
#include "nsIColorPicker.h"
#include "nsString.h"
#include "nsCOMPtr.h"
class mozIDOMWindowProxy;
namespace mozilla::dom {
class BrowsingContext;
} // namespace mozilla::dom
class nsBaseColorPicker : public nsIColorPicker {
public:
// nsIColorPicker
NS_IMETHOD Init(mozilla::dom::BrowsingContext* aBrowsingContext,
const nsAString& aTitle, const nsAString& aInitialColor,
const nsTArray<nsString>& aDefaultColors) override final;
NS_IMETHOD Open(nsIColorPickerShownCallback* aCallback) override final;
protected:
virtual ~nsBaseColorPicker() = default;
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;
nsCOMPtr<nsIColorPickerShownCallback> mCallback;
};
#endif // nsBaseColorPicker_h_

View File

@@ -345,15 +345,15 @@ NS_IMETHODIMP nsBaseFilePicker::SetDisplaySpecialDirectory(
bool nsBaseFilePicker::MaybeBlockFilePicker(
nsIFilePickerShownCallback* aCallback) {
MOZ_ASSERT(mBrowsingContext);
MOZ_ASSERT(XRE_IsParentProcess());
if (!mozilla::StaticPrefs::widget_disable_file_pickers()) {
return false;
}
if (mozilla::StaticPrefs::widget_disable_file_pickers()) {
if (aCallback) {
// File pickers are disabled, so we answer the callback with returnCancel.
aCallback->Done(nsIFilePicker::returnCancel);
}
if (mBrowsingContext) {
RefPtr<Element> topFrameElement = mBrowsingContext->GetTopFrameElement();
if (topFrameElement) {
// Dispatch an event that the frontend may use.
@@ -361,18 +361,6 @@ bool nsBaseFilePicker::MaybeBlockFilePicker(
topFrameElement->OwnerDoc(), topFrameElement, u"FilePickerBlocked"_ns,
mozilla::CanBubble::eYes, mozilla::Cancelable::eNo);
}
return true;
}
if (mBrowsingContext->Canonical()->CanOpenModalPicker()) {
return false;
}
if (aCallback) {
// File pickers are not allowed to open, so we respond to the callback with
// returnCancel.
aCallback->Done(nsIFilePicker::returnCancel);
}
return true;

View File

@@ -190,17 +190,23 @@ nsColorPicker::~nsColorPicker() {}
NS_IMPL_ISUPPORTS(nsColorPicker, nsIColorPicker)
NS_IMETHODIMP
nsColorPicker::InitNative(const nsTArray<nsString>& aDefaultColors) {
nsColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext,
const nsAString& title, const nsAString& aInitialColor,
const nsTArray<nsString>& aDefaultColors) {
MOZ_ASSERT(
aBrowsingContext,
"Null browsingContext passed to colorpicker, no color picker for you!");
mParentWidget =
mBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
aBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
mInitialColor = ColorStringToRGB(aInitialColor);
mDefaultColors.Assign(aDefaultColors);
return NS_OK;
}
NS_IMETHODIMP
nsColorPicker::OpenNative() {
nsCOMPtr<nsIRunnable> event =
new AsyncColorChooser(ColorStringToRGB(mInitialColor), mDefaultColors,
mParentWidget, mCallback);
nsColorPicker::Open(nsIColorPickerShownCallback* aCallback) {
NS_ENSURE_ARG(aCallback);
nsCOMPtr<nsIRunnable> event = new AsyncColorChooser(
mInitialColor, mDefaultColors, mParentWidget, aCallback);
return NS_DispatchToMainThread(event);
}

View File

@@ -10,8 +10,8 @@
#include <windows.h>
#include <commdlg.h>
#include "nsBaseColorPicker.h"
#include "nsCOMPtr.h"
#include "nsIColorPicker.h"
#include "nsThreadUtils.h"
class nsIWidget;
@@ -37,19 +37,17 @@ class AsyncColorChooser : public mozilla::Runnable {
nsCOMPtr<nsIColorPickerShownCallback> mCallback;
};
class nsColorPicker final : public nsBaseColorPicker {
class nsColorPicker : public nsIColorPicker {
virtual ~nsColorPicker();
public:
nsColorPicker();
NS_DECL_ISUPPORTS
NS_DECL_NSICOLORPICKER
private:
// nsBaseColorPicker
nsresult InitNative(const nsTArray<nsString>& aDefaultColors) override;
nsresult OpenNative() override;
COLORREF mInitialColor;
nsTArray<nsString> mDefaultColors;
nsCOMPtr<nsIWidget> mParentWidget;
};