| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 } | 390 } |
| 391 | 391 |
| 392 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser( | 392 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser( |
| 393 const DocumentEncodingData& data) { | 393 const DocumentEncodingData& data) { |
| 394 document()->setEncodingData(data); | 394 document()->setEncodingData(data); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void HTMLDocumentParser::validateSpeculations( | 397 void HTMLDocumentParser::validateSpeculations( |
| 398 std::unique_ptr<TokenizedChunk> chunk) { | 398 std::unique_ptr<TokenizedChunk> chunk) { |
| 399 ASSERT(chunk); | 399 ASSERT(chunk); |
| 400 // TODO(kouhei): We should simplify codepath here by disallowing |
| 401 // validateSpeculations |
| 402 // while isWaitingForScripts, and m_lastChunkBeforeScript can simply be |
| 403 // pushed to m_speculations. |
| 400 if (isWaitingForScripts()) { | 404 if (isWaitingForScripts()) { |
| 401 // We're waiting on a network script, just save the chunk, we'll get a | 405 // We're waiting on a network script, just save the chunk, we'll get a |
| 402 // second validateSpeculations call after the script completes. This call | 406 // second validateSpeculations call after the script completes. This call |
| 403 // should have been made immediately after runScriptsForPausedTreeBuilder | 407 // should have been made immediately after runScriptsForPausedTreeBuilder |
| 404 // which may have started a network load and left us waiting. | 408 // which may have started a network load and left us waiting. |
| 405 ASSERT(!m_lastChunkBeforeScript); | 409 ASSERT(!m_lastChunkBeforeScript); |
| 406 m_lastChunkBeforeScript = std::move(chunk); | 410 m_lastChunkBeforeScript = std::move(chunk); |
| 407 return; | 411 return; |
| 408 } | 412 } |
| 409 | 413 |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 // If either object has a blocking script, the parser should be paused. | 1053 // If either object has a blocking script, the parser should be paused. |
| 1050 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript || | 1054 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript || |
| 1051 m_reentryPermit->parserPauseFlag(); | 1055 m_reentryPermit->parserPauseFlag(); |
| 1052 } | 1056 } |
| 1053 | 1057 |
| 1054 void HTMLDocumentParser::resumeParsingAfterScriptExecution() { | 1058 void HTMLDocumentParser::resumeParsingAfterScriptExecution() { |
| 1055 ASSERT(!isExecutingScript()); | 1059 ASSERT(!isExecutingScript()); |
| 1056 ASSERT(!isWaitingForScripts()); | 1060 ASSERT(!isWaitingForScripts()); |
| 1057 | 1061 |
| 1058 if (m_haveBackgroundParser) { | 1062 if (m_haveBackgroundParser) { |
| 1059 validateSpeculations(std::move(m_lastChunkBeforeScript)); | 1063 if (m_lastChunkBeforeScript) { |
| 1060 ASSERT(!m_lastChunkBeforeScript); | 1064 validateSpeculations(std::move(m_lastChunkBeforeScript)); |
| 1061 pumpPendingSpeculations(); | 1065 DCHECK(!m_lastChunkBeforeScript); |
| 1066 pumpPendingSpeculations(); |
| 1067 } |
| 1062 return; | 1068 return; |
| 1063 } | 1069 } |
| 1064 | 1070 |
| 1065 m_insertionPreloadScanner.reset(); | 1071 m_insertionPreloadScanner.reset(); |
| 1066 pumpTokenizerIfPossible(); | 1072 if (m_tokenizer) { |
| 1073 pumpTokenizerIfPossible(); |
| 1074 } |
| 1067 endIfDelayed(); | 1075 endIfDelayed(); |
| 1068 } | 1076 } |
| 1069 | 1077 |
| 1070 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() { | 1078 void HTMLDocumentParser::appendCurrentInputStreamToPreloadScannerAndScan() { |
| 1071 ASSERT(m_preloadScanner); | 1079 ASSERT(m_preloadScanner); |
| 1072 m_preloadScanner->appendToEnd(m_input.current()); | 1080 m_preloadScanner->appendToEnd(m_input.current()); |
| 1073 scanAndPreload(m_preloadScanner.get()); | 1081 scanAndPreload(m_preloadScanner.get()); |
| 1074 } | 1082 } |
| 1075 | 1083 |
| 1076 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource) { | 1084 void HTMLDocumentParser::notifyScriptLoaded(Resource* cachedResource) { |
| 1077 ASSERT(m_scriptRunner); | 1085 ASSERT(m_scriptRunner); |
| 1078 ASSERT(!isExecutingScript()); | 1086 ASSERT(!isExecutingScript()); |
| 1079 | 1087 |
| 1080 if (isStopped()) { | 1088 if (isStopped()) { |
| 1081 return; | 1089 return; |
| 1082 } | 1090 } |
| 1083 | 1091 |
| 1084 if (isStopping()) { | 1092 if (isStopping()) { |
| 1085 attemptToRunDeferredScriptsAndEnd(); | 1093 attemptToRunDeferredScriptsAndEnd(); |
| 1086 return; | 1094 return; |
| 1087 } | 1095 } |
| 1088 | 1096 |
| 1089 m_scriptRunner->executeScriptsWaitingForLoad(cachedResource); | 1097 m_scriptRunner->executeScriptsWaitingForLoad(cachedResource); |
| 1090 if (!isWaitingForScripts()) | 1098 if (!isWaitingForScripts()) |
| 1091 resumeParsingAfterScriptExecution(); | 1099 resumeParsingAfterScriptExecution(); |
| 1092 } | 1100 } |
| 1093 | 1101 |
| 1094 void HTMLDocumentParser::executeScriptsWaitingForResources() { | 1102 void HTMLDocumentParser::executeScriptsWaitingForResources() { |
| 1103 DCHECK(document()->isScriptExecutionReady()); |
| 1104 |
| 1095 // Document only calls this when the Document owns the DocumentParser so this | 1105 // Document only calls this when the Document owns the DocumentParser so this |
| 1096 // will not be called in the DocumentFragment case. | 1106 // will not be called in the DocumentFragment case. |
| 1097 ASSERT(m_scriptRunner); | 1107 DCHECK(m_scriptRunner); |
| 1098 // Ignore calls unless we have a script blocking the parser waiting on a | |
| 1099 // stylesheet load. Otherwise we are currently parsing and this is a | |
| 1100 // re-entrant call from encountering a </ style> tag. | |
| 1101 if (!m_scriptRunner->hasScriptsWaitingForResources()) | |
| 1102 return; | |
| 1103 m_scriptRunner->executeScriptsWaitingForResources(); | 1108 m_scriptRunner->executeScriptsWaitingForResources(); |
| 1104 if (!isWaitingForScripts()) | 1109 if (!isWaitingForScripts()) |
| 1105 resumeParsingAfterScriptExecution(); | 1110 resumeParsingAfterScriptExecution(); |
| 1106 } | 1111 } |
| 1107 | 1112 |
| 1108 void HTMLDocumentParser::parseDocumentFragment( | 1113 void HTMLDocumentParser::parseDocumentFragment( |
| 1109 const String& source, | 1114 const String& source, |
| 1110 DocumentFragment* fragment, | 1115 DocumentFragment* fragment, |
| 1111 Element* contextElement, | 1116 Element* contextElement, |
| 1112 ParserContentPolicy parserContentPolicy) { | 1117 ParserContentPolicy parserContentPolicy) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 case Asynchronous: | 1306 case Asynchronous: |
| 1302 m_loadingTaskRunner->postTask( | 1307 m_loadingTaskRunner->postTask( |
| 1303 BLINK_FROM_HERE, | 1308 BLINK_FROM_HERE, |
| 1304 WTF::bind(function, std::forward<Ps>(parameters)...)); | 1309 WTF::bind(function, std::forward<Ps>(parameters)...)); |
| 1305 return; | 1310 return; |
| 1306 } | 1311 } |
| 1307 NOTREACHED(); | 1312 NOTREACHED(); |
| 1308 } | 1313 } |
| 1309 | 1314 |
| 1310 } // namespace blink | 1315 } // namespace blink |
| OLD | NEW |