From 93313b0ce3aada87f76948e6c65d455ee4998acf Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 23:33:52 -0500 Subject: Bug 1406325 - Part 5: Implement try to upgrade. Tag UXP Issue #1344 --- dom/base/nsContentUtils.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'dom/base/nsContentUtils.cpp') diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 8c157a8ee..87c879746 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -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 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 registry(window->CustomElements()); + if (!registry) { + return; + } + + registry->RegisterUnresolvedElement(aElement, aTypeName); +} + +/* static */ void +nsContentUtils::UnregisterUnresolvedElement(Element* aElement) +{ + MOZ_ASSERT(aElement); + + RefPtr typeAtom = + aElement->GetCustomElementData()->GetCustomElementType(); + nsIDocument* doc = aElement->OwnerDoc(); + nsPIDOMWindowInner* window(doc->GetInnerWindow()); + if (!window) { + return; + } + + RefPtr registry(window->CustomElements()); + if (!registry) { + return; + } + + registry->UnregisterUnresolvedElement(aElement, typeAtom); +} + /* static */ CustomElementDefinition* nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement, nsIAtom* aExtensionType, -- cgit v1.2.3