| 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 "config.h" |  | 
| 32 #include "core/dom/CustomElementRegistry.h" |  | 
| 33 |  | 
| 34 #include "HTMLNames.h" |  | 
| 35 #include "SVGNames.h" |  | 
| 36 #include "bindings/v8/CustomElementConstructorBuilder.h" |  | 
| 37 #include "core/dom/CustomElement.h" |  | 
| 38 #include "core/dom/CustomElementDefinition.h" |  | 
| 39 #include "core/dom/CustomElementException.h" |  | 
| 40 #include "core/dom/CustomElementRegistrationContext.h" |  | 
| 41 #include "core/dom/DocumentLifecycleObserver.h" |  | 
| 42 |  | 
| 43 namespace WebCore { |  | 
| 44 |  | 
| 45 class RegistrationContextObserver : public DocumentLifecycleObserver { |  | 
| 46 public: |  | 
| 47     explicit RegistrationContextObserver(Document* document) |  | 
| 48         : DocumentLifecycleObserver(document) |  | 
| 49         , m_wentAway(!document) |  | 
| 50     { |  | 
| 51     } |  | 
| 52 |  | 
| 53     bool registrationContextWentAway() { return m_wentAway; } |  | 
| 54 |  | 
| 55 private: |  | 
| 56     virtual void documentWasDisposed() OVERRIDE { m_wentAway = true; } |  | 
| 57 |  | 
| 58     bool m_wentAway; |  | 
| 59 }; |  | 
| 60 |  | 
| 61 CustomElementDefinition* CustomElementRegistry::registerElement(Document* docume
     nt, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& use
     rSuppliedName, CustomElement::NameSet validNames, ExceptionState& es) |  | 
| 62 { |  | 
| 63     // FIXME: In every instance except one it is the |  | 
| 64     // CustomElementConstructorBuilder that observes document |  | 
| 65     // destruction during registration. This responsibility should be |  | 
| 66     // consolidated in one place. |  | 
| 67     RegistrationContextObserver observer(document); |  | 
| 68 |  | 
| 69     AtomicString type = userSuppliedName.lower(); |  | 
| 70 |  | 
| 71     if (!constructorBuilder->isFeatureAllowed()) { |  | 
| 72         CustomElementException::throwException(CustomElementException::CannotReg
     isterFromExtension, type, es); |  | 
| 73         return 0; |  | 
| 74     } |  | 
| 75 |  | 
| 76     if (!CustomElement::isValidName(type, validNames)) { |  | 
| 77         CustomElementException::throwException(CustomElementException::InvalidNa
     me, type, es); |  | 
| 78         return 0; |  | 
| 79     } |  | 
| 80 |  | 
| 81     QualifiedName tagName = nullQName(); |  | 
| 82     if (!constructorBuilder->validateOptions(type, tagName, es)) |  | 
| 83         return 0; |  | 
| 84 |  | 
| 85     ASSERT(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
     espaceURI() == SVGNames::svgNamespaceURI); |  | 
| 86 |  | 
| 87     // FIXME: This should be done earlier in validateOptions. |  | 
| 88     if (m_registeredTypeNames.contains(type)) { |  | 
| 89         CustomElementException::throwException(CustomElementException::TypeAlrea
     dyRegistered, type, es); |  | 
| 90         return 0; |  | 
| 91     } |  | 
| 92 |  | 
| 93     ASSERT(!observer.registrationContextWentAway()); |  | 
| 94 |  | 
| 95     RefPtr<CustomElementLifecycleCallbacks> lifecycleCallbacks = constructorBuil
     der->createCallbacks(); |  | 
| 96 |  | 
| 97     // Consulting the constructor builder could execute script and |  | 
| 98     // kill the document. |  | 
| 99     if (observer.registrationContextWentAway()) { |  | 
| 100         CustomElementException::throwException(CustomElementException::ContextDe
     stroyedCreatingCallbacks, type, es); |  | 
| 101         return 0; |  | 
| 102     } |  | 
| 103 |  | 
| 104     const CustomElementDescriptor descriptor(type, tagName.namespaceURI(), tagNa
     me.localName()); |  | 
| 105     RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create
     (descriptor, lifecycleCallbacks); |  | 
| 106 |  | 
| 107     if (!constructorBuilder->createConstructor(document, definition.get(), es)) |  | 
| 108         return 0; |  | 
| 109 |  | 
| 110     m_definitions.add(descriptor, definition); |  | 
| 111     m_registeredTypeNames.add(descriptor.type()); |  | 
| 112 |  | 
| 113     if (!constructorBuilder->didRegisterDefinition(definition.get())) { |  | 
| 114         CustomElementException::throwException(CustomElementException::ContextDe
     stroyedRegisteringDefinition, type, es); |  | 
| 115         return 0; |  | 
| 116     } |  | 
| 117 |  | 
| 118     return definition.get(); |  | 
| 119 } |  | 
| 120 |  | 
| 121 CustomElementDefinition* CustomElementRegistry::find(const CustomElementDescript
     or& descriptor) const |  | 
| 122 { |  | 
| 123     return m_definitions.get(descriptor); |  | 
| 124 } |  | 
| 125 |  | 
| 126 } // namespace WebCore |  | 
| OLD | NEW | 
|---|