Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/custom/CustomElement.h" | 5 #include "core/dom/custom/CustomElement.h" |
| 6 | 6 |
| 7 #include "core/HTMLElementFactory.h" | |
| 8 #include "core/HTMLElementTypeHelpers.h" | |
| 7 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 8 #include "core/dom/QualifiedName.h" | 10 #include "core/dom/QualifiedName.h" |
| 9 #include "core/dom/custom/CEReactionsScope.h" | 11 #include "core/dom/custom/CEReactionsScope.h" |
| 10 #include "core/dom/custom/CustomElementDefinition.h" | 12 #include "core/dom/custom/CustomElementDefinition.h" |
| 11 #include "core/dom/custom/CustomElementReactionStack.h" | 13 #include "core/dom/custom/CustomElementReactionStack.h" |
| 12 #include "core/dom/custom/CustomElementRegistry.h" | 14 #include "core/dom/custom/CustomElementRegistry.h" |
| 13 #include "core/dom/custom/V0CustomElement.h" | 15 #include "core/dom/custom/V0CustomElement.h" |
| 14 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 16 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 15 #include "core/frame/LocalDOMWindow.h" | 17 #include "core/frame/LocalDOMWindow.h" |
| 16 #include "core/html/HTMLElement.h" | 18 #include "core/html/HTMLElement.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 static CustomElementDefinition* definitionFor( | 74 static CustomElementDefinition* definitionFor( |
| 73 const Document& document, | 75 const Document& document, |
| 74 const CustomElementDescriptor desc) { | 76 const CustomElementDescriptor desc) { |
| 75 if (CustomElementRegistry* registry = CustomElement::registry(document)) | 77 if (CustomElementRegistry* registry = CustomElement::registry(document)) |
| 76 return registry->definitionFor(desc); | 78 return registry->definitionFor(desc); |
| 77 return nullptr; | 79 return nullptr; |
| 78 } | 80 } |
| 79 | 81 |
| 80 HTMLElement* CustomElement::createCustomElementSync( | 82 HTMLElement* CustomElement::createCustomElementSync( |
| 81 Document& document, | 83 Document& document, |
| 82 const AtomicString& localName) { | 84 const AtomicString& localName, |
| 85 const AtomicString& is) { | |
| 83 return createCustomElementSync( | 86 return createCustomElementSync( |
| 84 document, | 87 document, |
| 85 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI)); | 88 QualifiedName(nullAtom, localName, HTMLNames::xhtmlNamespaceURI), is); |
| 86 } | 89 } |
| 87 | 90 |
| 91 // https://dom.spec.whatwg.org/#concept-create-element | |
| 88 HTMLElement* CustomElement::createCustomElementSync( | 92 HTMLElement* CustomElement::createCustomElementSync( |
| 89 Document& document, | 93 Document& document, |
| 90 const QualifiedName& tagName) { | 94 const QualifiedName& tagName, |
| 91 DCHECK(shouldCreateCustomElement(tagName)); | 95 const AtomicString& is) { |
| 92 if (CustomElementDefinition* definition = definitionFor( | 96 const AtomicString& name = is.isNull() ? tagName.localName() : is; |
| 93 document, | 97 DCHECK(shouldCreateCustomElement(name)); |
|
dominicc (has gone to gerrit)
2016/11/08 08:36:29
Could you do a debug build and try something like
| |
| 94 CustomElementDescriptor(tagName.localName(), tagName.localName()))) | 98 const CustomElementDescriptor desc(name, tagName.localName()); |
| 95 return definition->createElementSync(document, tagName); | 99 CustomElementDefinition* definition = definitionFor(document, desc); |
| 96 return createUndefinedElement(document, tagName); | 100 HTMLElement* element; |
| 101 | |
| 102 if (definition && desc.isAutonomous()) { | |
| 103 // 6. If definition is non-null and we have an autonomous custom element | |
| 104 element = definition->createElementSync(document, tagName); | |
| 105 } else if (definition) { | |
| 106 // 5. If definition is non-null and we have a customized built-in element | |
| 107 element = createUndefinedElement(document, tagName); | |
| 108 definition->upgrade(element); | |
| 109 } else { | |
| 110 // 7. Otherwise | |
| 111 element = createUndefinedElement(document, tagName); | |
| 112 } | |
| 113 return element; | |
| 97 } | 114 } |
| 98 | 115 |
| 99 HTMLElement* CustomElement::createCustomElementAsync( | 116 HTMLElement* CustomElement::createCustomElementAsync( |
| 100 Document& document, | 117 Document& document, |
| 101 const QualifiedName& tagName) { | 118 const QualifiedName& tagName) { |
| 102 DCHECK(shouldCreateCustomElement(tagName)); | 119 DCHECK(shouldCreateCustomElement(tagName)); |
| 103 | 120 |
| 104 // To create an element: | 121 // To create an element: |
| 105 // https://dom.spec.whatwg.org/#concept-create-element | 122 // https://dom.spec.whatwg.org/#concept-create-element |
| 106 // 6. If definition is non-null, then: | 123 // 6. If definition is non-null, then: |
| 107 // 6.2. If the synchronous custom elements flag is not set: | 124 // 6.2. If the synchronous custom elements flag is not set: |
| 108 if (CustomElementDefinition* definition = definitionFor( | 125 if (CustomElementDefinition* definition = definitionFor( |
| 109 document, | 126 document, |
| 110 CustomElementDescriptor(tagName.localName(), tagName.localName()))) | 127 CustomElementDescriptor(tagName.localName(), tagName.localName()))) |
| 111 return definition->createElementAsync(document, tagName); | 128 return definition->createElementAsync(document, tagName); |
| 112 | 129 |
| 113 return createUndefinedElement(document, tagName); | 130 return createUndefinedElement(document, tagName); |
| 114 } | 131 } |
| 115 | 132 |
| 133 // Create a HTMLElement | |
| 116 HTMLElement* CustomElement::createUndefinedElement( | 134 HTMLElement* CustomElement::createUndefinedElement( |
| 117 Document& document, | 135 Document& document, |
| 118 const QualifiedName& tagName) { | 136 const QualifiedName& tagName) { |
| 119 DCHECK(shouldCreateCustomElement(tagName)); | 137 bool shouldCreateBuiltin = |
| 138 htmlElementTypeForTag(tagName.localName()) != | |
| 139 HTMLElementType::kHTMLUnknownElement && | |
| 140 RuntimeEnabledFeatures::customElementsBuiltinEnabled(); | |
| 141 DCHECK(shouldCreateCustomElement(tagName) || shouldCreateBuiltin); | |
| 120 | 142 |
| 121 HTMLElement* element; | 143 HTMLElement* element; |
| 122 if (V0CustomElement::isValidName(tagName.localName()) && | 144 if (V0CustomElement::isValidName(tagName.localName()) && |
| 123 document.registrationContext()) { | 145 document.registrationContext()) { |
| 124 Element* v0element = document.registrationContext()->createCustomTagElement( | 146 Element* v0element = document.registrationContext()->createCustomTagElement( |
| 125 document, tagName); | 147 document, tagName); |
| 126 SECURITY_DCHECK(v0element->isHTMLElement()); | 148 SECURITY_DCHECK(v0element->isHTMLElement()); |
| 127 element = toHTMLElement(v0element); | 149 element = toHTMLElement(v0element); |
| 150 } else if (shouldCreateBuiltin) { | |
| 151 element = HTMLElementFactory::createHTMLElement( | |
| 152 tagName.localName(), document, nullptr, CreatedByCreateElement); | |
| 128 } else { | 153 } else { |
| 129 element = HTMLElement::create(tagName, document); | 154 element = HTMLElement::create(tagName, document); |
| 130 } | 155 } |
| 131 | 156 |
| 132 element->setCustomElementState(CustomElementState::Undefined); | 157 element->setCustomElementState(CustomElementState::Undefined); |
| 133 | 158 |
| 134 return element; | 159 return element; |
| 135 } | 160 } |
| 136 | 161 |
| 137 HTMLElement* CustomElement::createFailedElement(Document& document, | 162 HTMLElement* CustomElement::createFailedElement(Document& document, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 if (!registry) | 238 if (!registry) |
| 214 return; | 239 return; |
| 215 if (CustomElementDefinition* definition = registry->definitionFor( | 240 if (CustomElementDefinition* definition = registry->definitionFor( |
| 216 CustomElementDescriptor(element->localName(), element->localName()))) | 241 CustomElementDescriptor(element->localName(), element->localName()))) |
| 217 definition->enqueueUpgradeReaction(element); | 242 definition->enqueueUpgradeReaction(element); |
| 218 else | 243 else |
| 219 registry->addCandidate(element); | 244 registry->addCandidate(element); |
| 220 } | 245 } |
| 221 | 246 |
| 222 } // namespace blink | 247 } // namespace blink |
| OLD | NEW |