| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2013 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 "core/dom/custom/CustomElement.h" | |
| 32 | |
| 33 #include "core/HTMLNames.h" | |
| 34 #include "core/MathMLNames.h" | |
| 35 #include "core/SVGNames.h" | |
| 36 #include "core/dom/Document.h" | |
| 37 #include "core/dom/Element.h" | |
| 38 #include "core/dom/custom/CustomElementMicrotaskRunQueue.h" | |
| 39 #include "core/dom/custom/CustomElementObserver.h" | |
| 40 #include "core/dom/custom/CustomElementScheduler.h" | |
| 41 | |
| 42 namespace blink { | |
| 43 | |
| 44 CustomElementMicrotaskImportStep* CustomElement::didCreateImport(HTMLImportChild
* import) | |
| 45 { | |
| 46 return CustomElementScheduler::scheduleImport(import); | |
| 47 } | |
| 48 | |
| 49 void CustomElement::didFinishLoadingImport(Document& master) | |
| 50 { | |
| 51 master.customElementMicrotaskRunQueue()->requestDispatchIfNeeded(); | |
| 52 } | |
| 53 | |
| 54 Vector<AtomicString>& CustomElement::embedderCustomElementNames() | |
| 55 { | |
| 56 DEFINE_STATIC_LOCAL(Vector<AtomicString>, names, ()); | |
| 57 return names; | |
| 58 } | |
| 59 | |
| 60 void CustomElement::addEmbedderCustomElementName(const AtomicString& name) | |
| 61 { | |
| 62 AtomicString lower = name.lower(); | |
| 63 if (isValidName(lower, EmbedderNames)) | |
| 64 return; | |
| 65 embedderCustomElementNames().append(lower); | |
| 66 } | |
| 67 | |
| 68 static inline bool isValidNCName(const AtomicString& name) | |
| 69 { | |
| 70 if (kNotFound != name.find(':')) | |
| 71 return false; | |
| 72 | |
| 73 if (!name.getString().is8Bit()) { | |
| 74 const UChar32 c = name.characters16()[0]; | |
| 75 // These characters comes under CombiningChar in NCName and according to | |
| 76 // NCName only BaseChar and Ideodgraphic can come as first chars. | |
| 77 // Also these characters come under Letter_Other in UnicodeData, thats | |
| 78 // why they pass as valid document name. | |
| 79 if (c == 0x0B83 || c == 0x0F88 || c == 0x0F89 || c == 0x0F8A || c == 0x0
F8B) | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 return Document::isValidName(name.getString()); | |
| 84 } | |
| 85 | |
| 86 bool CustomElement::isValidName(const AtomicString& name, NameSet validNames) | |
| 87 { | |
| 88 if ((validNames & EmbedderNames) && kNotFound != embedderCustomElementNames(
).find(name)) | |
| 89 return Document::isValidName(name); | |
| 90 | |
| 91 if ((validNames & StandardNames) && kNotFound != name.find('-')) { | |
| 92 DEFINE_STATIC_LOCAL(Vector<AtomicString>, reservedNames, ()); | |
| 93 if (reservedNames.isEmpty()) { | |
| 94 // FIXME(crbug.com/426605): We should be able to remove this. | |
| 95 reservedNames.append(MathMLNames::annotation_xmlTag.localName()); | |
| 96 } | |
| 97 | |
| 98 if (kNotFound == reservedNames.find(name)) | |
| 99 return isValidNCName(name); | |
| 100 } | |
| 101 | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 void CustomElement::define(Element* element, CustomElementDefinition* definition
) | |
| 106 { | |
| 107 switch (element->getCustomElementState()) { | |
| 108 case Element::NotCustomElement: | |
| 109 case Element::Upgraded: | |
| 110 ASSERT_NOT_REACHED(); | |
| 111 break; | |
| 112 | |
| 113 case Element::WaitingForUpgrade: | |
| 114 element->setCustomElementDefinition(definition); | |
| 115 CustomElementScheduler::scheduleCallback(definition->callbacks(), elemen
t, CustomElementLifecycleCallbacks::CreatedCallback); | |
| 116 break; | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 void CustomElement::attributeDidChange(Element* element, const AtomicString& nam
e, const AtomicString& oldValue, const AtomicString& newValue) | |
| 121 { | |
| 122 DCHECK_EQ(element->getCustomElementState(), Element::Upgraded); | |
| 123 CustomElementScheduler::scheduleAttributeChangedCallback(element->customElem
entDefinition()->callbacks(), element, name, oldValue, newValue); | |
| 124 } | |
| 125 | |
| 126 void CustomElement::didAttach(Element* element, const Document& document) | |
| 127 { | |
| 128 DCHECK_EQ(element->getCustomElementState(), Element::Upgraded); | |
| 129 if (!document.domWindow()) | |
| 130 return; | |
| 131 CustomElementScheduler::scheduleCallback(element->customElementDefinition()-
>callbacks(), element, CustomElementLifecycleCallbacks::AttachedCallback); | |
| 132 } | |
| 133 | |
| 134 void CustomElement::didDetach(Element* element, const Document& document) | |
| 135 { | |
| 136 DCHECK_EQ(element->getCustomElementState(), Element::Upgraded); | |
| 137 if (!document.domWindow()) | |
| 138 return; | |
| 139 CustomElementScheduler::scheduleCallback(element->customElementDefinition()-
>callbacks(), element, CustomElementLifecycleCallbacks::DetachedCallback); | |
| 140 } | |
| 141 | |
| 142 void CustomElement::wasDestroyed(Element* element) | |
| 143 { | |
| 144 switch (element->getCustomElementState()) { | |
| 145 case Element::NotCustomElement: | |
| 146 ASSERT_NOT_REACHED(); | |
| 147 break; | |
| 148 | |
| 149 case Element::WaitingForUpgrade: | |
| 150 case Element::Upgraded: | |
| 151 CustomElementObserver::notifyElementWasDestroyed(element); | |
| 152 break; | |
| 153 } | |
| 154 } | |
| 155 | |
| 156 } // namespace blink | |
| OLD | NEW |