OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All |
7 * rights reserved. | 7 * rights reserved. |
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. |
9 * (http://www.torchmobile.com/) | 9 * (http://www.torchmobile.com/) |
10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 10 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #include "bindings/core/v8/Microtask.h" | 37 #include "bindings/core/v8/Microtask.h" |
38 #include "bindings/core/v8/ScriptController.h" | 38 #include "bindings/core/v8/ScriptController.h" |
39 #include "bindings/core/v8/SourceLocation.h" | 39 #include "bindings/core/v8/SourceLocation.h" |
40 #include "bindings/core/v8/StringOrDictionary.h" | 40 #include "bindings/core/v8/StringOrDictionary.h" |
41 #include "bindings/core/v8/V0CustomElementConstructorBuilder.h" | 41 #include "bindings/core/v8/V0CustomElementConstructorBuilder.h" |
42 #include "bindings/core/v8/V8DOMWrapper.h" | 42 #include "bindings/core/v8/V8DOMWrapper.h" |
43 #include "bindings/core/v8/V8ElementCreationOptions.h" | 43 #include "bindings/core/v8/V8ElementCreationOptions.h" |
44 #include "bindings/core/v8/V8PerIsolateData.h" | 44 #include "bindings/core/v8/V8PerIsolateData.h" |
45 #include "bindings/core/v8/WindowProxy.h" | 45 #include "bindings/core/v8/WindowProxy.h" |
46 #include "core/HTMLElementFactory.h" | 46 #include "core/HTMLElementFactory.h" |
47 #include "core/HTMLElementTypeHelpers.h" | |
47 #include "core/HTMLNames.h" | 48 #include "core/HTMLNames.h" |
48 #include "core/SVGElementFactory.h" | 49 #include "core/SVGElementFactory.h" |
49 #include "core/SVGNames.h" | 50 #include "core/SVGNames.h" |
50 #include "core/XMLNSNames.h" | 51 #include "core/XMLNSNames.h" |
51 #include "core/XMLNames.h" | 52 #include "core/XMLNames.h" |
52 #include "core/animation/CompositorPendingAnimations.h" | 53 #include "core/animation/CompositorPendingAnimations.h" |
53 #include "core/animation/DocumentAnimations.h" | 54 #include "core/animation/DocumentAnimations.h" |
54 #include "core/animation/DocumentTimeline.h" | 55 #include "core/animation/DocumentTimeline.h" |
55 #include "core/css/CSSFontSelector.h" | 56 #include "core/css/CSSFontSelector.h" |
56 #include "core/css/CSSStyleDeclaration.h" | 57 #include "core/css/CSSStyleDeclaration.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 #include "core/dom/StaticNodeList.h" | 106 #include "core/dom/StaticNodeList.h" |
106 #include "core/dom/StyleChangeReason.h" | 107 #include "core/dom/StyleChangeReason.h" |
107 #include "core/dom/StyleEngine.h" | 108 #include "core/dom/StyleEngine.h" |
108 #include "core/dom/TaskRunnerHelper.h" | 109 #include "core/dom/TaskRunnerHelper.h" |
109 #include "core/dom/TouchList.h" | 110 #include "core/dom/TouchList.h" |
110 #include "core/dom/TransformSource.h" | 111 #include "core/dom/TransformSource.h" |
111 #include "core/dom/TreeWalker.h" | 112 #include "core/dom/TreeWalker.h" |
112 #include "core/dom/VisitedLinkState.h" | 113 #include "core/dom/VisitedLinkState.h" |
113 #include "core/dom/XMLDocument.h" | 114 #include "core/dom/XMLDocument.h" |
114 #include "core/dom/custom/CustomElement.h" | 115 #include "core/dom/custom/CustomElement.h" |
116 #include "core/dom/custom/CustomElementDefinition.h" | |
117 #include "core/dom/custom/CustomElementDescriptor.h" | |
115 #include "core/dom/custom/CustomElementRegistry.h" | 118 #include "core/dom/custom/CustomElementRegistry.h" |
116 #include "core/dom/custom/V0CustomElementMicrotaskRunQueue.h" | 119 #include "core/dom/custom/V0CustomElementMicrotaskRunQueue.h" |
117 #include "core/dom/custom/V0CustomElementRegistrationContext.h" | 120 #include "core/dom/custom/V0CustomElementRegistrationContext.h" |
118 #include "core/dom/shadow/ElementShadow.h" | 121 #include "core/dom/shadow/ElementShadow.h" |
119 #include "core/dom/shadow/FlatTreeTraversal.h" | 122 #include "core/dom/shadow/FlatTreeTraversal.h" |
120 #include "core/dom/shadow/ShadowRoot.h" | 123 #include "core/dom/shadow/ShadowRoot.h" |
121 #include "core/editing/DragCaretController.h" | 124 #include "core/editing/DragCaretController.h" |
122 #include "core/editing/EditingUtilities.h" | 125 #include "core/editing/EditingUtilities.h" |
123 #include "core/editing/Editor.h" | 126 #include "core/editing/Editor.h" |
124 #include "core/editing/FrameSelection.h" | 127 #include "core/editing/FrameSelection.h" |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
702 exceptionState); | 705 exceptionState); |
703 if (impl.hasIs()) | 706 if (impl.hasIs()) |
704 return impl.is(); | 707 return impl.is(); |
705 | 708 |
706 return toCoreString(dict.v8Value()->ToString()); | 709 return toCoreString(dict.v8Value()->ToString()); |
707 } | 710 } |
708 | 711 |
709 return emptyString(); | 712 return emptyString(); |
710 } | 713 } |
711 | 714 |
715 // https://dom.spec.whatwg.org/#dom-document-createelement | |
712 Element* Document::createElement(const AtomicString& localName, | 716 Element* Document::createElement(const AtomicString& localName, |
713 const StringOrDictionary& stringOrOptions, | 717 const StringOrDictionary& stringOrOptions, |
714 ExceptionState& exceptionState) { | 718 ExceptionState& exceptionState) { |
719 // 1. If localName does not match Name production, throw InvalidCharacterError | |
715 if (!isValidName(localName)) { | 720 if (!isValidName(localName)) { |
716 exceptionState.throwDOMException( | 721 exceptionState.throwDOMException( |
717 InvalidCharacterError, | 722 InvalidCharacterError, |
718 "The tag name provided ('" + localName + "') is not a valid name."); | 723 "The tag name provided ('" + localName + "') is not a valid name."); |
719 return nullptr; | 724 return nullptr; |
720 } | 725 } |
721 | 726 |
727 // 2. localName converted to ASCII lowercase | |
728 const AtomicString& convertedLocalName = convertLocalName(localName); | |
729 | |
730 bool isV1 = stringOrOptions.isDictionary() || !registrationContext(); | |
731 bool createV1Builtin = stringOrOptions.isDictionary() && | |
732 RuntimeEnabledFeatures::customElementsBuiltinEnabled(); | |
733 bool shouldCreateBuiltin = createV1Builtin || stringOrOptions.isString(); | |
734 | |
735 // 3. | |
736 const AtomicString& is = | |
737 AtomicString(getTypeExtension(this, stringOrOptions, exceptionState)); | |
738 const AtomicString& name = shouldCreateBuiltin ? is : convertedLocalName; | |
739 | |
740 // 4. Let definition be result of lookup up custom element definition | |
741 CustomElementDefinition* definition = nullptr; | |
742 if (isV1) { | |
743 // Is the runtime flag enabled for customized builtin elements? | |
744 const CustomElementDescriptor desc = | |
745 RuntimeEnabledFeatures::customElementsBuiltinEnabled() | |
746 ? CustomElementDescriptor(name, convertedLocalName) | |
747 : CustomElementDescriptor(convertedLocalName, convertedLocalName); | |
748 definition = CustomElement::registry(*this)->definitionFor(desc); | |
749 | |
750 // 5. If 'is' is non-null and definition is null, throw NotFoundError | |
751 // TODO(yurak): https://github.com/w3c/webcomponents/issues/608 | |
dominicc (has gone to gerrit)
2016/11/18 01:53:45
In addition to the link to the issue, add some bri
| |
752 if (!definition && createV1Builtin) { | |
753 exceptionState.throwDOMException(NotFoundError, | |
754 "Custom element definition not found."); | |
755 return nullptr; | |
756 } | |
757 } | |
758 | |
759 // 7. Let element be the result of creating an element | |
722 Element* element; | 760 Element* element; |
723 | 761 |
724 if (CustomElement::shouldCreateCustomElement(convertLocalName(localName))) { | 762 if (definition) { |
725 element = CustomElement::createCustomElementSync( | 763 element = |
726 *this, convertLocalName(localName)); | 764 CustomElement::createCustomElementSync(*this, convertedLocalName, name); |
727 } else if (V0CustomElement::isValidName(localName) && registrationContext()) { | 765 } else if (V0CustomElement::isValidName(localName) && registrationContext()) { |
728 element = registrationContext()->createCustomTagElement( | 766 element = registrationContext()->createCustomTagElement( |
729 *this, QualifiedName(nullAtom, convertLocalName(localName), | 767 *this, QualifiedName(nullAtom, convertedLocalName, xhtmlNamespaceURI)); |
730 xhtmlNamespaceURI)); | |
731 } else { | 768 } else { |
732 element = createElement(localName, exceptionState); | 769 element = createElement(localName, exceptionState); |
733 if (exceptionState.hadException()) | 770 if (exceptionState.hadException()) |
734 return nullptr; | 771 return nullptr; |
735 } | 772 } |
736 | 773 |
737 String typeExtention = | 774 // 8. If 'is' is non-null, set 'is' attribute |
738 getTypeExtension(this, stringOrOptions, exceptionState); | 775 if (!is.isEmpty()) { |
739 if (!typeExtention.isEmpty()) { | 776 if (stringOrOptions.isString()) { |
740 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension( | 777 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension( |
741 element, AtomicString(typeExtention)); | 778 element, is); |
779 } else if (stringOrOptions.isDictionary()) { | |
780 element->setAttribute(HTMLNames::isAttr, is); | |
781 } | |
742 } | 782 } |
743 | 783 |
744 return element; | 784 return element; |
745 } | 785 } |
746 | 786 |
747 static inline QualifiedName createQualifiedName( | 787 static inline QualifiedName createQualifiedName( |
748 const AtomicString& namespaceURI, | 788 const AtomicString& namespaceURI, |
749 const AtomicString& qualifiedName, | 789 const AtomicString& qualifiedName, |
750 ExceptionState& exceptionState) { | 790 ExceptionState& exceptionState) { |
751 AtomicString prefix, localName; | 791 AtomicString prefix, localName; |
(...skipping 20 matching lines...) Expand all Loading... | |
772 QualifiedName qName( | 812 QualifiedName qName( |
773 createQualifiedName(namespaceURI, qualifiedName, exceptionState)); | 813 createQualifiedName(namespaceURI, qualifiedName, exceptionState)); |
774 if (qName == QualifiedName::null()) | 814 if (qName == QualifiedName::null()) |
775 return nullptr; | 815 return nullptr; |
776 | 816 |
777 if (CustomElement::shouldCreateCustomElement(qName)) | 817 if (CustomElement::shouldCreateCustomElement(qName)) |
778 return CustomElement::createCustomElementSync(*this, qName); | 818 return CustomElement::createCustomElementSync(*this, qName); |
779 return createElement(qName, CreatedByCreateElement); | 819 return createElement(qName, CreatedByCreateElement); |
780 } | 820 } |
781 | 821 |
822 // https://dom.spec.whatwg.org/#internal-createelementns-steps | |
782 Element* Document::createElementNS(const AtomicString& namespaceURI, | 823 Element* Document::createElementNS(const AtomicString& namespaceURI, |
783 const AtomicString& qualifiedName, | 824 const AtomicString& qualifiedName, |
784 const StringOrDictionary& stringOrOptions, | 825 const StringOrDictionary& stringOrOptions, |
785 ExceptionState& exceptionState) { | 826 ExceptionState& exceptionState) { |
827 // 1. Validate and extract | |
786 QualifiedName qName( | 828 QualifiedName qName( |
787 createQualifiedName(namespaceURI, qualifiedName, exceptionState)); | 829 createQualifiedName(namespaceURI, qualifiedName, exceptionState)); |
788 if (qName == QualifiedName::null()) | 830 if (qName == QualifiedName::null()) |
789 return nullptr; | 831 return nullptr; |
790 | 832 |
833 bool isV1 = stringOrOptions.isDictionary() || !registrationContext(); | |
834 bool createV1Builtin = stringOrOptions.isDictionary() && | |
835 RuntimeEnabledFeatures::customElementsBuiltinEnabled(); | |
836 bool shouldCreateBuiltin = createV1Builtin || stringOrOptions.isString(); | |
837 | |
838 // 2. | |
839 const AtomicString& is = | |
840 AtomicString(getTypeExtension(this, stringOrOptions, exceptionState)); | |
841 const AtomicString& name = shouldCreateBuiltin ? is : qualifiedName; | |
842 | |
843 if (!isValidName(qualifiedName)) { | |
844 exceptionState.throwDOMException( | |
845 InvalidCharacterError, | |
846 "The tag name provided ('" + qualifiedName + "') is not a valid name."); | |
847 return nullptr; | |
848 } | |
849 | |
850 // 3. Let definition be result of lookup up custom element definition | |
851 CustomElementDefinition* definition = nullptr; | |
852 if (isV1) { | |
853 const CustomElementDescriptor desc = | |
854 RuntimeEnabledFeatures::customElementsBuiltinEnabled() | |
855 ? CustomElementDescriptor(name, qualifiedName) | |
856 : CustomElementDescriptor(qualifiedName, qualifiedName); | |
857 definition = CustomElement::registry(*this)->definitionFor(desc); | |
858 | |
859 // 4. If 'is' is non-null and definition is null, throw NotFoundError | |
860 if (!definition && createV1Builtin) { | |
861 exceptionState.throwDOMException(NotFoundError, | |
862 "Custom element definition not found."); | |
863 return nullptr; | |
864 } | |
865 } | |
866 | |
867 // 5. Let element be the result of creating an element | |
791 Element* element; | 868 Element* element; |
792 if (CustomElement::shouldCreateCustomElement(qName)) | 869 |
793 element = CustomElement::createCustomElementSync(*this, qName); | 870 if (CustomElement::shouldCreateCustomElement(qName) || createV1Builtin) { |
794 else if (V0CustomElement::isValidName(qName.localName()) && | 871 element = CustomElement::createCustomElementSync(*this, qName, is); |
795 registrationContext()) | 872 } else if (V0CustomElement::isValidName(qName.localName()) && |
873 registrationContext()) { | |
796 element = registrationContext()->createCustomTagElement(*this, qName); | 874 element = registrationContext()->createCustomTagElement(*this, qName); |
797 else | 875 } else { |
798 element = createElement(qName, CreatedByCreateElement); | 876 element = createElement(qName, CreatedByCreateElement); |
877 } | |
799 | 878 |
800 String typeExtention = | 879 // 6. If 'is' is non-null, set 'is' attribute |
801 getTypeExtension(this, stringOrOptions, exceptionState); | 880 if (!is.isEmpty()) { |
802 if (!typeExtention.isEmpty()) { | 881 if (element->getCustomElementState() != CustomElementState::Custom) { |
803 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension( | 882 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension( |
804 element, AtomicString(typeExtention)); | 883 element, is); |
884 } else if (stringOrOptions.isDictionary()) { | |
885 element->setAttribute(HTMLNames::isAttr, is); | |
886 } | |
805 } | 887 } |
806 | 888 |
807 return element; | 889 return element; |
808 } | 890 } |
809 | 891 |
810 ScriptValue Document::registerElement(ScriptState* scriptState, | 892 ScriptValue Document::registerElement(ScriptState* scriptState, |
811 const AtomicString& name, | 893 const AtomicString& name, |
812 const ElementRegistrationOptions& options, | 894 const ElementRegistrationOptions& options, |
813 ExceptionState& exceptionState, | 895 ExceptionState& exceptionState, |
814 V0CustomElement::NameSet validNames) { | 896 V0CustomElement::NameSet validNames) { |
(...skipping 5629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6444 } | 6526 } |
6445 | 6527 |
6446 void showLiveDocumentInstances() { | 6528 void showLiveDocumentInstances() { |
6447 WeakDocumentSet& set = liveDocumentSet(); | 6529 WeakDocumentSet& set = liveDocumentSet(); |
6448 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); | 6530 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); |
6449 for (Document* document : set) | 6531 for (Document* document : set) |
6450 fprintf(stderr, "- Document %p URL: %s\n", document, | 6532 fprintf(stderr, "- Document %p URL: %s\n", document, |
6451 document->url().getString().utf8().data()); | 6533 document->url().getString().utf8().data()); |
6452 } | 6534 } |
6453 #endif | 6535 #endif |
OLD | NEW |