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

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

Issue 108483002: Have Document::parseQualifiedName() deal with AtomicStrings (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years 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
« no previous file with comments | « Source/core/dom/Document.h ('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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, localName, xhtmlNamespaceURI)); 702 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, localName, xhtmlNamespaceURI));
703 else 703 else
704 element = createElement(localName, exceptionState); 704 element = createElement(localName, exceptionState);
705 705
706 if (RuntimeEnabledFeatures::customElementsEnabled() && !typeExtension.isNull () && !typeExtension.isEmpty()) 706 if (RuntimeEnabledFeatures::customElementsEnabled() && !typeExtension.isNull () && !typeExtension.isEmpty())
707 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension); 707 CustomElementRegistrationContext::setIsAttributeAndTypeExtension(element .get(), typeExtension);
708 708
709 return element; 709 return element;
710 } 710 }
711 711
712 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const String& qualifiedName, const AtomicString& typeExtension, ExceptionState& exceptionState) 712 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& typeExtension, ExceptionS tate& exceptionState)
713 { 713 {
714 String prefix, localName; 714 AtomicString prefix, localName;
715 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) 715 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
716 return 0; 716 return 0;
717 717
718 QualifiedName qName(prefix, localName, namespaceURI); 718 QualifiedName qName(prefix, localName, namespaceURI);
719 if (!hasValidNamespaceForElements(qName)) { 719 if (!hasValidNamespaceForElements(qName)) {
720 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); 720 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError);
721 return 0; 721 return 0;
722 } 722 }
723 723
724 RefPtr<Element> element; 724 RefPtr<Element> element;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 } 1012 }
1013 1013
1014 NamedFlowCollection* Document::namedFlows() 1014 NamedFlowCollection* Document::namedFlows()
1015 { 1015 {
1016 if (!m_namedFlows) 1016 if (!m_namedFlows)
1017 m_namedFlows = NamedFlowCollection::create(this); 1017 m_namedFlows = NamedFlowCollection::create(this);
1018 1018
1019 return m_namedFlows.get(); 1019 return m_namedFlows.get();
1020 } 1020 }
1021 1021
1022 PassRefPtr<Element> Document::createElementNS(const String& namespaceURI, const String& qualifiedName, ExceptionState& exceptionState) 1022 PassRefPtr<Element> Document::createElementNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState& exceptionState)
1023 { 1023 {
1024 String prefix, localName; 1024 AtomicString prefix, localName;
1025 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) 1025 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
1026 return 0; 1026 return 0;
1027 1027
1028 QualifiedName qName(prefix, localName, namespaceURI); 1028 QualifiedName qName(prefix, localName, namespaceURI);
1029 if (!hasValidNamespaceForElements(qName)) { 1029 if (!hasValidNamespaceForElements(qName)) {
1030 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); 1030 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError);
1031 return 0; 1031 return 0;
1032 } 1032 }
1033 1033
1034 return createElement(qName, false); 1034 return createElement(qName, false);
(...skipping 2836 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 3871
3872 const UChar* characters = name.characters16(); 3872 const UChar* characters = name.characters16();
3873 3873
3874 if (isValidNameASCII(characters, length)) 3874 if (isValidNameASCII(characters, length))
3875 return true; 3875 return true;
3876 3876
3877 return isValidNameNonASCII(characters, length); 3877 return isValidNameNonASCII(characters, length);
3878 } 3878 }
3879 3879
3880 template<typename CharType> 3880 template<typename CharType>
3881 static bool parseQualifiedNameInternal(const String& qualifiedName, const CharTy pe* characters, unsigned length, String& prefix, String& localName, ExceptionSta te& exceptionState) 3881 static bool parseQualifiedNameInternal(const AtomicString& qualifiedName, const CharType* characters, unsigned length, AtomicString& prefix, AtomicString& local Name, ExceptionState& exceptionState)
3882 { 3882 {
3883 bool nameStart = true; 3883 bool nameStart = true;
3884 bool sawColon = false; 3884 bool sawColon = false;
3885 int colonPos = 0; 3885 int colonPos = 0;
3886 3886
3887 for (unsigned i = 0; i < length;) { 3887 for (unsigned i = 0; i < length;) {
3888 UChar32 c; 3888 UChar32 c;
3889 U16_NEXT(characters, i, length, c) 3889 U16_NEXT(characters, i, length, c)
3890 if (c == ':') { 3890 if (c == ':') {
3891 if (sawColon) { 3891 if (sawColon) {
(...skipping 11 matching lines...) Expand all
3903 nameStart = false; 3903 nameStart = false;
3904 } else { 3904 } else {
3905 if (!isValidNamePart(c)) { 3905 if (!isValidNamePart(c)) {
3906 exceptionState.throwUninformativeAndGenericDOMException(InvalidC haracterError); 3906 exceptionState.throwUninformativeAndGenericDOMException(InvalidC haracterError);
3907 return false; 3907 return false;
3908 } 3908 }
3909 } 3909 }
3910 } 3910 }
3911 3911
3912 if (!sawColon) { 3912 if (!sawColon) {
3913 prefix = String(); 3913 prefix = nullAtom;
3914 localName = qualifiedName; 3914 localName = qualifiedName;
3915 } else { 3915 } else {
3916 prefix = qualifiedName.substring(0, colonPos); 3916 prefix = AtomicString(characters, colonPos);
3917 if (prefix.isEmpty()) { 3917 if (prefix.isEmpty()) {
3918 exceptionState.throwUninformativeAndGenericDOMException(NamespaceErr or); 3918 exceptionState.throwUninformativeAndGenericDOMException(NamespaceErr or);
3919 return false; 3919 return false;
3920 } 3920 }
3921 localName = qualifiedName.substring(colonPos + 1); 3921 int prefixStart = colonPos + 1;
3922 localName = AtomicString(characters + prefixStart, length - prefixStart) ;
3922 } 3923 }
3923 3924
3924 if (localName.isEmpty()) { 3925 if (localName.isEmpty()) {
3925 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); 3926 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError);
3926 return false; 3927 return false;
3927 } 3928 }
3928 3929
3929 return true; 3930 return true;
3930 } 3931 }
3931 3932
3932 bool Document::parseQualifiedName(const String& qualifiedName, String& prefix, S tring& localName, ExceptionState& exceptionState) 3933 bool Document::parseQualifiedName(const AtomicString& qualifiedName, AtomicStrin g& prefix, AtomicString& localName, ExceptionState& exceptionState)
3933 { 3934 {
3934 unsigned length = qualifiedName.length(); 3935 unsigned length = qualifiedName.length();
3935 3936
3936 if (!length) { 3937 if (!length) {
3937 exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacter Error); 3938 exceptionState.throwUninformativeAndGenericDOMException(InvalidCharacter Error);
3938 return false; 3939 return false;
3939 } 3940 }
3940 3941
3941 if (qualifiedName.is8Bit()) 3942 if (qualifiedName.is8Bit())
3942 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, exceptionState); 3943 return parseQualifiedNameInternal(qualifiedName, qualifiedName.character s8(), length, prefix, localName, exceptionState);
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4139 4140
4140 WeakPtr<Document> Document::contextDocument() 4141 WeakPtr<Document> Document::contextDocument()
4141 { 4142 {
4142 if (m_contextDocument) 4143 if (m_contextDocument)
4143 return m_contextDocument; 4144 return m_contextDocument;
4144 if (m_frame) 4145 if (m_frame)
4145 return m_weakFactory.createWeakPtr(); 4146 return m_weakFactory.createWeakPtr();
4146 return WeakPtr<Document>(0); 4147 return WeakPtr<Document>(0);
4147 } 4148 }
4148 4149
4149 PassRefPtr<Attr> Document::createAttribute(const String& name, ExceptionState& e xceptionState) 4150 PassRefPtr<Attr> Document::createAttribute(const AtomicString& name, ExceptionSt ate& exceptionState)
4150 { 4151 {
4151 return createAttributeNS(String(), name, exceptionState, true); 4152 return createAttributeNS(nullAtom, name, exceptionState, true);
4152 } 4153 }
4153 4154
4154 PassRefPtr<Attr> Document::createAttributeNS(const String& namespaceURI, const S tring& qualifiedName, ExceptionState& exceptionState, bool shouldIgnoreNamespace Checks) 4155 PassRefPtr<Attr> Document::createAttributeNS(const AtomicString& namespaceURI, c onst AtomicString& qualifiedName, ExceptionState& exceptionState, bool shouldIgn oreNamespaceChecks)
4155 { 4156 {
4156 String prefix, localName; 4157 AtomicString prefix, localName;
4157 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState)) 4158 if (!parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
4158 return 0; 4159 return 0;
4159 4160
4160 QualifiedName qName(prefix, localName, namespaceURI); 4161 QualifiedName qName(prefix, localName, namespaceURI);
4161 4162
4162 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) { 4163 if (!shouldIgnoreNamespaceChecks && !hasValidNamespaceForAttributes(qName)) {
4163 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError); 4164 exceptionState.throwUninformativeAndGenericDOMException(NamespaceError);
4164 return 0; 4165 return 0;
4165 } 4166 }
4166 4167
(...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after
5210 } 5211 }
5211 5212
5212 FastTextAutosizer* Document::fastTextAutosizer() 5213 FastTextAutosizer* Document::fastTextAutosizer()
5213 { 5214 {
5214 if (!m_fastTextAutosizer && RuntimeEnabledFeatures::fastTextAutosizingEnable d()) 5215 if (!m_fastTextAutosizer && RuntimeEnabledFeatures::fastTextAutosizingEnable d())
5215 m_fastTextAutosizer = FastTextAutosizer::create(this); 5216 m_fastTextAutosizer = FastTextAutosizer::create(this);
5216 return m_fastTextAutosizer.get(); 5217 return m_fastTextAutosizer.get();
5217 } 5218 }
5218 5219
5219 } // namespace WebCore 5220 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Document.h ('k') | Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698