From 59c26110c1124844b5c6820573a8cb4807f1151a Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 19:48:05 -0500 Subject: Bug 1347634 - GetCustomElementData and SetCustomElementData don't need to be virtual; Tag UXP Issue #1344 --- dom/base/Element.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 0054f4800..7d926f6bb 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -4037,3 +4037,11 @@ Element::UpdateIntersectionObservation(DOMIntersectionObserver* aObserver, int32 } return false; } + +void +Element::SetCustomElementData(CustomElementData* aData) +{ + nsDOMSlots *slots = DOMSlots(); + MOZ_ASSERT(!slots->mCustomElementData, "Custom element data may not be changed once set."); + slots->mCustomElementData = aData; +} -- cgit v1.2.3 From cc533eaee5b800a534b93484598779debcdf5591 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 19:48:30 -0500 Subject: Bug 1377993 - Make node slots less memory hungry in common cases. Tag UXP Issue #1344 --- dom/base/Element.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 7d926f6bb..81cc41210 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1595,7 +1595,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, #endif { if (aBindingParent) { - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); slots->mBindingParent = aBindingParent; // Weak, so no addref happens. } @@ -1618,7 +1618,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, } ShadowRoot* parentContainingShadow = aParent->GetContainingShadow(); if (parentContainingShadow) { - DOMSlots()->mContainingShadow = parentContainingShadow; + ExtendedDOMSlots()->mContainingShadow = parentContainingShadow; } } @@ -2007,7 +2007,7 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) } #endif - nsDOMSlots* slots = GetExistingDOMSlots(); + nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); if (slots) { if (clearBindingParent) { slots->mBindingParent = nullptr; @@ -2055,7 +2055,7 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) nsICSSDeclaration* Element::GetSMILOverrideStyle() { - Element::nsDOMSlots *slots = DOMSlots(); + Element::nsExtendedDOMSlots* slots = ExtendedDOMSlots(); if (!slots->mSMILOverrideStyle) { slots->mSMILOverrideStyle = new nsDOMCSSAttributeDeclaration(this, true); @@ -2067,7 +2067,7 @@ Element::GetSMILOverrideStyle() DeclarationBlock* Element::GetSMILOverrideStyleDeclaration() { - Element::nsDOMSlots *slots = GetExistingDOMSlots(); + Element::nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots(); return slots ? slots->mSMILOverrideStyleDeclaration.get() : nullptr; } @@ -2075,7 +2075,7 @@ nsresult Element::SetSMILOverrideStyleDeclaration(DeclarationBlock* aDeclaration, bool aNotify) { - Element::nsDOMSlots *slots = DOMSlots(); + Element::nsExtendedDOMSlots* slots = ExtendedDOMSlots(); slots->mSMILOverrideStyleDeclaration = aDeclaration; @@ -3988,7 +3988,7 @@ Element::ClearDataset() nsDataHashtable, int32_t>* Element::RegisteredIntersectionObservers() { - nsDOMSlots* slots = DOMSlots(); + nsExtendedDOMSlots* slots = ExtendedDOMSlots(); return &slots->mRegisteredIntersectionObservers; } @@ -4041,7 +4041,7 @@ Element::UpdateIntersectionObservation(DOMIntersectionObserver* aObserver, int32 void Element::SetCustomElementData(CustomElementData* aData) { - nsDOMSlots *slots = DOMSlots(); + nsExtendedDOMSlots *slots = ExtendedDOMSlots(); MOZ_ASSERT(!slots->mCustomElementData, "Custom element data may not be changed once set."); slots->mCustomElementData = aData; } -- cgit v1.2.3 From 08fc057471e0f74a558de887e6f9ea9e19d42876 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 11:25:37 -0500 Subject: Bug 1334051 - Part 1: Include namespace in attributeChangedCallback. Per spec [1], we should include namesapce in attributeChangedCallback argurment list. [1] https://html.spec.whatwg.org/multipage/custom-elements.html#concept-upgrade-an-element, step 3 Tag UXP Issue #1344 --- dom/base/Element.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 81cc41210..247fbe79e 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2590,11 +2590,15 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, if (ownerDoc && GetCustomElementData()) { nsCOMPtr oldValueAtom = oldValue->GetAsAtom(); nsCOMPtr newValueAtom = valueForAfterSetAttr.GetAsAtom(); + nsAutoString ns; + nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns); + LifecycleCallbackArgs args = { nsDependentAtomString(aName), aModType == nsIDOMMutationEvent::ADDITION ? NullString() : nsDependentAtomString(oldValueAtom), - nsDependentAtomString(newValueAtom) + nsDependentAtomString(newValueAtom), + (ns.IsEmpty() ? NullString() : ns) }; nsContentUtils::EnqueueLifecycleCallback( @@ -2845,11 +2849,14 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsIDocument* ownerDoc = OwnerDoc(); if (ownerDoc && GetCustomElementData()) { + nsAutoString ns; + nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); nsCOMPtr oldValueAtom = oldValue.GetAsAtom(); LifecycleCallbackArgs args = { nsDependentAtomString(aName), nsDependentAtomString(oldValueAtom), - NullString() + NullString(), + (ns.IsEmpty() ? NullString() : ns) }; nsContentUtils::EnqueueLifecycleCallback( -- cgit v1.2.3 From bf004bb63bcc9e2ea5f9417461ecb3042b27a2fa Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 12:13:14 -0500 Subject: Bug 1334051 - Part 2: Invoke attributeChangedCallback only if attribute name is in the observed attribute list. We call attributeChangedCallback in two cases: 1. When any of the attributes in the observed attribute list has changed, appended, removed, or replaced. 2. When upgrading an element, for each attribute in element's attribute list that is in the observed attribute list. Note: w/ Fixup for not implementing an API Enhancement Bug 1363481. Tag UXP Issue #1344 --- dom/base/Element.cpp | 75 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 247fbe79e..5719b423d 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2586,23 +2586,29 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, UpdateState(aNotify); - nsIDocument* ownerDoc = OwnerDoc(); - if (ownerDoc && GetCustomElementData()) { - nsCOMPtr oldValueAtom = oldValue->GetAsAtom(); - nsCOMPtr newValueAtom = valueForAfterSetAttr.GetAsAtom(); - nsAutoString ns; - nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns); - - LifecycleCallbackArgs args = { - nsDependentAtomString(aName), - aModType == nsIDOMMutationEvent::ADDITION ? - NullString() : nsDependentAtomString(oldValueAtom), - nsDependentAtomString(newValueAtom), - (ns.IsEmpty() ? NullString() : ns) - }; - - nsContentUtils::EnqueueLifecycleCallback( - ownerDoc, nsIDocument::eAttributeChanged, this, &args); + if (nsContentUtils::IsWebComponentsEnabled()) { + if (CustomElementData* data = GetCustomElementData()) { + if (CustomElementDefinition* definition = + nsContentUtils::GetElementDefinitionIfObservingAttr(this, + data->mType, + aName)) { + nsCOMPtr oldValueAtom = oldValue->GetAsAtom(); + nsCOMPtr newValueAtom = valueForAfterSetAttr.GetAsAtom(); + nsAutoString ns; + nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNamespaceID, ns); + + LifecycleCallbackArgs args = { + nsDependentAtomString(aName), + aModType == nsIDOMMutationEvent::ADDITION ? + NullString() : nsDependentAtomString(oldValueAtom), + nsDependentAtomString(newValueAtom), + (ns.IsEmpty() ? NullString() : ns) + }; + + nsContentUtils::EnqueueLifecycleCallback( + OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition); + } + } } if (aCallAfterSetAttr) { @@ -2847,20 +2853,27 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, UpdateState(aNotify); - nsIDocument* ownerDoc = OwnerDoc(); - if (ownerDoc && GetCustomElementData()) { - nsAutoString ns; - nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); - nsCOMPtr oldValueAtom = oldValue.GetAsAtom(); - LifecycleCallbackArgs args = { - nsDependentAtomString(aName), - nsDependentAtomString(oldValueAtom), - NullString(), - (ns.IsEmpty() ? NullString() : ns) - }; - - nsContentUtils::EnqueueLifecycleCallback( - ownerDoc, nsIDocument::eAttributeChanged, this, &args); + if (nsContentUtils::IsWebComponentsEnabled()) { + if (CustomElementData* data = GetCustomElementData()) { + if (CustomElementDefinition* definition = + nsContentUtils::GetElementDefinitionIfObservingAttr(this, + data->mType, + aName)) { + nsAutoString ns; + nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); + + nsCOMPtr oldValueAtom = oldValue.GetAsAtom(); + LifecycleCallbackArgs args = { + nsDependentAtomString(aName), + nsDependentAtomString(oldValueAtom), + NullString(), + (ns.IsEmpty() ? NullString() : ns) + }; + + nsContentUtils::EnqueueLifecycleCallback( + OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition); + } + } } if (aNotify) { -- cgit v1.2.3 From 8573c572fbf5fa68defb3228e7f1450ec234d59b Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 15:31:44 -0500 Subject: Bug 1392970 - Part 1: Make CustomElementDefinition ref-counted and put it in CustomElementData. Tag UXP Issue #1344 --- dom/base/Element.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 5719b423d..e90d44476 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -4065,3 +4065,23 @@ Element::SetCustomElementData(CustomElementData* aData) MOZ_ASSERT(!slots->mCustomElementData, "Custom element data may not be changed once set."); slots->mCustomElementData = aData; } + +CustomElementDefinition* +Element::GetCustomElementDefinition() const +{ + CustomElementData* data = GetCustomElementData(); + if (!data) { + return nullptr; + } + + return data->GetCustomElementDefinition(); +} + +void +Element::SetCustomElementDefinition(CustomElementDefinition* aDefinition) +{ + CustomElementData* data = GetCustomElementData(); + MOZ_ASSERT(data); + + data->SetCustomElementDefinition(aDefinition); +} -- cgit v1.2.3 From 186782301c03f4b27e4edae07b0280e92c4e01d1 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 15:46:37 -0500 Subject: Bug 1334043 - Part 1: Replace attached callback (v0) with connected callback (v1). Tag UXP Issue #1344 --- dom/base/Element.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index e90d44476..7ab0699ed 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1685,13 +1685,12 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, } nsIDocument* composedDoc = GetComposedDoc(); - if (composedDoc) { - // Attached callback must be enqueued whenever custom element is inserted into a - // document and this document has a browsing context. - if (GetCustomElementData() && composedDoc->GetDocShell()) { - // Enqueue an attached callback for the custom element. + if (CustomElementRegistry::IsCustomElementEnabled() && composedDoc) { + // Connected callback must be enqueued whenever a custom element becomes + // connected. + if (GetCustomElementData()) { nsContentUtils::EnqueueLifecycleCallback( - composedDoc, nsIDocument::eAttached, this); + composedDoc, nsIDocument::eConnected, this); } } @@ -2586,7 +2585,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, UpdateState(aNotify); - if (nsContentUtils::IsWebComponentsEnabled()) { + if (CustomElementRegistry::IsCustomElementEnabled()) { if (CustomElementData* data = GetCustomElementData()) { if (CustomElementDefinition* definition = nsContentUtils::GetElementDefinitionIfObservingAttr(this, @@ -2853,7 +2852,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, UpdateState(aNotify); - if (nsContentUtils::IsWebComponentsEnabled()) { + if (CustomElementRegistry::IsCustomElementEnabled()) { if (CustomElementData* data = GetCustomElementData()) { if (CustomElementDefinition* definition = nsContentUtils::GetElementDefinitionIfObservingAttr(this, -- cgit v1.2.3 From 3d4c4100912132141881f40e90ddbd3aba8b0737 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 15:59:26 -0500 Subject: Bug 1334043 - Part 2: Make nsContentUtils::EnqueueLifecycleCallback static. We make nsContentUtils::EnqueueLifecycleCallback static so that it can be called without a window object. To achive this, we also make CustomElementReaction not taking a CustomElementRegistry in the constructor, as it can call Upgrade statically. Tag UXP Issue #1344 --- dom/base/Element.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 7ab0699ed..bfa0869c3 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1684,13 +1684,11 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, SetSubtreeRootPointer(aParent->SubtreeRoot()); } - nsIDocument* composedDoc = GetComposedDoc(); - if (CustomElementRegistry::IsCustomElementEnabled() && composedDoc) { + if (CustomElementRegistry::IsCustomElementEnabled() && IsInComposedDoc()) { // Connected callback must be enqueued whenever a custom element becomes // connected. if (GetCustomElementData()) { - nsContentUtils::EnqueueLifecycleCallback( - composedDoc, nsIDocument::eConnected, this); + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this); } } @@ -1989,8 +1987,7 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) // the document and this document has a browsing context. if (GetCustomElementData() && document->GetDocShell()) { // Enqueue a detached callback for the custom element. - nsContentUtils::EnqueueLifecycleCallback( - document, nsIDocument::eDetached, this); + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDetached, this); } } @@ -2605,7 +2602,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, }; nsContentUtils::EnqueueLifecycleCallback( - OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition); + nsIDocument::eAttributeChanged, this, &args, definition); } } } @@ -2870,7 +2867,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, }; nsContentUtils::EnqueueLifecycleCallback( - OwnerDoc(), nsIDocument::eAttributeChanged, this, &args, definition); + nsIDocument::eAttributeChanged, this, &args, definition); } } } -- cgit v1.2.3 From 6bbb9f062b63c5a920b1d240ba0d8575150dd01a Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 16:09:19 -0500 Subject: Bug 1334044: Replace detached callback (v0) with disconnected callback (v1). Tag UXP Issue #1344 --- dom/base/Element.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index bfa0869c3..bc1e27ba7 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1983,11 +1983,12 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) document->ClearBoxObjectFor(this); - // Detached must be enqueued whenever custom element is removed from - // the document and this document has a browsing context. - if (GetCustomElementData() && document->GetDocShell()) { - // Enqueue a detached callback for the custom element. - nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDetached, this); + // Disconnected must be enqueued whenever a connected custom element becomes + // disconnected. + if (CustomElementRegistry::IsCustomElementEnabled() && + GetCustomElementData()) { + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected, + this); } } -- cgit v1.2.3 From 8e6ce5fae721e5a4caf38b0b72e1c4a0324ae55e Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 5 Jan 2020 18:15:57 -0500 Subject: Bug 1121994 - Implement adopted callback for custom elements. Tag UXP Issue #1344 --- dom/base/Element.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index bc1e27ba7..9efa01439 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -2602,8 +2602,8 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, (ns.IsEmpty() ? NullString() : ns) }; - nsContentUtils::EnqueueLifecycleCallback( - nsIDocument::eAttributeChanged, this, &args, definition); + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged, + this, &args, nullptr, definition); } } } @@ -2867,8 +2867,8 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, (ns.IsEmpty() ? NullString() : ns) }; - nsContentUtils::EnqueueLifecycleCallback( - nsIDocument::eAttributeChanged, this, &args, definition); + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged, + this, &args, nullptr, definition); } } } -- cgit v1.2.3 From e62385604d8003b223a35dd79ceefa483d15aab6 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 22:17:12 -0500 Subject: Bug 1406325 - Part 1: Make sure custom element state is custom before sending callback. Tag UXP Issue #1344 --- dom/base/Element.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 9efa01439..9f9c8e6c0 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1687,7 +1687,8 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, if (CustomElementRegistry::IsCustomElementEnabled() && IsInComposedDoc()) { // Connected callback must be enqueued whenever a custom element becomes // connected. - if (GetCustomElementData()) { + CustomElementData* data = GetCustomElementData(); + if (data && data->mState == CustomElementData::State::eCustom) { nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this); } } @@ -1985,10 +1986,12 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) // Disconnected must be enqueued whenever a connected custom element becomes // disconnected. - if (CustomElementRegistry::IsCustomElementEnabled() && - GetCustomElementData()) { - nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected, - this); + if (CustomElementRegistry::IsCustomElementEnabled()) { + CustomElementData* data = GetCustomElementData(); + if (data && data->mState == CustomElementData::State::eCustom) { + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected, + this); + } } } @@ -2589,6 +2592,9 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, nsContentUtils::GetElementDefinitionIfObservingAttr(this, data->mType, aName)) { + MOZ_ASSERT(data->mState == CustomElementData::State::eCustom, + "AttributeChanged callback should fire only if " + "custom element state is custom"); nsCOMPtr oldValueAtom = oldValue->GetAsAtom(); nsCOMPtr newValueAtom = valueForAfterSetAttr.GetAsAtom(); nsAutoString ns; @@ -2856,6 +2862,9 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, nsContentUtils::GetElementDefinitionIfObservingAttr(this, data->mType, aName)) { + MOZ_ASSERT(data->mState == CustomElementData::State::eCustom, + "AttributeChanged callback should fire only if " + "custom element state is custom"); nsAutoString ns; nsContentUtils::NameSpaceManager()->GetNameSpaceURI(aNameSpaceID, ns); -- cgit v1.2.3 From fb657f7a1e3ef326214e0c42a5a0dd6dc0109338 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sun, 19 Jan 2020 22:59:16 -0500 Subject: Bug 1406325 - Part 4: Use mType for LookupCustomElementDefinition and also removing parts of v0. Tag UXP Issue #1344 --- dom/base/Element.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 9f9c8e6c0..fdaaed62a 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -479,7 +479,7 @@ Element::WrapObject(JSContext *aCx, JS::Handle aGivenProto) if (data) { // If this is a registered custom element then fix the prototype. nsContentUtils::GetCustomPrototype(OwnerDoc(), NodeInfo()->NamespaceID(), - data->mType, &customProto); + data->GetCustomElementType(), &customProto); if (customProto && NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(customProto))) { // Just go ahead and create with the right proto up front. Set @@ -2590,7 +2590,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID, if (CustomElementData* data = GetCustomElementData()) { if (CustomElementDefinition* definition = nsContentUtils::GetElementDefinitionIfObservingAttr(this, - data->mType, + data->GetCustomElementType(), aName)) { MOZ_ASSERT(data->mState == CustomElementData::State::eCustom, "AttributeChanged callback should fire only if " @@ -2860,7 +2860,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName, if (CustomElementData* data = GetCustomElementData()) { if (CustomElementDefinition* definition = nsContentUtils::GetElementDefinitionIfObservingAttr(this, - data->mType, + data->GetCustomElementType(), aName)) { MOZ_ASSERT(data->mState == CustomElementData::State::eCustom, "AttributeChanged callback should fire only if " -- cgit v1.2.3 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/Element.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index fdaaed62a..e77b43b86 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1688,8 +1688,13 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // Connected callback must be enqueued whenever a custom element becomes // connected. CustomElementData* data = GetCustomElementData(); - if (data && data->mState == CustomElementData::State::eCustom) { - nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, this); + if (data) { + 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. if (CustomElementRegistry::IsCustomElementEnabled()) { CustomElementData* data = GetCustomElementData(); - if (data && data->mState == CustomElementData::State::eCustom) { - nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eDisconnected, - this); + if (data) { + if (data->mState == CustomElementData::State::eCustom) { + 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); + } } } } -- cgit v1.2.3 From 4083a9abf76058d35f0277dd6857478fc6715137 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Mon, 20 Jan 2020 19:50:19 -0500 Subject: Bug 1396620 - Part 2: Fix compartment mismatch crash when doing old prototype swizzling for custom element Tag UXP Issue #1344 --- dom/base/Element.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'dom/base/Element.cpp') diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index e77b43b86..c8467e036 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -482,6 +482,10 @@ Element::WrapObject(JSContext *aCx, JS::Handle aGivenProto) data->GetCustomElementType(), &customProto); if (customProto && NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(customProto))) { + // The custom element prototype could be in different compartment. + if (!JS_WrapObject(aCx, &customProto)) { + return nullptr; + } // Just go ahead and create with the right proto up front. Set // customProto to null to flag that we don't need to do any post-facto // proto fixups here. -- cgit v1.2.3