Bug 1319342 - Clone a node should enqueue an upgrade reaction.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-05 18:26:21 -05:00 committed by Roy Tam
commit f077bd93a4
6 changed files with 23 additions and 97 deletions

View file

@ -479,19 +479,37 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
rv = aNode->Clone(nodeInfo, getter_AddRefs(clone));
NS_ENSURE_SUCCESS(rv, rv);
if (clone->IsElement()) {
if (CustomElementRegistry::IsCustomElementEnabled() && clone->IsElement()) {
// The cloned node may be a custom element that may require
// enqueing created callback and prototype swizzling.
// enqueing upgrade reaction.
Element* elem = clone->AsElement();
if (nsContentUtils::IsCustomElementName(nodeInfo->NameAtom())) {
nsContentUtils::SetupCustomElement(elem);
CustomElementDefinition* definition = nullptr;
RefPtr<nsIAtom> tagAtom = nodeInfo->NameAtom();
if (nsContentUtils::IsCustomElementName(tagAtom)) {
definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID());
if (definition) {
elem->SetCustomElementData(new CustomElementData(tagAtom));
nsContentUtils::EnqueueUpgradeReaction(elem, definition);
}
} else {
// Check if node may be custom element by type extension.
// ex. <button is="x-button">
nsAutoString extension;
if (elem->GetAttr(kNameSpaceID_None, nsGkAtoms::is, extension) &&
!extension.IsEmpty()) {
nsContentUtils::SetupCustomElement(elem, &extension);
definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID(),
&extension);
if (definition) {
RefPtr<nsIAtom> typeAtom = NS_Atomize(extension);
elem->SetCustomElementData(new CustomElementData(typeAtom));
nsContentUtils::EnqueueUpgradeReaction(elem, definition);
}
}
}
}