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