| OLD | NEW |
| 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, 2014 Apple Inc. All rights reserved. | 3 * Copyright (C) 2005, 2006, 2008, 2014 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 if (isStopped() || m_sawXSLTransform) | 368 if (isStopped() || m_sawXSLTransform) |
| 369 return; | 369 return; |
| 370 | 370 |
| 371 if (m_parserPaused) { | 371 if (m_parserPaused) { |
| 372 m_pendingSrc.append(source); | 372 m_pendingSrc.append(source); |
| 373 return; | 373 return; |
| 374 } | 374 } |
| 375 | 375 |
| 376 // JavaScript can detach the parser. Make sure this is not released | 376 // JavaScript can detach the parser. Make sure this is not released |
| 377 // before the end of this method. | 377 // before the end of this method. |
| 378 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 378 RawPtr<XMLDocumentParser> protect(this); |
| 379 | 379 |
| 380 doWrite(source.toString()); | 380 doWrite(source.toString()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* forma
ttedMessage, TextPosition position) | 383 void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* forma
ttedMessage, TextPosition position) |
| 384 { | 384 { |
| 385 m_xmlErrors.handleError(type, formattedMessage, position); | 385 m_xmlErrors.handleError(type, formattedMessage, position); |
| 386 if (type != XMLErrors::ErrorTypeWarning) | 386 if (type != XMLErrors::ErrorTypeWarning) |
| 387 m_sawError = true; | 387 m_sawError = true; |
| 388 if (type == XMLErrors::ErrorTypeFatal) | 388 if (type == XMLErrors::ErrorTypeFatal) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 document()->finishedParsing(); | 455 document()->finishedParsing(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void XMLDocumentParser::finish() | 458 void XMLDocumentParser::finish() |
| 459 { | 459 { |
| 460 // FIXME: We should ASSERT(!m_parserStopped) here, since it does not | 460 // FIXME: We should ASSERT(!m_parserStopped) here, since it does not |
| 461 // makes sense to call any methods on DocumentParser once it's been stopped. | 461 // makes sense to call any methods on DocumentParser once it's been stopped. |
| 462 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. | 462 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. |
| 463 | 463 |
| 464 // flush may ending up executing arbitrary script, and possibly detach the p
arser. | 464 // flush may ending up executing arbitrary script, and possibly detach the p
arser. |
| 465 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 465 RawPtr<XMLDocumentParser> protect(this); |
| 466 flush(); | 466 flush(); |
| 467 if (isDetached()) | 467 if (isDetached()) |
| 468 return; | 468 return; |
| 469 | 469 |
| 470 if (m_parserPaused) | 470 if (m_parserPaused) |
| 471 m_finishCalled = true; | 471 m_finishCalled = true; |
| 472 else | 472 else |
| 473 end(); | 473 end(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 void XMLDocumentParser::insertErrorMessageBlock() | 476 void XMLDocumentParser::insertErrorMessageBlock() |
| 477 { | 477 { |
| 478 m_xmlErrors.insertErrorMessageBlock(); | 478 m_xmlErrors.insertErrorMessageBlock(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 void XMLDocumentParser::notifyFinished(Resource* unusedResource) | 481 void XMLDocumentParser::notifyFinished(Resource* unusedResource) |
| 482 { | 482 { |
| 483 ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); | 483 ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); |
| 484 | 484 |
| 485 ScriptSourceCode sourceCode(m_pendingScript.get()); | 485 ScriptSourceCode sourceCode(m_pendingScript.get()); |
| 486 bool errorOccurred = m_pendingScript->errorOccurred(); | 486 bool errorOccurred = m_pendingScript->errorOccurred(); |
| 487 bool wasCanceled = m_pendingScript->wasCanceled(); | 487 bool wasCanceled = m_pendingScript->wasCanceled(); |
| 488 | 488 |
| 489 m_pendingScript->removeClient(this); | 489 m_pendingScript->removeClient(this); |
| 490 m_pendingScript = nullptr; | 490 m_pendingScript = nullptr; |
| 491 | 491 |
| 492 RefPtrWillBeRawPtr<Element> e = m_scriptElement; | 492 RawPtr<Element> e = m_scriptElement; |
| 493 m_scriptElement = nullptr; | 493 m_scriptElement = nullptr; |
| 494 | 494 |
| 495 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get()); | 495 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get()); |
| 496 ASSERT(scriptLoader); | 496 ASSERT(scriptLoader); |
| 497 | 497 |
| 498 // JavaScript can detach this parser, make sure it's kept alive even if | 498 // JavaScript can detach this parser, make sure it's kept alive even if |
| 499 // detached. | 499 // detached. |
| 500 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 500 RawPtr<XMLDocumentParser> protect(this); |
| 501 | 501 |
| 502 if (errorOccurred) { | 502 if (errorOccurred) { |
| 503 scriptLoader->dispatchErrorEvent(); | 503 scriptLoader->dispatchErrorEvent(); |
| 504 } else if (!wasCanceled) { | 504 } else if (!wasCanceled) { |
| 505 if (!scriptLoader->executeScript(sourceCode)) | 505 if (!scriptLoader->executeScript(sourceCode)) |
| 506 scriptLoader->dispatchErrorEvent(); | 506 scriptLoader->dispatchErrorEvent(); |
| 507 else | 507 else |
| 508 scriptLoader->dispatchLoadEvent(); | 508 scriptLoader->dispatchLoadEvent(); |
| 509 } | 509 } |
| 510 | 510 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 531 return true; | 531 return true; |
| 532 | 532 |
| 533 // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm: | 533 // FIXME: We need to implement the HTML5 XML Fragment parsing algorithm: |
| 534 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syn
tax.html#xml-fragment-parsing-algorithm | 534 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-xhtml-syn
tax.html#xml-fragment-parsing-algorithm |
| 535 // For now we have a hack for script/style innerHTML support: | 535 // For now we have a hack for script/style innerHTML support: |
| 536 if (contextElement && (contextElement->hasLocalName(scriptTag.localName()) |
| contextElement->hasLocalName(styleTag.localName()))) { | 536 if (contextElement && (contextElement->hasLocalName(scriptTag.localName()) |
| contextElement->hasLocalName(styleTag.localName()))) { |
| 537 fragment->parserAppendChild(fragment->document().createTextNode(chunk)); | 537 fragment->parserAppendChild(fragment->document().createTextNode(chunk)); |
| 538 return true; | 538 return true; |
| 539 } | 539 } |
| 540 | 540 |
| 541 RefPtrWillBeRawPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fra
gment, contextElement, parserContentPolicy); | 541 RawPtr<XMLDocumentParser> parser = XMLDocumentParser::create(fragment, conte
xtElement, parserContentPolicy); |
| 542 bool wellFormed = parser->appendFragmentSource(chunk); | 542 bool wellFormed = parser->appendFragmentSource(chunk); |
| 543 | 543 |
| 544 // Do not call finish(). Current finish() and doEnd() implementations touch | 544 // Do not call finish(). Current finish() and doEnd() implementations touch |
| 545 // the main Document/loader and can cause crashes in the fragment case. | 545 // the main Document/loader and can cause crashes in the fragment case. |
| 546 | 546 |
| 547 // Allows ~DocumentParser to assert it was detached before destruction. | 547 // Allows ~DocumentParser to assert it was detached before destruction. |
| 548 parser->detach(); | 548 parser->detach(); |
| 549 // appendFragmentSource()'s wellFormed is more permissive than wellFormed(). | 549 // appendFragmentSource()'s wellFormed is more permissive than wellFormed(). |
| 550 return wellFormed; | 550 return wellFormed; |
| 551 } | 551 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 return &globalDescriptor; | 667 return &globalDescriptor; |
| 668 | 668 |
| 669 KURL finalURL; | 669 KURL finalURL; |
| 670 RefPtr<SharedBuffer> data; | 670 RefPtr<SharedBuffer> data; |
| 671 | 671 |
| 672 { | 672 { |
| 673 Document* document = XMLDocumentParserScope::currentDocument; | 673 Document* document = XMLDocumentParserScope::currentDocument; |
| 674 XMLDocumentParserScope scope(0); | 674 XMLDocumentParserScope scope(0); |
| 675 // FIXME: We should restore the original global error handler as well. | 675 // FIXME: We should restore the original global error handler as well. |
| 676 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::xml,
ResourceFetcher::defaultResourceOptions()); | 676 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::xml,
ResourceFetcher::defaultResourceOptions()); |
| 677 RefPtrWillBeRawPtr<Resource> resource = RawResource::fetchSynchronously(
request, document->fetcher()); | 677 RawPtr<Resource> resource = RawResource::fetchSynchronously(request, doc
ument->fetcher()); |
| 678 if (resource && !resource->errorOccurred()) { | 678 if (resource && !resource->errorOccurred()) { |
| 679 data = resource->resourceBuffer(); | 679 data = resource->resourceBuffer(); |
| 680 finalURL = resource->response().url(); | 680 finalURL = resource->response().url(); |
| 681 } | 681 } |
| 682 } | 682 } |
| 683 | 683 |
| 684 // We have to check the URL again after the load to catch redirects. | 684 // We have to check the URL again after the load to catch redirects. |
| 685 // See <https://bugs.webkit.org/show_bug.cgi?id=21963>. | 685 // See <https://bugs.webkit.org/show_bug.cgi?id=21963>. |
| 686 if (!shouldAllowExternalLoad(finalURL)) | 686 if (!shouldAllowExternalLoad(finalURL)) |
| 687 return &globalDescriptor; | 687 return &globalDescriptor; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 , m_finishCalled(false) | 827 , m_finishCalled(false) |
| 828 , m_xmlErrors(&fragment->document()) | 828 , m_xmlErrors(&fragment->document()) |
| 829 , m_scriptStartPosition(TextPosition::belowRangePosition()) | 829 , m_scriptStartPosition(TextPosition::belowRangePosition()) |
| 830 , m_parsingFragment(true) | 830 , m_parsingFragment(true) |
| 831 { | 831 { |
| 832 #if !ENABLE(OILPAN) | 832 #if !ENABLE(OILPAN) |
| 833 fragment->ref(); | 833 fragment->ref(); |
| 834 #endif | 834 #endif |
| 835 | 835 |
| 836 // Add namespaces based on the parent node | 836 // Add namespaces based on the parent node |
| 837 WillBeHeapVector<RawPtrWillBeMember<Element>> elemStack; | 837 HeapVector<Member<Element>> elemStack; |
| 838 while (parentElement) { | 838 while (parentElement) { |
| 839 elemStack.append(parentElement); | 839 elemStack.append(parentElement); |
| 840 | 840 |
| 841 Element* grandParentElement = parentElement->parentElement(); | 841 Element* grandParentElement = parentElement->parentElement(); |
| 842 if (!grandParentElement) | 842 if (!grandParentElement) |
| 843 break; | 843 break; |
| 844 parentElement = grandParentElement; | 844 parentElement = grandParentElement; |
| 845 } | 845 } |
| 846 | 846 |
| 847 if (elemStack.isEmpty()) | 847 if (elemStack.isEmpty()) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 initializeParserContext(); | 901 initializeParserContext(); |
| 902 | 902 |
| 903 // Protect the libxml context from deletion during a callback | 903 // Protect the libxml context from deletion during a callback |
| 904 RefPtr<XMLParserContext> context = m_context; | 904 RefPtr<XMLParserContext> context = m_context; |
| 905 | 905 |
| 906 // libXML throws an error if you try to switch the encoding for an empty | 906 // libXML throws an error if you try to switch the encoding for an empty |
| 907 // string. | 907 // string. |
| 908 if (parseString.length()) { | 908 if (parseString.length()) { |
| 909 // JavaScript may cause the parser to detach during parseChunk | 909 // JavaScript may cause the parser to detach during parseChunk |
| 910 // keep this alive until this function is done. | 910 // keep this alive until this function is done. |
| 911 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 911 RawPtr<XMLDocumentParser> protect(this); |
| 912 | 912 |
| 913 XMLDocumentParserScope scope(document()); | 913 XMLDocumentParserScope scope(document()); |
| 914 TemporaryChange<bool> encodingScope(m_isCurrentlyParsing8BitChunk, parse
String.is8Bit()); | 914 TemporaryChange<bool> encodingScope(m_isCurrentlyParsing8BitChunk, parse
String.is8Bit()); |
| 915 parseChunk(context->context(), parseString); | 915 parseChunk(context->context(), parseString); |
| 916 | 916 |
| 917 // JavaScript (which may be run under the parseChunk callstack) may | 917 // JavaScript (which may be run under the parseChunk callstack) may |
| 918 // cause the parser to be stopped or detached. | 918 // cause the parser to be stopped or detached. |
| 919 if (isStopped()) | 919 if (isStopped()) |
| 920 return; | 920 return; |
| 921 } | 921 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 if (!prefix.isNull()) | 1015 if (!prefix.isNull()) |
| 1016 adjustedURI = m_prefixToNamespaceMap.get(prefix); | 1016 adjustedURI = m_prefixToNamespaceMap.get(prefix); |
| 1017 else | 1017 else |
| 1018 adjustedURI = m_defaultNamespaceURI; | 1018 adjustedURI = m_defaultNamespaceURI; |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 bool isFirstElement = !m_sawFirstElement; | 1021 bool isFirstElement = !m_sawFirstElement; |
| 1022 m_sawFirstElement = true; | 1022 m_sawFirstElement = true; |
| 1023 | 1023 |
| 1024 QualifiedName qName(prefix, localName, adjustedURI); | 1024 QualifiedName qName(prefix, localName, adjustedURI); |
| 1025 RefPtrWillBeRawPtr<Element> newElement = m_currentNode->document().createEle
ment(qName, true); | 1025 RawPtr<Element> newElement = m_currentNode->document().createElement(qName,
true); |
| 1026 if (!newElement) { | 1026 if (!newElement) { |
| 1027 stopParsing(); | 1027 stopParsing(); |
| 1028 return; | 1028 return; |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 Vector<Attribute> prefixedAttributes; | 1031 Vector<Attribute> prefixedAttributes; |
| 1032 TrackExceptionState exceptionState; | 1032 TrackExceptionState exceptionState; |
| 1033 handleNamespaceAttributes(prefixedAttributes, libxmlNamespaces, nbNamespaces
, exceptionState); | 1033 handleNamespaceAttributes(prefixedAttributes, libxmlNamespaces, nbNamespaces
, exceptionState); |
| 1034 if (exceptionState.hadException()) { | 1034 if (exceptionState.hadException()) { |
| 1035 setAttributes(newElement.get(), prefixedAttributes, getParserContentPoli
cy()); | 1035 setAttributes(newElement.get(), prefixedAttributes, getParserContentPoli
cy()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 if (isStopped()) | 1079 if (isStopped()) |
| 1080 return; | 1080 return; |
| 1081 | 1081 |
| 1082 if (m_parserPaused) { | 1082 if (m_parserPaused) { |
| 1083 m_pendingCallbacks.append(adoptPtr(new PendingEndElementNSCallback(m_scr
iptStartPosition))); | 1083 m_pendingCallbacks.append(adoptPtr(new PendingEndElementNSCallback(m_scr
iptStartPosition))); |
| 1084 return; | 1084 return; |
| 1085 } | 1085 } |
| 1086 | 1086 |
| 1087 // JavaScript can detach the parser. Make sure this is not released before | 1087 // JavaScript can detach the parser. Make sure this is not released before |
| 1088 // the end of this method. | 1088 // the end of this method. |
| 1089 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 1089 RawPtr<XMLDocumentParser> protect(this); |
| 1090 | 1090 |
| 1091 if (!updateLeafTextNode()) | 1091 if (!updateLeafTextNode()) |
| 1092 return; | 1092 return; |
| 1093 | 1093 |
| 1094 RefPtrWillBeRawPtr<ContainerNode> n = m_currentNode; | 1094 RawPtr<ContainerNode> n = m_currentNode; |
| 1095 if (m_currentNode->isElementNode()) | 1095 if (m_currentNode->isElementNode()) |
| 1096 toElement(n.get())->finishParsingChildren(); | 1096 toElement(n.get())->finishParsingChildren(); |
| 1097 | 1097 |
| 1098 if (!scriptingContentIsAllowed(getParserContentPolicy()) && n->isElementNode
() && toScriptLoaderIfPossible(toElement(n))) { | 1098 if (!scriptingContentIsAllowed(getParserContentPolicy()) && n->isElementNode
() && toScriptLoaderIfPossible(toElement(n))) { |
| 1099 popCurrentNode(); | 1099 popCurrentNode(); |
| 1100 n->remove(IGNORE_EXCEPTION); | 1100 n->remove(IGNORE_EXCEPTION); |
| 1101 return; | 1101 return; |
| 1102 } | 1102 } |
| 1103 | 1103 |
| 1104 if (!n->isElementNode() || !m_hasView) { | 1104 if (!n->isElementNode() || !m_hasView) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1198 if (m_parserPaused) { | 1198 if (m_parserPaused) { |
| 1199 m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallb
ack(target, data))); | 1199 m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallb
ack(target, data))); |
| 1200 return; | 1200 return; |
| 1201 } | 1201 } |
| 1202 | 1202 |
| 1203 if (!updateLeafTextNode()) | 1203 if (!updateLeafTextNode()) |
| 1204 return; | 1204 return; |
| 1205 | 1205 |
| 1206 // ### handle exceptions | 1206 // ### handle exceptions |
| 1207 TrackExceptionState exceptionState; | 1207 TrackExceptionState exceptionState; |
| 1208 RefPtrWillBeRawPtr<ProcessingInstruction> pi = m_currentNode->document().cre
ateProcessingInstruction(target, data, exceptionState); | 1208 RawPtr<ProcessingInstruction> pi = m_currentNode->document().createProcessin
gInstruction(target, data, exceptionState); |
| 1209 if (exceptionState.hadException()) | 1209 if (exceptionState.hadException()) |
| 1210 return; | 1210 return; |
| 1211 | 1211 |
| 1212 m_currentNode->parserAppendChild(pi.get()); | 1212 m_currentNode->parserAppendChild(pi.get()); |
| 1213 | 1213 |
| 1214 if (pi->isCSS()) | 1214 if (pi->isCSS()) |
| 1215 m_sawCSS = true; | 1215 m_sawCSS = true; |
| 1216 | 1216 |
| 1217 if (!RuntimeEnabledFeatures::xsltEnabled()) | 1217 if (!RuntimeEnabledFeatures::xsltEnabled()) |
| 1218 return; | 1218 return; |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 sax.initialized = XML_SAX2_MAGIC; | 1684 sax.initialized = XML_SAX2_MAGIC; |
| 1685 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); | 1685 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); |
| 1686 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; | 1686 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; |
| 1687 parseChunk(parser->context(), parseString); | 1687 parseChunk(parser->context(), parseString); |
| 1688 finishParsing(parser->context()); | 1688 finishParsing(parser->context()); |
| 1689 attrsOK = state.gotAttributes; | 1689 attrsOK = state.gotAttributes; |
| 1690 return state.attributes; | 1690 return state.attributes; |
| 1691 } | 1691 } |
| 1692 | 1692 |
| 1693 } // namespace blink | 1693 } // namespace blink |
| OLD | NEW |