Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 18548003: Rename ExceptionCode constants to use the names in the spec (2/3) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/DatasetDOMStringMap.cpp ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 } 776 }
777 777
778 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionCode& e c) 778 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionCode& e c)
779 { 779 {
780 String prefix, localName; 780 String prefix, localName;
781 if (!parseQualifiedName(qualifiedName, prefix, localName, ec)) 781 if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
782 return 0; 782 return 0;
783 783
784 QualifiedName qName(prefix, localName, namespaceURI); 784 QualifiedName qName(prefix, localName, namespaceURI);
785 if (!hasValidNamespaceForElements(qName)) { 785 if (!hasValidNamespaceForElements(qName)) {
786 ec = NAMESPACE_ERR; 786 ec = NamespaceError;
787 return 0; 787 return 0;
788 } 788 }
789 789
790 RefPtr<Element> element; 790 RefPtr<Element> element;
791 if (CustomElementRegistry::isCustomTagName(qName.localName())) 791 if (CustomElementRegistry::isCustomTagName(qName.localName()))
792 element = ensureCustomElementRegistry()->createCustomTagElement(qName); 792 element = ensureCustomElementRegistry()->createCustomTagElement(qName);
793 else 793 else
794 element = createElementNS(namespaceURI, qualifiedName, ec); 794 element = createElementNS(namespaceURI, qualifiedName, ec);
795 795
796 if (!typeExtension.isNull()) { 796 if (!typeExtension.isNull()) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 return createCDATASection(importedNode->nodeValue(), ec); 906 return createCDATASection(importedNode->nodeValue(), ec);
907 case PROCESSING_INSTRUCTION_NODE: 907 case PROCESSING_INSTRUCTION_NODE:
908 return createProcessingInstruction(importedNode->nodeName(), importedNod e->nodeValue(), ec); 908 return createProcessingInstruction(importedNode->nodeName(), importedNod e->nodeValue(), ec);
909 case COMMENT_NODE: 909 case COMMENT_NODE:
910 return createComment(importedNode->nodeValue()); 910 return createComment(importedNode->nodeValue());
911 case ELEMENT_NODE: { 911 case ELEMENT_NODE: {
912 Element* oldElement = toElement(importedNode); 912 Element* oldElement = toElement(importedNode);
913 // FIXME: The following check might be unnecessary. Is it possible that 913 // FIXME: The following check might be unnecessary. Is it possible that
914 // oldElement has mismatched prefix/namespace? 914 // oldElement has mismatched prefix/namespace?
915 if (!hasValidNamespaceForElements(oldElement->tagQName())) { 915 if (!hasValidNamespaceForElements(oldElement->tagQName())) {
916 ec = NAMESPACE_ERR; 916 ec = NamespaceError;
917 return 0; 917 return 0;
918 } 918 }
919 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false ); 919 RefPtr<Element> newElement = createElement(oldElement->tagQName(), false );
920 920
921 newElement->cloneDataFromElement(*oldElement); 921 newElement->cloneDataFromElement(*oldElement);
922 922
923 if (deep) { 923 if (deep) {
924 for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) { 924 for (Node* oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
925 RefPtr<Node> newChild = importNode(oldChild, true, ec); 925 RefPtr<Node> newChild = importNode(oldChild, true, ec);
926 if (ec) 926 if (ec)
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 } 1105 }
1106 1106
1107 PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec) 1107 PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionCode& ec)
1108 { 1108 {
1109 String prefix, localName; 1109 String prefix, localName;
1110 if (!parseQualifiedName(qualifiedName, prefix, localName, ec)) 1110 if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
1111 return 0; 1111 return 0;
1112 1112
1113 QualifiedName qName(prefix, localName, namespaceURI); 1113 QualifiedName qName(prefix, localName, namespaceURI);
1114 if (!hasValidNamespaceForElements(qName)) { 1114 if (!hasValidNamespaceForElements(qName)) {
1115 ec = NAMESPACE_ERR; 1115 ec = NamespaceError;
1116 return 0; 1116 return 0;
1117 } 1117 }
1118 1118
1119 return createElement(qName, false); 1119 return createElement(qName, false);
1120 } 1120 }
1121 1121
1122 String Document::readyState() const 1122 String Document::readyState() const
1123 { 1123 {
1124 DEFINE_STATIC_LOCAL(const String, loading, (ASCIILiteral("loading"))); 1124 DEFINE_STATIC_LOCAL(const String, loading, (ASCIILiteral("loading")));
1125 DEFINE_STATIC_LOCAL(const String, interactive, (ASCIILiteral("interactive")) ); 1125 DEFINE_STATIC_LOCAL(const String, interactive, (ASCIILiteral("interactive")) );
(...skipping 2476 matching lines...) Expand 10 before | Expand all | Expand 10 after
3602 return 0; 3602 return 0;
3603 return frame()->ownerElement(); 3603 return frame()->ownerElement();
3604 } 3604 }
3605 3605
3606 String Document::cookie(ExceptionCode& ec) const 3606 String Document::cookie(ExceptionCode& ec) const
3607 { 3607 {
3608 if (page() && !page()->settings()->cookieEnabled()) 3608 if (page() && !page()->settings()->cookieEnabled())
3609 return String(); 3609 return String();
3610 3610
3611 // FIXME: The HTML5 DOM spec states that this attribute can raise an 3611 // FIXME: The HTML5 DOM spec states that this attribute can raise an
3612 // INVALID_STATE_ERR exception on getting if the Document has no 3612 // InvalidStateError exception on getting if the Document has no
3613 // browsing context. 3613 // browsing context.
3614 3614
3615 if (!securityOrigin()->canAccessCookies()) { 3615 if (!securityOrigin()->canAccessCookies()) {
3616 ec = SECURITY_ERR; 3616 ec = SecurityError;
3617 return String(); 3617 return String();
3618 } 3618 }
3619 3619
3620 KURL cookieURL = this->cookieURL(); 3620 KURL cookieURL = this->cookieURL();
3621 if (cookieURL.isEmpty()) 3621 if (cookieURL.isEmpty())
3622 return String(); 3622 return String();
3623 3623
3624 return cookies(this, cookieURL); 3624 return cookies(this, cookieURL);
3625 } 3625 }
3626 3626
3627 void Document::setCookie(const String& value, ExceptionCode& ec) 3627 void Document::setCookie(const String& value, ExceptionCode& ec)
3628 { 3628 {
3629 if (page() && !page()->settings()->cookieEnabled()) 3629 if (page() && !page()->settings()->cookieEnabled())
3630 return; 3630 return;
3631 3631
3632 // FIXME: The HTML5 DOM spec states that this attribute can raise an 3632 // FIXME: The HTML5 DOM spec states that this attribute can raise an
3633 // INVALID_STATE_ERR exception on setting if the Document has no 3633 // InvalidStateError exception on setting if the Document has no
3634 // browsing context. 3634 // browsing context.
3635 3635
3636 if (!securityOrigin()->canAccessCookies()) { 3636 if (!securityOrigin()->canAccessCookies()) {
3637 ec = SECURITY_ERR; 3637 ec = SecurityError;
3638 return; 3638 return;
3639 } 3639 }
3640 3640
3641 KURL cookieURL = this->cookieURL(); 3641 KURL cookieURL = this->cookieURL();
3642 if (cookieURL.isEmpty()) 3642 if (cookieURL.isEmpty())
3643 return; 3643 return;
3644 3644
3645 setCookies(this, cookieURL, value); 3645 setCookies(this, cookieURL, value);
3646 } 3646 }
3647 3647
3648 String Document::referrer() const 3648 String Document::referrer() const
3649 { 3649 {
3650 if (frame()) 3650 if (frame())
3651 return frame()->loader()->referrer(); 3651 return frame()->loader()->referrer();
3652 return String(); 3652 return String();
3653 } 3653 }
3654 3654
3655 String Document::domain() const 3655 String Document::domain() const
3656 { 3656 {
3657 return securityOrigin()->domain(); 3657 return securityOrigin()->domain();
3658 } 3658 }
3659 3659
3660 void Document::setDomain(const String& newDomain, ExceptionCode& ec) 3660 void Document::setDomain(const String& newDomain, ExceptionCode& ec)
3661 { 3661 {
3662 if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin() ->protocol())) { 3662 if (SchemeRegistry::isDomainRelaxationForbiddenForURLScheme(securityOrigin() ->protocol())) {
3663 ec = SECURITY_ERR; 3663 ec = SecurityError;
3664 return; 3664 return;
3665 } 3665 }
3666 3666
3667 // Both NS and IE specify that changing the domain is only allowed when 3667 // Both NS and IE specify that changing the domain is only allowed when
3668 // the new domain is a suffix of the old domain. 3668 // the new domain is a suffix of the old domain.
3669 3669
3670 // FIXME: We should add logging indicating why a domain was not allowed. 3670 // FIXME: We should add logging indicating why a domain was not allowed.
3671 3671
3672 // If the new domain is the same as the old domain, still call 3672 // If the new domain is the same as the old domain, still call
3673 // securityOrigin()->setDomainForDOM. This will change the 3673 // securityOrigin()->setDomainForDOM. This will change the
3674 // security check behavior. For example, if a page loaded on port 8000 3674 // security check behavior. For example, if a page loaded on port 8000
3675 // assigns its current domain using document.domain, the page will 3675 // assigns its current domain using document.domain, the page will
3676 // allow other pages loaded on different ports in the same domain that 3676 // allow other pages loaded on different ports in the same domain that
3677 // have also assigned to access this page. 3677 // have also assigned to access this page.
3678 if (equalIgnoringCase(domain(), newDomain)) { 3678 if (equalIgnoringCase(domain(), newDomain)) {
3679 securityOrigin()->setDomainFromDOM(newDomain); 3679 securityOrigin()->setDomainFromDOM(newDomain);
3680 if (m_frame) 3680 if (m_frame)
3681 m_frame->script()->updateSecurityOrigin(); 3681 m_frame->script()->updateSecurityOrigin();
3682 return; 3682 return;
3683 } 3683 }
3684 3684
3685 int oldLength = domain().length(); 3685 int oldLength = domain().length();
3686 int newLength = newDomain.length(); 3686 int newLength = newDomain.length();
3687 // e.g. newDomain = webkit.org (10) and domain() = www.webkit.org (14) 3687 // e.g. newDomain = webkit.org (10) and domain() = www.webkit.org (14)
3688 if (newLength >= oldLength) { 3688 if (newLength >= oldLength) {
3689 ec = SECURITY_ERR; 3689 ec = SecurityError;
3690 return; 3690 return;
3691 } 3691 }
3692 3692
3693 String test = domain(); 3693 String test = domain();
3694 // Check that it's a subdomain, not e.g. "ebkit.org" 3694 // Check that it's a subdomain, not e.g. "ebkit.org"
3695 if (test[oldLength - newLength - 1] != '.') { 3695 if (test[oldLength - newLength - 1] != '.') {
3696 ec = SECURITY_ERR; 3696 ec = SecurityError;
3697 return; 3697 return;
3698 } 3698 }
3699 3699
3700 // Now test is "webkit.org" from domain() 3700 // Now test is "webkit.org" from domain()
3701 // and we check that it's the same thing as newDomain 3701 // and we check that it's the same thing as newDomain
3702 test.remove(0, oldLength - newLength); 3702 test.remove(0, oldLength - newLength);
3703 if (test != newDomain) { 3703 if (test != newDomain) {
3704 ec = SECURITY_ERR; 3704 ec = SecurityError;
3705 return; 3705 return;
3706 } 3706 }
3707 3707
3708 securityOrigin()->setDomainFromDOM(newDomain); 3708 securityOrigin()->setDomainFromDOM(newDomain);
3709 if (m_frame) 3709 if (m_frame)
3710 m_frame->script()->updateSecurityOrigin(); 3710 m_frame->script()->updateSecurityOrigin();
3711 } 3711 }
3712 3712
3713 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified 3713 // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-lastmodified
3714 String Document::lastModified() const 3714 String Document::lastModified() const
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 bool nameStart = true; 3814 bool nameStart = true;
3815 bool sawColon = false; 3815 bool sawColon = false;
3816 int colonPos = 0; 3816 int colonPos = 0;
3817 3817
3818 const UChar* s = qualifiedName.bloatedCharacters(); 3818 const UChar* s = qualifiedName.bloatedCharacters();
3819 for (unsigned i = 0; i < length;) { 3819 for (unsigned i = 0; i < length;) {
3820 UChar32 c; 3820 UChar32 c;
3821 U16_NEXT(s, i, length, c) 3821 U16_NEXT(s, i, length, c)
3822 if (c == ':') { 3822 if (c == ':') {
3823 if (sawColon) { 3823 if (sawColon) {
3824 ec = NAMESPACE_ERR; 3824 ec = NamespaceError;
3825 return false; // multiple colons: not allowed 3825 return false; // multiple colons: not allowed
3826 } 3826 }
3827 nameStart = true; 3827 nameStart = true;
3828 sawColon = true; 3828 sawColon = true;
3829 colonPos = i - 1; 3829 colonPos = i - 1;
3830 } else if (nameStart) { 3830 } else if (nameStart) {
3831 if (!isValidNameStart(c)) { 3831 if (!isValidNameStart(c)) {
3832 ec = InvalidCharacterError; 3832 ec = InvalidCharacterError;
3833 return false; 3833 return false;
3834 } 3834 }
3835 nameStart = false; 3835 nameStart = false;
3836 } else { 3836 } else {
3837 if (!isValidNamePart(c)) { 3837 if (!isValidNamePart(c)) {
3838 ec = InvalidCharacterError; 3838 ec = InvalidCharacterError;
3839 return false; 3839 return false;
3840 } 3840 }
3841 } 3841 }
3842 } 3842 }
3843 3843
3844 if (!sawColon) { 3844 if (!sawColon) {
3845 prefix = String(); 3845 prefix = String();
3846 localName = qualifiedName; 3846 localName = qualifiedName;
3847 } else { 3847 } else {
3848 prefix = qualifiedName.substring(0, colonPos); 3848 prefix = qualifiedName.substring(0, colonPos);
3849 if (prefix.isEmpty()) { 3849 if (prefix.isEmpty()) {
3850 ec = NAMESPACE_ERR; 3850 ec = NamespaceError;
3851 return false; 3851 return false;
3852 } 3852 }
3853 localName = qualifiedName.substring(colonPos + 1); 3853 localName = qualifiedName.substring(colonPos + 1);
3854 } 3854 }
3855 3855
3856 if (localName.isEmpty()) { 3856 if (localName.isEmpty()) {
3857 ec = NAMESPACE_ERR; 3857 ec = NamespaceError;
3858 return false; 3858 return false;
3859 } 3859 }
3860 3860
3861 return true; 3861 return true;
3862 } 3862 }
3863 3863
3864 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder) 3864 void Document::setDecoder(PassRefPtr<TextResourceDecoder> decoder)
3865 { 3865 {
3866 m_decoder = decoder; 3866 m_decoder = decoder;
3867 } 3867 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
4046 4046
4047 PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S tring& qualifiedName, ExceptionCode& ec, bool shouldIgnoreNamespaceChecks) 4047 PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S tring& qualifiedName, ExceptionCode& ec, bool shouldIgnoreNamespaceChecks)
4048 { 4048 {
4049 String prefix, localName; 4049 String prefix, localName;
4050 if (!parseQualifiedName(qualifiedName, prefix, localName, ec)) 4050 if (!parseQualifiedName(qualifiedName, prefix, localName, ec))
4051 return 0; 4051 return 0;
4052 4052
4053 QualifiedName qName(prefix, localName, namespaceURI); 4053 QualifiedName qName(prefix, localName, namespaceURI);
4054 4054
4055 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) { 4055 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) {
4056 ec = NAMESPACE_ERR; 4056 ec = NamespaceError;
4057 return 0; 4057 return 0;
4058 } 4058 }
4059 4059
4060 return Attr::create(this, qName, emptyString()); 4060 return Attr::create(this, qName, emptyString());
4061 } 4061 }
4062 4062
4063 const SVGDocumentExtensions* Document::svgExtensions() 4063 const SVGDocumentExtensions* Document::svgExtensions()
4064 { 4064 {
4065 return m_svgExtensions.get(); 4065 return m_svgExtensions.get();
4066 } 4066 }
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
5230 { 5230 {
5231 return DocumentLifecycleNotifier::create(this); 5231 return DocumentLifecycleNotifier::create(this);
5232 } 5232 }
5233 5233
5234 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5234 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5235 { 5235 {
5236 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5236 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5237 } 5237 }
5238 5238
5239 } // namespace WebCore 5239 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/DatasetDOMStringMap.cpp ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698