| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #include "core/xml/parser/XMLDocumentParserScope.h" | 60 #include "core/xml/parser/XMLDocumentParserScope.h" |
| 61 #include "core/xml/parser/XMLParserInput.h" | 61 #include "core/xml/parser/XMLParserInput.h" |
| 62 #include "platform/RuntimeEnabledFeatures.h" | 62 #include "platform/RuntimeEnabledFeatures.h" |
| 63 #include "platform/SharedBuffer.h" | 63 #include "platform/SharedBuffer.h" |
| 64 #include "platform/TraceEvent.h" | 64 #include "platform/TraceEvent.h" |
| 65 #include "platform/network/ResourceError.h" | 65 #include "platform/network/ResourceError.h" |
| 66 #include "platform/network/ResourceRequest.h" | 66 #include "platform/network/ResourceRequest.h" |
| 67 #include "platform/network/ResourceResponse.h" | 67 #include "platform/network/ResourceResponse.h" |
| 68 #include "platform/v8_inspector/public/ConsoleTypes.h" | 68 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 69 #include "platform/weborigin/SecurityOrigin.h" | 69 #include "platform/weborigin/SecurityOrigin.h" |
| 70 #include "wtf/PtrUtil.h" | |
| 71 #include "wtf/StringExtras.h" | 70 #include "wtf/StringExtras.h" |
| 72 #include "wtf/TemporaryChange.h" | 71 #include "wtf/TemporaryChange.h" |
| 73 #include "wtf/Threading.h" | 72 #include "wtf/Threading.h" |
| 74 #include "wtf/Vector.h" | 73 #include "wtf/Vector.h" |
| 75 #include "wtf/text/UTF8.h" | 74 #include "wtf/text/UTF8.h" |
| 76 #include <libxml/catalog.h> | 75 #include <libxml/catalog.h> |
| 77 #include <libxml/parser.h> | 76 #include <libxml/parser.h> |
| 78 #include <libxml/parserInternals.h> | 77 #include <libxml/parserInternals.h> |
| 79 #include <libxslt/xslt.h> | 78 #include <libxslt/xslt.h> |
| 80 #include <memory> | |
| 81 | 79 |
| 82 namespace blink { | 80 namespace blink { |
| 83 | 81 |
| 84 using namespace HTMLNames; | 82 using namespace HTMLNames; |
| 85 | 83 |
| 86 // FIXME: HTMLConstructionSite has a limit of 512, should these match? | 84 // FIXME: HTMLConstructionSite has a limit of 512, should these match? |
| 87 static const unsigned maxXMLTreeDepth = 5000; | 85 static const unsigned maxXMLTreeDepth = 5000; |
| 88 | 86 |
| 89 static inline String toString(const xmlChar* string, size_t length) | 87 static inline String toString(const xmlChar* string, size_t length) |
| 90 { | 88 { |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 } | 953 } |
| 956 | 954 |
| 957 void XMLDocumentParser::startElementNs(const AtomicString& localName, const Atom
icString& prefix, const AtomicString& uri, int nbNamespaces, | 955 void XMLDocumentParser::startElementNs(const AtomicString& localName, const Atom
icString& prefix, const AtomicString& uri, int nbNamespaces, |
| 958 const xmlChar** libxmlNamespaces, int nbAttributes, int nbDefaulted, const x
mlChar** libxmlAttributes) | 956 const xmlChar** libxmlNamespaces, int nbAttributes, int nbDefaulted, const x
mlChar** libxmlAttributes) |
| 959 { | 957 { |
| 960 if (isStopped()) | 958 if (isStopped()) |
| 961 return; | 959 return; |
| 962 | 960 |
| 963 if (m_parserPaused) { | 961 if (m_parserPaused) { |
| 964 m_scriptStartPosition = textPosition(); | 962 m_scriptStartPosition = textPosition(); |
| 965 m_pendingCallbacks.append(wrapUnique(new PendingStartElementNSCallback(l
ocalName, prefix, uri, nbNamespaces, libxmlNamespaces, | 963 m_pendingCallbacks.append(adoptPtr(new PendingStartElementNSCallback(loc
alName, prefix, uri, nbNamespaces, libxmlNamespaces, |
| 966 nbAttributes, nbDefaulted, libxmlAttributes))); | 964 nbAttributes, nbDefaulted, libxmlAttributes))); |
| 967 return; | 965 return; |
| 968 } | 966 } |
| 969 | 967 |
| 970 if (!updateLeafTextNode()) | 968 if (!updateLeafTextNode()) |
| 971 return; | 969 return; |
| 972 | 970 |
| 973 AtomicString adjustedURI = uri; | 971 AtomicString adjustedURI = uri; |
| 974 if (m_parsingFragment && adjustedURI.isNull()) { | 972 if (m_parsingFragment && adjustedURI.isNull()) { |
| 975 if (!prefix.isNull()) | 973 if (!prefix.isNull()) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 // runScriptsAtDocumentElementAvailable might have invalidated the docum
ent. | 1032 // runScriptsAtDocumentElementAvailable might have invalidated the docum
ent. |
| 1035 } | 1033 } |
| 1036 } | 1034 } |
| 1037 | 1035 |
| 1038 void XMLDocumentParser::endElementNs() | 1036 void XMLDocumentParser::endElementNs() |
| 1039 { | 1037 { |
| 1040 if (isStopped()) | 1038 if (isStopped()) |
| 1041 return; | 1039 return; |
| 1042 | 1040 |
| 1043 if (m_parserPaused) { | 1041 if (m_parserPaused) { |
| 1044 m_pendingCallbacks.append(wrapUnique(new PendingEndElementNSCallback(m_s
criptStartPosition))); | 1042 m_pendingCallbacks.append(adoptPtr(new PendingEndElementNSCallback(m_scr
iptStartPosition))); |
| 1045 return; | 1043 return; |
| 1046 } | 1044 } |
| 1047 | 1045 |
| 1048 if (!updateLeafTextNode()) | 1046 if (!updateLeafTextNode()) |
| 1049 return; | 1047 return; |
| 1050 | 1048 |
| 1051 ContainerNode* n = m_currentNode; | 1049 ContainerNode* n = m_currentNode; |
| 1052 if (m_currentNode->isElementNode()) | 1050 if (m_currentNode->isElementNode()) |
| 1053 toElement(n)->finishParsingChildren(); | 1051 toElement(n)->finishParsingChildren(); |
| 1054 | 1052 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 { | 1114 { |
| 1117 m_scriptStartPosition = textPosition; | 1115 m_scriptStartPosition = textPosition; |
| 1118 } | 1116 } |
| 1119 | 1117 |
| 1120 void XMLDocumentParser::characters(const xmlChar* chars, int length) | 1118 void XMLDocumentParser::characters(const xmlChar* chars, int length) |
| 1121 { | 1119 { |
| 1122 if (isStopped()) | 1120 if (isStopped()) |
| 1123 return; | 1121 return; |
| 1124 | 1122 |
| 1125 if (m_parserPaused) { | 1123 if (m_parserPaused) { |
| 1126 m_pendingCallbacks.append(wrapUnique(new PendingCharactersCallback(chars
, length))); | 1124 m_pendingCallbacks.append(adoptPtr(new PendingCharactersCallback(chars,
length))); |
| 1127 return; | 1125 return; |
| 1128 } | 1126 } |
| 1129 | 1127 |
| 1130 createLeafTextNodeIfNeeded(); | 1128 createLeafTextNodeIfNeeded(); |
| 1131 m_bufferedText.append(chars, length); | 1129 m_bufferedText.append(chars, length); |
| 1132 } | 1130 } |
| 1133 | 1131 |
| 1134 void XMLDocumentParser::error(XMLErrors::ErrorType type, const char* message, va
_list args) | 1132 void XMLDocumentParser::error(XMLErrors::ErrorType type, const char* message, va
_list args) |
| 1135 { | 1133 { |
| 1136 if (isStopped()) | 1134 if (isStopped()) |
| 1137 return; | 1135 return; |
| 1138 | 1136 |
| 1139 char formattedMessage[1024]; | 1137 char formattedMessage[1024]; |
| 1140 vsnprintf(formattedMessage, sizeof(formattedMessage) - 1, message, args); | 1138 vsnprintf(formattedMessage, sizeof(formattedMessage) - 1, message, args); |
| 1141 | 1139 |
| 1142 if (m_parserPaused) { | 1140 if (m_parserPaused) { |
| 1143 m_pendingCallbacks.append(wrapUnique(new PendingErrorCallback(type, rein
terpret_cast<const xmlChar*>(formattedMessage), lineNumber(), columnNumber()))); | 1141 m_pendingCallbacks.append(adoptPtr(new PendingErrorCallback(type, reinte
rpret_cast<const xmlChar*>(formattedMessage), lineNumber(), columnNumber()))); |
| 1144 return; | 1142 return; |
| 1145 } | 1143 } |
| 1146 | 1144 |
| 1147 handleError(type, formattedMessage, textPosition()); | 1145 handleError(type, formattedMessage, textPosition()); |
| 1148 } | 1146 } |
| 1149 | 1147 |
| 1150 void XMLDocumentParser::processingInstruction(const String& target, const String
& data) | 1148 void XMLDocumentParser::processingInstruction(const String& target, const String
& data) |
| 1151 { | 1149 { |
| 1152 if (isStopped()) | 1150 if (isStopped()) |
| 1153 return; | 1151 return; |
| 1154 | 1152 |
| 1155 if (m_parserPaused) { | 1153 if (m_parserPaused) { |
| 1156 m_pendingCallbacks.append(wrapUnique(new PendingProcessingInstructionCal
lback(target, data))); | 1154 m_pendingCallbacks.append(adoptPtr(new PendingProcessingInstructionCallb
ack(target, data))); |
| 1157 return; | 1155 return; |
| 1158 } | 1156 } |
| 1159 | 1157 |
| 1160 if (!updateLeafTextNode()) | 1158 if (!updateLeafTextNode()) |
| 1161 return; | 1159 return; |
| 1162 | 1160 |
| 1163 // ### handle exceptions | 1161 // ### handle exceptions |
| 1164 TrackExceptionState exceptionState; | 1162 TrackExceptionState exceptionState; |
| 1165 ProcessingInstruction* pi = m_currentNode->document().createProcessingInstru
ction(target, data, exceptionState); | 1163 ProcessingInstruction* pi = m_currentNode->document().createProcessingInstru
ction(target, data, exceptionState); |
| 1166 if (exceptionState.hadException()) | 1164 if (exceptionState.hadException()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1185 stopParsing(); | 1183 stopParsing(); |
| 1186 } | 1184 } |
| 1187 } | 1185 } |
| 1188 | 1186 |
| 1189 void XMLDocumentParser::cdataBlock(const String& text) | 1187 void XMLDocumentParser::cdataBlock(const String& text) |
| 1190 { | 1188 { |
| 1191 if (isStopped()) | 1189 if (isStopped()) |
| 1192 return; | 1190 return; |
| 1193 | 1191 |
| 1194 if (m_parserPaused) { | 1192 if (m_parserPaused) { |
| 1195 m_pendingCallbacks.append(wrapUnique(new PendingCDATABlockCallback(text)
)); | 1193 m_pendingCallbacks.append(adoptPtr(new PendingCDATABlockCallback(text)))
; |
| 1196 return; | 1194 return; |
| 1197 } | 1195 } |
| 1198 | 1196 |
| 1199 if (!updateLeafTextNode()) | 1197 if (!updateLeafTextNode()) |
| 1200 return; | 1198 return; |
| 1201 | 1199 |
| 1202 m_currentNode->parserAppendChild(CDATASection::create(m_currentNode->documen
t(), text)); | 1200 m_currentNode->parserAppendChild(CDATASection::create(m_currentNode->documen
t(), text)); |
| 1203 } | 1201 } |
| 1204 | 1202 |
| 1205 void XMLDocumentParser::comment(const String& text) | 1203 void XMLDocumentParser::comment(const String& text) |
| 1206 { | 1204 { |
| 1207 if (isStopped()) | 1205 if (isStopped()) |
| 1208 return; | 1206 return; |
| 1209 | 1207 |
| 1210 if (m_parserPaused) { | 1208 if (m_parserPaused) { |
| 1211 m_pendingCallbacks.append(wrapUnique(new PendingCommentCallback(text))); | 1209 m_pendingCallbacks.append(adoptPtr(new PendingCommentCallback(text))); |
| 1212 return; | 1210 return; |
| 1213 } | 1211 } |
| 1214 | 1212 |
| 1215 if (!updateLeafTextNode()) | 1213 if (!updateLeafTextNode()) |
| 1216 return; | 1214 return; |
| 1217 | 1215 |
| 1218 m_currentNode->parserAppendChild(Comment::create(m_currentNode->document(),
text)); | 1216 m_currentNode->parserAppendChild(Comment::create(m_currentNode->document(),
text)); |
| 1219 } | 1217 } |
| 1220 | 1218 |
| 1221 enum StandaloneInfo { | 1219 enum StandaloneInfo { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1246 { | 1244 { |
| 1247 updateLeafTextNode(); | 1245 updateLeafTextNode(); |
| 1248 } | 1246 } |
| 1249 | 1247 |
| 1250 void XMLDocumentParser::internalSubset(const String& name, const String& externa
lID, const String& systemID) | 1248 void XMLDocumentParser::internalSubset(const String& name, const String& externa
lID, const String& systemID) |
| 1251 { | 1249 { |
| 1252 if (isStopped()) | 1250 if (isStopped()) |
| 1253 return; | 1251 return; |
| 1254 | 1252 |
| 1255 if (m_parserPaused) { | 1253 if (m_parserPaused) { |
| 1256 m_pendingCallbacks.append(wrapUnique(new PendingInternalSubsetCallback(n
ame, externalID, systemID))); | 1254 m_pendingCallbacks.append(adoptPtr(new PendingInternalSubsetCallback(nam
e, externalID, systemID))); |
| 1257 return; | 1255 return; |
| 1258 } | 1256 } |
| 1259 | 1257 |
| 1260 if (document()) | 1258 if (document()) |
| 1261 document()->parserAppendChild(DocumentType::create(document(), name, ext
ernalID, systemID)); | 1259 document()->parserAppendChild(DocumentType::create(document(), name, ext
ernalID, systemID)); |
| 1262 } | 1260 } |
| 1263 | 1261 |
| 1264 static inline XMLDocumentParser* getParser(void* closure) | 1262 static inline XMLDocumentParser* getParser(void* closure) |
| 1265 { | 1263 { |
| 1266 xmlParserCtxtPtr ctxt = static_cast<xmlParserCtxtPtr>(closure); | 1264 xmlParserCtxtPtr ctxt = static_cast<xmlParserCtxtPtr>(closure); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 } | 1482 } |
| 1485 } | 1483 } |
| 1486 | 1484 |
| 1487 bool xmlViewerMode = !m_sawError && !m_sawCSS && !m_sawXSLTransform && hasNo
StyleInformation(document()); | 1485 bool xmlViewerMode = !m_sawError && !m_sawCSS && !m_sawXSLTransform && hasNo
StyleInformation(document()); |
| 1488 if (xmlViewerMode) { | 1486 if (xmlViewerMode) { |
| 1489 const char noStyleMessage[] = "This XML file does not appear to have any
style information associated with it. The document tree is shown below."; | 1487 const char noStyleMessage[] = "This XML file does not appear to have any
style information associated with it. The document tree is shown below."; |
| 1490 document()->setIsViewSource(true); | 1488 document()->setIsViewSource(true); |
| 1491 V8Document::PrivateScript::transformDocumentToTreeViewMethod(document()-
>frame(), document(), noStyleMessage); | 1489 V8Document::PrivateScript::transformDocumentToTreeViewMethod(document()-
>frame(), document(), noStyleMessage); |
| 1492 } else if (m_sawXSLTransform) { | 1490 } else if (m_sawXSLTransform) { |
| 1493 xmlDocPtr doc = xmlDocPtrForString(document(), m_originalSourceForTransf
orm.toString(), document()->url().getString()); | 1491 xmlDocPtr doc = xmlDocPtrForString(document(), m_originalSourceForTransf
orm.toString(), document()->url().getString()); |
| 1494 document()->setTransformSource(wrapUnique(new TransformSource(doc))); | 1492 document()->setTransformSource(adoptPtr(new TransformSource(doc))); |
| 1495 DocumentParser::stopParsing(); | 1493 DocumentParser::stopParsing(); |
| 1496 } | 1494 } |
| 1497 } | 1495 } |
| 1498 | 1496 |
| 1499 xmlDocPtr xmlDocPtrForString(Document* document, const String& source, const Str
ing& url) | 1497 xmlDocPtr xmlDocPtrForString(Document* document, const String& source, const Str
ing& url) |
| 1500 { | 1498 { |
| 1501 if (source.isEmpty()) | 1499 if (source.isEmpty()) |
| 1502 return 0; | 1500 return 0; |
| 1503 // Parse in a single chunk into an xmlDocPtr | 1501 // Parse in a single chunk into an xmlDocPtr |
| 1504 // FIXME: Hook up error handlers so that a failure to parse the main | 1502 // FIXME: Hook up error handlers so that a failure to parse the main |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1535 | 1533 |
| 1536 void XMLDocumentParser::resumeParsing() | 1534 void XMLDocumentParser::resumeParsing() |
| 1537 { | 1535 { |
| 1538 ASSERT(!isDetached()); | 1536 ASSERT(!isDetached()); |
| 1539 ASSERT(m_parserPaused); | 1537 ASSERT(m_parserPaused); |
| 1540 | 1538 |
| 1541 m_parserPaused = false; | 1539 m_parserPaused = false; |
| 1542 | 1540 |
| 1543 // First, execute any pending callbacks | 1541 // First, execute any pending callbacks |
| 1544 while (!m_pendingCallbacks.isEmpty()) { | 1542 while (!m_pendingCallbacks.isEmpty()) { |
| 1545 std::unique_ptr<PendingCallback> callback = m_pendingCallbacks.takeFirst
(); | 1543 OwnPtr<PendingCallback> callback = m_pendingCallbacks.takeFirst(); |
| 1546 callback->call(this); | 1544 callback->call(this); |
| 1547 | 1545 |
| 1548 // A callback paused the parser | 1546 // A callback paused the parser |
| 1549 if (m_parserPaused) | 1547 if (m_parserPaused) |
| 1550 return; | 1548 return; |
| 1551 } | 1549 } |
| 1552 | 1550 |
| 1553 // Then, write any pending data | 1551 // Then, write any pending data |
| 1554 SegmentedString rest = m_pendingSrc; | 1552 SegmentedString rest = m_pendingSrc; |
| 1555 m_pendingSrc.clear(); | 1553 m_pendingSrc.clear(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 sax.initialized = XML_SAX2_MAGIC; | 1639 sax.initialized = XML_SAX2_MAGIC; |
| 1642 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); | 1640 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); |
| 1643 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; | 1641 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; |
| 1644 parseChunk(parser->context(), parseString); | 1642 parseChunk(parser->context(), parseString); |
| 1645 finishParsing(parser->context()); | 1643 finishParsing(parser->context()); |
| 1646 attrsOK = state.gotAttributes; | 1644 attrsOK = state.gotAttributes; |
| 1647 return state.attributes; | 1645 return state.attributes; |
| 1648 } | 1646 } |
| 1649 | 1647 |
| 1650 } // namespace blink | 1648 } // namespace blink |
| OLD | NEW |