Bug 1406325 - Part 5: Implement try to upgrade.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-19 23:33:52 -05:00 committed by Roy Tam
commit dba59f0317
5 changed files with 121 additions and 14 deletions

View file

@ -227,6 +227,7 @@ extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
int ns_aware, const char** colon);
class imgLoader;
class nsIAtom;
using namespace mozilla::dom;
using namespace mozilla::ipc;
@ -9575,6 +9576,27 @@ nsContentUtils::HttpsStateIsModern(nsIDocument* aDocument)
return false;
}
/* static */ void
nsContentUtils::TryToUpgradeElement(Element* aElement)
{
NodeInfo* nodeInfo = aElement->NodeInfo();
RefPtr<nsIAtom> typeAtom =
aElement->GetCustomElementData()->GetCustomElementType();
CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID(),
typeAtom);
if (definition) {
nsContentUtils::EnqueueUpgradeReaction(aElement, definition);
} else {
// Add an unresolved custom element that is a candidate for
// upgrade when a custom element is connected to the document.
// We will make sure it's shadow-including tree order in bug 1326028.
nsContentUtils::RegisterUnresolvedElement(aElement, typeAtom);
}
}
/* static */ CustomElementDefinition*
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName,
@ -9604,6 +9626,46 @@ nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
return registry->LookupCustomElementDefinition(aLocalName, aTypeAtom);
}
/* static */ void
nsContentUtils::RegisterUnresolvedElement(Element* aElement, nsIAtom* aTypeName)
{
MOZ_ASSERT(aElement);
nsIDocument* doc = aElement->OwnerDoc();
nsPIDOMWindowInner* window(doc->GetInnerWindow());
if (!window) {
return;
}
RefPtr<CustomElementRegistry> registry(window->CustomElements());
if (!registry) {
return;
}
registry->RegisterUnresolvedElement(aElement, aTypeName);
}
/* static */ void
nsContentUtils::UnregisterUnresolvedElement(Element* aElement)
{
MOZ_ASSERT(aElement);
RefPtr<nsIAtom> typeAtom =
aElement->GetCustomElementData()->GetCustomElementType();
nsIDocument* doc = aElement->OwnerDoc();
nsPIDOMWindowInner* window(doc->GetInnerWindow());
if (!window) {
return;
}
RefPtr<CustomElementRegistry> registry(window->CustomElements());
if (!registry) {
return;
}
registry->UnregisterUnresolvedElement(aElement, typeAtom);
}
/* static */ CustomElementDefinition*
nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement,
nsIAtom* aExtensionType,