diff options
author | Gaming4JC <g4jc@hyperbola.info> | 2020-01-19 23:33:52 -0500 |
---|---|---|
committer | Gaming4JC <g4jc@hyperbola.info> | 2020-01-26 15:50:46 -0500 |
commit | 93313b0ce3aada87f76948e6c65d455ee4998acf (patch) | |
tree | fd8285a120168d8c6adf004c5822b4379acd4b46 /dom/base/nsContentUtils.cpp | |
parent | fb657f7a1e3ef326214e0c42a5a0dd6dc0109338 (diff) | |
download | uxp-93313b0ce3aada87f76948e6c65d455ee4998acf.tar.gz |
Bug 1406325 - Part 5: Implement try to upgrade.
Tag UXP Issue #1344
Diffstat (limited to 'dom/base/nsContentUtils.cpp')
-rw-r--r-- | dom/base/nsContentUtils.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 8c157a8ee7..87c879746a 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<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, |