summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGaming4JC <g4jc@hyperbola.info>2020-01-19 22:59:16 -0500
committerGaming4JC <g4jc@hyperbola.info>2020-01-26 15:50:46 -0500
commitfb657f7a1e3ef326214e0c42a5a0dd6dc0109338 (patch)
tree5b928a47adc3834d4248e82898ae30e2fe0df43c
parent72d4c0b8df4a0080ee10ba302dd4fafeacd0f560 (diff)
downloadUXP-fb657f7a1e3ef326214e0c42a5a0dd6dc0109338.tar
UXP-fb657f7a1e3ef326214e0c42a5a0dd6dc0109338.tar.gz
UXP-fb657f7a1e3ef326214e0c42a5a0dd6dc0109338.tar.lz
UXP-fb657f7a1e3ef326214e0c42a5a0dd6dc0109338.tar.xz
UXP-fb657f7a1e3ef326214e0c42a5a0dd6dc0109338.zip
Bug 1406325 - Part 4: Use mType for LookupCustomElementDefinition and also removing parts of v0.
Tag UXP Issue #1344
-rw-r--r--dom/base/CustomElementRegistry.cpp64
-rw-r--r--dom/base/CustomElementRegistry.h17
-rw-r--r--dom/base/Element.cpp6
-rw-r--r--dom/base/nsContentUtils.cpp37
-rw-r--r--dom/base/nsContentUtils.h5
-rw-r--r--dom/base/nsNodeUtils.cpp2
-rw-r--r--dom/html/nsHTMLContentSink.cpp8
-rw-r--r--parser/html/nsHtml5TreeOperation.cpp7
8 files changed, 34 insertions, 112 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp
index f17c2c7d9..fe2837f2a 100644
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -36,7 +36,6 @@ CustomElementCallback::Call()
nsIDocument* document = mThisObject->GetComposedDoc();
if (document) {
NodeInfo* ni = mThisObject->NodeInfo();
- nsDependentAtomString extType(mOwnerData->mType);
// We need to do this because at this point, CustomElementDefinition is
// not set to CustomElementData yet, so EnqueueLifecycleCallback will
@@ -45,7 +44,8 @@ CustomElementCallback::Call()
CustomElementDefinition* definition =
nsContentUtils::LookupCustomElementDefinition(document,
ni->LocalName(), ni->NamespaceID(),
- extType.IsEmpty() ? nullptr : &extType);
+ mOwnerData->GetCustomElementType());
+
nsContentUtils::EnqueueLifecycleCallback(
nsIDocument::eConnected, mThisObject, nullptr, nullptr, definition);
}
@@ -131,10 +131,10 @@ CustomElementData::CustomElementData(nsIAtom* aType)
}
CustomElementData::CustomElementData(nsIAtom* aType, State aState)
- : mType(aType)
- , mElementIsBeingCreated(false)
+ : mElementIsBeingCreated(false)
, mCreatedCallbackInvoked(true)
, mState(aState)
+ , mType(aType)
{
}
@@ -157,6 +157,12 @@ CustomElementData::GetCustomElementDefinition()
return mCustomElementDefinition;
}
+nsIAtom*
+CustomElementData::GetCustomElementType()
+{
+ return mType;
+}
+
void
CustomElementData::Traverse(nsCycleCollectionTraversalCallback& aCb) const
{
@@ -274,12 +280,10 @@ CustomElementRegistry::~CustomElementRegistry()
CustomElementDefinition*
CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName,
- const nsAString* aIs) const
+ nsIAtom* aTypeAtom) const
{
nsCOMPtr<nsIAtom> localNameAtom = NS_Atomize(aLocalName);
- nsCOMPtr<nsIAtom> typeAtom = aIs ? NS_Atomize(*aIs) : localNameAtom;
-
- CustomElementDefinition* data = mCustomDefinitions.GetWeak(typeAtom);
+ CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom);
if (data && data->mLocalName == localNameAtom) {
return data;
}
@@ -329,50 +333,6 @@ CustomElementRegistry::RegisterUnresolvedElement(Element* aElement, nsIAtom* aTy
return;
}
-void
-CustomElementRegistry::SetupCustomElement(Element* aElement,
- const nsAString* aTypeExtension)
-{
- nsCOMPtr<nsIAtom> tagAtom = aElement->NodeInfo()->NameAtom();
- nsCOMPtr<nsIAtom> typeAtom = aTypeExtension ?
- NS_Atomize(*aTypeExtension) : tagAtom;
-
- if (aTypeExtension && !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::is)) {
- // Custom element setup in the parser happens after the "is"
- // attribute is added.
- aElement->SetAttr(kNameSpaceID_None, nsGkAtoms::is, *aTypeExtension, true);
- }
-
- // SetupCustomElement() should be called with an element that don't have
- // CustomElementData setup, if not we will hit the assertion in
- // SetCustomElementData().
- aElement->SetCustomElementData(new CustomElementData(typeAtom));
-
- CustomElementDefinition* definition = LookupCustomElementDefinition(
- aElement->NodeInfo()->LocalName(), aTypeExtension);
-
- if (!definition) {
- // The type extension doesn't exist in the registry,
- // thus we don't need to enqueue callback or adjust
- // the "is" attribute, but it is possibly an upgrade candidate.
- RegisterUnresolvedElement(aElement, typeAtom);
- return;
- }
-
- if (definition->mLocalName != tagAtom) {
- // The element doesn't match the local name for the
- // definition, thus the element isn't a custom element
- // and we don't need to do anything more.
- return;
- }
-
- // Enqueuing the created callback will set the CustomElementData on the
- // element, causing prototype swizzling to occur in Element::WrapObject.
- // We make it synchronously for createElement/createElementNS in order to
- // pass tests. It'll be removed when we deprecate custom elements v0.
- // SyncInvokeReactions(nsIDocument::eCreated, aElement, definition);
-}
-
/* static */ UniquePtr<CustomElementCallback>
CustomElementRegistry::CreateCustomElementCallback(
nsIDocument::ElementCallbackType aType, Element* aCustomElement,
diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h
index d3dfef682..81d1c003c 100644
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -112,9 +112,7 @@ struct CustomElementData
explicit CustomElementData(nsIAtom* aType);
CustomElementData(nsIAtom* aType, State aState);
- // Custom element type, for <button is="x-button"> or <x-button>
- // this would be x-button.
- nsCOMPtr<nsIAtom> mType;
+
// Element is being created flag as described in the custom elements spec.
bool mElementIsBeingCreated;
// Flag to determine if the created callback has been invoked, thus it
@@ -132,6 +130,7 @@ struct CustomElementData
void SetCustomElementDefinition(CustomElementDefinition* aDefinition);
CustomElementDefinition* GetCustomElementDefinition();
+ nsIAtom* GetCustomElementType();
void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
void Unlink();
@@ -139,6 +138,9 @@ struct CustomElementData
private:
virtual ~CustomElementData() {}
+ // Custom element type, for <button is="x-button"> or <x-button>
+ // this would be x-button.
+ RefPtr<nsIAtom> mType;
RefPtr<CustomElementDefinition> mCustomElementDefinition;
};
@@ -361,18 +363,11 @@ public:
* https://html.spec.whatwg.org/#look-up-a-custom-element-definition
*/
CustomElementDefinition* LookupCustomElementDefinition(
- const nsAString& aLocalName, const nsAString* aIs = nullptr) const;
+ const nsAString& aLocalName, nsIAtom* aTypeAtom) const;
CustomElementDefinition* LookupCustomElementDefinition(
JSContext* aCx, JSObject *aConstructor) const;
- /**
- * Enqueue created callback or register upgrade candidate for
- * newly created custom elements, possibly extending an existing type.
- * ex. <x-button>, <button is="x-button> (type extension)
- */
- void SetupCustomElement(Element* aElement, const nsAString* aTypeExtension);
-
static void EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
Element* aCustomElement,
LifecycleCallbackArgs* aArgs,
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<JSObject*> 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 "
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 864319b17..8c157a8ee 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9579,7 +9579,7 @@ nsContentUtils::HttpsStateIsModern(nsIDocument* aDocument)
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName,
uint32_t aNameSpaceID,
- const nsAString* aIs)
+ nsIAtom* aTypeAtom)
{
MOZ_ASSERT(aDoc);
@@ -9601,40 +9601,7 @@ nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
return nullptr;
}
- return registry->LookupCustomElementDefinition(aLocalName, aIs);
-}
-
-/* static */ void
-nsContentUtils::SetupCustomElement(Element* aElement,
- const nsAString* aTypeExtension)
-{
- MOZ_ASSERT(aElement);
-
- nsCOMPtr<nsIDocument> doc = aElement->OwnerDoc();
-
- if (!doc) {
- return;
- }
-
- // To support imported document.
- doc = doc->MasterDocument();
-
- if (aElement->GetNameSpaceID() != kNameSpaceID_XHTML ||
- !doc->GetDocShell()) {
- return;
- }
-
- nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
- if (!window) {
- return;
- }
-
- RefPtr<CustomElementRegistry> registry(window->CustomElements());
- if (!registry) {
- return;
- }
-
- return registry->SetupCustomElement(aElement, aTypeExtension);
+ return registry->LookupCustomElementDefinition(aLocalName, aTypeAtom);
}
/* static */ CustomElementDefinition*
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index ae9b4c8c8..367ea7c13 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2719,10 +2719,7 @@ public:
LookupCustomElementDefinition(nsIDocument* aDoc,
const nsAString& aLocalName,
uint32_t aNameSpaceID,
- const nsAString* aIs = nullptr);
-
- static void SetupCustomElement(Element* aElement,
- const nsAString* aTypeExtension = nullptr);
+ nsIAtom* aTypeAtom);
static mozilla::dom::CustomElementDefinition*
GetElementDefinitionIfObservingAttr(Element* aCustomElement,
diff --git a/dom/base/nsNodeUtils.cpp b/dom/base/nsNodeUtils.cpp
index 85cd791c5..f79da6652 100644
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -501,7 +501,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, bool aClone, bool aDeep,
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID(),
- extension.IsEmpty() ? nullptr : &extension);
+ typeAtom);
if (definition) {
nsContentUtils::EnqueueUpgradeReaction(cloneElem, definition);
}
diff --git a/dom/html/nsHTMLContentSink.cpp b/dom/html/nsHTMLContentSink.cpp
index 518a3675e..7d60fffb5 100644
--- a/dom/html/nsHTMLContentSink.cpp
+++ b/dom/html/nsHTMLContentSink.cpp
@@ -267,6 +267,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
return NS_ERROR_OUT_OF_MEMORY;
nsIAtom *name = nodeInfo->NameAtom();
+ RefPtr<nsIAtom> tagAtom = nodeInfo->NameAtom();
+ RefPtr<nsIAtom> typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom;
NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
"Trying to HTML elements that don't have the XHTML namespace");
@@ -283,7 +285,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
nsContentUtils::LookupCustomElementDefinition(nodeInfo->GetDocument(),
nodeInfo->LocalName(),
nodeInfo->NamespaceID(),
- aIs);
+ typeAtom);
}
// It might be a problem that parser synchronously calls constructor, so filed
@@ -326,8 +328,6 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
// SetupCustomElement() should be called with an element that don't have
// CustomElementData setup, if not we will hit the assertion in
// SetCustomElementData().
- nsCOMPtr<nsIAtom> tagAtom = nodeInfo->NameAtom();
- nsCOMPtr<nsIAtom> typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom;
// Built-in element
*aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take();
(*aResult)->SetCustomElementData(new CustomElementData(typeAtom));
@@ -377,7 +377,7 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
if (CustomElementRegistry::IsCustomElementEnabled() &&
(isCustomElementName || aIs)) {
- nsContentUtils::SetupCustomElement(*aResult, aIs);
+ (*aResult)->SetCustomElementData(new CustomElementData(typeAtom));
}
return NS_OK;
diff --git a/parser/html/nsHtml5TreeOperation.cpp b/parser/html/nsHtml5TreeOperation.cpp
index a7d3da259..d530cbba3 100644
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -429,9 +429,12 @@ nsHtml5TreeOperation::CreateHTMLElement(
isCustomElement = (aCreator == NS_NewCustomElement || !isValue.IsEmpty());
if (isCustomElement && aFromParser != dom::FROM_PARSER_FRAGMENT) {
+ RefPtr<nsIAtom> tagAtom = nodeInfo->NameAtom();
+ RefPtr<nsIAtom> typeAtom =
+ isValue.IsEmpty() ? tagAtom : NS_Atomize(isValue);
+
definition = nsContentUtils::LookupCustomElementDefinition(document,
- nodeInfo->LocalName(), nodeInfo->NamespaceID(),
- (isValue.IsEmpty() ? nullptr : &isValue));
+ nodeInfo->LocalName(), nodeInfo->NamespaceID(), typeAtom);
if (definition) {
willExecuteScript = true;