Bug 1334043 - Part 1: Replace attached callback (v0) with connected callback (v1).

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-05 15:46:37 -05:00 • committed by Roy Tam
commit 207d5a2e3e
4 changed files with 27 additions and 25 deletions

View file

@ -28,14 +28,13 @@ CustomElementCallback::Call()
mOwnerData->mElementIsBeingCreated = true; mOwnerData->mElementIsBeingCreated = true;
// The callback hasn't actually been invoked yet, but we need to flip // The callback hasn't actually been invoked yet, but we need to flip
// this now in order to enqueue the attached callback. This is a spec // this now in order to enqueue the connected callback. This is a spec
// bug (w3c bug 27437). // bug (w3c bug 27437).
mOwnerData->mCreatedCallbackInvoked = true; mOwnerData->mCreatedCallbackInvoked = true;
// If ELEMENT is in a document and this document has a browsing context, // If ELEMENT is connected, enqueue connected callback for ELEMENT.
// enqueue attached callback for ELEMENT.
nsIDocument* document = mThisObject->GetComposedDoc(); nsIDocument* document = mThisObject->GetComposedDoc();
if (document && document->GetDocShell()) { if (document) {
NodeInfo* ni = mThisObject->NodeInfo(); NodeInfo* ni = mThisObject->NodeInfo();
nsDependentAtomString extType(mOwnerData->mType); nsDependentAtomString extType(mOwnerData->mType);
@ -48,15 +47,15 @@ CustomElementCallback::Call()
ni->LocalName(), ni->NamespaceID(), ni->LocalName(), ni->NamespaceID(),
extType.IsEmpty() ? nullptr : &extType); extType.IsEmpty() ? nullptr : &extType);
nsContentUtils::EnqueueLifecycleCallback( nsContentUtils::EnqueueLifecycleCallback(
document, nsIDocument::eAttached, mThisObject, nullptr, definition); document, nsIDocument::eConnected, mThisObject, nullptr, definition);
} }
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv); static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
mOwnerData->mElementIsBeingCreated = false; mOwnerData->mElementIsBeingCreated = false;
break; break;
} }
case nsIDocument::eAttached: case nsIDocument::eConnected:
static_cast<LifecycleAttachedCallback *>(mCallback.get())->Call(mThisObject, rv); static_cast<LifecycleConnectedCallback *>(mCallback.get())->Call(mThisObject, rv);
break; break;
case nsIDocument::eDetached: case nsIDocument::eDetached:
static_cast<LifecycleDetachedCallback *>(mCallback.get())->Call(mThisObject, rv); static_cast<LifecycleDetachedCallback *>(mCallback.get())->Call(mThisObject, rv);
@ -349,9 +348,9 @@ CustomElementRegistry::CreateCustomElementCallback(
} }
break; break;
case nsIDocument::eAttached: case nsIDocument::eConnected:
if (aDefinition->mCallbacks->mAttachedCallback.WasPassed()) { if (aDefinition->mCallbacks->mConnectedCallback.WasPassed()) {
func = aDefinition->mCallbacks->mAttachedCallback.Value(); func = aDefinition->mCallbacks->mConnectedCallback.Value();
} }
break; break;
@ -934,7 +933,11 @@ CustomElementRegistry::Upgrade(Element* aElement,
} }
// Step 4. // Step 4.
// TODO: Bug 1334043 - Implement connected lifecycle callbacks for custom elements if (aElement->IsInComposedDoc()) {
nsContentUtils::EnqueueLifecycleCallback(aElement->OwnerDoc(),
nsIDocument::eConnected, aElement,
nullptr, aDefinition);
}
// Step 5. // Step 5.
AutoConstructionStackEntry acs(aDefinition->mConstructionStack, AutoConstructionStackEntry acs(aDefinition->mConstructionStack,
@ -1129,9 +1132,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition)
cb.NoteXPCOMChild(callbacks->mCreatedCallback.Value()); cb.NoteXPCOMChild(callbacks->mCreatedCallback.Value());
} }
if (callbacks->mAttachedCallback.WasPassed()) { if (callbacks->mConnectedCallback.WasPassed()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mAttachedCallback"); NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mConnectedCallback");
cb.NoteXPCOMChild(callbacks->mAttachedCallback.Value()); cb.NoteXPCOMChild(callbacks->mConnectedCallback.Value());
} }
if (callbacks->mDetachedCallback.WasPassed()) { if (callbacks->mDetachedCallback.WasPassed()) {

View file

@ -1685,13 +1685,12 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
} }
nsIDocument* composedDoc = GetComposedDoc(); nsIDocument* composedDoc = GetComposedDoc();
if (composedDoc) { if (CustomElementRegistry::IsCustomElementEnabled() && composedDoc) {
// Attached callback must be enqueued whenever custom element is inserted into a // Connected callback must be enqueued whenever a custom element becomes
// document and this document has a browsing context. // connected.
if (GetCustomElementData() && composedDoc->GetDocShell()) { if (GetCustomElementData()) {
// Enqueue an attached callback for the custom element.
nsContentUtils::EnqueueLifecycleCallback( nsContentUtils::EnqueueLifecycleCallback(
composedDoc, nsIDocument::eAttached, this); composedDoc, nsIDocument::eConnected, this);
} }
} }
@ -2586,7 +2585,7 @@ Element::SetAttrAndNotify(int32_t aNamespaceID,
UpdateState(aNotify); UpdateState(aNotify);
if (nsContentUtils::IsWebComponentsEnabled()) { if (CustomElementRegistry::IsCustomElementEnabled()) {
if (CustomElementData* data = GetCustomElementData()) { if (CustomElementData* data = GetCustomElementData()) {
if (CustomElementDefinition* definition = if (CustomElementDefinition* definition =
nsContentUtils::GetElementDefinitionIfObservingAttr(this, nsContentUtils::GetElementDefinitionIfObservingAttr(this,
@ -2853,7 +2852,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsIAtom* aName,
UpdateState(aNotify); UpdateState(aNotify);
if (nsContentUtils::IsWebComponentsEnabled()) { if (CustomElementRegistry::IsCustomElementEnabled()) {
if (CustomElementData* data = GetCustomElementData()) { if (CustomElementData* data = GetCustomElementData()) {
if (CustomElementDefinition* definition = if (CustomElementDefinition* definition =
nsContentUtils::GetElementDefinitionIfObservingAttr(this, nsContentUtils::GetElementDefinitionIfObservingAttr(this,

View file

@ -2580,7 +2580,7 @@ public:
enum ElementCallbackType { enum ElementCallbackType {
eCreated, eCreated,
eAttached, eConnected,
eDetached, eDetached,
eAttributeChanged eAttributeChanged
}; };

View file

@ -11,7 +11,7 @@
*/ */
callback LifecycleCreatedCallback = void(); callback LifecycleCreatedCallback = void();
callback LifecycleAttachedCallback = void(); callback LifecycleConnectedCallback = void();
callback LifecycleDetachedCallback = void(); callback LifecycleDetachedCallback = void();
callback LifecycleAttributeChangedCallback = void(DOMString attrName, callback LifecycleAttributeChangedCallback = void(DOMString attrName,
DOMString? oldValue, DOMString? oldValue,
@ -20,7 +20,7 @@ callback LifecycleAttributeChangedCallback = void(DOMString attrName,
dictionary LifecycleCallbacks { dictionary LifecycleCallbacks {
LifecycleCreatedCallback? createdCallback; LifecycleCreatedCallback? createdCallback;
LifecycleAttachedCallback? attachedCallback; LifecycleConnectedCallback? connectedCallback;
LifecycleDetachedCallback? detachedCallback; LifecycleDetachedCallback? detachedCallback;
LifecycleAttributeChangedCallback? attributeChangedCallback; LifecycleAttributeChangedCallback? attributeChangedCallback;
}; };