| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 reservedNames.append(SVGNames::font_face_nameTag.localName()); | 92 reservedNames.append(SVGNames::font_face_nameTag.localName()); |
| 93 reservedNames.append(SVGNames::missing_glyphTag.localName()); | 93 reservedNames.append(SVGNames::missing_glyphTag.localName()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 if (notFound != reservedNames.find(name)) | 96 if (notFound != reservedNames.find(name)) |
| 97 return false; | 97 return false; |
| 98 | 98 |
| 99 return Document::isValidName(name.string()); | 99 return Document::isValidName(name.string()); |
| 100 } | 100 } |
| 101 | 101 |
| 102 PassRefPtr<CustomElementConstructor> CustomElementRegistry::registerElement(Scri
ptState* state, const AtomicString& userSuppliedName, const Dictionary& options,
ExceptionCode& ec) | 102 ScriptValue CustomElementRegistry::registerElement(ScriptState* state, const Ato
micString& userSuppliedName, const Dictionary& options, ExceptionCode& ec) |
| 103 { | 103 { |
| 104 RefPtr<CustomElementRegistry> protect(this); | 104 RefPtr<CustomElementRegistry> protect(this); |
| 105 | 105 |
| 106 if (!CustomElementHelpers::isFeatureAllowed(state)) | 106 if (!CustomElementHelpers::isFeatureAllowed(state)) |
| 107 return 0; | 107 return ScriptValue(); |
| 108 | 108 |
| 109 AtomicString name = userSuppliedName.lower(); | 109 AtomicString name = userSuppliedName.lower(); |
| 110 if (!isValidName(name)) { | 110 if (!isValidName(name)) { |
| 111 ec = INVALID_CHARACTER_ERR; | 111 ec = INVALID_CHARACTER_ERR; |
| 112 return 0; | 112 return ScriptValue(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 ScriptValue prototypeValue; | 115 ScriptValue prototypeValue; |
| 116 if (!options.get("prototype", prototypeValue)) { | 116 if (!options.get("prototype", prototypeValue)) { |
| 117 // FIXME: Implement the default value handling. | 117 // FIXME: Implement the default value handling. |
| 118 // Currently default value of the "prototype" parameter, which | 118 // Currently default value of the "prototype" parameter, which |
| 119 // is HTMLSpanElement.prototype, has an ambiguity about its | 119 // is HTMLSpanElement.prototype, has an ambiguity about its |
| 120 // behavior. The spec should be fixed before WebKit implements | 120 // behavior. The spec should be fixed before WebKit implements |
| 121 // it. https://www.w3.org/Bugs/Public/show_bug.cgi?id=20801 | 121 // it. https://www.w3.org/Bugs/Public/show_bug.cgi?id=20801 |
| 122 ec = INVALID_STATE_ERR; | 122 ec = INVALID_STATE_ERR; |
| 123 return 0; | 123 return ScriptValue(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 AtomicString namespaceURI; | 126 AtomicString namespaceURI; |
| 127 if (!CustomElementHelpers::isValidPrototypeParameter(prototypeValue, state,
namespaceURI)) { | 127 if (!CustomElementHelpers::isValidPrototypeParameter(prototypeValue, state,
namespaceURI)) { |
| 128 ec = INVALID_STATE_ERR; | 128 ec = INVALID_STATE_ERR; |
| 129 return 0; | 129 return ScriptValue(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 if (namespaceURI.isNull()) { | 132 if (namespaceURI.isNull()) { |
| 133 ec = NAMESPACE_ERR; | 133 ec = NAMESPACE_ERR; |
| 134 return 0; | 134 return ScriptValue(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 AtomicString type = name; | 137 AtomicString type = name; |
| 138 if (m_definitions.contains(type)) { | 138 if (m_definitions.contains(type)) { |
| 139 ec = INVALID_STATE_ERR; | 139 ec = INVALID_STATE_ERR; |
| 140 return 0; | 140 return ScriptValue(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 const QualifiedName* prototypeTagName = CustomElementHelpers::findLocalName(
prototypeValue); | 143 const QualifiedName* prototypeTagName = CustomElementHelpers::findLocalName(
prototypeValue); |
| 144 if (prototypeTagName) | 144 if (prototypeTagName) |
| 145 name = prototypeTagName->localName(); | 145 name = prototypeTagName->localName(); |
| 146 | 146 |
| 147 // A script execution could happen in isValidPrototypeParameter(), which kil
ls the document. | 147 // A script execution could happen in isValidPrototypeParameter(), which kil
ls the document. |
| 148 if (!document()) { | 148 if (!document()) { |
| 149 ec = INVALID_STATE_ERR; | 149 ec = INVALID_STATE_ERR; |
| 150 return 0; | 150 return ScriptValue(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 ASSERT(name == type || QualifiedName(nullAtom, name, namespaceURI) == *Custo
mElementHelpers::findLocalName(prototypeValue)); | 153 ASSERT(name == type || QualifiedName(nullAtom, name, namespaceURI) == *Custo
mElementHelpers::findLocalName(prototypeValue)); |
| 154 ASSERT(namespaceURI == HTMLNames::xhtmlNamespaceURI || namespaceURI == SVGNa
mes::svgNamespaceURI); | 154 ASSERT(namespaceURI == HTMLNames::xhtmlNamespaceURI || namespaceURI == SVGNa
mes::svgNamespaceURI); |
| 155 | 155 |
| 156 RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create
(type, name, namespaceURI); | 156 RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create
(type, name, namespaceURI); |
| 157 RefPtr<CustomElementConstructor> constructor = CustomElementConstructor::cre
ate(document(), definition->tagQName(), definition->isTypeExtension() ? definiti
on->type() : nullAtom); | 157 ScriptValue constructor = CustomElementHelpers::createConstructor(state, pro
totypeValue, document(), definition->namespaceURI(), definition->name(), definit
ion->isTypeExtension() ? definition->type() : nullAtom); |
| 158 if (!CustomElementHelpers::initializeConstructorWrapper(constructor.get(), p
rototypeValue, state)) { | 158 if (constructor.hasNoValue()) { |
| 159 ec = INVALID_STATE_ERR; | 159 ec = INVALID_STATE_ERR; |
| 160 return 0; | 160 return ScriptValue(); |
| 161 } | 161 } |
| 162 ASSERT(constructor.isFunction()); |
| 162 | 163 |
| 163 m_definitions.add(definition->type(), definition); | 164 m_definitions.add(definition->type(), definition); |
| 164 | 165 |
| 165 // Upgrade elements that were waiting for this definition. | 166 // Upgrade elements that were waiting for this definition. |
| 166 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate
s.takeUpgradeCandidatesFor(definition.get()); | 167 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate
s.takeUpgradeCandidatesFor(definition.get()); |
| 167 CustomElementHelpers::didRegisterDefinition(definition.get(), document(), up
gradeCandidates, prototypeValue); | 168 CustomElementHelpers::didRegisterDefinition(definition.get(), document(), up
gradeCandidates, prototypeValue); |
| 168 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand
idates.begin(); it != upgradeCandidates.end(); ++it) { | 169 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand
idates.begin(); it != upgradeCandidates.end(); ++it) { |
| 169 (*it)->setNeedsStyleRecalc(); // :unresolved has changed | 170 (*it)->setNeedsStyleRecalc(); // :unresolved has changed |
| 170 activate(CustomElementInvocation(*it)); | 171 activate(CustomElementInvocation(*it)); |
| 171 } | 172 } |
| 172 | 173 |
| 173 return constructor.release(); | 174 return constructor; |
| 174 } | 175 } |
| 175 | 176 |
| 176 bool CustomElementRegistry::isUnresolved(Element* element) const | 177 bool CustomElementRegistry::isUnresolved(Element* element) const |
| 177 { | 178 { |
| 178 return m_candidates.contains(element); | 179 return m_candidates.contains(element); |
| 179 } | 180 } |
| 180 | 181 |
| 181 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem
ent) const | 182 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem
ent) const |
| 182 { | 183 { |
| 183 ASSERT(element->document()->registry() == this); | 184 ASSERT(element->document()->registry() == this); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 while (!activeCustomElementRegistries().isEmpty()) { | 314 while (!activeCustomElementRegistries().isEmpty()) { |
| 314 Vector<RefPtr<CustomElementRegistry> > registries; | 315 Vector<RefPtr<CustomElementRegistry> > registries; |
| 315 copyToVector(activeCustomElementRegistries(), registries); | 316 copyToVector(activeCustomElementRegistries(), registries); |
| 316 activeCustomElementRegistries().clear(); | 317 activeCustomElementRegistries().clear(); |
| 317 for (size_t i = 0; i < registries.size(); ++i) | 318 for (size_t i = 0; i < registries.size(); ++i) |
| 318 registries[i]->deliverLifecycleCallbacks(); | 319 registries[i]->deliverLifecycleCallbacks(); |
| 319 } | 320 } |
| 320 } | 321 } |
| 321 | 322 |
| 322 } | 323 } |
| OLD | NEW |