| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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/CustomElementRegistry.h" | 31 #include "core/dom/custom/V0CustomElementRegistry.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/CustomElementConstructorBuilder.h" | 33 #include "bindings/core/v8/V0CustomElementConstructorBuilder.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/DocumentLifecycleObserver.h" | 36 #include "core/dom/DocumentLifecycleObserver.h" |
| 37 #include "core/dom/custom/CustomElementException.h" | 37 #include "core/dom/custom/V0CustomElementException.h" |
| 38 #include "core/dom/custom/CustomElementRegistrationContext.h" | 38 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 CustomElementDefinition* CustomElementRegistry::registerElement(Document* docume
nt, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& use
rSuppliedName, CustomElement::NameSet validNames, ExceptionState& exceptionState
) | 42 V0CustomElementDefinition* V0CustomElementRegistry::registerElement(Document* do
cument, V0CustomElementConstructorBuilder* constructorBuilder, const AtomicStrin
g& userSuppliedName, V0CustomElement::NameSet validNames, ExceptionState& except
ionState) |
| 43 { | 43 { |
| 44 AtomicString type = userSuppliedName.lower(); | 44 AtomicString type = userSuppliedName.lower(); |
| 45 | 45 |
| 46 if (!constructorBuilder->isFeatureAllowed()) { | 46 if (!constructorBuilder->isFeatureAllowed()) { |
| 47 CustomElementException::throwException(CustomElementException::CannotReg
isterFromExtension, type, exceptionState); | 47 V0CustomElementException::throwException(V0CustomElementException::Canno
tRegisterFromExtension, type, exceptionState); |
| 48 return 0; | 48 return 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 if (!CustomElement::isValidName(type, validNames)) { | 51 if (!V0CustomElement::isValidName(type, validNames)) { |
| 52 CustomElementException::throwException(CustomElementException::InvalidNa
me, type, exceptionState); | 52 V0CustomElementException::throwException(V0CustomElementException::Inval
idName, type, exceptionState); |
| 53 return 0; | 53 return 0; |
| 54 } | 54 } |
| 55 | 55 |
| 56 if (m_registeredTypeNames.contains(type)) { | 56 if (m_registeredTypeNames.contains(type)) { |
| 57 CustomElementException::throwException(CustomElementException::TypeAlrea
dyRegistered, type, exceptionState); | 57 V0CustomElementException::throwException(V0CustomElementException::TypeA
lreadyRegistered, type, exceptionState); |
| 58 return 0; | 58 return 0; |
| 59 } | 59 } |
| 60 | 60 |
| 61 QualifiedName tagName = QualifiedName::null(); | 61 QualifiedName tagName = QualifiedName::null(); |
| 62 if (!constructorBuilder->validateOptions(type, tagName, exceptionState)) | 62 if (!constructorBuilder->validateOptions(type, tagName, exceptionState)) |
| 63 return 0; | 63 return 0; |
| 64 | 64 |
| 65 DCHECK(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
espaceURI() == SVGNames::svgNamespaceURI); | 65 DCHECK(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
espaceURI() == SVGNames::svgNamespaceURI); |
| 66 | 66 |
| 67 DCHECK(!m_documentWasDetached); | 67 DCHECK(!m_documentWasDetached); |
| 68 | 68 |
| 69 CustomElementLifecycleCallbacks* lifecycleCallbacks = constructorBuilder->cr
eateCallbacks(); | 69 V0CustomElementLifecycleCallbacks* lifecycleCallbacks = constructorBuilder->
createCallbacks(); |
| 70 | 70 |
| 71 // Consulting the constructor builder could execute script and | 71 // Consulting the constructor builder could execute script and |
| 72 // kill the document. | 72 // kill the document. |
| 73 if (m_documentWasDetached) { | 73 if (m_documentWasDetached) { |
| 74 CustomElementException::throwException(CustomElementException::ContextDe
stroyedCreatingCallbacks, type, exceptionState); | 74 V0CustomElementException::throwException(V0CustomElementException::Conte
xtDestroyedCreatingCallbacks, type, exceptionState); |
| 75 return 0; | 75 return 0; |
| 76 } | 76 } |
| 77 | 77 |
| 78 const CustomElementDescriptor descriptor(type, tagName.namespaceURI(), tagNa
me.localName()); | 78 const V0CustomElementDescriptor descriptor(type, tagName.namespaceURI(), tag
Name.localName()); |
| 79 CustomElementDefinition* definition = CustomElementDefinition::create(descri
ptor, lifecycleCallbacks); | 79 V0CustomElementDefinition* definition = V0CustomElementDefinition::create(de
scriptor, lifecycleCallbacks); |
| 80 | 80 |
| 81 if (!constructorBuilder->createConstructor(document, definition, exceptionSt
ate)) | 81 if (!constructorBuilder->createConstructor(document, definition, exceptionSt
ate)) |
| 82 return 0; | 82 return 0; |
| 83 | 83 |
| 84 m_definitions.add(descriptor, definition); | 84 m_definitions.add(descriptor, definition); |
| 85 m_registeredTypeNames.add(descriptor.type()); | 85 m_registeredTypeNames.add(descriptor.type()); |
| 86 | 86 |
| 87 if (!constructorBuilder->didRegisterDefinition()) { | 87 if (!constructorBuilder->didRegisterDefinition()) { |
| 88 CustomElementException::throwException(CustomElementException::ContextDe
stroyedRegisteringDefinition, type, exceptionState); | 88 V0CustomElementException::throwException(V0CustomElementException::Conte
xtDestroyedRegisteringDefinition, type, exceptionState); |
| 89 return 0; | 89 return 0; |
| 90 } | 90 } |
| 91 | 91 |
| 92 return definition; | 92 return definition; |
| 93 } | 93 } |
| 94 | 94 |
| 95 CustomElementDefinition* CustomElementRegistry::find(const CustomElementDescript
or& descriptor) const | 95 V0CustomElementDefinition* V0CustomElementRegistry::find(const V0CustomElementDe
scriptor& descriptor) const |
| 96 { | 96 { |
| 97 return m_definitions.get(descriptor); | 97 return m_definitions.get(descriptor); |
| 98 } | 98 } |
| 99 | 99 |
| 100 DEFINE_TRACE(CustomElementRegistry) | 100 DEFINE_TRACE(V0CustomElementRegistry) |
| 101 { | 101 { |
| 102 visitor->trace(m_definitions); | 102 visitor->trace(m_definitions); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |