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

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

Issue 2002063003: Change "bool createdByParser" of createElement() to enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cestate
Patch Set: Add ImportNode Created 4 years, 6 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
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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 } 659 }
660 660
661 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState) 661 Element* Document::createElement(const AtomicString& name, ExceptionState& excep tionState)
662 { 662 {
663 if (!isValidName(name)) { 663 if (!isValidName(name)) {
664 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + name + "') is not a valid name."); 664 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + name + "') is not a valid name.");
665 return nullptr; 665 return nullptr;
666 } 666 }
667 667
668 if (isXHTMLDocument() || isHTMLDocument()) 668 if (isXHTMLDocument() || isHTMLDocument())
669 return HTMLElementFactory::createHTMLElement(convertLocalName(name), *th is, 0, false); 669 return HTMLElementFactory::createHTMLElement(convertLocalName(name), *th is, 0, CreatedByCreateElement);
670 670
671 return Element::create(QualifiedName(nullAtom, name, nullAtom), this); 671 return Element::create(QualifiedName(nullAtom, name, nullAtom), this);
672 } 672 }
673 673
674 Element* Document::createElement(const AtomicString& localName, const AtomicStri ng& typeExtension, ExceptionState& exceptionState) 674 Element* Document::createElement(const AtomicString& localName, const AtomicStri ng& typeExtension, ExceptionState& exceptionState)
675 { 675 {
676 if (!isValidName(localName)) { 676 if (!isValidName(localName)) {
677 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + localName + "') is not a valid name."); 677 exceptionState.throwDOMException(InvalidCharacterError, "The tag name pr ovided ('" + localName + "') is not a valid name.");
678 return nullptr; 678 return nullptr;
679 } 679 }
680 680
681 Element* element; 681 Element* element;
682 682
683 if (CustomElement::shouldCreateCustomElement(*this, localName)) { 683 if (CustomElement::shouldCreateCustomElement(*this, localName)) {
684 element = CustomElement::createCustomElement(*this, localName); 684 element = CustomElement::createCustomElement(*this, localName, CreatedBy CreateElement);
685 } else if (V0CustomElement::isValidName(localName) && registrationContext()) { 685 } else if (V0CustomElement::isValidName(localName) && registrationContext()) {
686 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, convertLocalName(localName), xhtmlNamespaceURI)); 686 element = registrationContext()->createCustomTagElement(*this, Qualified Name(nullAtom, convertLocalName(localName), xhtmlNamespaceURI));
687 } else { 687 } else {
688 element = createElement(localName, exceptionState); 688 element = createElement(localName, exceptionState);
689 if (exceptionState.hadException()) 689 if (exceptionState.hadException())
690 return nullptr; 690 return nullptr;
691 } 691 }
692 692
693 if (!typeExtension.isEmpty()) 693 if (!typeExtension.isEmpty())
694 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(eleme nt, typeExtension); 694 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(eleme nt, typeExtension);
(...skipping 15 matching lines...) Expand all
710 710
711 return qName; 711 return qName;
712 } 712 }
713 713
714 Element* Document::createElementNS(const AtomicString& namespaceURI, const Atomi cString& qualifiedName, ExceptionState& exceptionState) 714 Element* Document::createElementNS(const AtomicString& namespaceURI, const Atomi cString& qualifiedName, ExceptionState& exceptionState)
715 { 715 {
716 QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, excepti onState)); 716 QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, excepti onState));
717 if (qName == QualifiedName::null()) 717 if (qName == QualifiedName::null())
718 return nullptr; 718 return nullptr;
719 719
720 return createElement(qName, false); 720 return createElement(qName, CreatedByCreateElement);
721 } 721 }
722 722
723 Element* Document::createElementNS(const AtomicString& namespaceURI, const Atomi cString& qualifiedName, const AtomicString& typeExtension, ExceptionState& excep tionState) 723 Element* Document::createElementNS(const AtomicString& namespaceURI, const Atomi cString& qualifiedName, const AtomicString& typeExtension, ExceptionState& excep tionState)
724 { 724 {
725 QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, excepti onState)); 725 QualifiedName qName(createQualifiedName(namespaceURI, qualifiedName, excepti onState));
726 if (qName == QualifiedName::null()) 726 if (qName == QualifiedName::null())
727 return nullptr; 727 return nullptr;
728 728
729 Element* element; 729 Element* element;
730 if (CustomElement::shouldCreateCustomElement(*this, qName)) 730 if (CustomElement::shouldCreateCustomElement(*this, qName))
731 element = CustomElement::createCustomElement(*this, qName); 731 element = CustomElement::createCustomElement(*this, qName, CreatedByCrea teElement);
732 else if (V0CustomElement::isValidName(qName.localName()) && registrationCont ext()) 732 else if (V0CustomElement::isValidName(qName.localName()) && registrationCont ext())
733 element = registrationContext()->createCustomTagElement(*this, qName); 733 element = registrationContext()->createCustomTagElement(*this, qName);
734 else 734 else
735 element = createElement(qName, false); 735 element = createElement(qName, CreatedByCreateElement);
736 736
737 if (!typeExtension.isEmpty()) 737 if (!typeExtension.isEmpty())
738 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(eleme nt, typeExtension); 738 V0CustomElementRegistrationContext::setIsAttributeAndTypeExtension(eleme nt, typeExtension);
739 739
740 return element; 740 return element;
741 } 741 }
742 742
743 ScriptValue Document::registerElement(ScriptState* scriptState, const AtomicStri ng& name, const ElementRegistrationOptions& options, ExceptionState& exceptionSt ate, V0CustomElement::NameSet validNames) 743 ScriptValue Document::registerElement(ScriptState* scriptState, const AtomicStri ng& name, const ElementRegistrationOptions& options, ExceptionState& exceptionSt ate, V0CustomElement::NameSet validNames)
744 { 744 {
745 HostsUsingFeatures::countMainWorldOnly(scriptState, *this, HostsUsingFeature s::Feature::DocumentRegisterElement); 745 HostsUsingFeatures::countMainWorldOnly(scriptState, *this, HostsUsingFeature s::Feature::DocumentRegisterElement);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 return DocumentType::create(this, doctype->name(), doctype->publicId(), doctype->systemId()); 876 return DocumentType::create(this, doctype->name(), doctype->publicId(), doctype->systemId());
877 } 877 }
878 case ELEMENT_NODE: { 878 case ELEMENT_NODE: {
879 Element* oldElement = toElement(importedNode); 879 Element* oldElement = toElement(importedNode);
880 // FIXME: The following check might be unnecessary. Is it possible that 880 // FIXME: The following check might be unnecessary. Is it possible that
881 // oldElement has mismatched prefix/namespace? 881 // oldElement has mismatched prefix/namespace?
882 if (!hasValidNamespaceForElements(oldElement->tagQName())) { 882 if (!hasValidNamespaceForElements(oldElement->tagQName())) {
883 exceptionState.throwDOMException(NamespaceError, "The imported node has an invalid namespace."); 883 exceptionState.throwDOMException(NamespaceError, "The imported node has an invalid namespace.");
884 return nullptr; 884 return nullptr;
885 } 885 }
886 Element* newElement = createElement(oldElement->tagQName(), false); 886 Element* newElement = createElement(oldElement->tagQName(), CreatedByImp ortNode);
887 887
888 newElement->cloneDataFromElement(*oldElement); 888 newElement->cloneDataFromElement(*oldElement);
889 889
890 if (deep) { 890 if (deep) {
891 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt ate)) 891 if (!importContainerNodeChildren(oldElement, newElement, exceptionSt ate))
892 return nullptr; 892 return nullptr;
893 if (isHTMLTemplateElement(*oldElement) 893 if (isHTMLTemplateElement(*oldElement)
894 && !ensureTemplateDocument().importContainerNodeChildren( 894 && !ensureTemplateDocument().importContainerNodeChildren(
895 toHTMLTemplateElement(oldElement)->content(), 895 toHTMLTemplateElement(oldElement)->content(),
896 toHTMLTemplateElement(newElement)->content(), exceptionState )) 896 toHTMLTemplateElement(newElement)->content(), exceptionState ))
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 return qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI; 981 return qName.namespaceURI() == XMLNSNames::xmlnsNamespaceURI;
982 return qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI; 982 return qName.namespaceURI() != XMLNSNames::xmlnsNamespaceURI;
983 } 983 }
984 984
985 bool Document::hasValidNamespaceForAttributes(const QualifiedName& qName) 985 bool Document::hasValidNamespaceForAttributes(const QualifiedName& qName)
986 { 986 {
987 return hasValidNamespaceForElements(qName); 987 return hasValidNamespaceForElements(qName);
988 } 988 }
989 989
990 // FIXME: This should really be in a possible ElementFactory class 990 // FIXME: This should really be in a possible ElementFactory class
991 Element* Document::createElement(const QualifiedName& qName, bool createdByParse r) 991 Element* Document::createElement(const QualifiedName& qName, CreateElementFlags flags)
992 { 992 {
993 Element* e = nullptr; 993 Element* e = nullptr;
994 994
995 // FIXME: Use registered namespaces and look up in a hash to find the right factory. 995 // FIXME: Use registered namespaces and look up in a hash to find the right factory.
996 if (qName.namespaceURI() == xhtmlNamespaceURI) 996 if (qName.namespaceURI() == xhtmlNamespaceURI)
997 e = HTMLElementFactory::createHTMLElement(qName.localName(), *this, 0, c reatedByParser); 997 e = HTMLElementFactory::createHTMLElement(qName.localName(), *this, 0, f lags);
998 else if (qName.namespaceURI() == SVGNames::svgNamespaceURI) 998 else if (qName.namespaceURI() == SVGNames::svgNamespaceURI)
999 e = SVGElementFactory::createSVGElement(qName.localName(), *this, create dByParser); 999 e = SVGElementFactory::createSVGElement(qName.localName(), *this, flags) ;
1000 1000
1001 if (e) 1001 if (e)
1002 m_sawElementsInKnownNamespaces = true; 1002 m_sawElementsInKnownNamespaces = true;
1003 else 1003 else
1004 e = Element::create(qName, this); 1004 e = Element::create(qName, this);
1005 1005
1006 if (e->prefix() != qName.prefix()) 1006 if (e->prefix() != qName.prefix())
1007 e->setTagNameForCreateElementNS(qName); 1007 e->setTagNameForCreateElementNS(qName);
1008 1008
1009 DCHECK(qName == e->tagQName()); 1009 DCHECK(qName == e->tagQName());
(...skipping 5009 matching lines...) Expand 10 before | Expand all | Expand 10 after
6019 #ifndef NDEBUG 6019 #ifndef NDEBUG
6020 using namespace blink; 6020 using namespace blink;
6021 void showLiveDocumentInstances() 6021 void showLiveDocumentInstances()
6022 { 6022 {
6023 Document::WeakDocumentSet& set = Document::liveDocumentSet(); 6023 Document::WeakDocumentSet& set = Document::liveDocumentSet();
6024 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 6024 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
6025 for (Document* document : set) 6025 for (Document* document : set)
6026 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data()); 6026 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().get String().utf8().data());
6027 } 6027 }
6028 #endif 6028 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.h ('k') | third_party/WebKit/Source/core/dom/Element.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698