2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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
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.
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.
32 #include "core/dom/custom/CustomElement.h"
34 #include "core/HTMLNames.h"
35 #include "core/MathMLNames.h"
36 #include "core/SVGNames.h"
37 #include "core/dom/Document.h"
38 #include "core/dom/Element.h"
39 #include "core/dom/custom/CustomElementMicrotaskRunQueue.h"
40 #include "core/dom/custom/CustomElementObserver.h"
41 #include "core/dom/custom/CustomElementScheduler.h"
45 CustomElementMicrotaskImportStep* CustomElement::didCreateImport(HTMLImportChild* import)
47 return CustomElementScheduler::scheduleImport(import);
50 void CustomElement::didFinishLoadingImport(Document& master)
52 master.customElementMicrotaskRunQueue()->requestDispatchIfNeeded();
55 Vector<AtomicString>& CustomElement::embedderCustomElementNames()
57 DEFINE_STATIC_LOCAL(Vector<AtomicString>, names, ());
61 void CustomElement::addEmbedderCustomElementName(const AtomicString& name)
63 AtomicString lower = name.lower();
64 if (isValidName(lower, EmbedderNames))
66 embedderCustomElementNames().append(lower);
69 bool CustomElement::isValidName(const AtomicString& name, NameSet validNames)
71 if ((validNames & EmbedderNames) && kNotFound != embedderCustomElementNames().find(name))
72 return Document::isValidName(name);
74 if ((validNames & StandardNames) && kNotFound != name.find('-')) {
75 DEFINE_STATIC_LOCAL(Vector<AtomicString>, reservedNames, ());
76 if (reservedNames.isEmpty()) {
77 reservedNames.append(MathMLNames::annotation_xmlTag.localName());
79 reservedNames.append(SVGNames::font_faceTag.localName());
80 reservedNames.append(SVGNames::font_face_srcTag.localName());
81 reservedNames.append(SVGNames::font_face_uriTag.localName());
82 reservedNames.append(SVGNames::font_face_formatTag.localName());
83 reservedNames.append(SVGNames::font_face_nameTag.localName());
84 reservedNames.append(SVGNames::missing_glyphTag.localName());
88 if (kNotFound == reservedNames.find(name))
89 return Document::isValidName(name.string());
95 void CustomElement::define(Element* element, PassRefPtr<CustomElementDefinition> passDefinition)
97 RefPtr<CustomElementDefinition> definition(passDefinition);
99 switch (element->customElementState()) {
100 case Element::NotCustomElement:
101 case Element::Upgraded:
102 ASSERT_NOT_REACHED();
105 case Element::WaitingForUpgrade:
106 element->setCustomElementDefinition(definition);
107 CustomElementScheduler::scheduleCallback(definition->callbacks(), element, CustomElementLifecycleCallbacks::CreatedCallback);
112 void CustomElement::attributeDidChange(Element* element, const AtomicString& name, const AtomicString& oldValue, const AtomicString& newValue)
114 ASSERT(element->customElementState() == Element::Upgraded);
115 CustomElementScheduler::scheduleAttributeChangedCallback(element->customElementDefinition()->callbacks(), element, name, oldValue, newValue);
118 void CustomElement::didAttach(Element* element, const Document& document)
120 ASSERT(element->customElementState() == Element::Upgraded);
121 if (!document.domWindow())
123 CustomElementScheduler::scheduleCallback(element->customElementDefinition()->callbacks(), element, CustomElementLifecycleCallbacks::AttachedCallback);
126 void CustomElement::didDetach(Element* element, const Document& document)
128 ASSERT(element->customElementState() == Element::Upgraded);
129 if (!document.domWindow())
131 CustomElementScheduler::scheduleCallback(element->customElementDefinition()->callbacks(), element, CustomElementLifecycleCallbacks::DetachedCallback);
134 void CustomElement::wasDestroyed(Element* element)
136 switch (element->customElementState()) {
137 case Element::NotCustomElement:
138 ASSERT_NOT_REACHED();
141 case Element::WaitingForUpgrade:
142 case Element::Upgraded:
143 CustomElementObserver::notifyElementWasDestroyed(element);