| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/dom/custom/CustomElementRegistrationContext.h" | 31 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionState.h" | 33 #include "bindings/core/v8/ExceptionState.h" |
| 34 #include "core/HTMLNames.h" | 34 #include "core/HTMLNames.h" |
| 35 #include "core/SVGNames.h" | 35 #include "core/SVGNames.h" |
| 36 #include "core/dom/Document.h" | 36 #include "core/dom/Document.h" |
| 37 #include "core/dom/Element.h" | 37 #include "core/dom/Element.h" |
| 38 #include "core/dom/custom/CustomElement.h" | 38 #include "core/dom/custom/V0CustomElement.h" |
| 39 #include "core/dom/custom/CustomElementDefinition.h" | 39 #include "core/dom/custom/V0CustomElementDefinition.h" |
| 40 #include "core/dom/custom/CustomElementScheduler.h" | 40 #include "core/dom/custom/V0CustomElementScheduler.h" |
| 41 #include "core/html/HTMLElement.h" | 41 #include "core/html/HTMLElement.h" |
| 42 #include "core/html/HTMLUnknownElement.h" | 42 #include "core/html/HTMLUnknownElement.h" |
| 43 #include "core/svg/SVGUnknownElement.h" | 43 #include "core/svg/SVGUnknownElement.h" |
| 44 | 44 |
| 45 namespace blink { | 45 namespace blink { |
| 46 | 46 |
| 47 CustomElementRegistrationContext::CustomElementRegistrationContext() | 47 V0CustomElementRegistrationContext::V0CustomElementRegistrationContext() |
| 48 : m_candidates(CustomElementUpgradeCandidateMap::create()) | 48 : m_candidates(V0CustomElementUpgradeCandidateMap::create()) |
| 49 { | 49 { |
| 50 } | 50 } |
| 51 | 51 |
| 52 void CustomElementRegistrationContext::registerElement(Document* document, Custo
mElementConstructorBuilder* constructorBuilder, const AtomicString& type, Custom
Element::NameSet validNames, ExceptionState& exceptionState) | 52 void V0CustomElementRegistrationContext::registerElement(Document* document, V0C
ustomElementConstructorBuilder* constructorBuilder, const AtomicString& type, V0
CustomElement::NameSet validNames, ExceptionState& exceptionState) |
| 53 { | 53 { |
| 54 CustomElementDefinition* definition = m_registry.registerElement(document, c
onstructorBuilder, type, validNames, exceptionState); | 54 V0CustomElementDefinition* definition = m_registry.registerElement(document,
constructorBuilder, type, validNames, exceptionState); |
| 55 | 55 |
| 56 if (!definition) | 56 if (!definition) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 // Upgrade elements that were waiting for this definition. | 59 // Upgrade elements that were waiting for this definition. |
| 60 CustomElementUpgradeCandidateMap::ElementSet* upgradeCandidates = m_candidat
es->takeUpgradeCandidatesFor(definition->descriptor()); | 60 V0CustomElementUpgradeCandidateMap::ElementSet* upgradeCandidates = m_candid
ates->takeUpgradeCandidatesFor(definition->descriptor()); |
| 61 | 61 |
| 62 if (!upgradeCandidates) | 62 if (!upgradeCandidates) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 for (const auto& candidate : *upgradeCandidates) | 65 for (const auto& candidate : *upgradeCandidates) |
| 66 CustomElement::define(candidate, definition); | 66 V0CustomElement::define(candidate, definition); |
| 67 } | 67 } |
| 68 | 68 |
| 69 Element* CustomElementRegistrationContext::createCustomTagElement(Document& docu
ment, const QualifiedName& tagName) | 69 Element* V0CustomElementRegistrationContext::createCustomTagElement(Document& do
cument, const QualifiedName& tagName) |
| 70 { | 70 { |
| 71 DCHECK(CustomElement::isValidName(tagName.localName())); | 71 DCHECK(V0CustomElement::isValidName(tagName.localName())); |
| 72 | 72 |
| 73 Element* element; | 73 Element* element; |
| 74 | 74 |
| 75 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { | 75 if (HTMLNames::xhtmlNamespaceURI == tagName.namespaceURI()) { |
| 76 element = HTMLElement::create(tagName, document); | 76 element = HTMLElement::create(tagName, document); |
| 77 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { | 77 } else if (SVGNames::svgNamespaceURI == tagName.namespaceURI()) { |
| 78 element = SVGUnknownElement::create(tagName, document); | 78 element = SVGUnknownElement::create(tagName, document); |
| 79 } else { | 79 } else { |
| 80 // XML elements are not custom elements, so return early. | 80 // XML elements are not custom elements, so return early. |
| 81 return Element::create(tagName, &document); | 81 return Element::create(tagName, &document); |
| 82 } | 82 } |
| 83 | 83 |
| 84 element->setCustomElementState(Element::WaitingForUpgrade); | 84 element->setCustomElementState(Element::WaitingForUpgrade); |
| 85 resolveOrScheduleResolution(element, nullAtom); | 85 resolveOrScheduleResolution(element, nullAtom); |
| 86 return element; | 86 return element; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void CustomElementRegistrationContext::didGiveTypeExtension(Element* element, co
nst AtomicString& type) | 89 void V0CustomElementRegistrationContext::didGiveTypeExtension(Element* element,
const AtomicString& type) |
| 90 { | 90 { |
| 91 resolveOrScheduleResolution(element, type); | 91 resolveOrScheduleResolution(element, type); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void CustomElementRegistrationContext::resolveOrScheduleResolution(Element* elem
ent, const AtomicString& typeExtension) | 94 void V0CustomElementRegistrationContext::resolveOrScheduleResolution(Element* el
ement, const AtomicString& typeExtension) |
| 95 { | 95 { |
| 96 // If an element has a custom tag name it takes precedence over | 96 // If an element has a custom tag name it takes precedence over |
| 97 // the "is" attribute (if any). | 97 // the "is" attribute (if any). |
| 98 const AtomicString& type = CustomElement::isValidName(element->localName()) | 98 const AtomicString& type = V0CustomElement::isValidName(element->localName()
) |
| 99 ? element->localName() | 99 ? element->localName() |
| 100 : typeExtension; | 100 : typeExtension; |
| 101 DCHECK(!type.isNull()); | 101 DCHECK(!type.isNull()); |
| 102 | 102 |
| 103 CustomElementDescriptor descriptor(type, element->namespaceURI(), element->l
ocalName()); | 103 V0CustomElementDescriptor descriptor(type, element->namespaceURI(), element-
>localName()); |
| 104 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); | 104 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); |
| 105 | 105 |
| 106 CustomElementScheduler::resolveOrScheduleResolution(this, element, descripto
r); | 106 V0CustomElementScheduler::resolveOrScheduleResolution(this, element, descrip
tor); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void CustomElementRegistrationContext::resolve(Element* element, const CustomEle
mentDescriptor& descriptor) | 109 void V0CustomElementRegistrationContext::resolve(Element* element, const V0Custo
mElementDescriptor& descriptor) |
| 110 { | 110 { |
| 111 CustomElementDefinition* definition = m_registry.find(descriptor); | 111 V0CustomElementDefinition* definition = m_registry.find(descriptor); |
| 112 if (definition) { | 112 if (definition) { |
| 113 CustomElement::define(element, definition); | 113 V0CustomElement::define(element, definition); |
| 114 } else { | 114 } else { |
| 115 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); | 115 DCHECK_EQ(element->getCustomElementState(), Element::WaitingForUpgrade); |
| 116 m_candidates->add(descriptor, element); | 116 m_candidates->add(descriptor, element); |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 void CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element* e
lement, const AtomicString& type) | 120 void V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(Element*
element, const AtomicString& type) |
| 121 { | 121 { |
| 122 DCHECK(element); | 122 DCHECK(element); |
| 123 DCHECK(!type.isEmpty()); | 123 DCHECK(!type.isEmpty()); |
| 124 element->setAttribute(HTMLNames::isAttr, type); | 124 element->setAttribute(HTMLNames::isAttr, type); |
| 125 setTypeExtension(element, type); | 125 setTypeExtension(element, type); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void CustomElementRegistrationContext::setTypeExtension(Element* element, const
AtomicString& type) | 128 void V0CustomElementRegistrationContext::setTypeExtension(Element* element, cons
t AtomicString& type) |
| 129 { | 129 { |
| 130 if (!element->isHTMLElement() && !element->isSVGElement()) | 130 if (!element->isHTMLElement() && !element->isSVGElement()) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 CustomElementRegistrationContext* context = element->document().registration
Context(); | 133 V0CustomElementRegistrationContext* context = element->document().registrati
onContext(); |
| 134 if (!context) | 134 if (!context) |
| 135 return; | 135 return; |
| 136 | 136 |
| 137 if (element->isCustomElement()) { | 137 if (element->isCustomElement()) { |
| 138 // This can happen if: | 138 // This can happen if: |
| 139 // 1. The element has a custom tag, which takes precedence over | 139 // 1. The element has a custom tag, which takes precedence over |
| 140 // type extensions. | 140 // type extensions. |
| 141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an | 141 // 2. Undoing a command (eg ReplaceNodeWithSpan) recycles an |
| 142 // element but tries to overwrite its attribute list. | 142 // element but tries to overwrite its attribute list. |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Custom tags take precedence over type extensions | 146 // Custom tags take precedence over type extensions |
| 147 DCHECK(!CustomElement::isValidName(element->localName())); | 147 DCHECK(!V0CustomElement::isValidName(element->localName())); |
| 148 | 148 |
| 149 if (!CustomElement::isValidName(type)) | 149 if (!V0CustomElement::isValidName(type)) |
| 150 return; | 150 return; |
| 151 | 151 |
| 152 element->setCustomElementState(Element::WaitingForUpgrade); | 152 element->setCustomElementState(Element::WaitingForUpgrade); |
| 153 context->didGiveTypeExtension(element, element->document().convertLocalName(
type)); | 153 context->didGiveTypeExtension(element, element->document().convertLocalName(
type)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 DEFINE_TRACE(CustomElementRegistrationContext) | 156 DEFINE_TRACE(V0CustomElementRegistrationContext) |
| 157 { | 157 { |
| 158 visitor->trace(m_candidates); | 158 visitor->trace(m_candidates); |
| 159 visitor->trace(m_registry); | 159 visitor->trace(m_registry); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |