summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-05 15:46:37 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:28 -0500
commit186782301c03f4b27e4edae07b0280e92c4e01d1 (patch)
treedf00e6dbd5de72de0d5c7ab62ddc089bb93c86bd /dom
parent42331663e643b8366c4ec87a929161fa3fb8d775 (diff)
downloadUXP-186782301c03f4b27e4edae07b0280e92c4e01d1.tar
UXP-186782301c03f4b27e4edae07b0280e92c4e01d1.tar.gz
UXP-186782301c03f4b27e4edae07b0280e92c4e01d1.tar.lz
UXP-186782301c03f4b27e4edae07b0280e92c4e01d1.tar.xz
UXP-186782301c03f4b27e4edae07b0280e92c4e01d1.zip
Bug 1334043 - Part 1: Replace attached callback (v0) with connected callback (v1).
Tag UXP Issue #1344
Diffstat (limited to 'dom')
-rw-r--r--dom/base/CustomElementRegistry.cpp31
-rw-r--r--dom/base/Element.cpp15
-rw-r--r--dom/base/nsIDocument.h2
-rw-r--r--dom/webidl/WebComponents.webidl4
4 files changed, 27 insertions, 25 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp
index 1a4b5d45a..efbad781f 100644
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -28,14 +28,13 @@ CustomElementCallback::Call()
mOwnerData->mElementIsBeingCreated = true;
// 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).
mOwnerData->mCreatedCallbackInvoked = true;
- // If ELEMENT is in a document and this document has a browsing context,
- // enqueue attached callback for ELEMENT.
+ // If ELEMENT is connected, enqueue connected callback for ELEMENT.
nsIDocument* document = mThisObject->GetComposedDoc();
- if (document && document->GetDocShell()) {
+ if (document) {
NodeInfo* ni = mThisObject->NodeInfo();
nsDependentAtomString extType(mOwnerData->mType);
@@ -48,15 +47,15 @@ CustomElementCallback::Call()
ni->LocalName(), ni->NamespaceID(),
extType.IsEmpty() ? nullptr : &extType);
nsContentUtils::EnqueueLifecycleCallback(
- document, nsIDocument::eAttached, mThisObject, nullptr, definition);
+ document, nsIDocument::eConnected, mThisObject, nullptr, definition);
}
static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv);
mOwnerData->mElementIsBeingCreated = false;
break;
}
- case nsIDocument::eAttached:
- static_cast<LifecycleAttachedCallback *>(mCallback.get())->Call(mThisObject, rv);
+ case nsIDocument::eConnected:
+ static_cast<LifecycleConnectedCallback *>(mCallback.get())->Call(mThisObject, rv);
break;
case nsIDocument::eDetached:
static_cast<LifecycleDetachedCallback *>(mCallback.get())->Call(mThisObject, rv);
@@ -349,9 +348,9 @@ CustomElementRegistry::CreateCustomElementCallback(
}
break;
- case nsIDocument::eAttached:
- if (aDefinition->mCallbacks->mAttachedCallback.WasPassed()) {
- func = aDefinition->mCallbacks->mAttachedCallback.Value();
+ case nsIDocument::eConnected:
+ if (aDefinition->mCallbacks->mConnectedCallback.WasPassed()) {
+ func = aDefinition->mCallbacks->mConnectedCallback.Value();
}
break;
@@ -934,7 +933,11 @@ CustomElementRegistry::Upgrade(Element* aElement,
}
// 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.
AutoConstructionStackEntry acs(aDefinition->mConstructionStack,
@@ -1129,9 +1132,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition)
cb.NoteXPCOMChild(callbacks->mCreatedCallback.Value());
}
- if (callbacks->mAttachedCallback.WasPassed()) {
- NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mAttachedCallback");
- cb.NoteXPCOMChild(callbacks->mAttachedCallback.Value());
+ if (callbacks->mConnectedCallback.WasPassed()) {
+ NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mConnectedCallback");
+ cb.NoteXPCOMChild(callbacks->mConnectedCallback.Value());
}
if (callbacks->mDetachedCallback.WasPassed()) {
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,
diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h
index e44ab047e..0f05bbfcb 100644
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -2580,7 +2580,7 @@ public:
enum ElementCallbackType {
eCreated,
- eAttached,
+ eConnected,
eDetached,
eAttributeChanged
};
diff --git a/dom/webidl/WebComponents.webidl b/dom/webidl/WebComponents.webidl
index 19ca38c0d..8623bcbae 100644
--- a/dom/webidl/WebComponents.webidl
+++ b/dom/webidl/WebComponents.webidl
@@ -11,7 +11,7 @@
*/
callback LifecycleCreatedCallback = void();
-callback LifecycleAttachedCallback = void();
+callback LifecycleConnectedCallback = void();
callback LifecycleDetachedCallback = void();
callback LifecycleAttributeChangedCallback = void(DOMString attrName,
DOMString? oldValue,
@@ -20,7 +20,7 @@ callback LifecycleAttributeChangedCallback = void(DOMString attrName,
dictionary LifecycleCallbacks {
LifecycleCreatedCallback? createdCallback;
- LifecycleAttachedCallback? attachedCallback;
+ LifecycleConnectedCallback? connectedCallback;
LifecycleDetachedCallback? detachedCallback;
LifecycleAttributeChangedCallback? attributeChangedCallback;
};