зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1406325 - Part 4: Use mType for LookupCustomElementDefinition and also removing parts of v0. f=echen, r=smaug
This commit is contained in:
Родитель
2319f825df
Коммит
d1400ac8b1
|
@ -38,8 +38,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
|
||||
// fail to find the CE definition for this custom element.
|
||||
|
@ -47,7 +45,7 @@ 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);
|
||||
|
@ -132,10 +130,10 @@ CustomElementData::CustomElementData(nsAtom* aType)
|
|||
}
|
||||
|
||||
CustomElementData::CustomElementData(nsAtom* aType, State aState)
|
||||
: mType(aType)
|
||||
, mElementIsBeingCreated(false)
|
||||
: mElementIsBeingCreated(false)
|
||||
, mCreatedCallbackInvoked(true)
|
||||
, mState(aState)
|
||||
, mType(aType)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -158,6 +156,12 @@ CustomElementData::GetCustomElementDefinition()
|
|||
return mCustomElementDefinition;
|
||||
}
|
||||
|
||||
nsAtom*
|
||||
CustomElementData::GetCustomElementType()
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
void
|
||||
CustomElementData::Traverse(nsCycleCollectionTraversalCallback& aCb) const
|
||||
{
|
||||
|
@ -269,12 +273,10 @@ CustomElementRegistry::~CustomElementRegistry()
|
|||
|
||||
CustomElementDefinition*
|
||||
CustomElementRegistry::LookupCustomElementDefinition(const nsAString& aLocalName,
|
||||
const nsAString* aIs) const
|
||||
nsAtom* aTypeAtom) const
|
||||
{
|
||||
RefPtr<nsAtom> localNameAtom = NS_Atomize(aLocalName);
|
||||
RefPtr<nsAtom> typeAtom = aIs ? NS_Atomize(*aIs) : localNameAtom;
|
||||
|
||||
CustomElementDefinition* data = mCustomDefinitions.GetWeak(typeAtom);
|
||||
CustomElementDefinition* data = mCustomDefinitions.GetWeak(aTypeAtom);
|
||||
if (data && data->mLocalName == localNameAtom) {
|
||||
return data;
|
||||
}
|
||||
|
@ -322,50 +324,6 @@ CustomElementRegistry::RegisterUnresolvedElement(Element* aElement, nsAtom* aTyp
|
|||
aElement->AddStates(NS_EVENT_STATE_UNRESOLVED);
|
||||
}
|
||||
|
||||
void
|
||||
CustomElementRegistry::SetupCustomElement(Element* aElement,
|
||||
const nsAString* aTypeExtension)
|
||||
{
|
||||
RefPtr<nsAtom> tagAtom = aElement->NodeInfo()->NameAtom();
|
||||
RefPtr<nsAtom> 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,
|
||||
|
|
|
@ -114,9 +114,7 @@ struct CustomElementData
|
|||
|
||||
explicit CustomElementData(nsAtom* aType);
|
||||
CustomElementData(nsAtom* aType, State aState);
|
||||
// Custom element type, for <button is="x-button"> or <x-button>
|
||||
// this would be x-button.
|
||||
RefPtr<nsAtom> 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
|
||||
|
@ -134,6 +132,7 @@ struct CustomElementData
|
|||
|
||||
void SetCustomElementDefinition(CustomElementDefinition* aDefinition);
|
||||
CustomElementDefinition* GetCustomElementDefinition();
|
||||
nsAtom* GetCustomElementType();
|
||||
|
||||
void Traverse(nsCycleCollectionTraversalCallback& aCb) const;
|
||||
void Unlink();
|
||||
|
@ -141,6 +140,9 @@ struct CustomElementData
|
|||
private:
|
||||
virtual ~CustomElementData() {}
|
||||
|
||||
// Custom element type, for <button is="x-button"> or <x-button>
|
||||
// this would be x-button.
|
||||
RefPtr<nsAtom> mType;
|
||||
RefPtr<CustomElementDefinition> mCustomElementDefinition;
|
||||
};
|
||||
|
||||
|
@ -370,18 +372,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, nsAtom* 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,
|
||||
|
|
|
@ -524,7 +524,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
|
||||
|
@ -2771,7 +2771,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 "
|
||||
|
@ -3078,7 +3078,7 @@ Element::UnsetAttr(int32_t aNameSpaceID, nsAtom* 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 "
|
||||
|
|
|
@ -10123,7 +10123,7 @@ nsContentUtils::HttpsStateIsModern(nsIDocument* aDocument)
|
|||
nsContentUtils::LookupCustomElementDefinition(nsIDocument* aDoc,
|
||||
const nsAString& aLocalName,
|
||||
uint32_t aNameSpaceID,
|
||||
const nsAString* aIs)
|
||||
nsAtom* aTypeAtom)
|
||||
{
|
||||
MOZ_ASSERT(aDoc);
|
||||
|
||||
|
@ -10142,37 +10142,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;
|
||||
}
|
||||
|
||||
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*
|
||||
|
|
|
@ -3037,10 +3037,8 @@ public:
|
|||
LookupCustomElementDefinition(nsIDocument* aDoc,
|
||||
const nsAString& aLocalName,
|
||||
uint32_t aNameSpaceID,
|
||||
const nsAString* aIs = nullptr);
|
||||
nsAtom* aTypeAtom);
|
||||
|
||||
static void SetupCustomElement(Element* aElement,
|
||||
const nsAString* aTypeExtension = nullptr);
|
||||
|
||||
static mozilla::dom::CustomElementDefinition*
|
||||
GetElementDefinitionIfObservingAttr(Element* aCustomElement,
|
||||
|
|
|
@ -485,7 +485,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);
|
||||
}
|
||||
|
|
|
@ -259,6 +259,8 @@ NS_NewHTMLElement(Element** aResult, already_AddRefed<mozilla::dom::NodeInfo>&&
|
|||
RefPtr<mozilla::dom::NodeInfo> nodeInfo = aNodeInfo;
|
||||
|
||||
nsAtom *name = nodeInfo->NameAtom();
|
||||
RefPtr<nsAtom> tagAtom = nodeInfo->NameAtom();
|
||||
RefPtr<nsAtom> typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom;
|
||||
|
||||
NS_ASSERTION(nodeInfo->NamespaceEquals(kNameSpaceID_XHTML),
|
||||
"Trying to HTML elements that don't have the XHTML namespace");
|
||||
|
@ -275,7 +277,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
|
||||
|
@ -318,8 +320,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().
|
||||
RefPtr<nsAtom> tagAtom = nodeInfo->NameAtom();
|
||||
RefPtr<nsAtom> typeAtom = aIs ? NS_Atomize(*aIs) : tagAtom;
|
||||
// Built-in element
|
||||
*aResult = CreateHTMLElement(tag, nodeInfo.forget(), aFromParser).take();
|
||||
(*aResult)->SetCustomElementData(new CustomElementData(typeAtom));
|
||||
|
@ -369,7 +369,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;
|
||||
|
|
|
@ -407,9 +407,12 @@ nsHtml5TreeOperation::CreateHTMLElement(
|
|||
|
||||
isCustomElement = (aCreator == NS_NewCustomElement || !isValue.IsEmpty());
|
||||
if (isCustomElement && aFromParser != dom::FROM_PARSER_FRAGMENT) {
|
||||
RefPtr<nsAtom> tagAtom = nodeInfo->NameAtom();
|
||||
RefPtr<nsAtom> 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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче