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