| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 m_reentryPermit(HTMLParserReentryPermit::create()), | 127 m_reentryPermit(HTMLParserReentryPermit::create()), |
| 128 m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken) | 128 m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken) |
| 129 : nullptr), | 129 : nullptr), |
| 130 m_tokenizer(syncPolicy == ForceSynchronousParsing | 130 m_tokenizer(syncPolicy == ForceSynchronousParsing |
| 131 ? HTMLTokenizer::create(m_options) | 131 ? HTMLTokenizer::create(m_options) |
| 132 : nullptr), | 132 : nullptr), |
| 133 m_loadingTaskRunner( | 133 m_loadingTaskRunner( |
| 134 TaskRunnerHelper::get(TaskType::Networking, &document)->clone()), | 134 TaskRunnerHelper::get(TaskType::Networking, &document)->clone()), |
| 135 m_parserScheduler( | 135 m_parserScheduler( |
| 136 syncPolicy == AllowAsynchronousParsing | 136 syncPolicy == AllowAsynchronousParsing |
| 137 ? HTMLParserScheduler::create(this, m_loadingTaskRunner.get()) | 137 ? HTMLParserScheduler::create(document, |
| 138 this, |
| 139 m_loadingTaskRunner.get()) |
| 138 : nullptr), | 140 : nullptr), |
| 139 m_xssAuditorDelegate(&document), | 141 m_xssAuditorDelegate(&document), |
| 140 m_weakFactory(this), | 142 m_weakFactory(this), |
| 141 m_preloader(HTMLResourcePreloader::create(document)), | 143 m_preloader(HTMLResourcePreloader::create(document)), |
| 142 m_tokenizedChunkQueue(TokenizedChunkQueue::create()), | 144 m_tokenizedChunkQueue(TokenizedChunkQueue::create()), |
| 143 m_evaluator(DocumentWriteEvaluator::create(document)), | 145 m_evaluator(DocumentWriteEvaluator::create(document)), |
| 144 m_pendingCSPMetaToken(nullptr), | 146 m_pendingCSPMetaToken(nullptr), |
| 145 m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing), | 147 m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing), |
| 146 m_endWasDelayed(false), | 148 m_endWasDelayed(false), |
| 147 m_haveBackgroundParser(false), | 149 m_haveBackgroundParser(false), |
| 148 m_tasksWereSuspended(false), | |
| 149 m_pumpSessionNestingLevel(0), | 150 m_pumpSessionNestingLevel(0), |
| 150 m_pumpSpeculationsSessionNestingLevel(0), | 151 m_pumpSpeculationsSessionNestingLevel(0), |
| 151 m_isParsingAtLineNumber(false), | 152 m_isParsingAtLineNumber(false), |
| 152 m_triedLoadingLinkHeaders(false) { | 153 m_triedLoadingLinkHeaders(false) { |
| 153 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); | 154 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); |
| 154 // Threading is not allowed in prefetch mode. | 155 // Threading is not allowed in prefetch mode. |
| 155 DCHECK(!document.isPrefetchOnly() || !shouldUseThreading()); | 156 DCHECK(!document.isPrefetchOnly() || !shouldUseThreading()); |
| 156 | 157 |
| 157 ThreadState::current()->registerPreFinalizer(this); | 158 ThreadState::current()->registerPreFinalizer(this); |
| 158 } | 159 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 const CompactHTMLToken& token = chunk->tokens->at(index); | 375 const CompactHTMLToken& token = chunk->tokens->at(index); |
| 375 ASSERT(token.type() == HTMLToken::TokenType::Character); | 376 ASSERT(token.type() == HTMLToken::TokenType::Character); |
| 376 evaluateAndPreloadScriptForDocumentWrite(token.data()); | 377 evaluateAndPreloadScriptForDocumentWrite(token.data()); |
| 377 } | 378 } |
| 378 } | 379 } |
| 379 } | 380 } |
| 380 | 381 |
| 381 for (auto& chunk : pendingChunks) | 382 for (auto& chunk : pendingChunks) |
| 382 m_speculations.append(std::move(chunk)); | 383 m_speculations.append(std::move(chunk)); |
| 383 | 384 |
| 384 if (!isWaitingForScripts() && !isScheduledForResume()) { | 385 if (!isWaitingForScripts() && !isScheduledForResume()) |
| 385 if (m_tasksWereSuspended) | 386 m_parserScheduler->scheduleForResume(); |
| 386 m_parserScheduler->forceResumeAfterYield(); | |
| 387 else | |
| 388 m_parserScheduler->scheduleForResume(); | |
| 389 } | |
| 390 } | 387 } |
| 391 | 388 |
| 392 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser( | 389 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser( |
| 393 const DocumentEncodingData& data) { | 390 const DocumentEncodingData& data) { |
| 394 document()->setEncodingData(data); | 391 document()->setEncodingData(data); |
| 395 } | 392 } |
| 396 | 393 |
| 397 void HTMLDocumentParser::validateSpeculations( | 394 void HTMLDocumentParser::validateSpeculations( |
| 398 std::unique_ptr<TokenizedChunk> chunk) { | 395 std::unique_ptr<TokenizedChunk> chunk) { |
| 399 ASSERT(chunk); | 396 ASSERT(chunk); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1116 Element* contextElement, | 1113 Element* contextElement, |
| 1117 ParserContentPolicy parserContentPolicy) { | 1114 ParserContentPolicy parserContentPolicy) { |
| 1118 HTMLDocumentParser* parser = | 1115 HTMLDocumentParser* parser = |
| 1119 HTMLDocumentParser::create(fragment, contextElement, parserContentPolicy); | 1116 HTMLDocumentParser::create(fragment, contextElement, parserContentPolicy); |
| 1120 parser->append(source); | 1117 parser->append(source); |
| 1121 parser->finish(); | 1118 parser->finish(); |
| 1122 // Allows ~DocumentParser to assert it was detached before destruction. | 1119 // Allows ~DocumentParser to assert it was detached before destruction. |
| 1123 parser->detach(); | 1120 parser->detach(); |
| 1124 } | 1121 } |
| 1125 | 1122 |
| 1126 void HTMLDocumentParser::suspendScheduledTasks() { | |
| 1127 ASSERT(!m_tasksWereSuspended); | |
| 1128 m_tasksWereSuspended = true; | |
| 1129 if (m_parserScheduler) | |
| 1130 m_parserScheduler->suspend(); | |
| 1131 } | |
| 1132 | |
| 1133 void HTMLDocumentParser::resumeScheduledTasks() { | |
| 1134 ASSERT(m_tasksWereSuspended); | |
| 1135 m_tasksWereSuspended = false; | |
| 1136 if (m_parserScheduler) | |
| 1137 m_parserScheduler->resume(); | |
| 1138 } | |
| 1139 | |
| 1140 void HTMLDocumentParser::appendBytes(const char* data, size_t length) { | 1123 void HTMLDocumentParser::appendBytes(const char* data, size_t length) { |
| 1141 if (!length || isStopped()) | 1124 if (!length || isStopped()) |
| 1142 return; | 1125 return; |
| 1143 | 1126 |
| 1144 if (shouldUseThreading()) { | 1127 if (shouldUseThreading()) { |
| 1145 double bytesReceivedTime = monotonicallyIncreasingTimeMS(); | 1128 double bytesReceivedTime = monotonicallyIncreasingTimeMS(); |
| 1146 if (!m_haveBackgroundParser) | 1129 if (!m_haveBackgroundParser) |
| 1147 startBackgroundParser(); | 1130 startBackgroundParser(); |
| 1148 | 1131 |
| 1149 std::unique_ptr<Vector<char>> buffer = makeUnique<Vector<char>>(length); | 1132 std::unique_ptr<Vector<char>> buffer = makeUnique<Vector<char>>(length); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 case Asynchronous: | 1289 case Asynchronous: |
| 1307 m_loadingTaskRunner->postTask( | 1290 m_loadingTaskRunner->postTask( |
| 1308 BLINK_FROM_HERE, | 1291 BLINK_FROM_HERE, |
| 1309 WTF::bind(function, std::forward<Ps>(parameters)...)); | 1292 WTF::bind(function, std::forward<Ps>(parameters)...)); |
| 1310 return; | 1293 return; |
| 1311 } | 1294 } |
| 1312 NOTREACHED(); | 1295 NOTREACHED(); |
| 1313 } | 1296 } |
| 1314 | 1297 |
| 1315 } // namespace blink | 1298 } // namespace blink |
| OLD | NEW |