| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 m_leafTextNode->appendData(toString(m_bufferedText.data(), m_bufferedText.si
ze())); | 409 m_leafTextNode->appendData(toString(m_bufferedText.data(), m_bufferedText.si
ze())); |
| 410 m_bufferedText.clear(); | 410 m_bufferedText.clear(); |
| 411 m_leafTextNode = nullptr; | 411 m_leafTextNode = nullptr; |
| 412 | 412 |
| 413 // Mutation event handlers executed by appendData() might detach this parser
. | 413 // Mutation event handlers executed by appendData() might detach this parser
. |
| 414 return !isStopped(); | 414 return !isStopped(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 void XMLDocumentParser::detach() | 417 void XMLDocumentParser::detach() |
| 418 { | 418 { |
| 419 if (m_pendingScript) { |
| 420 m_pendingScript->removeClient(this); |
| 421 m_pendingScript = nullptr; |
| 422 } |
| 419 clearCurrentNodeStack(); | 423 clearCurrentNodeStack(); |
| 420 ScriptableDocumentParser::detach(); | 424 ScriptableDocumentParser::detach(); |
| 421 } | 425 } |
| 422 | 426 |
| 423 void XMLDocumentParser::end() | 427 void XMLDocumentParser::end() |
| 424 { | 428 { |
| 425 TRACE_EVENT0("blink", "XMLDocumentParser::end"); | 429 TRACE_EVENT0("blink", "XMLDocumentParser::end"); |
| 426 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is
called. | 430 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is
called. |
| 427 // I don't believe XMLDocumentParserQt needs doEnd called in the fragment ca
se. | 431 // I don't believe XMLDocumentParserQt needs doEnd called in the fragment ca
se. |
| 428 ASSERT(!m_parsingFragment); | 432 ASSERT(!m_parsingFragment); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 483 |
| 480 void XMLDocumentParser::notifyFinished(Resource* unusedResource) | 484 void XMLDocumentParser::notifyFinished(Resource* unusedResource) |
| 481 { | 485 { |
| 482 ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); | 486 ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); |
| 483 | 487 |
| 484 ScriptSourceCode sourceCode(m_pendingScript.get()); | 488 ScriptSourceCode sourceCode(m_pendingScript.get()); |
| 485 bool errorOccurred = m_pendingScript->errorOccurred(); | 489 bool errorOccurred = m_pendingScript->errorOccurred(); |
| 486 bool wasCanceled = m_pendingScript->wasCanceled(); | 490 bool wasCanceled = m_pendingScript->wasCanceled(); |
| 487 | 491 |
| 488 m_pendingScript->removeClient(this); | 492 m_pendingScript->removeClient(this); |
| 489 m_pendingScript = 0; | 493 m_pendingScript = nullptr; |
| 490 | 494 |
| 491 RefPtrWillBeRawPtr<Element> e = m_scriptElement; | 495 RefPtrWillBeRawPtr<Element> e = m_scriptElement; |
| 492 m_scriptElement = nullptr; | 496 m_scriptElement = nullptr; |
| 493 | 497 |
| 494 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get()); | 498 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e.get()); |
| 495 ASSERT(scriptLoader); | 499 ASSERT(scriptLoader); |
| 496 | 500 |
| 497 // JavaScript can detach this parser, make sure it's kept alive even if | 501 // JavaScript can detach this parser, make sure it's kept alive even if |
| 498 // detached. | 502 // detached. |
| 499 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); | 503 RefPtrWillBeRawPtr<XMLDocumentParser> protect(this); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 return &globalDescriptor; | 670 return &globalDescriptor; |
| 667 | 671 |
| 668 KURL finalURL; | 672 KURL finalURL; |
| 669 RefPtr<SharedBuffer> data; | 673 RefPtr<SharedBuffer> data; |
| 670 | 674 |
| 671 { | 675 { |
| 672 Document* document = XMLDocumentParserScope::currentDocument; | 676 Document* document = XMLDocumentParserScope::currentDocument; |
| 673 XMLDocumentParserScope scope(0); | 677 XMLDocumentParserScope scope(0); |
| 674 // FIXME: We should restore the original global error handler as well. | 678 // FIXME: We should restore the original global error handler as well. |
| 675 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::xml,
ResourceFetcher::defaultResourceOptions()); | 679 FetchRequest request(ResourceRequest(url), FetchInitiatorTypeNames::xml,
ResourceFetcher::defaultResourceOptions()); |
| 676 ResourcePtr<Resource> resource = RawResource::fetchSynchronously(request
, document->fetcher()); | 680 RefPtrWillBeRawPtr<Resource> resource = RawResource::fetchSynchronously(
request, document->fetcher()); |
| 677 if (resource && !resource->errorOccurred()) { | 681 if (resource && !resource->errorOccurred()) { |
| 678 data = resource->resourceBuffer(); | 682 data = resource->resourceBuffer(); |
| 679 finalURL = resource->response().url(); | 683 finalURL = resource->response().url(); |
| 680 } | 684 } |
| 681 } | 685 } |
| 682 | 686 |
| 683 // We have to check the URL again after the load to catch redirects. | 687 // We have to check the URL again after the load to catch redirects. |
| 684 // See <https://bugs.webkit.org/show_bug.cgi?id=21963>. | 688 // See <https://bugs.webkit.org/show_bug.cgi?id=21963>. |
| 685 if (!shouldAllowExternalLoad(finalURL)) | 689 if (!shouldAllowExternalLoad(finalURL)) |
| 686 return &globalDescriptor; | 690 return &globalDescriptor; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 , m_isCurrentlyParsing8BitChunk(false) | 799 , m_isCurrentlyParsing8BitChunk(false) |
| 796 , m_sawError(false) | 800 , m_sawError(false) |
| 797 , m_sawCSS(false) | 801 , m_sawCSS(false) |
| 798 , m_sawXSLTransform(false) | 802 , m_sawXSLTransform(false) |
| 799 , m_sawFirstElement(false) | 803 , m_sawFirstElement(false) |
| 800 , m_isXHTMLDocument(false) | 804 , m_isXHTMLDocument(false) |
| 801 , m_parserPaused(false) | 805 , m_parserPaused(false) |
| 802 , m_requestingScript(false) | 806 , m_requestingScript(false) |
| 803 , m_finishCalled(false) | 807 , m_finishCalled(false) |
| 804 , m_xmlErrors(&document) | 808 , m_xmlErrors(&document) |
| 805 , m_pendingScript(0) | |
| 806 , m_scriptStartPosition(TextPosition::belowRangePosition()) | 809 , m_scriptStartPosition(TextPosition::belowRangePosition()) |
| 807 , m_parsingFragment(false) | 810 , m_parsingFragment(false) |
| 808 { | 811 { |
| 809 // This is XML being used as a document resource. | 812 // This is XML being used as a document resource. |
| 810 if (frameView && document.isXMLDocument()) | 813 if (frameView && document.isXMLDocument()) |
| 811 UseCounter::count(document, UseCounter::XMLDocument); | 814 UseCounter::count(document, UseCounter::XMLDocument); |
| 812 } | 815 } |
| 813 | 816 |
| 814 XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
Element, ParserContentPolicy parserContentPolicy) | 817 XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
Element, ParserContentPolicy parserContentPolicy) |
| 815 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) | 818 : ScriptableDocumentParser(fragment->document(), parserContentPolicy) |
| 816 , m_hasView(false) | 819 , m_hasView(false) |
| 817 , m_context(nullptr) | 820 , m_context(nullptr) |
| 818 , m_currentNode(fragment) | 821 , m_currentNode(fragment) |
| 819 , m_isCurrentlyParsing8BitChunk(false) | 822 , m_isCurrentlyParsing8BitChunk(false) |
| 820 , m_sawError(false) | 823 , m_sawError(false) |
| 821 , m_sawCSS(false) | 824 , m_sawCSS(false) |
| 822 , m_sawXSLTransform(false) | 825 , m_sawXSLTransform(false) |
| 823 , m_sawFirstElement(false) | 826 , m_sawFirstElement(false) |
| 824 , m_isXHTMLDocument(false) | 827 , m_isXHTMLDocument(false) |
| 825 , m_parserPaused(false) | 828 , m_parserPaused(false) |
| 826 , m_requestingScript(false) | 829 , m_requestingScript(false) |
| 827 , m_finishCalled(false) | 830 , m_finishCalled(false) |
| 828 , m_xmlErrors(&fragment->document()) | 831 , m_xmlErrors(&fragment->document()) |
| 829 , m_pendingScript(0) | |
| 830 , m_scriptStartPosition(TextPosition::belowRangePosition()) | 832 , m_scriptStartPosition(TextPosition::belowRangePosition()) |
| 831 , m_parsingFragment(true) | 833 , m_parsingFragment(true) |
| 832 { | 834 { |
| 833 #if !ENABLE(OILPAN) | 835 #if !ENABLE(OILPAN) |
| 834 fragment->ref(); | 836 fragment->ref(); |
| 835 #endif | 837 #endif |
| 836 | 838 |
| 837 // Add namespaces based on the parent node | 839 // Add namespaces based on the parent node |
| 838 WillBeHeapVector<RawPtrWillBeMember<Element>> elemStack; | 840 WillBeHeapVector<RawPtrWillBeMember<Element>> elemStack; |
| 839 while (parentElement) { | 841 while (parentElement) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 866 | 868 |
| 867 XMLParserContext::~XMLParserContext() | 869 XMLParserContext::~XMLParserContext() |
| 868 { | 870 { |
| 869 if (m_context->myDoc) | 871 if (m_context->myDoc) |
| 870 xmlFreeDoc(m_context->myDoc); | 872 xmlFreeDoc(m_context->myDoc); |
| 871 xmlFreeParserCtxt(m_context); | 873 xmlFreeParserCtxt(m_context); |
| 872 } | 874 } |
| 873 | 875 |
| 874 XMLDocumentParser::~XMLDocumentParser() | 876 XMLDocumentParser::~XMLDocumentParser() |
| 875 { | 877 { |
| 878 ASSERT(!m_pendingScript); |
| 876 #if !ENABLE(OILPAN) | 879 #if !ENABLE(OILPAN) |
| 877 // The XMLDocumentParser will always be detached before being destroyed. | 880 // The XMLDocumentParser will always be detached before being destroyed. |
| 878 ASSERT(m_currentNodeStack.isEmpty()); | 881 ASSERT(m_currentNodeStack.isEmpty()); |
| 879 ASSERT(!m_currentNode); | 882 ASSERT(!m_currentNode); |
| 880 #endif | 883 #endif |
| 881 | |
| 882 // FIXME: m_pendingScript handling should be moved into XMLDocumentParser.cp
p! | |
| 883 if (m_pendingScript) | |
| 884 m_pendingScript->removeClient(this); | |
| 885 } | 884 } |
| 886 | 885 |
| 887 DEFINE_TRACE(XMLDocumentParser) | 886 DEFINE_TRACE(XMLDocumentParser) |
| 888 { | 887 { |
| 889 visitor->trace(m_currentNode); | 888 visitor->trace(m_currentNode); |
| 890 #if ENABLE(OILPAN) | 889 #if ENABLE(OILPAN) |
| 891 visitor->trace(m_currentNodeStack); | 890 visitor->trace(m_currentNodeStack); |
| 892 #endif | 891 #endif |
| 893 visitor->trace(m_leafTextNode); | 892 visitor->trace(m_leafTextNode); |
| 894 visitor->trace(m_xmlErrors); | 893 visitor->trace(m_xmlErrors); |
| 894 visitor->trace(m_pendingScript); |
| 895 visitor->trace(m_scriptElement); | 895 visitor->trace(m_scriptElement); |
| 896 ScriptableDocumentParser::trace(visitor); | 896 ScriptableDocumentParser::trace(visitor); |
| 897 } | 897 } |
| 898 | 898 |
| 899 void XMLDocumentParser::doWrite(const String& parseString) | 899 void XMLDocumentParser::doWrite(const String& parseString) |
| 900 { | 900 { |
| 901 TRACE_EVENT0("blink", "XMLDocumentParser::doWrite"); | 901 TRACE_EVENT0("blink", "XMLDocumentParser::doWrite"); |
| 902 ASSERT(!isDetached()); | 902 ASSERT(!isDetached()); |
| 903 if (!m_context) | 903 if (!m_context) |
| 904 initializeParserContext(); | 904 initializeParserContext(); |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 sax.initialized = XML_SAX2_MAGIC; | 1698 sax.initialized = XML_SAX2_MAGIC; |
| 1699 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); | 1699 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); |
| 1700 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; | 1700 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; |
| 1701 parseChunk(parser->context(), parseString); | 1701 parseChunk(parser->context(), parseString); |
| 1702 finishParsing(parser->context()); | 1702 finishParsing(parser->context()); |
| 1703 attrsOK = state.gotAttributes; | 1703 attrsOK = state.gotAttributes; |
| 1704 return state.attributes; | 1704 return state.attributes; |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 } // namespace blink | 1707 } // namespace blink |
| OLD | NEW |