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 12 matching lines...) Expand all Loading... |
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/V0CustomElementRegistry.h" | 31 #include "core/dom/custom/V0CustomElementRegistry.h" |
32 | 32 |
| 33 #include "bindings/core/v8/ScriptState.h" |
33 #include "bindings/core/v8/V0CustomElementConstructorBuilder.h" | 34 #include "bindings/core/v8/V0CustomElementConstructorBuilder.h" |
| 35 #include "bindings/core/v8/V8Binding.h" |
34 #include "core/HTMLNames.h" | 36 #include "core/HTMLNames.h" |
35 #include "core/SVGNames.h" | 37 #include "core/SVGNames.h" |
| 38 #include "core/dom/Document.h" |
| 39 #include "core/dom/custom/CustomElementsRegistry.h" |
36 #include "core/dom/custom/V0CustomElementException.h" | 40 #include "core/dom/custom/V0CustomElementException.h" |
37 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 41 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
| 42 #include "core/frame/LocalDOMWindow.h" |
38 | 43 |
39 namespace blink { | 44 namespace blink { |
40 | 45 |
41 V0CustomElementDefinition* V0CustomElementRegistry::registerElement(Document* do
cument, V0CustomElementConstructorBuilder* constructorBuilder, const AtomicStrin
g& userSuppliedName, V0CustomElement::NameSet validNames, ExceptionState& except
ionState) | 46 static bool v1CustomElementIsDefined(ScriptState* scriptState, const AtomicStrin
g& name) |
| 47 { |
| 48 CustomElementsRegistry* registry = |
| 49 scriptState->domWindow()->customElements(scriptState); |
| 50 return registry && registry->nameIsDefined(name); |
| 51 } |
| 52 |
| 53 bool V0CustomElementRegistry::nameIsDefined(const AtomicString& name) const |
| 54 { |
| 55 return m_registeredTypeNames.contains(name); |
| 56 } |
| 57 |
| 58 V0CustomElementDefinition* V0CustomElementRegistry::registerElement(ScriptState*
scriptState, Document* document, V0CustomElementConstructorBuilder* constructor
Builder, const AtomicString& userSuppliedName, V0CustomElement::NameSet validNam
es, ExceptionState& exceptionState) |
42 { | 59 { |
43 AtomicString type = userSuppliedName.lower(); | 60 AtomicString type = userSuppliedName.lower(); |
44 | 61 |
45 if (!constructorBuilder->isFeatureAllowed()) { | 62 if (!constructorBuilder->isFeatureAllowed()) { |
46 V0CustomElementException::throwException(V0CustomElementException::Canno
tRegisterFromExtension, type, exceptionState); | 63 V0CustomElementException::throwException(V0CustomElementException::Canno
tRegisterFromExtension, type, exceptionState); |
47 return 0; | 64 return 0; |
48 } | 65 } |
49 | 66 |
50 if (!V0CustomElement::isValidName(type, validNames)) { | 67 if (!V0CustomElement::isValidName(type, validNames)) { |
51 V0CustomElementException::throwException(V0CustomElementException::Inval
idName, type, exceptionState); | 68 V0CustomElementException::throwException(V0CustomElementException::Inval
idName, type, exceptionState); |
52 return 0; | 69 return 0; |
53 } | 70 } |
54 | 71 |
55 if (m_registeredTypeNames.contains(type)) { | 72 if (m_registeredTypeNames.contains(type) || v1CustomElementIsDefined(scriptS
tate, type)) { |
56 V0CustomElementException::throwException(V0CustomElementException::TypeA
lreadyRegistered, type, exceptionState); | 73 V0CustomElementException::throwException(V0CustomElementException::TypeA
lreadyRegistered, type, exceptionState); |
57 return 0; | 74 return 0; |
58 } | 75 } |
59 | 76 |
60 QualifiedName tagName = QualifiedName::null(); | 77 QualifiedName tagName = QualifiedName::null(); |
61 if (!constructorBuilder->validateOptions(type, tagName, exceptionState)) | 78 if (!constructorBuilder->validateOptions(type, tagName, exceptionState)) |
62 return 0; | 79 return 0; |
63 | 80 |
64 DCHECK(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
espaceURI() == SVGNames::svgNamespaceURI); | 81 DCHECK(tagName.namespaceURI() == HTMLNames::xhtmlNamespaceURI || tagName.nam
espaceURI() == SVGNames::svgNamespaceURI); |
65 | 82 |
(...skipping 29 matching lines...) Expand all Loading... |
95 { | 112 { |
96 return m_definitions.get(descriptor); | 113 return m_definitions.get(descriptor); |
97 } | 114 } |
98 | 115 |
99 DEFINE_TRACE(V0CustomElementRegistry) | 116 DEFINE_TRACE(V0CustomElementRegistry) |
100 { | 117 { |
101 visitor->trace(m_definitions); | 118 visitor->trace(m_definitions); |
102 } | 119 } |
103 | 120 |
104 } // namespace blink | 121 } // namespace blink |
OLD | NEW |