Chromium Code Reviews| 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 RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create (state, type, name, namespaceURI, prototypeValue); | 153 RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create (state, type, name, namespaceURI, prototypeValue); |
| 154 | 154 |
| 155 RefPtr<CustomElementConstructor> constructor = CustomElementConstructor::cre ate(document(), definition->tagQName(), definition->isTypeExtension() ? definiti on->type() : nullAtom); | 155 ScriptValue constructor = CustomElementHelpers::createConstructor(state, pro totypeValue, document(), definition->namespaceURI(), definition->name(), definit ion->isTypeExtension() ? definition->type() : nullAtom); |
|
Hajime Morrita
2013/06/10 04:32:22
Can this fail? We might need some guard if so.
| |
| 156 if (!CustomElementHelpers::initializeConstructorWrapper(constructor.get(), p rototypeValue, state)) { | |
| 157 ec = INVALID_STATE_ERR; | |
| 158 return 0; | |
| 159 } | |
| 160 | 156 |
| 161 m_definitions.add(definition->type(), definition); | 157 m_definitions.add(definition->type(), definition); |
| 162 | 158 |
| 163 // Upgrade elements that were waiting for this definition. | 159 // Upgrade elements that were waiting for this definition. |
| 164 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate s.takeUpgradeCandidatesFor(definition.get()); | 160 CustomElementUpgradeCandidateMap::ElementSet upgradeCandidates = m_candidate s.takeUpgradeCandidatesFor(definition.get()); |
| 165 CustomElementHelpers::upgradeWrappers(document(), upgradeCandidates, definit ion->prototype()); | 161 CustomElementHelpers::upgradeWrappers(document(), upgradeCandidates, definit ion->prototype()); |
| 166 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand idates.begin(); it != upgradeCandidates.end(); ++it) { | 162 for (CustomElementUpgradeCandidateMap::ElementSet::iterator it = upgradeCand idates.begin(); it != upgradeCandidates.end(); ++it) { |
| 167 (*it)->setNeedsStyleRecalc(); // :unresolved has changed | 163 (*it)->setNeedsStyleRecalc(); // :unresolved has changed |
| 168 activate(CustomElementInvocation(*it)); | 164 activate(CustomElementInvocation(*it)); |
| 169 } | 165 } |
| 170 | 166 |
| 171 return constructor.release(); | 167 return constructor; |
| 172 } | 168 } |
| 173 | 169 |
| 174 bool CustomElementRegistry::isUnresolved(Element* element) const | 170 bool CustomElementRegistry::isUnresolved(Element* element) const |
| 175 { | 171 { |
| 176 return m_candidates.contains(element); | 172 return m_candidates.contains(element); |
| 177 } | 173 } |
| 178 | 174 |
| 179 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const | 175 PassRefPtr<CustomElementDefinition> CustomElementRegistry::findFor(Element* elem ent) const |
| 180 { | 176 { |
| 181 ASSERT(element->document()->registry() == this); | 177 ASSERT(element->document()->registry() == this); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 while (!activeCustomElementRegistries().isEmpty()) { | 307 while (!activeCustomElementRegistries().isEmpty()) { |
| 312 Vector<RefPtr<CustomElementRegistry> > registries; | 308 Vector<RefPtr<CustomElementRegistry> > registries; |
| 313 copyToVector(activeCustomElementRegistries(), registries); | 309 copyToVector(activeCustomElementRegistries(), registries); |
| 314 activeCustomElementRegistries().clear(); | 310 activeCustomElementRegistries().clear(); |
| 315 for (size_t i = 0; i < registries.size(); ++i) | 311 for (size_t i = 0; i < registries.size(); ++i) |
| 316 registries[i]->deliverLifecycleCallbacks(); | 312 registries[i]->deliverLifecycleCallbacks(); |
| 317 } | 313 } |
| 318 } | 314 } |
| 319 | 315 |
| 320 } | 316 } |
| OLD | NEW |