summaryrefslogtreecommitdiffstats
path: root/dom/base
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-05 15:37:32 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:28 -0500
commit42331663e643b8366c4ec87a929161fa3fb8d775 (patch)
tree8e8a3043ae6369ef2c18b1fe2c76f3decf2ecb8b /dom/base
parent8573c572fbf5fa68defb3228e7f1450ec234d59b (diff)
downloadUXP-42331663e643b8366c4ec87a929161fa3fb8d775.tar
UXP-42331663e643b8366c4ec87a929161fa3fb8d775.tar.gz
UXP-42331663e643b8366c4ec87a929161fa3fb8d775.tar.lz
UXP-42331663e643b8366c4ec87a929161fa3fb8d775.tar.xz
UXP-42331663e643b8366c4ec87a929161fa3fb8d775.zip
Bug 1392970 - Part 2: Get CustomElementDefinition from CustomElementData when possible.
Tag UXP Issue #1344
Diffstat (limited to 'dom/base')
-rw-r--r--dom/base/CustomElementRegistry.cpp65
-rw-r--r--dom/base/nsContentUtils.cpp7
2 files changed, 26 insertions, 46 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp
index b752fdda7..1a4b5d45a 100644
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -36,8 +36,19 @@ CustomElementCallback::Call()
// enqueue attached callback for ELEMENT.
nsIDocument* document = mThisObject->GetComposedDoc();
if (document && document->GetDocShell()) {
+ NodeInfo* ni = mThisObject->NodeInfo();
+ nsDependentAtomString extType(mOwnerData->mType);
+
+ // We need to do this because at this point, CustomElementDefinition is
+ // not set to CustomElementData yet, so EnqueueLifecycleCallback will
+ // fail to find the CE definition for this custom element.
+ // This will go away eventually since there is no created callback in v1.
+ CustomElementDefinition* definition =
+ nsContentUtils::LookupCustomElementDefinition(document,
+ ni->LocalName(), ni->NamespaceID(),
+ extType.IsEmpty() ? nullptr : &extType);
nsContentUtils::EnqueueLifecycleCallback(
- document, nsIDocument::eAttached, mThisObject);
+ document, nsIDocument::eAttached, mThisObject, nullptr, definition);
}
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
@@ -324,51 +335,35 @@ CustomElementRegistry::CreateCustomElementCallback(
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition)
{
+ MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null");
+
RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
MOZ_ASSERT(elementData, "CustomElementData should exist");
- // Let DEFINITION be ELEMENT's definition
- CustomElementDefinition* definition = aDefinition;
- if (!definition) {
- mozilla::dom::NodeInfo* info = aCustomElement->NodeInfo();
-
- // Make sure we get the correct definition in case the element
- // is a extended custom element e.g. <button is="x-button">.
- nsCOMPtr<nsIAtom> typeAtom = elementData ?
- elementData->mType.get() : info->NameAtom();
-
- definition = mCustomDefinitions.GetWeak(typeAtom);
- if (!definition || definition->mLocalName != info->NameAtom()) {
- // Trying to enqueue a callback for an element that is not
- // a custom element. We are done, nothing to do.
- return nullptr;
- }
- }
-
// Let CALLBACK be the callback associated with the key NAME in CALLBACKS.
CallbackFunction* func = nullptr;
switch (aType) {
case nsIDocument::eCreated:
- if (definition->mCallbacks->mCreatedCallback.WasPassed()) {
- func = definition->mCallbacks->mCreatedCallback.Value();
+ if (aDefinition->mCallbacks->mCreatedCallback.WasPassed()) {
+ func = aDefinition->mCallbacks->mCreatedCallback.Value();
}
break;
case nsIDocument::eAttached:
- if (definition->mCallbacks->mAttachedCallback.WasPassed()) {
- func = definition->mCallbacks->mAttachedCallback.Value();
+ if (aDefinition->mCallbacks->mAttachedCallback.WasPassed()) {
+ func = aDefinition->mCallbacks->mAttachedCallback.Value();
}
break;
case nsIDocument::eDetached:
- if (definition->mCallbacks->mDetachedCallback.WasPassed()) {
- func = definition->mCallbacks->mDetachedCallback.Value();
+ if (aDefinition->mCallbacks->mDetachedCallback.WasPassed()) {
+ func = aDefinition->mCallbacks->mDetachedCallback.Value();
}
break;
case nsIDocument::eAttributeChanged:
- if (definition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
- func = definition->mCallbacks->mAttributeChangedCallback.Value();
+ if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) {
+ func = aDefinition->mCallbacks->mAttributeChangedCallback.Value();
}
break;
}
@@ -403,21 +398,11 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
LifecycleCallbackArgs* aArgs,
CustomElementDefinition* aDefinition)
{
- RefPtr<CustomElementData> elementData = aCustomElement->GetCustomElementData();
- MOZ_ASSERT(elementData, "CustomElementData should exist");
-
- // Let DEFINITION be ELEMENT's definition
CustomElementDefinition* definition = aDefinition;
if (!definition) {
- mozilla::dom::NodeInfo* info = aCustomElement->NodeInfo();
-
- // Make sure we get the correct definition in case the element
- // is a extended custom element e.g. <button is="x-button">.
- nsCOMPtr<nsIAtom> typeAtom = elementData ?
- elementData->mType.get() : info->NameAtom();
-
- definition = mCustomDefinitions.GetWeak(typeAtom);
- if (!definition || definition->mLocalName != info->NameAtom()) {
+ definition = aCustomElement->GetCustomElementDefinition();
+ if (!definition ||
+ definition->mLocalName != aCustomElement->NodeInfo()->NameAtom()) {
return;
}
}
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index f8964d198..b029f9793 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9642,13 +9642,8 @@ nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement,
nsIAtom* aExtensionType,
nsIAtom* aAttrName)
{
- nsString extType = nsDependentAtomString(aExtensionType);
- NodeInfo *ni = aCustomElement->NodeInfo();
-
CustomElementDefinition* definition =
- LookupCustomElementDefinition(aCustomElement->OwnerDoc(), ni->LocalName(),
- ni->NamespaceID(),
- extType.IsEmpty() ? nullptr : &extType);
+ aCustomElement->GetCustomElementDefinition();
// Custom element not defined yet or attribute is not in the observed
// attribute list.