diff options
-rw-r--r-- | dom/base/CustomElementRegistry.cpp | 35 | ||||
-rw-r--r-- | dom/base/CustomElementRegistry.h | 19 | ||||
-rw-r--r-- | dom/base/Element.cpp | 8 | ||||
-rw-r--r-- | dom/base/nsContentUtils.cpp | 2 | ||||
-rw-r--r-- | dom/base/nsContentUtils.h | 2 | ||||
-rw-r--r-- | dom/base/nsIDocument.h | 1 | ||||
-rw-r--r-- | dom/base/nsNodeUtils.cpp | 17 | ||||
-rw-r--r-- | dom/webidl/WebComponents.webidl | 3 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/adopted-callback.html.ini | 84 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/reactions/ChildNode.html.ini | 10 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/reactions/Document.html.ini | 4 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/reactions/Node.html.ini | 9 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/reactions/ParentNode.html.ini | 8 | ||||
-rw-r--r-- | testing/web-platform/meta/custom-elements/reactions/Range.html.ini | 4 |
14 files changed, 76 insertions, 130 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index 069611f653..bad100cf59 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -47,7 +47,7 @@ CustomElementCallback::Call() ni->LocalName(), ni->NamespaceID(), extType.IsEmpty() ? nullptr : &extType); nsContentUtils::EnqueueLifecycleCallback( - nsIDocument::eConnected, mThisObject, nullptr, definition); + nsIDocument::eConnected, mThisObject, nullptr, nullptr, definition); } static_cast<LifecycleCreatedCallback *>(mCallback.get())->Call(mThisObject, rv); @@ -60,6 +60,10 @@ CustomElementCallback::Call() case nsIDocument::eDisconnected: static_cast<LifecycleDisconnectedCallback *>(mCallback.get())->Call(mThisObject, rv); break; + case nsIDocument::eAdopted: + static_cast<LifecycleAdoptedCallback *>(mCallback.get())->Call(mThisObject, + mAdoptedCallbackArgs.mOldDocument, mAdoptedCallbackArgs.mNewDocument, rv); + break; case nsIDocument::eAttributeChanged: static_cast<LifecycleAttributeChangedCallback *>(mCallback.get())->Call(mThisObject, mArgs.name, mArgs.oldValue, mArgs.newValue, mArgs.namespaceURI, rv); @@ -332,7 +336,9 @@ CustomElementRegistry::SetupCustomElement(Element* aElement, /* static */ UniquePtr<CustomElementCallback> CustomElementRegistry::CreateCustomElementCallback( nsIDocument::ElementCallbackType aType, Element* aCustomElement, - LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition) + LifecycleCallbackArgs* aArgs, + LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, + CustomElementDefinition* aDefinition) { MOZ_ASSERT(aDefinition, "CustomElementDefinition should not be null"); @@ -360,6 +366,12 @@ CustomElementRegistry::CreateCustomElementCallback( } break; + case nsIDocument::eAdopted: + if (aDefinition->mCallbacks->mAdoptedCallback.WasPassed()) { + func = aDefinition->mCallbacks->mAdoptedCallback.Value(); + } + break; + case nsIDocument::eAttributeChanged: if (aDefinition->mCallbacks->mAttributeChangedCallback.WasPassed()) { func = aDefinition->mCallbacks->mAttributeChangedCallback.Value(); @@ -388,6 +400,9 @@ CustomElementRegistry::CreateCustomElementCallback( callback->SetArgs(*aArgs); } + if (aAdoptedCallbackArgs) { + callback->SetAdoptedCallbackArgs(*aAdoptedCallbackArgs); + } return Move(callback); } @@ -395,6 +410,7 @@ CustomElementRegistry::CreateCustomElementCallback( CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, Element* aCustomElement, LifecycleCallbackArgs* aArgs, + LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, CustomElementDefinition* aDefinition) { CustomElementDefinition* definition = aDefinition; @@ -407,7 +423,8 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType } auto callback = - CreateCustomElementCallback(aType, aCustomElement, aArgs, definition); + CreateCustomElementCallback(aType, aCustomElement, aArgs, + aAdoptedCallbackArgs, definition); if (!callback) { return; } @@ -926,7 +943,7 @@ CustomElementRegistry::Upgrade(Element* aElement, }; nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAttributeChanged, aElement, - &args, aDefinition); + &args, nullptr, aDefinition); } } } @@ -934,7 +951,7 @@ CustomElementRegistry::Upgrade(Element* aElement, // Step 4. if (aElement->IsInComposedDoc()) { nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eConnected, aElement, - nullptr, aDefinition); + nullptr, nullptr, aDefinition); } // Step 5. @@ -958,7 +975,8 @@ CustomElementRegistry::Upgrade(Element* aElement, // This is for old spec. nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eCreated, - aElement, nullptr, aDefinition); + aElement, nullptr, + nullptr, aDefinition); } //----------------------------------------------------- @@ -1141,6 +1159,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CustomElementDefinition) cb.NoteXPCOMChild(callbacks->mDisconnectedCallback.Value()); } + if (callbacks->mAdoptedCallback.WasPassed()) { + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCallbacks->mAdoptedCallback"); + cb.NoteXPCOMChild(callbacks->mAdoptedCallback.Value()); + } + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mConstructor"); cb.NoteXPCOMChild(tmp->mConstructor); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h index 30e2c00abb..e9b2bee56b 100644 --- a/dom/base/CustomElementRegistry.h +++ b/dom/base/CustomElementRegistry.h @@ -38,6 +38,12 @@ struct LifecycleCallbackArgs nsString namespaceURI; }; +struct LifecycleAdoptedCallbackArgs +{ + nsCOMPtr<nsIDocument> mOldDocument; + nsCOMPtr<nsIDocument> mNewDocument; +}; + class CustomElementCallback { public: @@ -54,6 +60,13 @@ public: mArgs = aArgs; } + void SetAdoptedCallbackArgs(LifecycleAdoptedCallbackArgs& aAdoptedCallbackArgs) + { + MOZ_ASSERT(mType == nsIDocument::eAdopted, + "Arguments are only used by adopted callback."); + mAdoptedCallbackArgs = aAdoptedCallbackArgs; + } + private: // The this value to use for invocation of the callback. RefPtr<Element> mThisObject; @@ -63,6 +76,7 @@ private: // Arguments to be passed to the callback, // used by the attribute changed callback. LifecycleCallbackArgs mArgs; + LifecycleAdoptedCallbackArgs mAdoptedCallbackArgs; // CustomElementData that contains this callback in the // callback queue. CustomElementData* mOwnerData; @@ -365,6 +379,7 @@ public: static void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, Element* aCustomElement, LifecycleCallbackArgs* aArgs, + LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, CustomElementDefinition* aDefinition); void GetCustomPrototype(nsIAtom* aAtom, @@ -381,7 +396,9 @@ private: static UniquePtr<CustomElementCallback> CreateCustomElementCallback( nsIDocument::ElementCallbackType aType, Element* aCustomElement, - LifecycleCallbackArgs* aArgs, CustomElementDefinition* aDefinition); + LifecycleCallbackArgs* aArgs, + LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, + CustomElementDefinition* aDefinition); /** * Registers an unresolved custom element that is a candidate for diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index bc1e27ba77..9efa01439d 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); } } } diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 76171dda02..864319b170 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -9676,6 +9676,7 @@ nsContentUtils::EnqueueUpgradeReaction(Element* aElement, nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, Element* aCustomElement, LifecycleCallbackArgs* aArgs, + LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs, CustomElementDefinition* aDefinition) { // No DocGroup means no custom element reactions stack. @@ -9684,6 +9685,7 @@ nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, } CustomElementRegistry::EnqueueLifecycleCallback(aType, aCustomElement, aArgs, + aAdoptedCallbackArgs, aDefinition); } diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 5075bcb6dc..ae9b4c8c8c 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -126,6 +126,7 @@ class EventTarget; class IPCDataTransfer; class IPCDataTransferItem; struct LifecycleCallbackArgs; +struct LifecycleAdoptedCallbackArgs; class NodeInfo; class nsIContentChild; class nsIContentParent; @@ -2734,6 +2735,7 @@ public: static void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType, Element* aCustomElement, mozilla::dom::LifecycleCallbackArgs* aArgs = nullptr, + mozilla::dom::LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs = nullptr, mozilla::dom::CustomElementDefinition* aDefinition = nullptr); static void GetCustomPrototype(nsIDocument* aDoc, diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index c620d1d09b..66f30a6bc7 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -2582,6 +2582,7 @@ public: eCreated, eConnected, eDisconnected, + eAdopted, eAttributeChanged }; diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp index c38f08a3d8..ce023ccfad 100644 --- a/dom/base/nsNodeUtils.cpp +++ b/dom/base/nsNodeUtils.cpp @@ -526,6 +526,23 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep, nsIDocument* newDoc = aNode->OwnerDoc(); if (newDoc) { + if (CustomElementRegistry::IsCustomElementEnabled()) { + // Adopted callback must be enqueued whenever a node’s + // shadow-including inclusive descendants that is custom. + Element* element = aNode->IsElement() ? aNode->AsElement() : nullptr; + if (element) { + RefPtr<CustomElementData> data = element->GetCustomElementData(); + if (data && data->mState == CustomElementData::State::eCustom) { + LifecycleAdoptedCallbackArgs args = { + oldDoc, + newDoc + }; + nsContentUtils::EnqueueLifecycleCallback(nsIDocument::eAdopted, + element, nullptr, &args); + } + } + } + // XXX what if oldDoc is null, we don't know if this should be // registered or not! Can that really happen? if (wasRegistered) { diff --git a/dom/webidl/WebComponents.webidl b/dom/webidl/WebComponents.webidl index 2c2d9fb53c..008f594109 100644 --- a/dom/webidl/WebComponents.webidl +++ b/dom/webidl/WebComponents.webidl @@ -13,6 +13,8 @@ callback LifecycleCreatedCallback = void(); callback LifecycleConnectedCallback = void(); callback LifecycleDisconnectedCallback = void(); +callback LifecycleAdoptedCallback = void(Document? oldDocument, + Document? newDocment); callback LifecycleAttributeChangedCallback = void(DOMString attrName, DOMString? oldValue, DOMString? newValue, @@ -22,6 +24,7 @@ dictionary LifecycleCallbacks { LifecycleCreatedCallback? createdCallback; LifecycleConnectedCallback? connectedCallback; LifecycleDisconnectedCallback? disconnectedCallback; + LifecycleAdoptedCallback? adoptedCallback; LifecycleAttributeChangedCallback? attributeChangedCallback; }; diff --git a/testing/web-platform/meta/custom-elements/adopted-callback.html.ini b/testing/web-platform/meta/custom-elements/adopted-callback.html.ini index 3cb7bc1fbc..e35f704acf 100644 --- a/testing/web-platform/meta/custom-elements/adopted-callback.html.ini +++ b/testing/web-platform/meta/custom-elements/adopted-callback.html.ini @@ -1,17 +1,5 @@ [adopted-callback.html] type: testharness - [Inserting a custom element into the document of the template elements must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke adoptedCallback] expected: FAIL @@ -24,18 +12,6 @@ [Inserting a custom element into a detached shadow tree that belongs to the document of the template elements must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into a new document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into a new document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into a new document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into a new document must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in a new document must enqueue and invoke adoptedCallback] expected: FAIL @@ -48,18 +24,6 @@ [Inserting a custom element into a detached shadow tree that belongs to a new document must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into a cloned document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into a cloned document must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke adoptedCallback] expected: FAIL @@ -72,18 +36,6 @@ [Inserting a custom element into a detached shadow tree that belongs to a cloned document must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke adoptedCallback] expected: FAIL @@ -96,18 +48,6 @@ [Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke adoptedCallback] expected: FAIL @@ -120,18 +60,6 @@ [Inserting a custom element into a detached shadow tree that belongs to an HTML document created by createDocument must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into the document of an iframe must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into the document of an iframe must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in the document of an iframe must enqueue and invoke adoptedCallback] expected: FAIL @@ -144,18 +72,6 @@ [Inserting a custom element into a detached shadow tree that belongs to the document of an iframe must enqueue and invoke adoptedCallback] expected: FAIL - [Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] - expected: FAIL - - [Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] - expected: FAIL - - [Moving an ancestor of custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback] - expected: FAIL - [Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke adoptedCallback] expected: FAIL diff --git a/testing/web-platform/meta/custom-elements/reactions/ChildNode.html.ini b/testing/web-platform/meta/custom-elements/reactions/ChildNode.html.ini deleted file mode 100644 index edef1ed9fc..0000000000 --- a/testing/web-platform/meta/custom-elements/reactions/ChildNode.html.ini +++ /dev/null @@ -1,10 +0,0 @@ -[ChildNode.html] - type: testharness - [before on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - - [after on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - - [replaceWith on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL diff --git a/testing/web-platform/meta/custom-elements/reactions/Document.html.ini b/testing/web-platform/meta/custom-elements/reactions/Document.html.ini index 71f9e29a41..0c42955de2 100644 --- a/testing/web-platform/meta/custom-elements/reactions/Document.html.ini +++ b/testing/web-platform/meta/custom-elements/reactions/Document.html.ini @@ -2,7 +2,3 @@ type: testharness [importNode on Document must construct a new custom element when importing a custom element] expected: FAIL - - [adoptNode on Document must enqueue an adopted reaction when importing a custom element] - expected: FAIL - diff --git a/testing/web-platform/meta/custom-elements/reactions/Node.html.ini b/testing/web-platform/meta/custom-elements/reactions/Node.html.ini index b65e80813b..c14ca17dff 100644 --- a/testing/web-platform/meta/custom-elements/reactions/Node.html.ini +++ b/testing/web-platform/meta/custom-elements/reactions/Node.html.ini @@ -20,12 +20,3 @@ [cloneNode on Node must enqueue an attributeChanged reaction when cloning an element only for observed attributes] expected: FAIL - - [insertBefore on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - - [appendChild on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - - [replaceChild on ChildNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL diff --git a/testing/web-platform/meta/custom-elements/reactions/ParentNode.html.ini b/testing/web-platform/meta/custom-elements/reactions/ParentNode.html.ini deleted file mode 100644 index b982c66e6d..0000000000 --- a/testing/web-platform/meta/custom-elements/reactions/ParentNode.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[ParentNode.html] - type: testharness - [prepend on ParentNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - - [append on ParentNode must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - diff --git a/testing/web-platform/meta/custom-elements/reactions/Range.html.ini b/testing/web-platform/meta/custom-elements/reactions/Range.html.ini index e44d6d3894..62ab491adc 100644 --- a/testing/web-platform/meta/custom-elements/reactions/Range.html.ini +++ b/testing/web-platform/meta/custom-elements/reactions/Range.html.ini @@ -8,7 +8,3 @@ [cloneContents on Range must enqueue an attributeChanged reaction when cloning an element only for observed attributes] expected: FAIL - - [insertNode on Range must enqueue a disconnected reaction, an adopted reaction, and a connected reaction when the custom element was in another document] - expected: FAIL - |