diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-05 15:59:26 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:29 -0500 |
commit | 3d4c4100912132141881f40e90ddbd3aba8b0737 (patch) | |
tree | 92a662145f0243654c42c8cf830cebf5df7aa30f /dom/base | |
parent | 186782301c03f4b27e4edae07b0280e92c4e01d1 (diff) | |
download | UXP-3d4c4100912132141881f40e90ddbd3aba8b0737.tar UXP-3d4c4100912132141881f40e90ddbd3aba8b0737.tar.gz UXP-3d4c4100912132141881f40e90ddbd3aba8b0737.tar.lz UXP-3d4c4100912132141881f40e90ddbd3aba8b0737.tar.xz UXP-3d4c4100912132141881f40e90ddbd3aba8b0737.zip |
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
Diffstat (limited to 'dom/base')
-rw-r--r-- | dom/base/CustomElementRegistry.cpp | 33 | ||||
-rw-r--r-- | dom/base/CustomElementRegistry.h | 33 | ||||
-rw-r--r-- | dom/base/Element.cpp | 13 | ||||
-rw-r--r-- | dom/base/nsContentUtils.cpp | 34 | ||||
-rw-r--r-- | dom/base/nsContentUtils.h | 3 |
5 files changed, 41 insertions, 75 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index efbad781f..67498a59b 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -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); } //----------------------------------------------------- diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index 89e754365..f73a8707e 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -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); diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 7ab0699ed..bfa0869c3 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -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); } } } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index b029f9793..76171dda0 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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()) { - return; - } - - nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow()); - if (!window) { - return; - } - - RefPtr<CustomElementRegistry> registry(window->CustomElements()); - if (!registry) { + // No DocGroup means no custom element reactions stack. + if (!aCustomElement->OwnerDoc()->GetDocGroup()) { return; } - registry->EnqueueLifecycleCallback(aType, aCustomElement, aArgs, aDefinition); + CustomElementRegistry::EnqueueLifecycleCallback(aType, aCustomElement, aArgs, + aDefinition); } /* static */ void diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 1828d8b21..5075bcb6d 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -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); |