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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 private: | 305 private: |
306 XMLErrors::ErrorType m_type; | 306 XMLErrors::ErrorType m_type; |
307 xmlChar* m_message; | 307 xmlChar* m_message; |
308 OrdinalNumber m_lineNumber; | 308 OrdinalNumber m_lineNumber; |
309 OrdinalNumber m_columnNumber; | 309 OrdinalNumber m_columnNumber; |
310 }; | 310 }; |
311 | 311 |
312 void XMLDocumentParser::pushCurrentNode(ContainerNode* n) | 312 void XMLDocumentParser::pushCurrentNode(ContainerNode* n) |
313 { | 313 { |
314 ASSERT(n); | 314 DCHECK(n); |
315 ASSERT(m_currentNode); | 315 DCHECK(m_currentNode); |
316 m_currentNodeStack.append(m_currentNode); | 316 m_currentNodeStack.append(m_currentNode); |
317 m_currentNode = n; | 317 m_currentNode = n; |
318 if (m_currentNodeStack.size() > maxXMLTreeDepth) | 318 if (m_currentNodeStack.size() > maxXMLTreeDepth) |
319 handleError(XMLErrors::ErrorTypeFatal, "Excessive node nesting.", textPo
sition()); | 319 handleError(XMLErrors::ErrorTypeFatal, "Excessive node nesting.", textPo
sition()); |
320 } | 320 } |
321 | 321 |
322 void XMLDocumentParser::popCurrentNode() | 322 void XMLDocumentParser::popCurrentNode() |
323 { | 323 { |
324 if (!m_currentNode) | 324 if (!m_currentNode) |
325 return; | 325 return; |
326 ASSERT(m_currentNodeStack.size()); | 326 DCHECK(m_currentNodeStack.size()); |
327 m_currentNode = m_currentNodeStack.last(); | 327 m_currentNode = m_currentNodeStack.last(); |
328 m_currentNodeStack.removeLast(); | 328 m_currentNodeStack.removeLast(); |
329 } | 329 } |
330 | 330 |
331 void XMLDocumentParser::clearCurrentNodeStack() | 331 void XMLDocumentParser::clearCurrentNodeStack() |
332 { | 332 { |
333 m_currentNode = nullptr; | 333 m_currentNode = nullptr; |
334 m_leafTextNode = nullptr; | 334 m_leafTextNode = nullptr; |
335 | 335 |
336 if (m_currentNodeStack.size()) { // Aborted parsing. | 336 if (m_currentNodeStack.size()) { // Aborted parsing. |
337 m_currentNodeStack.clear(); | 337 m_currentNodeStack.clear(); |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 void XMLDocumentParser::insert(const SegmentedString&) | 341 void XMLDocumentParser::insert(const SegmentedString&) |
342 { | 342 { |
343 ASSERT_NOT_REACHED(); | 343 NOTREACHED(); |
344 } | 344 } |
345 | 345 |
346 void XMLDocumentParser::append(const String& inputSource) | 346 void XMLDocumentParser::append(const String& inputSource) |
347 { | 347 { |
348 const SegmentedString source(inputSource); | 348 const SegmentedString source(inputSource); |
349 if (m_sawXSLTransform || !m_sawFirstElement) | 349 if (m_sawXSLTransform || !m_sawFirstElement) |
350 m_originalSourceForTransform.append(source); | 350 m_originalSourceForTransform.append(source); |
351 | 351 |
352 if (isStopped() || m_sawXSLTransform) | 352 if (isStopped() || m_sawXSLTransform) |
353 return; | 353 return; |
(...skipping 13 matching lines...) Expand all Loading... |
367 m_sawError = true; | 367 m_sawError = true; |
368 if (type == XMLErrors::ErrorTypeFatal) | 368 if (type == XMLErrors::ErrorTypeFatal) |
369 stopParsing(); | 369 stopParsing(); |
370 } | 370 } |
371 | 371 |
372 void XMLDocumentParser::createLeafTextNodeIfNeeded() | 372 void XMLDocumentParser::createLeafTextNodeIfNeeded() |
373 { | 373 { |
374 if (m_leafTextNode) | 374 if (m_leafTextNode) |
375 return; | 375 return; |
376 | 376 |
377 ASSERT(m_bufferedText.size() == 0); | 377 DCHECK_EQ(m_bufferedText.size(), 0u); |
378 m_leafTextNode = Text::create(m_currentNode->document(), ""); | 378 m_leafTextNode = Text::create(m_currentNode->document(), ""); |
379 m_currentNode->parserAppendChild(m_leafTextNode.get()); | 379 m_currentNode->parserAppendChild(m_leafTextNode.get()); |
380 } | 380 } |
381 | 381 |
382 bool XMLDocumentParser::updateLeafTextNode() | 382 bool XMLDocumentParser::updateLeafTextNode() |
383 { | 383 { |
384 if (isStopped()) | 384 if (isStopped()) |
385 return false; | 385 return false; |
386 | 386 |
387 if (!m_leafTextNode) | 387 if (!m_leafTextNode) |
(...skipping 16 matching lines...) Expand all Loading... |
404 } | 404 } |
405 clearCurrentNodeStack(); | 405 clearCurrentNodeStack(); |
406 ScriptableDocumentParser::detach(); | 406 ScriptableDocumentParser::detach(); |
407 } | 407 } |
408 | 408 |
409 void XMLDocumentParser::end() | 409 void XMLDocumentParser::end() |
410 { | 410 { |
411 TRACE_EVENT0("blink", "XMLDocumentParser::end"); | 411 TRACE_EVENT0("blink", "XMLDocumentParser::end"); |
412 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is
called. | 412 // XMLDocumentParserLibxml2 will do bad things to the document if doEnd() is
called. |
413 // I don't believe XMLDocumentParserQt needs doEnd called in the fragment ca
se. | 413 // I don't believe XMLDocumentParserQt needs doEnd called in the fragment ca
se. |
414 ASSERT(!m_parsingFragment); | 414 DCHECK(!m_parsingFragment); |
415 | 415 |
416 doEnd(); | 416 doEnd(); |
417 | 417 |
418 // doEnd() call above can detach the parser and null out its document. | 418 // doEnd() call above can detach the parser and null out its document. |
419 // In that case, we just bail out. | 419 // In that case, we just bail out. |
420 if (isDetached()) | 420 if (isDetached()) |
421 return; | 421 return; |
422 | 422 |
423 // doEnd() could process a script tag, thus pausing parsing. | 423 // doEnd() could process a script tag, thus pausing parsing. |
424 if (m_parserPaused) | 424 if (m_parserPaused) |
425 return; | 425 return; |
426 | 426 |
427 if (m_sawError) | 427 if (m_sawError) |
428 insertErrorMessageBlock(); | 428 insertErrorMessageBlock(); |
429 else | 429 else |
430 updateLeafTextNode(); | 430 updateLeafTextNode(); |
431 | 431 |
432 if (isParsing()) | 432 if (isParsing()) |
433 prepareToStopParsing(); | 433 prepareToStopParsing(); |
434 document()->setReadyState(Document::Interactive); | 434 document()->setReadyState(Document::Interactive); |
435 clearCurrentNodeStack(); | 435 clearCurrentNodeStack(); |
436 document()->finishedParsing(); | 436 document()->finishedParsing(); |
437 } | 437 } |
438 | 438 |
439 void XMLDocumentParser::finish() | 439 void XMLDocumentParser::finish() |
440 { | 440 { |
441 // FIXME: We should ASSERT(!m_parserStopped) here, since it does not | 441 // FIXME: We should DCHECK(!m_parserStopped) here, since it does not |
442 // makes sense to call any methods on DocumentParser once it's been stopped. | 442 // makes sense to call any methods on DocumentParser once it's been stopped. |
443 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. | 443 // However, FrameLoader::stop calls DocumentParser::finish unconditionally. |
444 | 444 |
445 flush(); | 445 flush(); |
446 if (isDetached()) | 446 if (isDetached()) |
447 return; | 447 return; |
448 | 448 |
449 if (m_parserPaused) | 449 if (m_parserPaused) |
450 m_finishCalled = true; | 450 m_finishCalled = true; |
451 else | 451 else |
452 end(); | 452 end(); |
453 } | 453 } |
454 | 454 |
455 void XMLDocumentParser::insertErrorMessageBlock() | 455 void XMLDocumentParser::insertErrorMessageBlock() |
456 { | 456 { |
457 m_xmlErrors.insertErrorMessageBlock(); | 457 m_xmlErrors.insertErrorMessageBlock(); |
458 } | 458 } |
459 | 459 |
460 void XMLDocumentParser::notifyFinished(Resource* unusedResource) | 460 void XMLDocumentParser::notifyFinished(Resource* unusedResource) |
461 { | 461 { |
462 ASSERT_UNUSED(unusedResource, unusedResource == m_pendingScript); | 462 DCHECK_EQ(unusedResource, m_pendingScript); |
463 | 463 |
464 ScriptSourceCode sourceCode(m_pendingScript.get()); | 464 ScriptSourceCode sourceCode(m_pendingScript.get()); |
465 bool errorOccurred = m_pendingScript->errorOccurred(); | 465 bool errorOccurred = m_pendingScript->errorOccurred(); |
466 bool wasCanceled = m_pendingScript->wasCanceled(); | 466 bool wasCanceled = m_pendingScript->wasCanceled(); |
467 double scriptParserBlockingTime = m_parserBlockingPendingScriptLoadStartTime
; | 467 double scriptParserBlockingTime = m_parserBlockingPendingScriptLoadStartTime
; |
468 m_parserBlockingPendingScriptLoadStartTime = 0.0; | 468 m_parserBlockingPendingScriptLoadStartTime = 0.0; |
469 | 469 |
470 m_pendingScript->removeClient(this); | 470 m_pendingScript->removeClient(this); |
471 m_pendingScript = nullptr; | 471 m_pendingScript = nullptr; |
472 | 472 |
473 Element* e = m_scriptElement; | 473 Element* e = m_scriptElement; |
474 m_scriptElement = nullptr; | 474 m_scriptElement = nullptr; |
475 | 475 |
476 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e); | 476 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(e); |
477 ASSERT(scriptLoader); | 477 DCHECK(scriptLoader); |
478 | 478 |
479 if (errorOccurred) { | 479 if (errorOccurred) { |
480 scriptLoader->dispatchErrorEvent(); | 480 scriptLoader->dispatchErrorEvent(); |
481 } else if (!wasCanceled) { | 481 } else if (!wasCanceled) { |
482 if (scriptParserBlockingTime > 0.0) { | 482 if (scriptParserBlockingTime > 0.0) { |
483 DocumentParserTiming::from(*document()).recordParserBlockedOnScriptL
oadDuration(monotonicallyIncreasingTime() - scriptParserBlockingTime, scriptLoad
er->wasCreatedDuringDocumentWrite()); | 483 DocumentParserTiming::from(*document()).recordParserBlockedOnScriptL
oadDuration(monotonicallyIncreasingTime() - scriptParserBlockingTime, scriptLoad
er->wasCreatedDuringDocumentWrite()); |
484 } | 484 } |
485 | 485 |
486 if (!scriptLoader->executeScript(sourceCode)) | 486 if (!scriptLoader->executeScript(sourceCode)) |
487 scriptLoader->dispatchErrorEvent(); | 487 scriptLoader->dispatchErrorEvent(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 XMLDocumentParserScope::currentDocument->addConsoleMessage(ConsoleMe
ssage::create(SecurityMessageSource, ErrorMessageLevel, message)); | 632 XMLDocumentParserScope::currentDocument->addConsoleMessage(ConsoleMe
ssage::create(SecurityMessageSource, ErrorMessageLevel, message)); |
633 } | 633 } |
634 return false; | 634 return false; |
635 } | 635 } |
636 | 636 |
637 return true; | 637 return true; |
638 } | 638 } |
639 | 639 |
640 static void* openFunc(const char* uri) | 640 static void* openFunc(const char* uri) |
641 { | 641 { |
642 ASSERT(XMLDocumentParserScope::currentDocument); | 642 DCHECK(XMLDocumentParserScope::currentDocument); |
643 ASSERT(currentThread() == libxmlLoaderThread); | 643 DCHECK_EQ(currentThread(), libxmlLoaderThread); |
644 | 644 |
645 KURL url(KURL(), uri); | 645 KURL url(KURL(), uri); |
646 | 646 |
647 if (!shouldAllowExternalLoad(url)) | 647 if (!shouldAllowExternalLoad(url)) |
648 return &globalDescriptor; | 648 return &globalDescriptor; |
649 | 649 |
650 KURL finalURL; | 650 KURL finalURL; |
651 RefPtr<SharedBuffer> data; | 651 RefPtr<SharedBuffer> data; |
652 | 652 |
653 { | 653 { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 843 |
844 XMLParserContext::~XMLParserContext() | 844 XMLParserContext::~XMLParserContext() |
845 { | 845 { |
846 if (m_context->myDoc) | 846 if (m_context->myDoc) |
847 xmlFreeDoc(m_context->myDoc); | 847 xmlFreeDoc(m_context->myDoc); |
848 xmlFreeParserCtxt(m_context); | 848 xmlFreeParserCtxt(m_context); |
849 } | 849 } |
850 | 850 |
851 XMLDocumentParser::~XMLDocumentParser() | 851 XMLDocumentParser::~XMLDocumentParser() |
852 { | 852 { |
853 ASSERT(!m_pendingScript); | 853 DCHECK(!m_pendingScript); |
854 } | 854 } |
855 | 855 |
856 DEFINE_TRACE(XMLDocumentParser) | 856 DEFINE_TRACE(XMLDocumentParser) |
857 { | 857 { |
858 visitor->trace(m_currentNode); | 858 visitor->trace(m_currentNode); |
859 visitor->trace(m_currentNodeStack); | 859 visitor->trace(m_currentNodeStack); |
860 visitor->trace(m_leafTextNode); | 860 visitor->trace(m_leafTextNode); |
861 visitor->trace(m_xmlErrors); | 861 visitor->trace(m_xmlErrors); |
862 visitor->trace(m_pendingScript); | 862 visitor->trace(m_pendingScript); |
863 visitor->trace(m_scriptElement); | 863 visitor->trace(m_scriptElement); |
864 ScriptableDocumentParser::trace(visitor); | 864 ScriptableDocumentParser::trace(visitor); |
865 ScriptResourceClient::trace(visitor); | 865 ScriptResourceClient::trace(visitor); |
866 } | 866 } |
867 | 867 |
868 void XMLDocumentParser::doWrite(const String& parseString) | 868 void XMLDocumentParser::doWrite(const String& parseString) |
869 { | 869 { |
870 TRACE_EVENT0("blink", "XMLDocumentParser::doWrite"); | 870 TRACE_EVENT0("blink", "XMLDocumentParser::doWrite"); |
871 ASSERT(!isDetached()); | 871 DCHECK(!isDetached()); |
872 if (!m_context) | 872 if (!m_context) |
873 initializeParserContext(); | 873 initializeParserContext(); |
874 | 874 |
875 // Protect the libxml context from deletion during a callback | 875 // Protect the libxml context from deletion during a callback |
876 RefPtr<XMLParserContext> context = m_context; | 876 RefPtr<XMLParserContext> context = m_context; |
877 | 877 |
878 // libXML throws an error if you try to switch the encoding for an empty | 878 // libXML throws an error if you try to switch the encoding for an empty |
879 // string. | 879 // string. |
880 if (parseString.length()) { | 880 if (parseString.length()) { |
881 XMLDocumentParserScope scope(document()); | 881 XMLDocumentParserScope scope(document()); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 return; | 1080 return; |
1081 } | 1081 } |
1082 | 1082 |
1083 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element); | 1083 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element); |
1084 if (!scriptLoader) { | 1084 if (!scriptLoader) { |
1085 popCurrentNode(); | 1085 popCurrentNode(); |
1086 return; | 1086 return; |
1087 } | 1087 } |
1088 | 1088 |
1089 // Don't load external scripts for standalone documents (for now). | 1089 // Don't load external scripts for standalone documents (for now). |
1090 ASSERT(!m_pendingScript); | 1090 DCHECK(!m_pendingScript); |
1091 m_requestingScript = true; | 1091 m_requestingScript = true; |
1092 | 1092 |
1093 if (scriptLoader->prepareScript(m_scriptStartPosition, ScriptLoader::AllowLe
gacyTypeInTypeAttribute)) { | 1093 if (scriptLoader->prepareScript(m_scriptStartPosition, ScriptLoader::AllowLe
gacyTypeInTypeAttribute)) { |
1094 // FIXME: Script execution should be shared between | 1094 // FIXME: Script execution should be shared between |
1095 // the libxml2 and Qt XMLDocumentParser implementations. | 1095 // the libxml2 and Qt XMLDocumentParser implementations. |
1096 | 1096 |
1097 | 1097 |
1098 if (scriptLoader->readyToBeParserExecuted()) { | 1098 if (scriptLoader->readyToBeParserExecuted()) { |
1099 if (!scriptLoader->executeScript(ScriptSourceCode(scriptLoader->scri
ptContent(), document()->url(), m_scriptStartPosition))) { | 1099 if (!scriptLoader->executeScript(ScriptSourceCode(scriptLoader->scri
ptContent(), document()->url(), m_scriptStartPosition))) { |
1100 scriptLoader->dispatchErrorEvent(); | 1100 scriptLoader->dispatchErrorEvent(); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 | 1344 |
1345 static size_t convertUTF16EntityToUTF8(const UChar* utf16Entity, size_t numberOf
CodeUnits, char* target, size_t targetSize) | 1345 static size_t convertUTF16EntityToUTF8(const UChar* utf16Entity, size_t numberOf
CodeUnits, char* target, size_t targetSize) |
1346 { | 1346 { |
1347 const char* originalTarget = target; | 1347 const char* originalTarget = target; |
1348 WTF::Unicode::ConversionResult conversionResult = WTF::Unicode::convertUTF16
ToUTF8(&utf16Entity, | 1348 WTF::Unicode::ConversionResult conversionResult = WTF::Unicode::convertUTF16
ToUTF8(&utf16Entity, |
1349 utf16Entity + numberOfCodeUnits, &target, target + targetSize); | 1349 utf16Entity + numberOfCodeUnits, &target, target + targetSize); |
1350 if (conversionResult != WTF::Unicode::conversionOK) | 1350 if (conversionResult != WTF::Unicode::conversionOK) |
1351 return 0; | 1351 return 0; |
1352 | 1352 |
1353 // Even though we must pass the length, libxml expects the entity string to
be null terminated. | 1353 // Even though we must pass the length, libxml expects the entity string to
be null terminated. |
1354 ASSERT(target > originalTarget + 1); | 1354 DCHECK_GT(target, originalTarget + 1); |
1355 *target = '\0'; | 1355 *target = '\0'; |
1356 return target - originalTarget; | 1356 return target - originalTarget; |
1357 } | 1357 } |
1358 | 1358 |
1359 static xmlEntityPtr getXHTMLEntity(const xmlChar* name) | 1359 static xmlEntityPtr getXHTMLEntity(const xmlChar* name) |
1360 { | 1360 { |
1361 UChar utf16DecodedEntity[4]; | 1361 UChar utf16DecodedEntity[4]; |
1362 size_t numberOfCodeUnits = decodeNamedEntityToUCharArray(reinterpret_cast<co
nst char*>(name), utf16DecodedEntity); | 1362 size_t numberOfCodeUnits = decodeNamedEntityToUCharArray(reinterpret_cast<co
nst char*>(name), utf16DecodedEntity); |
1363 if (!numberOfCodeUnits) | 1363 if (!numberOfCodeUnits) |
1364 return 0; | 1364 return 0; |
1365 | 1365 |
1366 ASSERT(numberOfCodeUnits <= 4); | 1366 DCHECK_LE(numberOfCodeUnits, 4u); |
1367 size_t entityLengthInUTF8 = convertUTF16EntityToUTF8(utf16DecodedEntity, num
berOfCodeUnits, | 1367 size_t entityLengthInUTF8 = convertUTF16EntityToUTF8(utf16DecodedEntity, num
berOfCodeUnits, |
1368 reinterpret_cast<char*>(sharedXHTMLEntityResult), WTF_ARRAY_LENGTH(share
dXHTMLEntityResult)); | 1368 reinterpret_cast<char*>(sharedXHTMLEntityResult), WTF_ARRAY_LENGTH(share
dXHTMLEntityResult)); |
1369 if (!entityLengthInUTF8) | 1369 if (!entityLengthInUTF8) |
1370 return 0; | 1370 return 0; |
1371 | 1371 |
1372 xmlEntityPtr entity = sharedXHTMLEntity(); | 1372 xmlEntityPtr entity = sharedXHTMLEntity(); |
1373 entity->length = entityLengthInUTF8; | 1373 entity->length = entityLengthInUTF8; |
1374 entity->name = name; | 1374 entity->name = name; |
1375 return entity; | 1375 return entity; |
1376 } | 1376 } |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 sax.initialized = XML_SAX2_MAGIC; | 1468 sax.initialized = XML_SAX2_MAGIC; |
1469 m_sawError = false; | 1469 m_sawError = false; |
1470 m_sawCSS = false; | 1470 m_sawCSS = false; |
1471 m_sawXSLTransform = false; | 1471 m_sawXSLTransform = false; |
1472 m_sawFirstElement = false; | 1472 m_sawFirstElement = false; |
1473 | 1473 |
1474 XMLDocumentParserScope scope(document()); | 1474 XMLDocumentParserScope scope(document()); |
1475 if (m_parsingFragment) { | 1475 if (m_parsingFragment) { |
1476 m_context = XMLParserContext::createMemoryParser(&sax, this, chunk); | 1476 m_context = XMLParserContext::createMemoryParser(&sax, this, chunk); |
1477 } else { | 1477 } else { |
1478 ASSERT(!chunk.data()); | 1478 DCHECK(!chunk.data()); |
1479 m_context = XMLParserContext::createStringParser(&sax, this); | 1479 m_context = XMLParserContext::createStringParser(&sax, this); |
1480 } | 1480 } |
1481 } | 1481 } |
1482 | 1482 |
1483 void XMLDocumentParser::doEnd() | 1483 void XMLDocumentParser::doEnd() |
1484 { | 1484 { |
1485 if (!isStopped()) { | 1485 if (!isStopped()) { |
1486 if (m_context) { | 1486 if (m_context) { |
1487 // Tell libxml we're done. | 1487 // Tell libxml we're done. |
1488 { | 1488 { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 | 1538 |
1539 void XMLDocumentParser::stopParsing() | 1539 void XMLDocumentParser::stopParsing() |
1540 { | 1540 { |
1541 DocumentParser::stopParsing(); | 1541 DocumentParser::stopParsing(); |
1542 if (context()) | 1542 if (context()) |
1543 xmlStopParser(context()); | 1543 xmlStopParser(context()); |
1544 } | 1544 } |
1545 | 1545 |
1546 void XMLDocumentParser::resumeParsing() | 1546 void XMLDocumentParser::resumeParsing() |
1547 { | 1547 { |
1548 ASSERT(!isDetached()); | 1548 DCHECK(!isDetached()); |
1549 ASSERT(m_parserPaused); | 1549 DCHECK(m_parserPaused); |
1550 | 1550 |
1551 m_parserPaused = false; | 1551 m_parserPaused = false; |
1552 | 1552 |
1553 // First, execute any pending callbacks | 1553 // First, execute any pending callbacks |
1554 while (!m_pendingCallbacks.isEmpty()) { | 1554 while (!m_pendingCallbacks.isEmpty()) { |
1555 std::unique_ptr<PendingCallback> callback = m_pendingCallbacks.takeFirst
(); | 1555 std::unique_ptr<PendingCallback> callback = m_pendingCallbacks.takeFirst
(); |
1556 callback->call(this); | 1556 callback->call(this); |
1557 | 1557 |
1558 // A callback paused the parser | 1558 // A callback paused the parser |
1559 if (m_parserPaused) | 1559 if (m_parserPaused) |
1560 return; | 1560 return; |
1561 } | 1561 } |
1562 | 1562 |
1563 // Then, write any pending data | 1563 // Then, write any pending data |
1564 SegmentedString rest = m_pendingSrc; | 1564 SegmentedString rest = m_pendingSrc; |
1565 m_pendingSrc.clear(); | 1565 m_pendingSrc.clear(); |
1566 // There is normally only one string left, so toString() shouldn't copy. | 1566 // There is normally only one string left, so toString() shouldn't copy. |
1567 // In any case, the XML parser runs on the main thread and it's OK if | 1567 // In any case, the XML parser runs on the main thread and it's OK if |
1568 // the passed string has more than one reference. | 1568 // the passed string has more than one reference. |
1569 append(rest.toString().impl()); | 1569 append(rest.toString().impl()); |
1570 | 1570 |
1571 // Finally, if finish() has been called and write() didn't result | 1571 // Finally, if finish() has been called and write() didn't result |
1572 // in any further callbacks being queued, call end() | 1572 // in any further callbacks being queued, call end() |
1573 if (m_finishCalled && m_pendingCallbacks.isEmpty()) | 1573 if (m_finishCalled && m_pendingCallbacks.isEmpty()) |
1574 end(); | 1574 end(); |
1575 } | 1575 } |
1576 | 1576 |
1577 bool XMLDocumentParser::appendFragmentSource(const String& chunk) | 1577 bool XMLDocumentParser::appendFragmentSource(const String& chunk) |
1578 { | 1578 { |
1579 ASSERT(!m_context); | 1579 DCHECK(!m_context); |
1580 ASSERT(m_parsingFragment); | 1580 DCHECK(m_parsingFragment); |
1581 | 1581 |
1582 CString chunkAsUtf8 = chunk.utf8(); | 1582 CString chunkAsUtf8 = chunk.utf8(); |
1583 | 1583 |
1584 // libxml2 takes an int for a length, and therefore can't handle XML chunks | 1584 // libxml2 takes an int for a length, and therefore can't handle XML chunks |
1585 // larger than 2 GiB. | 1585 // larger than 2 GiB. |
1586 if (chunkAsUtf8.length() > INT_MAX) | 1586 if (chunkAsUtf8.length() > INT_MAX) |
1587 return false; | 1587 return false; |
1588 | 1588 |
1589 TRACE_EVENT0("blink", "XMLDocumentParser::appendFragmentSource"); | 1589 TRACE_EVENT0("blink", "XMLDocumentParser::appendFragmentSource"); |
1590 initializeParserContext(chunkAsUtf8); | 1590 initializeParserContext(chunkAsUtf8); |
1591 xmlParseContent(context()); | 1591 xmlParseContent(context()); |
1592 endDocument(); // Close any open text nodes. | 1592 endDocument(); // Close any open text nodes. |
1593 | 1593 |
1594 // FIXME: If this code is actually needed, it should probably move to | 1594 // FIXME: If this code is actually needed, it should probably move to |
1595 // finish() | 1595 // finish() |
1596 // XMLDocumentParserQt has a similar check (m_stream.error() == | 1596 // XMLDocumentParserQt has a similar check (m_stream.error() == |
1597 // QXmlStreamReader::PrematureEndOfDocumentError) in doEnd(). Check if all | 1597 // QXmlStreamReader::PrematureEndOfDocumentError) in doEnd(). Check if all |
1598 // the chunk has been processed. | 1598 // the chunk has been processed. |
1599 long bytesProcessed = xmlByteConsumed(context()); | 1599 long bytesProcessed = xmlByteConsumed(context()); |
1600 if (bytesProcessed == -1 || static_cast<unsigned long>(bytesProcessed) != ch
unkAsUtf8.length()) { | 1600 if (bytesProcessed == -1 || static_cast<unsigned long>(bytesProcessed) != ch
unkAsUtf8.length()) { |
1601 // FIXME: I don't believe we can hit this case without also having seen | 1601 // FIXME: I don't believe we can hit this case without also having seen |
1602 // an error or a null byte. If we hit this ASSERT, we've found a test | 1602 // an error or a null byte. If we hit this DCHECK, we've found a test |
1603 // case which demonstrates the need for this code. | 1603 // case which demonstrates the need for this code. |
1604 ASSERT(m_sawError || (bytesProcessed >= 0 && !chunkAsUtf8.data()[bytesPr
ocessed])); | 1604 DCHECK(m_sawError || (bytesProcessed >= 0 && !chunkAsUtf8.data()[bytesPr
ocessed])); |
1605 return false; | 1605 return false; |
1606 } | 1606 } |
1607 | 1607 |
1608 // No error if the chunk is well formed or it is not but we have no error. | 1608 // No error if the chunk is well formed or it is not but we have no error. |
1609 return context()->wellFormed || !xmlCtxtGetLastError(context()); | 1609 return context()->wellFormed || !xmlCtxtGetLastError(context()); |
1610 } | 1610 } |
1611 | 1611 |
1612 // -------------------------------- | 1612 // -------------------------------- |
1613 | 1613 |
1614 struct AttributeParseState { | 1614 struct AttributeParseState { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 sax.initialized = XML_SAX2_MAGIC; | 1651 sax.initialized = XML_SAX2_MAGIC; |
1652 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); | 1652 RefPtr<XMLParserContext> parser = XMLParserContext::createStringParser(&sax,
&state); |
1653 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; | 1653 String parseString = "<?xml version=\"1.0\"?><attrs " + string + " />"; |
1654 parseChunk(parser->context(), parseString); | 1654 parseChunk(parser->context(), parseString); |
1655 finishParsing(parser->context()); | 1655 finishParsing(parser->context()); |
1656 attrsOK = state.gotAttributes; | 1656 attrsOK = state.gotAttributes; |
1657 return state.attributes; | 1657 return state.attributes; |
1658 } | 1658 } |
1659 | 1659 |
1660 } // namespace blink | 1660 } // namespace blink |
OLD | NEW |