Index: Source/core/html/parser/HTMLDocumentParser.cpp |
diff --git a/Source/core/html/parser/HTMLDocumentParser.cpp b/Source/core/html/parser/HTMLDocumentParser.cpp |
index 6bca677c02e08de0064c97a3c99077c6e1283ac9..3b86992673c0b91bd3c699a500e346c773fb6629 100644 |
--- a/Source/core/html/parser/HTMLDocumentParser.cpp |
+++ b/Source/core/html/parser/HTMLDocumentParser.cpp |
@@ -331,23 +331,21 @@ void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa |
{ |
TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser"); |
- // alert(), runModalDialog, and the JavaScript Debugger all run nested event loops |
- // which can cause this method to be re-entered. We detect re-entry using |
- // hasActiveParser(), save the chunk as a speculation, and return. |
- if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->activeParserCount() > 0) { |
+ // ApplicationCache needs to be initialized before issuing preloads. |
+ // We suspend preload until HTMLHTMLElement is inserted and |
+ // ApplicationCache is initialized. |
+ if (!document()->documentElement()) { |
+ for (auto& request : m_queuedPreloads) |
+ m_queuedPreloads.append(request.release()); |
+ } else { |
+ ASSERT(m_queuedPreloads.isEmpty()); |
m_preloader->takeAndPreload(chunk->preloads); |
- m_speculations.append(chunk); |
- return; |
} |
- // processParsedChunkFromBackgroundParser can cause this parser to be detached from the Document, |
- // but we need to ensure it isn't deleted yet. |
- RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); |
- |
- ASSERT(m_speculations.isEmpty()); |
- chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately. |
m_speculations.append(chunk); |
- pumpPendingSpeculations(); |
+ |
+ if (!isWaitingForScripts()) |
+ m_parserScheduler->scheduleForResume(); |
} |
void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const DocumentEncodingData& data) |
@@ -464,6 +462,9 @@ size_t HTMLDocumentParser::processParsedChunkFromBackgroundParser(PassOwnPtr<Par |
constructTreeFromCompactHTMLToken(*it); |
+ if (!m_queuedPreloads.isEmpty() && document()->documentElement()) |
+ m_preloader->takeAndPreload(m_queuedPreloads); |
+ |
if (isStopped()) |
break; |