| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * 3. Neither the name of Google Inc. nor the names of its contributors | |
| 15 * may be used to endorse or promote products derived from this | |
| 16 * software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "core/dom/custom/CustomElementRegistry.h" | |
| 32 | |
| 33 #include "bindings/core/v8/CustomElementConstructorBuilder.h" | |
| 34 #include "core/HTMLNames.h" | |
| 35 #include "core/SVGNames.h" | |
| 36 #include "core/dom/DocumentLifecycleObserver.h" | |
| 37 #include "core/dom/custom/CustomElementException.h" | |
| 38 #include "core/dom/custom/CustomElementRegistrationContext.h" | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 CustomElementDefinition* CustomElementRegistry::registerElement(Document* docume
nt, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& use
rSuppliedName, CustomElement::NameSet validNames, ExceptionState& exceptionState
) | |
| 43 { | |
| 44 AtomicString type = userSuppliedName.lower(); | |
| 45 | |
| 46 if (!constructorBuilder->isFeatureAllowed()) { | |
| 47 CustomElementException::throwException(CustomElementException::CannotReg
isterFromExtension, type, exceptionState); | |
| 48 return 0; | |
| 49 } | |
| 50 | |
| 51 if (!CustomElement::isValidName(type, validNames)) { | |
| 52 CustomElementException::throwException(CustomElementException::InvalidNa
me, type, exceptionState); | |
| 53 return 0; | |
| 54 } | |
| 55 | |
| 56 if (m_registeredTypeNames.contains(type)) { | |
| 57 CustomElementException::throwException(CustomElementException::TypeAlrea
dyRegistered, type, exceptionState); | |
| 58 return 0; | |
| 59 } | |
| 60 | |
| 61 QualifiedName tagName = QualifiedName::null(); | |
| 62 if (!constructorBuilder->validateOptions(type, tagName, exceptionState)) | |
| 63 return 0; | |
| 64 | |
| 65 DCHECK(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
espaceURI() == SVGNames::svgNamespaceURI); | |
| 66 | |
| 67 DCHECK(!m_documentWasDetached); | |
| 68 | |
| 69 CustomElementLifecycleCallbacks* lifecycleCallbacks = constructorBuilder->cr
eateCallbacks(); | |
| 70 | |
| 71 // Consulting the constructor builder could execute script and | |
| 72 // kill the document. | |
| 73 if (m_documentWasDetached) { | |
| 74 CustomElementException::throwException(CustomElementException::ContextDe
stroyedCreatingCallbacks, type, exceptionState); | |
| 75 return 0; | |
| 76 } | |
| 77 | |
| 78 const CustomElementDescriptor descriptor(type, tagName.namespaceURI(), tagNa
me.localName()); | |
| 79 CustomElementDefinition* definition = CustomElementDefinition::create(descri
ptor, lifecycleCallbacks); | |
| 80 | |
| 81 if (!constructorBuilder->createConstructor(document, definition, exceptionSt
ate)) | |
| 82 return 0; | |
| 83 | |
| 84 m_definitions.add(descriptor, definition); | |
| 85 m_registeredTypeNames.add(descriptor.type()); | |
| 86 | |
| 87 if (!constructorBuilder->didRegisterDefinition()) { | |
| 88 CustomElementException::throwException(CustomElementException::ContextDe
stroyedRegisteringDefinition, type, exceptionState); | |
| 89 return 0; | |
| 90 } | |
| 91 | |
| 92 return definition; | |
| 93 } | |
| 94 | |
| 95 CustomElementDefinition* CustomElementRegistry::find(const CustomElementDescript
or& descriptor) const | |
| 96 { | |
| 97 return m_definitions.get(descriptor); | |
| 98 } | |
| 99 | |
| 100 DEFINE_TRACE(CustomElementRegistry) | |
| 101 { | |
| 102 visitor->trace(m_definitions); | |
| 103 } | |
| 104 | |
| 105 } // namespace blink | |
| OLD | NEW |