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
parent fb657f7a1e
commit 93313b0ce3
5 changed files with 121 additions and 14 deletions
+18
View File
@@ -333,6 +333,24 @@ CustomElementRegistry::RegisterUnresolvedElement(Element* aElement, nsIAtom* aTy
return; return;
} }
void
CustomElementRegistry::UnregisterUnresolvedElement(Element* aElement,
nsIAtom* aTypeName)
{
nsTArray<nsWeakPtr>* candidates;
if (mCandidatesMap.Get(aTypeName, &candidates)) {
MOZ_ASSERT(candidates);
// We don't need to iterate the candidates array and remove the element from
// the array for performance reason. It'll be handled by bug 1396620.
for (size_t i = 0; i < candidates->Length(); ++i) {
nsCOMPtr<Element> elem = do_QueryReferent(candidates->ElementAt(i));
if (elem && elem.get() == aElement) {
candidates->RemoveElementAt(i);
}
}
}
}
/* static */ UniquePtr<CustomElementCallback> /* static */ UniquePtr<CustomElementCallback>
CustomElementRegistry::CreateCustomElementCallback( CustomElementRegistry::CreateCustomElementCallback(
nsIDocument::ElementCallbackType aType, Element* aCustomElement, nsIDocument::ElementCallbackType aType, Element* aCustomElement,
+15 -9
View File
@@ -383,15 +383,6 @@ public:
*/ */
static void Upgrade(Element* aElement, CustomElementDefinition* aDefinition, ErrorResult& aRv); static void Upgrade(Element* aElement, CustomElementDefinition* aDefinition, ErrorResult& aRv);
private:
~CustomElementRegistry();
static UniquePtr<CustomElementCallback> CreateCustomElementCallback(
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
LifecycleCallbackArgs* aArgs,
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
CustomElementDefinition* aDefinition);
/** /**
* Registers an unresolved custom element that is a candidate for * Registers an unresolved custom element that is a candidate for
* upgrade when the definition is registered via registerElement. * upgrade when the definition is registered via registerElement.
@@ -403,6 +394,21 @@ private:
void RegisterUnresolvedElement(Element* aElement, void RegisterUnresolvedElement(Element* aElement,
nsIAtom* aTypeName = nullptr); nsIAtom* aTypeName = nullptr);
/**
* Unregister an unresolved custom element that is a candidate for
* upgrade when a custom element is removed from tree.
*/
void UnregisterUnresolvedElement(Element* aElement,
nsIAtom* aTypeName = nullptr);
private:
~CustomElementRegistry();
static UniquePtr<CustomElementCallback> CreateCustomElementCallback(
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
LifecycleCallbackArgs* aArgs,
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
CustomElementDefinition* aDefinition);
void UpgradeCandidates(nsIAtom* aKey, void UpgradeCandidates(nsIAtom* aKey,
CustomElementDefinition* aDefinition, CustomElementDefinition* aDefinition,
ErrorResult& aRv); ErrorResult& aRv);
+17 -5
View File
@@ -1688,8 +1688,13 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
// Connected callback must be enqueued whenever a custom element becomes // Connected callback must be enqueued whenever a custom element becomes
// connected. // connected.
CustomElementData* data = GetCustomElementData(); CustomElementData* data = GetCustomElementData();
if (data && data->mState == CustomElementData::State::eCustom) { if (data) {
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this); if (data->mState == CustomElementData::State::eCustom) {
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this);
} else {
// Step 7.7.2.2 https://dom.spec.whatwg.org/#concept-node-insert
nsContentUtils::TryToUpgradeElement(this);
}
} }
} }
@@ -1988,9 +1993,16 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent)
// disconnected. // disconnected.
if (CustomElementRegistry::IsCustomElementEnabled()) { if (CustomElementRegistry::IsCustomElementEnabled()) {
CustomElementData* data = GetCustomElementData(); CustomElementData* data = GetCustomElementData();
if (data && data->mState == CustomElementData::State::eCustom) { if (data) {
nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected, if (data->mState == CustomElementData::State::eCustom) {
this); nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected,
this);
} else {
// Remove an unresolved custom element that is a candidate for
// upgrade when a custom element is disconnected.
// We will make sure it's shadow-including tree order in bug 1326028.
nsContentUtils::UnregisterUnresolvedElement(this);
}
} }
} }
} }
+62
View File
@@ -227,6 +227,7 @@ extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
int ns_aware, const char** colon); int ns_aware, const char** colon);
class imgLoader; class imgLoader;
class nsIAtom;
using namespace mozilla::dom; using namespace mozilla::dom;
using namespace mozilla::ipc; using namespace mozilla::ipc;
@@ -9575,6 +9576,27 @@ nsContentUtils::HttpsStateIsModern(nsIDocument* aDocument)
return false; 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* /* static */ CustomElementDefinition*
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc, nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName, const nsAString& aLocalName,
@@ -9604,6 +9626,46 @@ nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
return registry->LookupCustomElementDefinition(aLocalName, aTypeAtom); 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* /* static */ CustomElementDefinition*
nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement, nsContentUtils::GetElementDefinitionIfObservingAttr(Element* aCustomElement,
nsIAtom* aExtensionType, nsIAtom* aExtensionType,
+9
View File
@@ -2711,6 +2711,12 @@ public:
*/ */
static bool HttpsStateIsModern(nsIDocument* aDocument); static bool HttpsStateIsModern(nsIDocument* aDocument);
/**
* Try to upgrade an element.
* https://html.spec.whatwg.org/multipage/custom-elements.html#concept-try-upgrade
*/
static void TryToUpgradeElement(Element* aElement);
/** /**
* Looking up a custom element definition. * Looking up a custom element definition.
* https://html.spec.whatwg.org/#look-up-a-custom-element-definition * https://html.spec.whatwg.org/#look-up-a-custom-element-definition
@@ -2721,6 +2727,9 @@ public:
uint32_t aNameSpaceID, uint32_t aNameSpaceID,
nsIAtom* aTypeAtom); nsIAtom* aTypeAtom);
static void RegisterUnresolvedElement(Element* aElement, nsIAtom* aTypeName);
static void UnregisterUnresolvedElement(Element* aElement);
static mozilla::dom::CustomElementDefinition* static mozilla::dom::CustomElementDefinition*
GetElementDefinitionIfObservingAttr(Element* aCustomElement, GetElementDefinitionIfObservingAttr(Element* aCustomElement,
nsIAtom* aExtensionType, nsIAtom* aExtensionType,