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

Side by Side Diff: Source/core/xml/parser/XMLDocumentParser.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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/xml/XSLTProcessorLibxslt.cpp ('k') | Source/web/AutofillPopupMenuClient.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) 2000 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2000 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) 4 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 5 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2008 Holger Hans Peter Freyther 7 * Copyright (C) 2008 Holger Hans Peter Freyther
8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 8 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 if (type != XMLErrors::warning) 365 if (type != XMLErrors::warning)
366 m_sawError = true; 366 m_sawError = true;
367 if (type == XMLErrors::fatal) 367 if (type == XMLErrors::fatal)
368 stopParsing(); 368 stopParsing();
369 } 369 }
370 370
371 void XMLDocumentParser::enterText() 371 void XMLDocumentParser::enterText()
372 { 372 {
373 ASSERT(m_bufferedText.size() == 0); 373 ASSERT(m_bufferedText.size() == 0);
374 ASSERT(!m_leafTextNode); 374 ASSERT(!m_leafTextNode);
375 m_leafTextNode = Text::create(m_currentNode->document(), ""); 375 m_leafTextNode = Text::create(&m_currentNode->document(), "");
376 m_currentNode->parserAppendChild(m_leafTextNode.get(), DeprecatedAttachNow); 376 m_currentNode->parserAppendChild(m_leafTextNode.get(), DeprecatedAttachNow);
377 } 377 }
378 378
379 void XMLDocumentParser::exitText() 379 void XMLDocumentParser::exitText()
380 { 380 {
381 if (isStopped()) 381 if (isStopped())
382 return; 382 return;
383 383
384 if (!m_leafTextNode) 384 if (!m_leafTextNode)
385 return; 385 return;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 492
493 bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragm ent* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy) 493 bool XMLDocumentParser::parseDocumentFragment(const String& chunk, DocumentFragm ent* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy)
494 { 494 {
495 if (!chunk.length()) 495 if (!chunk.length())
496 return true; 496 return true;
497 497
498 // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm: 498 // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm:
499 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syn tax.html#xml-fragment-parsing-algorithm 499 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syn tax.html#xml-fragment-parsing-algorithm
500 // For now we have a hack for script/style innerHTML support: 500 // For now we have a hack for script/style innerHTML support:
501 if (contextElement && (contextElement->hasLocalName(HTMLNames::scriptTag) || contextElement->hasLocalName(HTMLNames::styleTag))) { 501 if (contextElement && (contextElement->hasLocalName(HTMLNames::scriptTag) || contextElement->hasLocalName(HTMLNames::styleTag))) {
502 fragment->parserAppendChild(fragment->document()->createTextNode(chunk)) ; 502 fragment->parserAppendChild(fragment->document().createTextNode(chunk));
503 return true; 503 return true;
504 } 504 }
505 505
506 RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, conte xtElement, parserContentPolicy); 506 RefPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, conte xtElement, parserContentPolicy);
507 bool wellFormed = parser->appendFragmentSource(chunk); 507 bool wellFormed = parser->appendFragmentSource(chunk);
508 // Do not call finish(). Current finish() and doEnd() implementations touch the main Document/loader 508 // Do not call finish(). Current finish() and doEnd() implementations touch the main Document/loader
509 // and can cause crashes in the fragment case. 509 // and can cause crashes in the fragment case.
510 parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction. 510 parser->detach(); // Allows ~DocumentParser to assert it was detached before destruction.
511 return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than wellFormed(). 511 return wellFormed; // appendFragmentSource()'s wellFormed is more permissive than wellFormed().
512 } 512 }
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 , m_xmlErrors(document) 771 , m_xmlErrors(document)
772 , m_pendingScript(0) 772 , m_pendingScript(0)
773 , m_scriptStartPosition(TextPosition::belowRangePosition()) 773 , m_scriptStartPosition(TextPosition::belowRangePosition())
774 , m_parsingFragment(false) 774 , m_parsingFragment(false)
775 { 775 {
776 // This is XML being used as a document resource. 776 // This is XML being used as a document resource.
777 UseCounter::count(document, UseCounter::XMLDocument); 777 UseCounter::count(document, UseCounter::XMLDocument);
778 } 778 }
779 779
780 XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent Element, ParserContentPolicy parserContentPolicy) 780 XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent Element, ParserContentPolicy parserContentPolicy)
781 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) 781 : ScriptableDocumentParser(&fragment->document(), parserContentPolicy)
782 , m_view(0) 782 , m_view(0)
783 , m_context(0) 783 , m_context(0)
784 , m_currentNode(fragment) 784 , m_currentNode(fragment)
785 , m_isCurrentlyParsing8BitChunk(false) 785 , m_isCurrentlyParsing8BitChunk(false)
786 , m_sawError(false) 786 , m_sawError(false)
787 , m_sawCSS(false) 787 , m_sawCSS(false)
788 , m_sawXSLTransform(false) 788 , m_sawXSLTransform(false)
789 , m_sawFirstElement(false) 789 , m_sawFirstElement(false)
790 , m_isXHTMLDocument(false) 790 , m_isXHTMLDocument(false)
791 , m_parserPaused(false) 791 , m_parserPaused(false)
792 , m_requestingScript(false) 792 , m_requestingScript(false)
793 , m_finishCalled(false) 793 , m_finishCalled(false)
794 , m_xmlErrors(fragment->document()) 794 , m_xmlErrors(&fragment->document())
795 , m_pendingScript(0) 795 , m_pendingScript(0)
796 , m_scriptStartPosition(TextPosition::belowRangePosition()) 796 , m_scriptStartPosition(TextPosition::belowRangePosition())
797 , m_parsingFragment(true) 797 , m_parsingFragment(true)
798 { 798 {
799 fragment->ref(); 799 fragment->ref();
800 800
801 // Add namespaces based on the parent node 801 // Add namespaces based on the parent node
802 Vector<Element*> elemStack; 802 Vector<Element*> elemStack;
803 while (parentElement) { 803 while (parentElement) {
804 elemStack.append(parentElement); 804 elemStack.append(parentElement);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 if (!prefix.isNull()) 950 if (!prefix.isNull())
951 adjustedURI = m_prefixToNamespaceMap.get(prefix); 951 adjustedURI = m_prefixToNamespaceMap.get(prefix);
952 else 952 else
953 adjustedURI = m_defaultNamespaceURI; 953 adjustedURI = m_defaultNamespaceURI;
954 } 954 }
955 955
956 bool isFirstElement = !m_sawFirstElement; 956 bool isFirstElement = !m_sawFirstElement;
957 m_sawFirstElement = true; 957 m_sawFirstElement = true;
958 958
959 QualifiedName qName(prefix, localName, adjustedURI); 959 QualifiedName qName(prefix, localName, adjustedURI);
960 RefPtr<Element> newElement = m_currentNode->document()->createElement(qName, true); 960 RefPtr<Element> newElement = m_currentNode->document().createElement(qName, true);
961 if (!newElement) { 961 if (!newElement) {
962 stopParsing(); 962 stopParsing();
963 return; 963 return;
964 } 964 }
965 965
966 Vector<Attribute> prefixedAttributes; 966 Vector<Attribute> prefixedAttributes;
967 TrackExceptionState es; 967 TrackExceptionState es;
968 handleNamespaceAttributes(prefixedAttributes, libxmlNamespaces, nbNamespaces , es); 968 handleNamespaceAttributes(prefixedAttributes, libxmlNamespaces, nbNamespaces , es);
969 if (es.hadException()) { 969 if (es.hadException()) {
970 setAttributes(newElement.get(), prefixedAttributes, parserContentPolicy( )); 970 setAttributes(newElement.get(), prefixedAttributes, parserContentPolicy( ));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1126
1127 if (m_parserPaused) { 1127 if (m_parserPaused) {
1128 m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallb ack(target ,data))); 1128 m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallb ack(target ,data)));
1129 return; 1129 return;
1130 } 1130 }
1131 1131
1132 exitText(); 1132 exitText();
1133 1133
1134 // ### handle exceptions 1134 // ### handle exceptions
1135 TrackExceptionState es; 1135 TrackExceptionState es;
1136 RefPtr<ProcessingInstruction> pi = m_currentNode->document()->createProcessi ngInstruction(target, data, es); 1136 RefPtr<ProcessingInstruction> pi = m_currentNode->document().createProcessin gInstruction(target, data, es);
1137 if (es.hadException()) 1137 if (es.hadException())
1138 return; 1138 return;
1139 1139
1140 pi->setCreatedByParser(true); 1140 pi->setCreatedByParser(true);
1141 1141
1142 m_currentNode->parserAppendChild(pi.get(), DeprecatedAttachNow); 1142 m_currentNode->parserAppendChild(pi.get(), DeprecatedAttachNow);
1143 1143
1144 pi->finishParsingChildren(); 1144 pi->finishParsingChildren();
1145 1145
1146 if (pi->isCSS()) 1146 if (pi->isCSS())
1147 m_sawCSS = true; 1147 m_sawCSS = true;
1148 m_sawXSLTransform = !m_sawFirstElement && pi->isXSL(); 1148 m_sawXSLTransform = !m_sawFirstElement && pi->isXSL();
1149 if (m_sawXSLTransform && !document()->transformSourceDocument()) 1149 if (m_sawXSLTransform && !document()->transformSourceDocument())
1150 stopParsing(); 1150 stopParsing();
1151 } 1151 }
1152 1152
1153 void XMLDocumentParser::cdataBlock(const String& text) 1153 void XMLDocumentParser::cdataBlock(const String& text)
1154 { 1154 {
1155 if (isStopped()) 1155 if (isStopped())
1156 return; 1156 return;
1157 1157
1158 if (m_parserPaused) { 1158 if (m_parserPaused) {
1159 m_pendingCallbacks.append(adoptPtr(new PendingCDATABlockCallback(text))) ; 1159 m_pendingCallbacks.append(adoptPtr(new PendingCDATABlockCallback(text))) ;
1160 return; 1160 return;
1161 } 1161 }
1162 1162
1163 exitText(); 1163 exitText();
1164 1164
1165 RefPtr<CDATASection> newNode = CDATASection::create(m_currentNode->document( ), text); 1165 RefPtr<CDATASection> newNode = CDATASection::create(&m_currentNode->document (), text);
1166 m_currentNode->parserAppendChild(newNode.get(), DeprecatedAttachNow); 1166 m_currentNode->parserAppendChild(newNode.get(), DeprecatedAttachNow);
1167 } 1167 }
1168 1168
1169 void XMLDocumentParser::comment(const String& text) 1169 void XMLDocumentParser::comment(const String& text)
1170 { 1170 {
1171 if (isStopped()) 1171 if (isStopped())
1172 return; 1172 return;
1173 1173
1174 if (m_parserPaused) { 1174 if (m_parserPaused) {
1175 m_pendingCallbacks.append(adoptPtr(new PendingCommentCallback(text))); 1175 m_pendingCallbacks.append(adoptPtr(new PendingCommentCallback(text)));
1176 return; 1176 return;
1177 } 1177 }
1178 1178
1179 exitText(); 1179 exitText();
1180 1180
1181 RefPtr<Comment> newNode = Comment::create(m_currentNode->document(), text); 1181 RefPtr<Comment> newNode = Comment::create(&m_currentNode->document(), text);
1182 m_currentNode->parserAppendChild(newNode.get(), DeprecatedAttachNow); 1182 m_currentNode->parserAppendChild(newNode.get(), DeprecatedAttachNow);
1183 } 1183 }
1184 1184
1185 enum StandaloneInfo { 1185 enum StandaloneInfo {
1186 StandaloneUnspecified = -2, 1186 StandaloneUnspecified = -2,
1187 NoXMlDeclaration, 1187 NoXMlDeclaration,
1188 StandaloneNo, 1188 StandaloneNo,
1189 StandaloneYes 1189 StandaloneYes
1190 }; 1190 };
1191 1191
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 sax.initialized = XML_SAX2_MAGIC; 1614 sax.initialized = XML_SAX2_MAGIC;
1615 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state); 1615 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax, &state);
1616 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; 1616 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />";
1617 parseChunk(parser->context(), parseString); 1617 parseChunk(parser->context(), parseString);
1618 finishParsing(parser->context()); 1618 finishParsing(parser->context());
1619 attrsOK = state.gotAttributes; 1619 attrsOK = state.gotAttributes;
1620 return state.attributes; 1620 return state.attributes;
1621 } 1621 }
1622 1622
1623 } // namespace WebCore 1623 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/xml/XSLTProcessorLibxslt.cpp ('k') | Source/web/AutofillPopupMenuClient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698