Chromium Code Reviews| 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 r ights reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. |
| 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
| 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 if (newDocumentElement == m_documentElement) | 679 if (newDocumentElement == m_documentElement) |
| 680 return; | 680 return; |
| 681 m_documentElement = newDocumentElement; | 681 m_documentElement = newDocumentElement; |
| 682 // The root style used for media query matching depends on the document elem ent. | 682 // The root style used for media query matching depends on the document elem ent. |
| 683 clearStyleResolver(); | 683 clearStyleResolver(); |
| 684 } | 684 } |
| 685 | 685 |
| 686 PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionS tate& exceptionState) | 686 PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionS tate& exceptionState) |
| 687 { | 687 { |
| 688 if (!isValidName(name)) { | 688 if (!isValidName(name)) { |
| 689 exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacter Error); | 689 exceptionState.throwDOMException(InvalidCharacterError, "'" + name + "' is not a valid element name."); |
| 690 return 0; | 690 return 0; |
| 691 } | 691 } |
| 692 | 692 |
| 693 if (isXHTMLDocument() || isHTMLDocument()) | 693 if (isXHTMLDocument() || isHTMLDocument()) |
| 694 return HTMLElementFactory::createHTMLElement(isHTMLDocument() ? name.low er() : name, document(), 0, false); | 694 return HTMLElementFactory::createHTMLElement(isHTMLDocument() ? name.low er() : name, document(), 0, false); |
| 695 | 695 |
| 696 return createElement(QualifiedName(nullAtom, name, nullAtom), false); | 696 return createElement(QualifiedName(nullAtom, name, nullAtom), false); |
| 697 } | 697 } |
| 698 | 698 |
| 699 PassRefPtr<Element> Document::createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionState& exceptionState) | 699 PassRefPtr<Element> Document::createElement(const AtomicString& localName, const AtomicString& typeExtension, ExceptionState& exceptionState) |
| 700 { | 700 { |
| 701 if (!isValidName(localName)) { | 701 if (!isValidName(localName)) { |
| 702 exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacter Error); | 702 exceptionState.throwDOMException(InvalidCharacterError, "'" + localName + "' is not a valid element name."); |
|
sof
2013/12/20 11:10:53
Tangential, but are there missing checks of except
Mike West
2013/12/20 11:38:49
Good eye. Would you like to take care of that in a
sof
2013/12/20 12:21:12
I can take care of it right away.
| |
| 703 return 0; | 703 return 0; |
| 704 } | 704 } |
| 705 | 705 |
| 706 RefPtr<Element> element; | 706 RefPtr<Element> element; |
| 707 | 707 |
| 708 if (RuntimeEnabledFeatures::customElementsEnabled() && CustomElement::isVali dName(localName) && registrationContext()) | 708 if (RuntimeEnabledFeatures::customElementsEnabled() && CustomElement::isVali dName(localName) && registrationContext()) |
| 709 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, localName, xhtmlNamespaceURI)); | 709 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, localName, xhtmlNamespaceURI)); |
| 710 else | 710 else |
| 711 element = createElement(localName, exceptionState); | 711 element = createElement(localName, exceptionState); |
| 712 | 712 |
| 713 if (RuntimeEnabledFeatures::customElementsEnabled() && !typeExtension.isNull () && !typeExtension.isEmpty()) | 713 if (RuntimeEnabledFeatures::customElementsEnabled() && !typeExtension.isNull () && !typeExtension.isEmpty()) |
| 714 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension); | 714 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension); |
| 715 | 715 |
| 716 return element; | 716 return element; |
| 717 } | 717 } |
| 718 | 718 |
| 719 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& typeExtension, ExceptionS tate& exceptionState) | 719 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& typeExtension, ExceptionS tate& exceptionState) |
| 720 { | 720 { |
| 721 AtomicString prefix, localName; | 721 AtomicString prefix, localName; |
| 722 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) | 722 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) |
| 723 return 0; | 723 return 0; |
| 724 | 724 |
| 725 QualifiedName qName(prefix, localName, namespaceURI); | 725 QualifiedName qName(prefix, localName, namespaceURI); |
| 726 if (!hasValidNamespaceForElements(qName)) { | 726 if (!hasValidNamespaceForElements(qName)) { |
| 727 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); | 727 exceptionState.throwDOMException(NamespaceError, "'" + namespaceURI + "' is not a valid namespace for elements."); |
| 728 return 0; | 728 return 0; |
| 729 } | 729 } |
| 730 | 730 |
| 731 RefPtr<Element> element; | 731 RefPtr<Element> element; |
| 732 if (CustomElement::isValidName(qName.localName()) && registrationContext()) | 732 if (CustomElement::isValidName(qName.localName()) && registrationContext()) |
| 733 element = registrationContext()->createCustomTagElement(*this, qName); | 733 element = registrationContext()->createCustomTagElement(*this, qName); |
| 734 else | 734 else |
| 735 element = createElementNS(namespaceURI, qualifiedName, exceptionState); | 735 element = createElementNS(namespaceURI, qualifiedName, exceptionState); |
| 736 | 736 |
| 737 if (!typeExtension.isNull() && !typeExtension.isEmpty()) | 737 if (!typeExtension.isNull() && !typeExtension.isEmpty()) |
| 738 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension); | 738 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension); |
| 739 | 739 |
| 740 return element; | 740 return element; |
| 741 } | 741 } |
| 742 | 742 |
| 743 ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicS tring& name, ExceptionState& exceptionState) | 743 ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicS tring& name, ExceptionState& exceptionState) |
| 744 { | 744 { |
| 745 return registerElement(state, name, Dictionary(), exceptionState); | 745 return registerElement(state, name, Dictionary(), exceptionState); |
| 746 } | 746 } |
| 747 | 747 |
| 748 ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicS tring& name, const Dictionary& options, ExceptionState& exceptionState, CustomEl ement::NameSet validNames) | 748 ScriptValue Document::registerElement(WebCore::ScriptState* state, const AtomicS tring& name, const Dictionary& options, ExceptionState& exceptionState, CustomEl ement::NameSet validNames) |
| 749 { | 749 { |
| 750 if (!registrationContext()) { | 750 if (!registrationContext()) { |
| 751 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 751 exceptionState.throwDOMException(NotSupportedError, "No element registra tion context is available."); |
| 752 return ScriptValue(); | 752 return ScriptValue(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 CustomElementConstructorBuilder constructorBuilder(state, &options); | 755 CustomElementConstructorBuilder constructorBuilder(state, &options); |
| 756 registrationContext()->registerElement(this, &constructorBuilder, name, vali dNames, exceptionState); | 756 registrationContext()->registerElement(this, &constructorBuilder, name, vali dNames, exceptionState); |
| 757 return constructorBuilder.bindingsReturnValue(); | 757 return constructorBuilder.bindingsReturnValue(); |
| 758 } | 758 } |
| 759 | 759 |
| 760 void Document::setImport(HTMLImport* import) | 760 void Document::setImport(HTMLImport* import) |
| 761 { | 761 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 784 } | 784 } |
| 785 | 785 |
| 786 PassRefPtr<Comment> Document::createComment(const String& data) | 786 PassRefPtr<Comment> Document::createComment(const String& data) |
| 787 { | 787 { |
| 788 return Comment::create(*this, data); | 788 return Comment::create(*this, data); |
| 789 } | 789 } |
| 790 | 790 |
| 791 PassRefPtr<CDATASection> Document::createCDATASection(const String& data, Except ionState& exceptionState) | 791 PassRefPtr<CDATASection> Document::createCDATASection(const String& data, Except ionState& exceptionState) |
| 792 { | 792 { |
| 793 if (isHTMLDocument()) { | 793 if (isHTMLDocument()) { |
| 794 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 794 exceptionState.throwDOMException(NotSupportedError, "This is an HTML doc ument, which does not allow CData sections."); |
| 795 return 0; | 795 return 0; |
| 796 } | 796 } |
| 797 if (data.contains("]]>")) { | 797 if (data.contains("]]>")) { |
| 798 exceptionState.throwDOMException(InvalidCharacterError, "String cannot c ontain ']]>' since that is the end delimiter of a CData section."); | 798 exceptionState.throwDOMException(InvalidCharacterError, "String cannot c ontain ']]>' since that is the end delimiter of a CData section."); |
| 799 return 0; | 799 return 0; |
| 800 } | 800 } |
| 801 return CDATASection::create(*this, data); | 801 return CDATASection::create(*this, data); |
| 802 } | 802 } |
| 803 | 803 |
| 804 PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const St ring& target, const String& data, ExceptionState& exceptionState) | 804 PassRefPtr<ProcessingInstruction> Document::createProcessingInstruction(const St ring& target, const String& data, ExceptionState& exceptionState) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 820 } | 820 } |
| 821 | 821 |
| 822 PassRefPtr<CSSStyleDeclaration> Document::createCSSStyleDeclaration() | 822 PassRefPtr<CSSStyleDeclaration> Document::createCSSStyleDeclaration() |
| 823 { | 823 { |
| 824 return MutableStylePropertySet::create()->ensureCSSStyleDeclaration(); | 824 return MutableStylePropertySet::create()->ensureCSSStyleDeclaration(); |
| 825 } | 825 } |
| 826 | 826 |
| 827 PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionSt ate& exceptionState) | 827 PassRefPtr<Node> Document::importNode(Node* importedNode, bool deep, ExceptionSt ate& exceptionState) |
| 828 { | 828 { |
| 829 if (!importedNode) { | 829 if (!importedNode) { |
| 830 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 830 exceptionState.throwDOMException(NotSupportedError, "The node provided i s invalid."); |
| 831 return 0; | 831 return 0; |
| 832 } | 832 } |
| 833 | 833 |
| 834 switch (importedNode->nodeType()) { | 834 switch (importedNode->nodeType()) { |
| 835 case TEXT_NODE: | 835 case TEXT_NODE: |
| 836 return createTextNode(importedNode->nodeValue()); | 836 return createTextNode(importedNode->nodeValue()); |
| 837 case CDATA_SECTION_NODE: | 837 case CDATA_SECTION_NODE: |
| 838 return createCDATASection(importedNode->nodeValue(), exceptionState); | 838 return createCDATASection(importedNode->nodeValue(), exceptionState); |
| 839 case PROCESSING_INSTRUCTION_NODE: | 839 case PROCESSING_INSTRUCTION_NODE: |
| 840 return createProcessingInstruction(importedNode->nodeName(), importedNod e->nodeValue(), exceptionState); | 840 return createProcessingInstruction(importedNode->nodeName(), importedNod e->nodeValue(), exceptionState); |
| 841 case COMMENT_NODE: | 841 case COMMENT_NODE: |
| 842 return createComment(importedNode->nodeValue()); | 842 return createComment(importedNode->nodeValue()); |
| 843 case DOCUMENT_TYPE_NODE: { | 843 case DOCUMENT_TYPE_NODE: { |
| 844 DocumentType* doctype = toDocumentType(importedNode); | 844 DocumentType* doctype = toDocumentType(importedNode); |
| 845 return DocumentType::create(this, doctype->name(), doctype->publicId(), doctype->systemId()); | 845 return DocumentType::create(this, doctype->name(), doctype->publicId(), doctype->systemId()); |
| 846 } | 846 } |
| 847 case ELEMENT_NODE: { | 847 case ELEMENT_NODE: { |
| 848 Element* oldElement = toElement(importedNode); | 848 Element* oldElement = toElement(importedNode); |
| 849 // FIXME: The following check might be unnecessary. Is it possible that | 849 // FIXME: The following check might be unnecessary. Is it possible that |
| 850 // oldElement has mismatched prefix/namespace? | 850 // oldElement has mismatched prefix/namespace? |
| 851 if (!hasValidNamespaceForElements(oldElement->tagQName())) { | 851 if (!hasValidNamespaceForElements(oldElement->tagQName())) { |
| 852 exceptionState.throwUninformativeAndGenericDOMException(NamespaceErr or); | 852 exceptionState.throwDOMException(NamespaceError, "The imported node has an invalid namespace."); |
| 853 return 0; | 853 return 0; |
| 854 } | 854 } |
| 855 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false ); | 855 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false ); |
| 856 | 856 |
| 857 newElement->cloneDataFromElement(*oldElement); | 857 newElement->cloneDataFromElement(*oldElement); |
| 858 | 858 |
| 859 if (deep) { | 859 if (deep) { |
| 860 for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) { | 860 for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) { |
| 861 RefPtr<Node> newChild = importNode(oldChild, true, exceptionStat e); | 861 RefPtr<Node> newChild = importNode(oldChild, true, exceptionStat e); |
| 862 if (exceptionState.hadException()) | 862 if (exceptionState.hadException()) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 893 return newFragment.release(); | 893 return newFragment.release(); |
| 894 } | 894 } |
| 895 case ENTITY_NODE: | 895 case ENTITY_NODE: |
| 896 case NOTATION_NODE: | 896 case NOTATION_NODE: |
| 897 // FIXME: It should be possible to import these node types, however in D OM3 the DocumentType is readonly, so there isn't much sense in doing that. | 897 // FIXME: It should be possible to import these node types, however in D OM3 the DocumentType is readonly, so there isn't much sense in doing that. |
| 898 // Ability to add these imported nodes to a DocumentType will be conside red for addition to a future release of the DOM. | 898 // Ability to add these imported nodes to a DocumentType will be conside red for addition to a future release of the DOM. |
| 899 case DOCUMENT_NODE: | 899 case DOCUMENT_NODE: |
| 900 case XPATH_NAMESPACE_NODE: | 900 case XPATH_NAMESPACE_NODE: |
| 901 break; | 901 break; |
| 902 } | 902 } |
| 903 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedError); | 903 Element* el = toElement(importedNode); |
| 904 exceptionState.throwDOMException(NotSupportedError, "The node to import is o f type '" + el->tagName() + "', which may not be imported."); | |
| 904 return 0; | 905 return 0; |
| 905 } | 906 } |
| 906 | 907 |
| 907 PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionState& ex ceptionState) | 908 PassRefPtr<Node> Document::adoptNode(PassRefPtr<Node> source, ExceptionState& ex ceptionState) |
| 908 { | 909 { |
| 909 if (!source) { | 910 if (!source) { |
| 910 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 911 exceptionState.throwDOMException(NotSupportedError, "The node provided i s invalid."); |
| 911 return 0; | 912 return 0; |
| 912 } | 913 } |
| 913 | 914 |
| 914 EventQueueScope scope; | 915 EventQueueScope scope; |
| 915 | 916 |
| 916 switch (source->nodeType()) { | 917 switch (source->nodeType()) { |
| 917 case ENTITY_NODE: | 918 case ENTITY_NODE: |
| 918 case NOTATION_NODE: | 919 case NOTATION_NODE: |
| 919 case DOCUMENT_NODE: | 920 case DOCUMENT_NODE: |
| 920 case DOCUMENT_TYPE_NODE: | 921 case DOCUMENT_TYPE_NODE: |
| 921 case XPATH_NAMESPACE_NODE: | 922 case XPATH_NAMESPACE_NODE: { |
| 922 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 923 Element* el = toElement(source.get()); |
| 924 exceptionState.throwDOMException(NotSupportedError, "The node provided i s of type '" + el->tagName() + "', which may not be adopted."); | |
| 923 return 0; | 925 return 0; |
| 926 } | |
| 924 case ATTRIBUTE_NODE: { | 927 case ATTRIBUTE_NODE: { |
| 925 Attr* attr = toAttr(source.get()); | 928 Attr* attr = toAttr(source.get()); |
| 926 if (attr->ownerElement()) | 929 if (attr->ownerElement()) |
| 927 attr->ownerElement()->removeAttributeNode(attr, exceptionState); | 930 attr->ownerElement()->removeAttributeNode(attr, exceptionState); |
| 928 break; | 931 break; |
| 929 } | 932 } |
| 930 default: | 933 default: |
| 931 if (source->isShadowRoot()) { | 934 if (source->isShadowRoot()) { |
| 932 // ShadowRoot cannot disconnect itself from the host node. | 935 // ShadowRoot cannot disconnect itself from the host node. |
| 933 exceptionState.throwUninformativeAndGenericDOMException(HierarchyReq uestError); | 936 exceptionState.throwDOMException(HierarchyRequestError, "The node pr ovided is a shadow root, which may not be adopted."); |
| 934 return 0; | 937 return 0; |
| 935 } | 938 } |
| 936 | 939 |
| 937 if (source->isFrameOwnerElement()) { | 940 if (source->isFrameOwnerElement()) { |
| 938 HTMLFrameOwnerElement* frameOwnerElement = toHTMLFrameOwnerElement(s ource.get()); | 941 HTMLFrameOwnerElement* frameOwnerElement = toHTMLFrameOwnerElement(s ource.get()); |
| 939 if (frame() && frame()->tree().isDescendantOf(frameOwnerElement->con tentFrame())) { | 942 if (frame() && frame()->tree().isDescendantOf(frameOwnerElement->con tentFrame())) { |
| 940 exceptionState.throwUninformativeAndGenericDOMException(Hierarch yRequestError); | 943 exceptionState.throwDOMException(HierarchyRequestError, "The nod e provided is a frame which contains this document."); |
| 941 return 0; | 944 return 0; |
| 942 } | 945 } |
| 943 } | 946 } |
| 944 if (source->parentNode()) { | 947 if (source->parentNode()) { |
| 945 source->parentNode()->removeChild(source.get(), exceptionState); | 948 source->parentNode()->removeChild(source.get(), exceptionState); |
| 946 if (exceptionState.hadException()) | 949 if (exceptionState.hadException()) |
| 947 return 0; | 950 return 0; |
| 948 } | 951 } |
| 949 } | 952 } |
| 950 | 953 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1030 } | 1033 } |
| 1031 | 1034 |
| 1032 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState) | 1035 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState) |
| 1033 { | 1036 { |
| 1034 AtomicString prefix, localName; | 1037 AtomicString prefix, localName; |
| 1035 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) | 1038 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) |
| 1036 return 0; | 1039 return 0; |
| 1037 | 1040 |
| 1038 QualifiedName qName(prefix, localName, namespaceURI); | 1041 QualifiedName qName(prefix, localName, namespaceURI); |
| 1039 if (!hasValidNamespaceForElements(qName)) { | 1042 if (!hasValidNamespaceForElements(qName)) { |
| 1040 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); | 1043 exceptionState.throwDOMException(NamespaceError, "'" + namespaceURI + "' is an invalid namespace for elements."); |
| 1041 return 0; | 1044 return 0; |
| 1042 } | 1045 } |
| 1043 | 1046 |
| 1044 return createElement(qName, false); | 1047 return createElement(qName, false); |
| 1045 } | 1048 } |
| 1046 | 1049 |
| 1047 String Document::readyState() const | 1050 String Document::readyState() const |
| 1048 { | 1051 { |
| 1049 DEFINE_STATIC_LOCAL(const String, loading, ("loading")); | 1052 DEFINE_STATIC_LOCAL(const String, loading, ("loading")); |
| 1050 DEFINE_STATIC_LOCAL(const String, interactive, ("interactive")); | 1053 DEFINE_STATIC_LOCAL(const String, interactive, ("interactive")); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 return; | 1132 return; |
| 1130 m_contentLanguage = language; | 1133 m_contentLanguage = language; |
| 1131 | 1134 |
| 1132 // Document's style depends on the content language. | 1135 // Document's style depends on the content language. |
| 1133 setNeedsStyleRecalc(); | 1136 setNeedsStyleRecalc(); |
| 1134 } | 1137 } |
| 1135 | 1138 |
| 1136 void Document::setXMLVersion(const String& version, ExceptionState& exceptionSta te) | 1139 void Document::setXMLVersion(const String& version, ExceptionState& exceptionSta te) |
| 1137 { | 1140 { |
| 1138 if (!implementation()->hasFeature("XML", String())) { | 1141 if (!implementation()->hasFeature("XML", String())) { |
| 1139 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1142 exceptionState.throwDOMException(NotSupportedError, "This document does not support XML."); |
| 1140 return; | 1143 return; |
| 1141 } | 1144 } |
| 1142 | 1145 |
| 1143 if (!XMLDocumentParser::supportsXMLVersion(version)) { | 1146 if (!XMLDocumentParser::supportsXMLVersion(version)) { |
| 1144 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1147 exceptionState.throwDOMException(NotSupportedError, "This document does not support the XML version '" + version + "'."); |
| 1145 return; | 1148 return; |
| 1146 } | 1149 } |
| 1147 | 1150 |
| 1148 m_xmlVersion = version; | 1151 m_xmlVersion = version; |
| 1149 } | 1152 } |
| 1150 | 1153 |
| 1151 void Document::setXMLStandalone(bool standalone, ExceptionState& exceptionState) | 1154 void Document::setXMLStandalone(bool standalone, ExceptionState& exceptionState) |
| 1152 { | 1155 { |
| 1153 if (!implementation()->hasFeature("XML", String())) { | 1156 if (!implementation()->hasFeature("XML", String())) { |
| 1154 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1157 exceptionState.throwDOMException(NotSupportedError, "This document does not support XML."); |
| 1155 return; | 1158 return; |
| 1156 } | 1159 } |
| 1157 | 1160 |
| 1158 m_xmlStandalone = standalone ? Standalone : NotStandalone; | 1161 m_xmlStandalone = standalone ? Standalone : NotStandalone; |
| 1159 } | 1162 } |
| 1160 | 1163 |
| 1161 KURL Document::baseURI() const | 1164 KURL Document::baseURI() const |
| 1162 { | 1165 { |
| 1163 return m_baseURL; | 1166 return m_baseURL; |
| 1164 } | 1167 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1443 | 1446 |
| 1444 PassRefPtr<Range> Document::createRange() | 1447 PassRefPtr<Range> Document::createRange() |
| 1445 { | 1448 { |
| 1446 return Range::create(*this); | 1449 return Range::create(*this); |
| 1447 } | 1450 } |
| 1448 | 1451 |
| 1449 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, ExceptionState & exceptionState) | 1452 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, ExceptionState & exceptionState) |
| 1450 { | 1453 { |
| 1451 // FIXME: Probably this should be handled within the bindings layer and Type Error should be thrown. | 1454 // FIXME: Probably this should be handled within the bindings layer and Type Error should be thrown. |
| 1452 if (!root) { | 1455 if (!root) { |
| 1453 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1456 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1454 return 0; | 1457 return 0; |
| 1455 } | 1458 } |
| 1456 return NodeIterator::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilte r>()); | 1459 return NodeIterator::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilte r>()); |
| 1457 } | 1460 } |
| 1458 | 1461 |
| 1459 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatT oShow, ExceptionState& exceptionState) | 1462 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatT oShow, ExceptionState& exceptionState) |
| 1460 { | 1463 { |
| 1461 if (!root) { | 1464 if (!root) { |
| 1462 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1465 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1463 return 0; | 1466 return 0; |
| 1464 } | 1467 } |
| 1465 // FIXME: It might be a good idea to emit a warning if |whatToShow| contains a bit that is not defined in | 1468 // FIXME: It might be a good idea to emit a warning if |whatToShow| contains a bit that is not defined in |
| 1466 // NodeFilter. | 1469 // NodeFilter. |
| 1467 return NodeIterator::create(root, whatToShow, PassRefPtr<NodeFilter>()); | 1470 return NodeIterator::create(root, whatToShow, PassRefPtr<NodeFilter>()); |
| 1468 } | 1471 } |
| 1469 | 1472 |
| 1470 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatT oShow, PassRefPtr<NodeFilter> filter, ExceptionState& exceptionState) | 1473 PassRefPtr<NodeIterator> Document::createNodeIterator(Node* root, unsigned whatT oShow, PassRefPtr<NodeFilter> filter, ExceptionState& exceptionState) |
| 1471 { | 1474 { |
| 1472 if (!root) { | 1475 if (!root) { |
| 1473 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1476 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1474 return 0; | 1477 return 0; |
| 1475 } | 1478 } |
| 1476 // FIXME: Ditto. | 1479 // FIXME: Ditto. |
| 1477 return NodeIterator::create(root, whatToShow, filter); | 1480 return NodeIterator::create(root, whatToShow, filter); |
| 1478 } | 1481 } |
| 1479 | 1482 |
| 1480 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, ExceptionState& ex ceptionState) | 1483 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, ExceptionState& ex ceptionState) |
| 1481 { | 1484 { |
| 1482 if (!root) { | 1485 if (!root) { |
| 1483 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1486 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1484 return 0; | 1487 return 0; |
| 1485 } | 1488 } |
| 1486 return TreeWalker::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilter> ()); | 1489 return TreeWalker::create(root, NodeFilter::SHOW_ALL, PassRefPtr<NodeFilter> ()); |
| 1487 } | 1490 } |
| 1488 | 1491 |
| 1489 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToSho w, ExceptionState& exceptionState) | 1492 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToSho w, ExceptionState& exceptionState) |
| 1490 { | 1493 { |
| 1491 if (!root) { | 1494 if (!root) { |
| 1492 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1495 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1493 return 0; | 1496 return 0; |
| 1494 } | 1497 } |
| 1495 return TreeWalker::create(root, whatToShow, PassRefPtr<NodeFilter>()); | 1498 return TreeWalker::create(root, whatToShow, PassRefPtr<NodeFilter>()); |
| 1496 } | 1499 } |
| 1497 | 1500 |
| 1498 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToSho w, PassRefPtr<NodeFilter> filter, ExceptionState& exceptionState) | 1501 PassRefPtr<TreeWalker> Document::createTreeWalker(Node* root, unsigned whatToSho w, PassRefPtr<NodeFilter> filter, ExceptionState& exceptionState) |
| 1499 { | 1502 { |
| 1500 if (!root) { | 1503 if (!root) { |
| 1501 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); | 1504 exceptionState.throwDOMException(NotSupportedError, "The provided node i s invalid."); |
| 1502 return 0; | 1505 return 0; |
| 1503 } | 1506 } |
| 1504 return TreeWalker::create(root, whatToShow, filter); | 1507 return TreeWalker::create(root, whatToShow, filter); |
| 1505 } | 1508 } |
| 1506 | 1509 |
| 1507 void Document::scheduleStyleRecalc() | 1510 void Document::scheduleStyleRecalc() |
| 1508 { | 1511 { |
| 1509 if (shouldDisplaySeamlesslyWithParent()) { | 1512 if (shouldDisplaySeamlesslyWithParent()) { |
| 1510 // When we're seamless, our parent document manages our style recalcs. | 1513 // When we're seamless, our parent document manages our style recalcs. |
| 1511 ownerElement()->setNeedsStyleRecalc(); | 1514 ownerElement()->setNeedsStyleRecalc(); |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2231 return toHTMLElement(child); | 2234 return toHTMLElement(child); |
| 2232 } | 2235 } |
| 2233 | 2236 |
| 2234 return 0; | 2237 return 0; |
| 2235 } | 2238 } |
| 2236 | 2239 |
| 2237 void Document::setBody(PassRefPtr<HTMLElement> prpNewBody, ExceptionState& excep tionState) | 2240 void Document::setBody(PassRefPtr<HTMLElement> prpNewBody, ExceptionState& excep tionState) |
| 2238 { | 2241 { |
| 2239 RefPtr<HTMLElement> newBody = prpNewBody; | 2242 RefPtr<HTMLElement> newBody = prpNewBody; |
| 2240 | 2243 |
| 2241 if (!newBody || !documentElement()) { | 2244 if (!newBody) { |
| 2242 exceptionState.throwUninformativeAndGenericDOMException(HierarchyRequest Error); | 2245 exceptionState.throwDOMException(HierarchyRequestError, "The node provid ed is invalid."); |
| 2246 return; | |
| 2247 } | |
| 2248 if (!documentElement()) { | |
| 2249 exceptionState.throwDOMException(HierarchyRequestError, "No document ele ment exists."); | |
| 2243 return; | 2250 return; |
| 2244 } | 2251 } |
| 2245 | 2252 |
| 2246 if (!newBody->hasTagName(bodyTag) && !newBody->hasTagName(framesetTag)) { | 2253 if (!newBody->hasTagName(bodyTag) && !newBody->hasTagName(framesetTag)) { |
| 2247 exceptionState.throwUninformativeAndGenericDOMException(HierarchyRequest Error); | 2254 exceptionState.throwDOMException(HierarchyRequestError, "The new body el ement is of type '" + newBody->tagName() + "'. It must be either a 'BODY' or 'FR AMESET' element."); |
| 2248 return; | 2255 return; |
| 2249 } | 2256 } |
| 2250 | 2257 |
| 2251 HTMLElement* oldBody = body(); | 2258 HTMLElement* oldBody = body(); |
| 2252 if (oldBody == newBody) | 2259 if (oldBody == newBody) |
| 2253 return; | 2260 return; |
| 2254 | 2261 |
| 2255 if (oldBody) | 2262 if (oldBody) |
| 2256 documentElement()->replaceChild(newBody.release(), oldBody, exceptionSta te); | 2263 documentElement()->replaceChild(newBody.release(), oldBody, exceptionSta te); |
| 2257 else | 2264 else |
| (...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3650 event->setTarget(domWindow()); | 3657 event->setTarget(domWindow()); |
| 3651 ensureScriptedAnimationController().enqueuePerFrameEvent(event.release()); | 3658 ensureScriptedAnimationController().enqueuePerFrameEvent(event.release()); |
| 3652 } | 3659 } |
| 3653 | 3660 |
| 3654 PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionState& exceptionState) | 3661 PassRefPtr<Event> Document::createEvent(const String& eventType, ExceptionState& exceptionState) |
| 3655 { | 3662 { |
| 3656 RefPtr<Event> event = EventFactory::create(eventType); | 3663 RefPtr<Event> event = EventFactory::create(eventType); |
| 3657 if (event) | 3664 if (event) |
| 3658 return event.release(); | 3665 return event.release(); |
| 3659 | 3666 |
| 3660 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedError); | 3667 exceptionState.throwDOMException(NotSupportedError, "The provided event type ('" + eventType + "') is invalid."); |
| 3661 return 0; | 3668 return 0; |
| 3662 } | 3669 } |
| 3663 | 3670 |
| 3664 void Document::addMutationEventListenerTypeIfEnabled(ListenerType listenerType) | 3671 void Document::addMutationEventListenerTypeIfEnabled(ListenerType listenerType) |
| 3665 { | 3672 { |
| 3666 if (ContextFeatures::mutationEventsEnabled(this)) | 3673 if (ContextFeatures::mutationEventsEnabled(this)) |
| 3667 addListenerType(listenerType); | 3674 addListenerType(listenerType); |
| 3668 } | 3675 } |
| 3669 | 3676 |
| 3670 void Document::addListenerTypeIfNeeded(const AtomicString& eventType) | 3677 void Document::addListenerTypeIfNeeded(const AtomicString& eventType) |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3925 { | 3932 { |
| 3926 bool nameStart = true; | 3933 bool nameStart = true; |
| 3927 bool sawColon = false; | 3934 bool sawColon = false; |
| 3928 int colonPos = 0; | 3935 int colonPos = 0; |
| 3929 | 3936 |
| 3930 for (unsigned i = 0; i < length;) { | 3937 for (unsigned i = 0; i < length;) { |
| 3931 UChar32 c; | 3938 UChar32 c; |
| 3932 U16_NEXT(characters, i, length, c) | 3939 U16_NEXT(characters, i, length, c) |
| 3933 if (c == ':') { | 3940 if (c == ':') { |
| 3934 if (sawColon) { | 3941 if (sawColon) { |
| 3935 exceptionState.throwUninformativeAndGenericDOMException(Namespac eError); | 3942 exceptionState.throwDOMException(NamespaceError, "Multiple colon s (':') are not allowed."); |
| 3936 return false; // multiple colons: not allowed | 3943 return false; // multiple colons: not allowed |
| 3937 } | 3944 } |
| 3938 nameStart = true; | 3945 nameStart = true; |
| 3939 sawColon = true; | 3946 sawColon = true; |
| 3940 colonPos = i - 1; | 3947 colonPos = i - 1; |
| 3941 } else if (nameStart) { | 3948 } else if (nameStart) { |
| 3942 if (!isValidNameStart(c)) { | 3949 if (!isValidNameStart(c)) { |
| 3943 exceptionState.throwUninformativeAndGenericDOMException(InvalidC haracterError); | 3950 StringBuilder message; |
| 3951 message.append("The character '"); | |
| 3952 message.append(c); | |
| 3953 message.append("' may not be used to start a name."); | |
| 3954 exceptionState.throwDOMException(InvalidCharacterError, message. toString()); | |
| 3944 return false; | 3955 return false; |
| 3945 } | 3956 } |
| 3946 nameStart = false; | 3957 nameStart = false; |
| 3947 } else { | 3958 } else { |
| 3948 if (!isValidNamePart(c)) { | 3959 if (!isValidNamePart(c)) { |
| 3949 exceptionState.throwUninformativeAndGenericDOMException(InvalidC haracterError); | 3960 StringBuilder message; |
|
sof
2013/12/20 11:10:53
String::format() a shorter alternative?
Mike West
2013/12/20 11:38:49
StringBuilder has an explicit 'append(UChar32)' me
| |
| 3961 message.append("The character '"); | |
| 3962 message.append(c); | |
| 3963 message.append("' may not be used in a name."); | |
| 3964 exceptionState.throwDOMException(InvalidCharacterError, message. toString()); | |
| 3950 return false; | 3965 return false; |
| 3951 } | 3966 } |
| 3952 } | 3967 } |
| 3953 } | 3968 } |
| 3954 | 3969 |
| 3955 if (!sawColon) { | 3970 if (!sawColon) { |
| 3956 prefix = nullAtom; | 3971 prefix = nullAtom; |
| 3957 localName = qualifiedName; | 3972 localName = qualifiedName; |
| 3958 } else { | 3973 } else { |
| 3959 prefix = AtomicString(characters, colonPos); | 3974 prefix = AtomicString(characters, colonPos); |
| 3960 if (prefix.isEmpty()) { | 3975 if (prefix.isEmpty()) { |
| 3961 exceptionState.throwUninformativeAndGenericDOMException(NamespaceErr or); | 3976 exceptionState.throwDOMException(NamespaceError, "A colon (':') may not be used to begin a name."); |
| 3962 return false; | 3977 return false; |
| 3963 } | 3978 } |
| 3964 int prefixStart = colonPos + 1; | 3979 int prefixStart = colonPos + 1; |
| 3965 localName = AtomicString(characters + prefixStart, length - prefixStart) ; | 3980 localName = AtomicString(characters + prefixStart, length - prefixStart) ; |
| 3966 } | 3981 } |
| 3967 | 3982 |
| 3968 if (localName.isEmpty()) { | 3983 if (localName.isEmpty()) { |
| 3969 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); | 3984 exceptionState.throwDOMException(NamespaceError, "The specified name is empty."); |
| 3970 return false; | 3985 return false; |
| 3971 } | 3986 } |
| 3972 | 3987 |
| 3973 return true; | 3988 return true; |
| 3974 } | 3989 } |
| 3975 | 3990 |
| 3976 bool Document::parseQualifiedName(const AtomicString& qualifiedName, AtomicStrin g& prefix, AtomicString& localName, ExceptionState& exceptionState) | 3991 bool Document::parseQualifiedName(const AtomicString& qualifiedName, AtomicStrin g& prefix, AtomicString& localName, ExceptionState& exceptionState) |
| 3977 { | 3992 { |
| 3978 unsigned length = qualifiedName.length(); | 3993 unsigned length = qualifiedName.length(); |
| 3979 | 3994 |
| 3980 if (!length) { | 3995 if (!length) { |
| 3981 exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacter Error); | 3996 exceptionState.throwDOMException(InvalidCharacterError, "The provided qu alified name is empty."); |
| 3982 return false; | 3997 return false; |
| 3983 } | 3998 } |
| 3984 | 3999 |
| 3985 if (qualifiedName.is8Bit()) | 4000 if (qualifiedName.is8Bit()) |
| 3986 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, exceptionState); | 4001 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, exceptionState); |
| 3987 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, exceptionState); | 4002 return parseQualifiedNameInternal(qualifiedName, qualifiedName.characters16( ), length, prefix, localName, exceptionState); |
| 3988 } | 4003 } |
| 3989 | 4004 |
| 3990 void Document::setEncodingData(const DocumentEncodingData& newData) | 4005 void Document::setEncodingData(const DocumentEncodingData& newData) |
| 3991 { | 4006 { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4197 | 4212 |
| 4198 PassRefPtr<Attr> Document::createAttributeNS(const AtomicString& namespaceURI, c onst AtomicString& qualifiedName, ExceptionState& exceptionState, bool shouldIgn oreNamespaceChecks) | 4213 PassRefPtr<Attr> Document::createAttributeNS(const AtomicString& namespaceURI, c onst AtomicString& qualifiedName, ExceptionState& exceptionState, bool shouldIgn oreNamespaceChecks) |
| 4199 { | 4214 { |
| 4200 AtomicString prefix, localName; | 4215 AtomicString prefix, localName; |
| 4201 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) | 4216 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) |
| 4202 return 0; | 4217 return 0; |
| 4203 | 4218 |
| 4204 QualifiedName qName(prefix, localName, namespaceURI); | 4219 QualifiedName qName(prefix, localName, namespaceURI); |
| 4205 | 4220 |
| 4206 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) { | 4221 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) { |
| 4207 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); | 4222 exceptionState.throwDOMException(NamespaceError, "The namespace '" + nam espaceURI + "' is invalid."); |
| 4208 return 0; | 4223 return 0; |
| 4209 } | 4224 } |
| 4210 | 4225 |
| 4211 return Attr::create(*this, qName, emptyString()); | 4226 return Attr::create(*this, qName, emptyString()); |
| 4212 } | 4227 } |
| 4213 | 4228 |
| 4214 const SVGDocumentExtensions* Document::svgExtensions() | 4229 const SVGDocumentExtensions* Document::svgExtensions() |
| 4215 { | 4230 { |
| 4216 return m_svgExtensions.get(); | 4231 return m_svgExtensions.get(); |
| 4217 } | 4232 } |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5249 } | 5264 } |
| 5250 | 5265 |
| 5251 FastTextAutosizer* Document::fastTextAutosizer() | 5266 FastTextAutosizer* Document::fastTextAutosizer() |
| 5252 { | 5267 { |
| 5253 if (!m_fastTextAutosizer && RuntimeEnabledFeatures::fastTextAutosizingEnable d()) | 5268 if (!m_fastTextAutosizer && RuntimeEnabledFeatures::fastTextAutosizingEnable d()) |
| 5254 m_fastTextAutosizer = FastTextAutosizer::create(this); | 5269 m_fastTextAutosizer = FastTextAutosizer::create(this); |
| 5255 return m_fastTextAutosizer.get(); | 5270 return m_fastTextAutosizer.get(); |
| 5256 } | 5271 } |
| 5257 | 5272 |
| 5258 } // namespace WebCore | 5273 } // namespace WebCore |
| OLD | NEW |