Changeset 91008 in webkit
- Timestamp:
- Jul 14, 2011 10:15:04 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/CMakeLists.txt
r90849 r91008 1364 1364 xml/DOMParser.cpp 1365 1365 xml/NativeXPathNSResolver.cpp 1366 xml/XMLErrors.cpp 1366 1367 xml/XMLHttpRequest.cpp 1367 1368 xml/XMLHttpRequestProgressEventThrottle.cpp -
trunk/Source/WebCore/ChangeLog
r91006 r91008 1 2011-07-14 Vsevolod Vlasov <vsevik@chromium.org> 2 3 Move XML errors handling out from XMLDocumentParser (refactoring). 4 https://bugs.webkit.org/show_bug.cgi?id=64305 5 6 XML errors handling logic is moved out from XMLDocumentParser to allow using it for XSLT error handling as well. 7 8 Reviewed by Adam Barth. 9 10 No tests needed as there is no new functionality added. 11 12 * CMakeLists.txt: 13 * GNUmakefile.list.am: 14 * WebCore.gypi: 15 * WebCore.pro: 16 * WebCore.vcproj/WebCore.vcproj: 17 * WebCore.xcodeproj/project.pbxproj: 18 * xml/XMLErrors.cpp: Added. 19 (WebCore::XMLErrors::XMLErrors): 20 (WebCore::XMLErrors::handleError): 21 (WebCore::XMLErrors::appendErrorMessage): 22 (WebCore::createXHTMLParserErrorHeader): 23 (WebCore::XMLErrors::insertErrorMessageBlock): 24 * xml/XMLErrors.h: Added. 25 * xml/parser/XMLDocumentParser.cpp: 26 (WebCore::XMLDocumentParser::pushCurrentNode): 27 (WebCore::XMLDocumentParser::handleError): 28 (WebCore::XMLDocumentParser::insertErrorMessageBlock): 29 * xml/parser/XMLDocumentParser.h: 30 * xml/parser/XMLDocumentParserLibxml2.cpp: 31 (WebCore::PendingCallbacks::appendErrorCallback): 32 (WebCore::XMLDocumentParser::XMLDocumentParser): 33 (WebCore::XMLDocumentParser::doWrite): 34 (WebCore::XMLDocumentParser::error): 35 (WebCore::warningHandler): 36 (WebCore::fatalErrorHandler): 37 (WebCore::normalErrorHandler): 38 * xml/parser/XMLDocumentParserQt.cpp: 39 (WebCore::XMLDocumentParser::XMLDocumentParser): 40 (WebCore::XMLDocumentParser::doWrite): 41 (WebCore::XMLDocumentParser::doEnd): 42 (WebCore::XMLDocumentParser::parse): 43 (WebCore::XMLDocumentParser::parseStartElement): 44 (WebCore::XMLDocumentParser::parseDtd): 45 1 46 2011-07-14 Vsevolod Vlasov <vsevik@chromium.org> 2 47 -
trunk/Source/WebCore/GNUmakefile.list.am
r90953 r91008 3808 3808 Source/WebCore/xml/NativeXPathNSResolver.cpp \ 3809 3809 Source/WebCore/xml/NativeXPathNSResolver.h \ 3810 Source/WebCore/xml/XMLErrors.cpp \ 3811 Source/WebCore/xml/XMLErrors.h \ 3810 3812 Source/WebCore/xml/XMLHttpRequest.cpp \ 3811 3813 Source/WebCore/xml/XMLHttpRequestException.h \ -
trunk/Source/WebCore/WebCore.gypi
r90996 r91008 6112 6112 'xml/NativeXPathNSResolver.cpp', 6113 6113 'xml/NativeXPathNSResolver.h', 6114 'xml/XMLErrors.cpp', 6115 'xml/XMLErrors.h', 6114 6116 'xml/XMLHttpRequest.cpp', 6115 6117 'xml/XMLHttpRequest.h', -
trunk/Source/WebCore/WebCore.pro
r90849 r91008 1196 1196 xml/XMLHttpRequestProgressEventThrottle.cpp \ 1197 1197 xml/XMLHttpRequestUpload.cpp \ 1198 xml/XMLErrors.cpp \ 1198 1199 xml/XMLSerializer.cpp \ 1199 1200 xml/parser/XMLDocumentParser.cpp … … 2498 2499 xml/XMLHttpRequest.h \ 2499 2500 xml/XMLHttpRequestUpload.h \ 2501 xml/XMLErrors.h \ 2500 2502 xml/XMLSerializer.h \ 2501 2503 xml/XPathEvaluator.h \ -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r90863 r91008 42061 42061 </File> 42062 42062 <File 42063 RelativePath="..\xml\XMLErrors.cpp" 42064 > 42065 </File> 42066 <File 42067 RelativePath="..\xml\XMLErrors.h" 42068 > 42069 </File> 42070 <File 42063 42071 RelativePath="..\xml\XMLHttpRequest.cpp" 42064 42072 > -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r90911 r91008 1468 1468 59C27F05138D28C10079B7E2 /* NetworkResourcesData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59C27F04138D28C10079B7E2 /* NetworkResourcesData.cpp */; }; 1469 1469 59C27F07138D28CF0079B7E2 /* NetworkResourcesData.h in Headers */ = {isa = PBXBuildFile; fileRef = 59C27F06138D28CF0079B7E2 /* NetworkResourcesData.h */; }; 1470 59C28045138DC2410079B7E2 /* XMLErrors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59C28043138DC2410079B7E2 /* XMLErrors.cpp */; }; 1471 59C28046138DC2410079B7E2 /* XMLErrors.h in Headers */ = {isa = PBXBuildFile; fileRef = 59C28044138DC2410079B7E2 /* XMLErrors.h */; }; 1470 1472 59D1C10411EB5DCF00B638C8 /* DeviceOrientation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59D1C10311EB5DCF00B638C8 /* DeviceOrientation.cpp */; }; 1471 1473 59E560A71105336600AA1258 /* JavaClassJSC.h in Headers */ = {isa = PBXBuildFile; fileRef = 59E560A61105336600AA1258 /* JavaClassJSC.h */; }; … … 8007 8009 59C27F04138D28C10079B7E2 /* NetworkResourcesData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkResourcesData.cpp; sourceTree = "<group>"; }; 8008 8010 59C27F06138D28CF0079B7E2 /* NetworkResourcesData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkResourcesData.h; sourceTree = "<group>"; }; 8011 59C28043138DC2410079B7E2 /* XMLErrors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLErrors.cpp; sourceTree = "<group>"; }; 8012 59C28044138DC2410079B7E2 /* XMLErrors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLErrors.h; sourceTree = "<group>"; }; 8009 8013 59D1C10311EB5DCF00B638C8 /* DeviceOrientation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeviceOrientation.cpp; sourceTree = "<group>"; }; 8010 8014 59E560A61105336600AA1258 /* JavaClassJSC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JavaClassJSC.h; path = jsc/JavaClassJSC.h; sourceTree = "<group>"; }; … … 18969 18973 E10B9B6A0B747599003ED890 /* NativeXPathNSResolver.h */, 18970 18974 A833C7F60A2CF1D800D57664 /* xmlattrs.in */, 18975 59C28043138DC2410079B7E2 /* XMLErrors.cpp */, 18976 59C28044138DC2410079B7E2 /* XMLErrors.h */, 18971 18977 BC772C440C4EB2C60083285F /* XMLHttpRequest.cpp */, 18972 18978 BC772C450C4EB2C60083285F /* XMLHttpRequest.h */, … … 23045 23051 00B9318813BA8DBA0035A948 /* XMLDocumentParser.h in Headers */, 23046 23052 00B9318C13BA8DCC0035A948 /* XMLDocumentParserScope.h in Headers */, 23053 59C28046138DC2410079B7E2 /* XMLErrors.h in Headers */, 23047 23054 BC772C470C4EB2C60083285F /* XMLHttpRequest.h in Headers */, 23048 23055 BC60D9C90D2A29E500B9918F /* XMLHttpRequestException.h in Headers */, … … 25814 25821 00B9318913BA8DBC0035A948 /* XMLDocumentParserLibxml2.cpp in Sources */, 25815 25822 00B9318B13BA8DC90035A948 /* XMLDocumentParserScope.cpp in Sources */, 25823 59C28045138DC2410079B7E2 /* XMLErrors.cpp in Sources */, 25816 25824 BC772C460C4EB2C60083285F /* XMLHttpRequest.cpp in Sources */, 25817 25825 A136A00C1134DBD200CC8D50 /* XMLHttpRequestProgressEventThrottle.cpp in Sources */, -
trunk/Source/WebCore/xml/parser/XMLDocumentParser.cpp
r90269 r91008 51 51 #include "TextResourceDecoder.h" 52 52 #include "TreeDepthLimit.h" 53 #include <wtf/text/WTFString.h>53 #include "XMLErrors.h" 54 54 #include <wtf/StringExtras.h> 55 55 #include <wtf/Threading.h> … … 66 66 67 67 using namespace HTMLNames; 68 69 const int maxErrors = 25;70 68 71 69 void XMLDocumentParser::pushCurrentNode(ContainerNode* n) … … 78 76 m_currentNode = n; 79 77 if (m_currentNodeStack.size() > maxDOMTreeDepth) 80 handleError( fatal, "Excessive node nesting.", lineNumber(), columnNumber());78 handleError(XMLErrors::fatal, "Excessive node nesting.", lineNumber(), columnNumber()); 81 79 } 82 80 … … 136 134 } 137 135 138 void XMLDocumentParser::handleError( ErrorType type, const char* m, int lineNumber, int columnNumber)136 void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* m, int lineNumber, int columnNumber) 139 137 { 140 138 handleError(type, m, TextPosition1(WTF::OneBasedNumber::fromOneBasedInt(lineNumber), WTF::OneBasedNumber::fromOneBasedInt(columnNumber))); 141 139 } 142 140 143 void XMLDocumentParser::handleError(ErrorType type, const char* m, TextPosition1 position) 144 { 145 if (type == fatal || (m_errorCount < maxErrors && m_lastErrorPosition.m_line != position.m_line && m_lastErrorPosition.m_column != position.m_column)) { 146 switch (type) { 147 case warning: 148 m_errorMessages += "warning on line " + String::number(position.m_line.oneBasedInt()) + " at column " + String::number(position.m_column.oneBasedInt()) + ": " + m; 149 break; 150 case fatal: 151 case nonFatal: 152 m_errorMessages += "error on line " + String::number(position.m_line.oneBasedInt()) + " at column " + String::number(position.m_column.oneBasedInt()) + ": " + m; 153 } 154 155 m_lastErrorPosition = position; 156 ++m_errorCount; 157 } 158 159 if (type != warning) 141 void XMLDocumentParser::handleError(XMLErrors::ErrorType type, const char* m, TextPosition1 position) 142 { 143 m_xmlErrors.handleError(type, m, position); 144 if (type != XMLErrors::warning) 160 145 m_sawError = true; 161 162 if (type == fatal) 146 if (type == XMLErrors::fatal) 163 147 stopParsing(); 164 148 } … … 252 236 } 253 237 254 static inline RefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages)255 {256 RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), false);257 reportElement->setAttribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");258 259 ExceptionCode ec = 0;260 RefPtr<Element> h3 = doc->createElement(h3Tag, false);261 reportElement->appendChild(h3.get(), ec);262 h3->appendChild(doc->createTextNode("This page contains the following errors:"), ec);263 264 RefPtr<Element> fixed = doc->createElement(divTag, false);265 reportElement->appendChild(fixed.get(), ec);266 fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px");267 fixed->appendChild(doc->createTextNode(errorMessages), ec);268 269 h3 = doc->createElement(h3Tag, false);270 reportElement->appendChild(h3.get(), ec);271 h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), ec);272 273 return reportElement;274 }275 276 238 void XMLDocumentParser::insertErrorMessageBlock() 277 239 { … … 280 242 return; 281 243 #endif 282 // One or more errors occurred during parsing of the code. Display an error block to the user above 283 // the normal content (the DOM tree is created manually and includes line/col info regarding 284 // where the errors are located) 285 286 // Create elements for display 287 ExceptionCode ec = 0; 288 Document* document = this->document(); 289 RefPtr<Element> documentElement = document->documentElement(); 290 if (!documentElement) { 291 RefPtr<Element> rootElement = document->createElement(htmlTag, false); 292 document->appendChild(rootElement, ec); 293 RefPtr<Element> body = document->createElement(bodyTag, false); 294 rootElement->appendChild(body, ec); 295 documentElement = body.get(); 296 } 297 #if ENABLE(SVG) 298 else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) { 299 RefPtr<Element> rootElement = document->createElement(htmlTag, false); 300 RefPtr<Element> body = document->createElement(bodyTag, false); 301 rootElement->appendChild(body, ec); 302 body->appendChild(documentElement, ec); 303 document->appendChild(rootElement.get(), ec); 304 documentElement = body.get(); 305 } 306 #endif 307 RefPtr<Element> reportElement = createXHTMLParserErrorHeader(document, m_errorMessages); 308 documentElement->insertBefore(reportElement, documentElement->firstChild(), ec); 309 #if ENABLE(XSLT) 310 if (document->transformSourceDocument()) { 311 RefPtr<Element> paragraph = document->createElement(pTag, false); 312 paragraph->setAttribute(styleAttr, "white-space: normal"); 313 paragraph->appendChild(document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), ec); 314 reportElement->appendChild(paragraph.release(), ec); 315 } 316 #endif 317 document->updateStyleIfNeeded(); 244 245 m_xmlErrors.insertErrorMessageBlock(); 318 246 } 319 247 -
trunk/Source/WebCore/xml/parser/XMLDocumentParser.h
r90269 r91008 31 31 #include "ScriptableDocumentParser.h" 32 32 #include "SegmentedString.h" 33 #include "XMLErrors.h" 33 34 #include <wtf/HashMap.h> 34 35 #include <wtf/OwnPtr.h> … … 87 88 88 89 // Exposed for callbacks: 89 enum ErrorType { warning, nonFatal, fatal }; 90 void handleError(ErrorType, const char* message, int lineNumber, int columnNumber); 91 void handleError(ErrorType, const char* message, TextPosition1); 90 void handleError(XMLErrors::ErrorType, const char* message, int lineNumber, int columnNumber); 91 void handleError(XMLErrors::ErrorType, const char* message, TextPosition1); 92 92 93 93 void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; } … … 149 149 public: 150 150 // callbacks from parser SAX 151 void error( ErrorType, const char* message, va_list args) WTF_ATTRIBUTE_PRINTF(3, 0);151 void error(XMLErrors::ErrorType, const char* message, va_list args) WTF_ATTRIBUTE_PRINTF(3, 0); 152 152 void startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces, 153 153 const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar** libxmlAttributes); … … 208 208 bool m_finishCalled; 209 209 210 int m_errorCount; 211 TextPosition1 m_lastErrorPosition; 212 String m_errorMessages; 210 XMLErrors m_xmlErrors; 213 211 214 212 CachedResourceHandle<CachedScript> m_pendingScript; -
trunk/Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp
r90269 r91008 173 173 } 174 174 175 void appendErrorCallback(XML DocumentParser::ErrorType type, const xmlChar* message, int lineNumber, int columnNumber)175 void appendErrorCallback(XMLErrors::ErrorType type, const xmlChar* message, int lineNumber, int columnNumber) 176 176 { 177 177 OwnPtr<PendingErrorCallback> callback = adoptPtr(new PendingErrorCallback); … … 329 329 } 330 330 331 XML DocumentParser::ErrorType type;331 XMLErrors::ErrorType type; 332 332 xmlChar* message; 333 333 int lineNumber; … … 563 563 , m_requestingScript(false) 564 564 , m_finishCalled(false) 565 , m_errorCount(0) 566 , m_lastErrorPosition(TextPosition1::belowRangePosition()) 565 , m_xmlErrors(document) 567 566 , m_pendingScript(0) 568 567 , m_scriptStartPosition(TextPosition1::belowRangePosition()) … … 590 589 , m_requestingScript(false) 591 590 , m_finishCalled(false) 592 , m_errorCount(0) 593 , m_lastErrorPosition(TextPosition1::belowRangePosition()) 591 , m_xmlErrors(fragment->document()) 594 592 , m_pendingScript(0) 595 593 , m_scriptStartPosition(TextPosition1::belowRangePosition()) … … 676 674 if (document()->decoder() && document()->decoder()->sawError()) { 677 675 // If the decoder saw an error, report it as fatal (stops parsing) 678 handleError( fatal, "Encoding error", context->context()->input->line, context->context()->input->col);676 handleError(XMLErrors::fatal, "Encoding error", context->context()->input->line, context->context()->input->col); 679 677 } 680 678 } … … 936 934 } 937 935 938 void XMLDocumentParser::error( ErrorType type, const char* message, va_list args)936 void XMLDocumentParser::error(XMLErrors::ErrorType type, const char* message, va_list args) 939 937 { 940 938 if (isStopped()) … … 1158 1156 va_list args; 1159 1157 va_start(args, message); 1160 getParser(closure)->error(XML DocumentParser::warning, message, args);1158 getParser(closure)->error(XMLErrors::warning, message, args); 1161 1159 va_end(args); 1162 1160 } … … 1167 1165 va_list args; 1168 1166 va_start(args, message); 1169 getParser(closure)->error(XML DocumentParser::fatal, message, args);1167 getParser(closure)->error(XMLErrors::fatal, message, args); 1170 1168 va_end(args); 1171 1169 } … … 1176 1174 va_list args; 1177 1175 va_start(args, message); 1178 getParser(closure)->error(XML DocumentParser::nonFatal, message, args);1176 getParser(closure)->error(XMLErrors::nonFatal, message, args); 1179 1177 va_end(args); 1180 1178 } -
trunk/Source/WebCore/xml/parser/XMLDocumentParserQt.cpp
r90269 r91008 102 102 , m_requestingScript(false) 103 103 , m_finishCalled(false) 104 , m_errorCount(0) 105 , m_lastErrorPosition(TextPosition1::belowRangePosition()) 104 , m_xmlErrors(document) 106 105 , m_pendingScript(0) 107 106 , m_scriptStartPosition(TextPosition1::belowRangePosition()) … … 129 128 , m_requestingScript(false) 130 129 , m_finishCalled(false) 131 , m_errorCount(0) 132 , m_lastErrorPosition(TextPosition1::belowRangePosition()) 130 , m_xmlErrors(fragment->document()) 133 131 , m_pendingScript(0) 134 132 , m_scriptStartPosition(TextPosition1::belowRangePosition()) … … 186 184 if (document()->decoder() && document()->decoder()->sawError()) { 187 185 // If the decoder saw an error, report it as fatal (stops parsing) 188 handleError( fatal, "Encoding error", lineNumber(), columnNumber());186 handleError(XMLErrors::fatal, "Encoding error", lineNumber(), columnNumber()); 189 187 return; 190 188 } … … 226 224 if (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError 227 225 || (m_wroteText && !m_sawFirstElement && !m_sawXSLTransform && !m_sawError)) 228 handleError( fatal, qPrintable(m_stream.errorString()), lineNumber(), columnNumber());226 handleError(XMLErrors::fatal, qPrintable(m_stream.errorString()), lineNumber(), columnNumber()); 229 227 } 230 228 … … 383 381 #if ENABLE(XHTMLMP) 384 382 if (document()->isXHTMLMPDocument() && !m_hasDocTypeDeclaration) { 385 handleError( fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber());383 handleError(XMLErrors::fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber()); 386 384 break; 387 385 } … … 441 439 default: { 442 440 if (m_stream.error() != QXmlStreamReader::PrematureEndOfDocumentError) { 443 ErrorType type = (m_stream.error() == QXmlStreamReader::NotWellFormedError) ?444 fatal :warning;441 XMLErrors::ErrorType type = (m_stream.error() == QXmlStreamReader::NotWellFormedError) ? 442 XMLErrors::fatal : XMLErrors::warning; 445 443 handleError(type, qPrintable(m_stream.errorString()), lineNumber(), 446 444 columnNumber()); … … 502 500 // MUST be 'http://www.w3.org/1999/xhtml' 503 501 if (localName != HTMLNames::htmlTag.localName()) { 504 handleError( fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber());502 handleError(XMLErrors::fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber()); 505 503 return; 506 504 } … … 706 704 || (publicId == QLatin1String("-//WAPFORUM//DTD XHTML Mobile 1.0//EN"))) { 707 705 if (AtomicString(name) != HTMLNames::htmlTag.localName()) { 708 handleError( fatal, "Invalid DOCTYPE declaration, expected 'html' as root element.", lineNumber(), columnNumber());706 handleError(XMLErrors::fatal, "Invalid DOCTYPE declaration, expected 'html' as root element.", lineNumber(), columnNumber()); 709 707 return; 710 708 }
Note: See TracChangeset
for help on using the changeset viewer.