mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-08 00:38:39 +09:00
Bug 1334043 - Part 2: Make nsContentUtils::EnqueueLifecycleCallback static.
We make nsContentUtils::EnqueueLifecycleCallback static so that it can be called without a window object. To achive this, we also make CustomElementReaction not taking a CustomElementRegistry in the constructor, as it can call Upgrade statically. Tag UXP Issue #1344
This commit is contained in:
parent
207d5a2e3e
commit
befa1027e3
5 changed files with 41 additions and 75 deletions
|
|
@ -47,7 +47,7 @@ CustomElementCallback::Call()
|
|||
ni->LocalName(), ni->NamespaceID(),
|
||||
extType.IsEmpty() ? nullptr : &extType);
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
document, nsIDocument::eConnected, mThisObject, nullptr, definition);
|
||||
nsIDocument::eConnected, mThisObject, nullptr, definition);
|
||||
}
|
||||
|
||||
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
|
||||
|
|
@ -329,7 +329,7 @@ CustomElementRegistry::SetupCustomElement(Element* aElement,
|
|||
// SyncInvokeReactions(nsIDocument::eCreated, aElement, definition);
|
||||
}
|
||||
|
||||
UniquePtr<CustomElementCallback>
|
||||
/* static */ UniquePtr<CustomElementCallback>
|
||||
CustomElementRegistry::CreateCustomElementCallback(
|
||||
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
|
||||
|
|
@ -391,7 +391,7 @@ CustomElementRegistry::CreateCustomElementCallback(
|
|||
return Move(callback);
|
||||
}
|
||||
|
||||
void
|
||||
/* static */ void
|
||||
CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
|
|
@ -412,7 +412,7 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
|
|||
return;
|
||||
}
|
||||
|
||||
DocGroup* docGroup = mWindow->GetDocGroup();
|
||||
DocGroup* docGroup = aCustomElement->OwnerDoc()->GetDocGroup();
|
||||
if (!docGroup) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
|
|||
|
||||
CustomElementReactionsStack* reactionsStack =
|
||||
docGroup->CustomElementReactionsStack();
|
||||
reactionsStack->EnqueueCallbackReaction(this, aCustomElement, definition,
|
||||
reactionsStack->EnqueueCallbackReaction(aCustomElement, definition,
|
||||
Move(callback));
|
||||
}
|
||||
|
||||
|
|
@ -467,7 +467,7 @@ CustomElementRegistry::UpgradeCandidates(nsIAtom* aKey,
|
|||
continue;
|
||||
}
|
||||
|
||||
reactionsStack->EnqueueUpgradeReaction(this, elem, aDefinition);
|
||||
reactionsStack->EnqueueUpgradeReaction(elem, aDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -924,8 +924,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
(attrValue.IsEmpty() ? NullString() : attrValue),
|
||||
(namespaceURI.IsEmpty() ? NullString() : namespaceURI)
|
||||
};
|
||||
nsContentUtils::EnqueueLifecycleCallback(aElement->OwnerDoc(),
|
||||
nsIDocument::eAttributeChanged,
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged,
|
||||
aElement,
|
||||
&args, aDefinition);
|
||||
}
|
||||
|
|
@ -934,8 +933,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
|
||||
// Step 4.
|
||||
if (aElement->IsInComposedDoc()) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(aElement->OwnerDoc(),
|
||||
nsIDocument::eConnected, aElement,
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, aElement,
|
||||
nullptr, aDefinition);
|
||||
}
|
||||
|
||||
|
|
@ -959,8 +957,7 @@ CustomElementRegistry::Upgrade(Element* aElement,
|
|||
aElement->SetCustomElementDefinition(aDefinition);
|
||||
|
||||
// This is for old spec.
|
||||
nsContentUtils::EnqueueLifecycleCallback(aElement->OwnerDoc(),
|
||||
nsIDocument::eCreated,
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eCreated,
|
||||
aElement, nullptr, aDefinition);
|
||||
}
|
||||
|
||||
|
|
@ -1004,20 +1001,18 @@ CustomElementReactionsStack::PopAndInvokeElementQueue()
|
|||
}
|
||||
|
||||
void
|
||||
CustomElementReactionsStack::EnqueueUpgradeReaction(CustomElementRegistry* aRegistry,
|
||||
Element* aElement,
|
||||
CustomElementReactionsStack::EnqueueUpgradeReaction(Element* aElement,
|
||||
CustomElementDefinition* aDefinition)
|
||||
{
|
||||
Enqueue(aElement, new CustomElementUpgradeReaction(aRegistry, aDefinition));
|
||||
Enqueue(aElement, new CustomElementUpgradeReaction(aDefinition));
|
||||
}
|
||||
|
||||
void
|
||||
CustomElementReactionsStack::EnqueueCallbackReaction(CustomElementRegistry* aRegistry,
|
||||
Element* aElement,
|
||||
CustomElementReactionsStack::EnqueueCallbackReaction(Element* aElement,
|
||||
CustomElementDefinition* aDefinition,
|
||||
UniquePtr<CustomElementCallback> aCustomElementCallback)
|
||||
{
|
||||
Enqueue(aElement, new CustomElementCallbackReaction(aRegistry, aDefinition,
|
||||
Enqueue(aElement, new CustomElementCallbackReaction(aDefinition,
|
||||
Move(aCustomElementCallback)));
|
||||
}
|
||||
|
||||
|
|
@ -1176,7 +1171,7 @@ CustomElementDefinition::CustomElementDefinition(nsIAtom* aType,
|
|||
/* virtual */ void
|
||||
CustomElementUpgradeReaction::Invoke(Element* aElement, ErrorResult& aRv)
|
||||
{
|
||||
mRegistry->Upgrade(aElement, mDefinition, aRv);
|
||||
CustomElementRegistry::Upgrade(aElement, mDefinition, aRv);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -198,10 +198,8 @@ private:
|
|||
class CustomElementReaction
|
||||
{
|
||||
public:
|
||||
explicit CustomElementReaction(CustomElementRegistry* aRegistry,
|
||||
CustomElementDefinition* aDefinition)
|
||||
: mRegistry(aRegistry)
|
||||
, mDefinition(aDefinition)
|
||||
explicit CustomElementReaction(CustomElementDefinition* aDefinition)
|
||||
: mDefinition(aDefinition)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -212,16 +210,14 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
CustomElementRegistry* mRegistry;
|
||||
CustomElementDefinition* mDefinition;
|
||||
};
|
||||
|
||||
class CustomElementUpgradeReaction final : public CustomElementReaction
|
||||
{
|
||||
public:
|
||||
explicit CustomElementUpgradeReaction(CustomElementRegistry* aRegistry,
|
||||
CustomElementDefinition* aDefinition)
|
||||
: CustomElementReaction(aRegistry, aDefinition)
|
||||
explicit CustomElementUpgradeReaction(CustomElementDefinition* aDefinition)
|
||||
: CustomElementReaction(aDefinition)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -232,10 +228,9 @@ private:
|
|||
class CustomElementCallbackReaction final : public CustomElementReaction
|
||||
{
|
||||
public:
|
||||
CustomElementCallbackReaction(CustomElementRegistry* aRegistry,
|
||||
CustomElementDefinition* aDefinition,
|
||||
CustomElementCallbackReaction(CustomElementDefinition* aDefinition,
|
||||
UniquePtr<CustomElementCallback> aCustomElementCallback)
|
||||
: CustomElementReaction(aRegistry, aDefinition)
|
||||
: CustomElementReaction(aDefinition)
|
||||
, mCustomElementCallback(Move(aCustomElementCallback))
|
||||
{
|
||||
}
|
||||
|
|
@ -271,16 +266,14 @@ public:
|
|||
* Enqueue a custom element upgrade reaction
|
||||
* https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-upgrade-reaction
|
||||
*/
|
||||
void EnqueueUpgradeReaction(CustomElementRegistry* aRegistry,
|
||||
Element* aElement,
|
||||
void EnqueueUpgradeReaction(Element* aElement,
|
||||
CustomElementDefinition* aDefinition);
|
||||
|
||||
/**
|
||||
* Enqueue a custom element callback reaction
|
||||
* https://html.spec.whatwg.org/multipage/scripting.html#enqueue-a-custom-element-callback-reaction
|
||||
*/
|
||||
void EnqueueCallbackReaction(CustomElementRegistry* aRegistry,
|
||||
Element* aElement,
|
||||
void EnqueueCallbackReaction(Element* aElement,
|
||||
CustomElementDefinition* aDefinition,
|
||||
UniquePtr<CustomElementCallback> aCustomElementCallback);
|
||||
|
||||
|
|
@ -368,10 +361,10 @@ public:
|
|||
*/
|
||||
void SetupCustomElement(Element* aElement, const nsAString* aTypeExtension);
|
||||
|
||||
void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
CustomElementDefinition* aDefinition);
|
||||
static void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
CustomElementDefinition* aDefinition);
|
||||
|
||||
void GetCustomPrototype(nsIAtom* aAtom,
|
||||
JS::MutableHandle<JSObject*> aPrototype);
|
||||
|
|
@ -385,7 +378,7 @@ public:
|
|||
private:
|
||||
~CustomElementRegistry();
|
||||
|
||||
UniquePtr<CustomElementCallback> CreateCustomElementCallback(
|
||||
static UniquePtr<CustomElementCallback> CreateCustomElementCallback(
|
||||
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition);
|
||||
|
||||
|
|
|
|||
|
|
@ -1684,13 +1684,11 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|||
SetSubtreeRootPointer(aParent->SubtreeRoot());
|
||||
}
|
||||
|
||||
nsIDocument* composedDoc = GetComposedDoc();
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() && composedDoc) {
|
||||
if (CustomElementRegistry::IsCustomElementEnabled() && IsInComposedDoc()) {
|
||||
// Connected callback must be enqueued whenever a custom element becomes
|
||||
// connected.
|
||||
if (GetCustomElementData()) {
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
composedDoc, nsIDocument::eConnected, this);
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1989,8 +1987,7 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent)
|
|||
// the document and this document has a browsing context.
|
||||
if (GetCustomElementData() && document->GetDocShell()) {
|
||||
// Enqueue a detached callback for the custom element.
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
document, nsIDocument::eDetached, this);
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDetached, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2605,7 +2602,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
|
|||
};
|
||||
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition);
|
||||
nsIDocument::eAttributeChanged, this, &args, definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2870,7 +2867,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|||
};
|
||||
|
||||
nsContentUtils::EnqueueLifecycleCallback(
|
||||
OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition);
|
||||
nsIDocument::eAttributeChanged, this, &args, definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9661,48 +9661,30 @@ nsContentUtils::EnqueueUpgradeReaction(Element* aElement,
|
|||
MOZ_ASSERT(aElement);
|
||||
|
||||
nsIDocument* doc = aElement->OwnerDoc();
|
||||
nsPIDOMWindowInner* window(doc->GetInnerWindow());
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<CustomElementRegistry> registry(window->CustomElements());
|
||||
if (!registry) {
|
||||
// No DocGroup means no custom element reactions stack.
|
||||
if (!doc->GetDocGroup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CustomElementReactionsStack* stack =
|
||||
doc->GetDocGroup()->CustomElementReactionsStack();
|
||||
stack->EnqueueUpgradeReaction(registry, aElement, aDefinition);
|
||||
stack->EnqueueUpgradeReaction(aElement, aDefinition);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument* aDoc,
|
||||
nsIDocument::ElementCallbackType aType,
|
||||
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
LifecycleCallbackArgs* aArgs,
|
||||
CustomElementDefinition* aDefinition)
|
||||
{
|
||||
MOZ_ASSERT(aDoc);
|
||||
|
||||
// To support imported document.
|
||||
nsCOMPtr<nsIDocument> doc = aDoc->MasterDocument();
|
||||
|
||||
if (!doc->GetDocShell()) {
|
||||
// No DocGroup means no custom element reactions stack.
|
||||
if (!aCustomElement->OwnerDoc()->GetDocGroup()) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<CustomElementRegistry> registry(window->CustomElements());
|
||||
if (!registry) {
|
||||
return;
|
||||
}
|
||||
|
||||
registry->EnqueueLifecycleCallback(aType, aCustomElement, aArgs, aDefinition);
|
||||
CustomElementRegistry::EnqueueLifecycleCallback(aType, aCustomElement, aArgs,
|
||||
aDefinition);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
|
|
|
|||
|
|
@ -2731,8 +2731,7 @@ public:
|
|||
static void EnqueueUpgradeReaction(Element* aElement,
|
||||
mozilla::dom::CustomElementDefinition* aDefinition);
|
||||
|
||||
static void EnqueueLifecycleCallback(nsIDocument* aDoc,
|
||||
nsIDocument::ElementCallbackType aType,
|
||||
static void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
|
||||
Element* aCustomElement,
|
||||
mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr,
|
||||
mozilla::dom::CustomElementDefinition* aDefinition = nullptr);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue