Bug 1932512 - Pass BrowsingContext to nsIColorPicker::Init; r=geckoview-reviewers,win-reviewers,mac-reviewers,emilio,spohl,m_kato,rkraesig
Differential Revision: https://phabricator.services.mozilla.com/D229682
This commit is contained in:
@@ -736,8 +736,8 @@ nsresult HTMLInputElement::InitColorPicker() {
|
||||
|
||||
nsCOMPtr<Document> doc = OwnerDoc();
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> win = doc->GetWindow();
|
||||
if (!win) {
|
||||
RefPtr<BrowsingContext> bc = doc->GetBrowsingContext();
|
||||
if (!bc) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@@ -759,7 +759,7 @@ nsresult HTMLInputElement::InitColorPicker() {
|
||||
nsAutoString initialValue;
|
||||
GetNonFileValueInternal(initialValue);
|
||||
nsTArray<nsString> colors = GetColorsFromList();
|
||||
nsresult rv = colorPicker->Init(win, title, initialValue, colors);
|
||||
nsresult rv = colorPicker->Init(bc, title, initialValue, colors);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIColorPickerShownCallback> callback =
|
||||
|
||||
@@ -3522,10 +3522,22 @@ BrowserParent::GetAuthPrompt(uint32_t aPromptReason, const nsIID& iid,
|
||||
}
|
||||
|
||||
already_AddRefed<PColorPickerParent> BrowserParent::AllocPColorPickerParent(
|
||||
const MaybeDiscarded<BrowsingContext>& aBrowsingContext,
|
||||
const nsString& aTitle, const nsString& aInitialColor,
|
||||
const nsTArray<nsString>& aDefaultColors) {
|
||||
return MakeAndAddRef<ColorPickerParent>(aTitle, aInitialColor,
|
||||
aDefaultColors);
|
||||
RefPtr<CanonicalBrowsingContext> browsingContext =
|
||||
[&]() -> CanonicalBrowsingContext* {
|
||||
if (aBrowsingContext.IsNullOrDiscarded()) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!aBrowsingContext.get_canonical()->IsOwnedByProcess(
|
||||
Manager()->ChildID())) {
|
||||
return nullptr;
|
||||
}
|
||||
return aBrowsingContext.get_canonical();
|
||||
}();
|
||||
return MakeAndAddRef<ColorPickerParent>(browsingContext, aTitle,
|
||||
aInitialColor, aDefaultColors);
|
||||
}
|
||||
|
||||
already_AddRefed<nsFrameLoader> BrowserParent::GetFrameLoader(
|
||||
|
||||
@@ -426,6 +426,7 @@ class BrowserParent final : public PBrowserParent,
|
||||
const int32_t& aAppUnitsPerDevPixel);
|
||||
|
||||
already_AddRefed<PColorPickerParent> AllocPColorPickerParent(
|
||||
const MaybeDiscarded<BrowsingContext>& aBrowsingContext,
|
||||
const nsString& aTitle, const nsString& aInitialColor,
|
||||
const nsTArray<nsString>& aDefaultColors);
|
||||
|
||||
|
||||
@@ -38,23 +38,17 @@ void ColorPickerParent::ColorPickerShownCallback::Destroy() {
|
||||
}
|
||||
|
||||
bool ColorPickerParent::CreateColorPicker() {
|
||||
if (!mBrowsingContext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
|
||||
if (!mPicker) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Element* ownerElement = BrowserParent::GetFrom(Manager())->GetOwnerElement();
|
||||
if (!ownerElement) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowOuter> window = ownerElement->OwnerDoc()->GetWindow();
|
||||
if (!window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return NS_SUCCEEDED(
|
||||
mPicker->Init(window, mTitle, mInitialColor, mDefaultColors));
|
||||
mPicker->Init(mBrowsingContext, mTitle, mInitialColor, mDefaultColors));
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ColorPickerParent::RecvOpen() {
|
||||
|
||||
@@ -14,9 +14,11 @@ namespace mozilla::dom {
|
||||
|
||||
class ColorPickerParent : public PColorPickerParent {
|
||||
public:
|
||||
ColorPickerParent(const nsString& aTitle, const nsString& aInitialColor,
|
||||
ColorPickerParent(BrowsingContext* aBrowsingContext, const nsString& aTitle,
|
||||
const nsString& aInitialColor,
|
||||
const nsTArray<nsString>& aDefaultColors)
|
||||
: mTitle(aTitle),
|
||||
: mBrowsingContext(aBrowsingContext),
|
||||
mTitle(aTitle),
|
||||
mInitialColor(aInitialColor),
|
||||
mDefaultColors(aDefaultColors.Clone()) {}
|
||||
|
||||
@@ -45,6 +47,7 @@ class ColorPickerParent : public PColorPickerParent {
|
||||
|
||||
bool CreateColorPicker();
|
||||
|
||||
RefPtr<BrowsingContext> mBrowsingContext;
|
||||
RefPtr<ColorPickerShownCallback> mCallback;
|
||||
nsCOMPtr<nsIColorPicker> mPicker;
|
||||
|
||||
|
||||
@@ -413,7 +413,9 @@ parent:
|
||||
* Create an asynchronous color picker on the parent side,
|
||||
* but don't open it yet.
|
||||
*/
|
||||
async PColorPicker(nsString title, nsString initialColor, nsString[] defaultColors);
|
||||
async PColorPicker(MaybeDiscardedBrowsingContext aBrowsingContext,
|
||||
nsString title, nsString initialColor,
|
||||
nsString[] defaultColors);
|
||||
|
||||
async PFilePicker(nsString aTitle, Mode aMode, MaybeDiscardedBrowsingContext aBrowsingContext);
|
||||
|
||||
|
||||
@@ -47,3 +47,8 @@
|
||||
# undef False
|
||||
# define X11False 0
|
||||
#endif
|
||||
|
||||
#ifdef DestroyAll
|
||||
# undef DestroyAll
|
||||
# define X11DestroyAll 0
|
||||
#endif
|
||||
|
||||
@@ -14,8 +14,8 @@ const { debug, warn } = GeckoViewUtils.initLogging("ColorPickerDelegate");
|
||||
|
||||
export class ColorPickerDelegate {
|
||||
// TODO(bug 1805397): Implement default colors
|
||||
init(aParent, aTitle, aInitialColor, aDefaultColors) {
|
||||
this._prompt = new lazy.GeckoViewPrompter(aParent);
|
||||
init(aBrowsingContext, aTitle, aInitialColor, aDefaultColors) {
|
||||
this._prompt = new lazy.GeckoViewPrompter(aBrowsingContext);
|
||||
this._msg = {
|
||||
type: "color",
|
||||
title: aTitle,
|
||||
|
||||
@@ -70,13 +70,13 @@ function MockColorPickerInstance(window) {
|
||||
}
|
||||
MockColorPickerInstance.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIColorPicker"]),
|
||||
init(aParent, aTitle, aInitialColor, aDefaultColors) {
|
||||
this.parent = aParent;
|
||||
init(aBrowsingContext, aTitle, aInitialColor, aDefaultColors) {
|
||||
this.browsingContext = aBrowsingContext;
|
||||
this.initialColor = aInitialColor;
|
||||
this.defaultColors = aDefaultColors;
|
||||
},
|
||||
initialColor: "",
|
||||
parent: null,
|
||||
browsingContext: null,
|
||||
open(aColorPickerShownCallback) {
|
||||
MockColorPicker.showing = true;
|
||||
MockColorPicker.shown = true;
|
||||
|
||||
@@ -96,8 +96,8 @@ nsColorPicker::~nsColorPicker() {
|
||||
|
||||
// TODO(bug 1805397): Implement default colors
|
||||
NS_IMETHODIMP
|
||||
nsColorPicker::Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
|
||||
const nsAString& aInitialColor,
|
||||
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");
|
||||
|
||||
@@ -5,7 +5,13 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#ifdef MOZ_X11
|
||||
# include "X11UndefineNone.h"
|
||||
#endif
|
||||
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsColorPicker.h"
|
||||
@@ -61,12 +67,13 @@ GtkColorSelection* nsColorPicker::WidgetGetColorSelection(GtkWidget* widget) {
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsColorPicker::Init(mozIDOMWindowProxy* aParent,
|
||||
const nsAString& title,
|
||||
const nsAString& initialColor,
|
||||
const nsTArray<nsString>& aDefaultColors) {
|
||||
auto* parent = nsPIDOMWindowOuter::From(aParent);
|
||||
mParentWidget = mozilla::widget::WidgetUtils::DOMWindowToWidget(parent);
|
||||
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 =
|
||||
aBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
|
||||
mTitle = title;
|
||||
mInitialColor = initialColor;
|
||||
mDefaultColors.Assign(aDefaultColors);
|
||||
|
||||
@@ -13,16 +13,18 @@ using namespace mozilla::dom;
|
||||
NS_IMPL_ISUPPORTS(nsColorPickerProxy, nsIColorPicker)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsColorPickerProxy::Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
|
||||
nsColorPickerProxy::Init(BrowsingContext* aBrowsingContext,
|
||||
const nsAString& aTitle,
|
||||
const nsAString& aInitialColor,
|
||||
const nsTArray<nsString>& aDefaultColors) {
|
||||
BrowserChild* browserChild = BrowserChild::GetFrom(aParent);
|
||||
BrowserChild* browserChild =
|
||||
BrowserChild::GetFrom(aBrowsingContext->GetDocShell());
|
||||
if (!browserChild) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
browserChild->SendPColorPickerConstructor(this, aTitle, aInitialColor,
|
||||
aDefaultColors);
|
||||
browserChild->SendPColorPickerConstructor(this, aBrowsingContext, aTitle,
|
||||
aInitialColor, aDefaultColors);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface mozIDOMWindowProxy;
|
||||
webidl BrowsingContext;
|
||||
|
||||
/**
|
||||
* nsIColorPicker is representing colors as strings because the internal
|
||||
@@ -55,14 +55,15 @@ interface nsIColorPicker : nsISupports
|
||||
* one used by the underlying backend or an arbitrary one. The backend could
|
||||
* also assert.
|
||||
*
|
||||
* @param parent nsIDOMWindow parent. This dialog will be dependent
|
||||
* on this parent. parent must be non-null.
|
||||
* @param title The title for the color picker widget.
|
||||
* @param initialColor The color to show when the widget is opened. The
|
||||
* parameter has to follow the format specified on top
|
||||
* of this file.
|
||||
* @param browsingContext The context in which the color picker is being
|
||||
* shown, must be non-null.
|
||||
* @param title The title for the color picker widget.
|
||||
* @param initialColor The color to show when the widget is opened. The
|
||||
* parameter has to follow the format specified on
|
||||
* top of this file.
|
||||
*/
|
||||
void init(in mozIDOMWindowProxy parent, in AString title, in AString initialColor, in Array<AString> defaultColors);
|
||||
void init(in BrowsingContext browsingContext, in AString title,
|
||||
in AString initialColor, in Array<AString> defaultColors);
|
||||
|
||||
/**
|
||||
* Opens the color dialog asynchrounously.
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/AutoRestore.h"
|
||||
#include "mozilla/dom/BrowsingContext.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsString.h"
|
||||
#include "WidgetUtils.h"
|
||||
@@ -188,13 +190,14 @@ nsColorPicker::~nsColorPicker() {}
|
||||
NS_IMPL_ISUPPORTS(nsColorPicker, nsIColorPicker)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsColorPicker::Init(mozIDOMWindowProxy* parent, const nsAString& title,
|
||||
const nsAString& aInitialColor,
|
||||
nsColorPicker::Init(mozilla::dom::BrowsingContext* aBrowsingContext,
|
||||
const nsAString& title, const nsAString& aInitialColor,
|
||||
const nsTArray<nsString>& aDefaultColors) {
|
||||
MOZ_ASSERT(parent,
|
||||
"Null parent passed to colorpicker, no color picker for you!");
|
||||
MOZ_ASSERT(
|
||||
aBrowsingContext,
|
||||
"Null browsingContext passed to colorpicker, no color picker for you!");
|
||||
mParentWidget =
|
||||
WidgetUtils::DOMWindowToWidget(nsPIDOMWindowOuter::From(parent));
|
||||
aBrowsingContext->Canonical()->GetParentProcessWidgetContaining();
|
||||
mInitialColor = ColorStringToRGB(aInitialColor);
|
||||
mDefaultColors.Assign(aDefaultColors);
|
||||
return NS_OK;
|
||||
|
||||
Reference in New Issue
Block a user