| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 , m_options(&document) | 142 , m_options(&document) |
| 143 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) | 143 , m_token(syncPolicy == ForceSynchronousParsing ? adoptPtr(new HTMLToken) :
nullptr) |
| 144 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) | 144 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) |
| 145 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) | 145 , m_scriptRunner(HTMLScriptRunner::create(&document, this)) |
| 146 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) | 146 , m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy
(), reportErrors, m_options)) |
| 147 , m_loadingTaskRunner(adoptPtr(document.loadingTaskRunner()->clone())) | 147 , m_loadingTaskRunner(adoptPtr(document.loadingTaskRunner()->clone())) |
| 148 , m_parserScheduler(HTMLParserScheduler::create(this, m_loadingTaskRunner.ge
t())) | 148 , m_parserScheduler(HTMLParserScheduler::create(this, m_loadingTaskRunner.ge
t())) |
| 149 , m_xssAuditorDelegate(&document) | 149 , m_xssAuditorDelegate(&document) |
| 150 , m_weakFactory(this) | 150 , m_weakFactory(this) |
| 151 , m_preloader(HTMLResourcePreloader::create(document)) | 151 , m_preloader(HTMLResourcePreloader::create(document)) |
| 152 , m_parsedChunkQueue(ParsedChunkQueue::create()) | |
| 153 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) | 152 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) |
| 154 , m_endWasDelayed(false) | 153 , m_endWasDelayed(false) |
| 155 , m_haveBackgroundParser(false) | 154 , m_haveBackgroundParser(false) |
| 156 , m_tasksWereSuspended(false) | 155 , m_tasksWereSuspended(false) |
| 157 , m_pumpSessionNestingLevel(0) | 156 , m_pumpSessionNestingLevel(0) |
| 158 , m_pumpSpeculationsSessionNestingLevel(0) | 157 , m_pumpSpeculationsSessionNestingLevel(0) |
| 159 , m_isParsingAtLineNumber(false) | 158 , m_isParsingAtLineNumber(false) |
| 160 { | 159 { |
| 161 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); | 160 ASSERT(shouldUseThreading() || (m_token && m_tokenizer)); |
| 162 } | 161 } |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // should happen is that assigning window.location causes the | 348 // should happen is that assigning window.location causes the |
| 350 // parser to stop parsing cleanly. The problem is we're not | 349 // parser to stop parsing cleanly. The problem is we're not |
| 351 // perpared to do that at every point where we run JavaScript. | 350 // perpared to do that at every point where we run JavaScript. |
| 352 if (!isParsingFragment() | 351 if (!isParsingFragment() |
| 353 && document()->frame() && document()->frame()->navigationScheduler().loc
ationChangePending()) | 352 && document()->frame() && document()->frame()->navigationScheduler().loc
ationChangePending()) |
| 354 return false; | 353 return false; |
| 355 | 354 |
| 356 return true; | 355 return true; |
| 357 } | 356 } |
| 358 | 357 |
| 359 void HTMLDocumentParser::notifyPendingParsedChunks() | 358 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa
rsedChunk> chunk) |
| 360 { | 359 { |
| 361 TRACE_EVENT0("blink", "HTMLDocumentParser::notifyPendingParsedChunks"); | 360 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser"); |
| 362 ASSERT(m_parsedChunkQueue); | |
| 363 | |
| 364 Vector<OwnPtr<ParsedChunk>> pendingChunks; | |
| 365 m_parsedChunkQueue->takeAll(pendingChunks); | |
| 366 | 361 |
| 367 if (!isParsing()) | 362 if (!isParsing()) |
| 368 return; | 363 return; |
| 369 | 364 |
| 370 // ApplicationCache needs to be initialized before issuing preloads. | 365 // ApplicationCache needs to be initialized before issuing preloads. |
| 371 // We suspend preload until HTMLHTMLElement is inserted and | 366 // We suspend preload until HTMLHTMLElement is inserted and |
| 372 // ApplicationCache is initialized. | 367 // ApplicationCache is initialized. |
| 373 if (!document()->documentElement()) { | 368 if (!document()->documentElement()) { |
| 374 for (auto& chunk : pendingChunks) { | 369 for (auto& request : chunk->preloads) |
| 375 for (auto& request : chunk->preloads) | 370 m_queuedPreloads.append(request.release()); |
| 376 m_queuedPreloads.append(request.release()); | |
| 377 } | |
| 378 } else { | 371 } else { |
| 379 // We can safely assume that there are no queued preloads request after | 372 // We can safely assume that there are no queued preloads request after |
| 380 // the document element is available, as we empty the queue immediately | 373 // the document element is available, as we empty the queue immediately |
| 381 // after the document element is created in pumpPendingSpeculations(). | 374 // after the document element is created in pumpPendingSpeculations(). |
| 382 ASSERT(m_queuedPreloads.isEmpty()); | 375 ASSERT(m_queuedPreloads.isEmpty()); |
| 383 for (auto& chunk : pendingChunks) | 376 m_preloader->takeAndPreload(chunk->preloads); |
| 384 m_preloader->takeAndPreload(chunk->preloads); | |
| 385 } | 377 } |
| 386 | 378 |
| 387 for (auto& chunk : pendingChunks) | 379 m_speculations.append(chunk); |
| 388 m_speculations.append(chunk.release()); | |
| 389 | 380 |
| 390 if (!isWaitingForScripts() && !isScheduledForResume()) { | 381 if (!isWaitingForScripts() && !isScheduledForResume()) { |
| 391 if (m_tasksWereSuspended) | 382 if (m_tasksWereSuspended) |
| 392 m_parserScheduler->forceResumeAfterYield(); | 383 m_parserScheduler->forceResumeAfterYield(); |
| 393 else | 384 else |
| 394 m_parserScheduler->scheduleForResume(); | 385 m_parserScheduler->scheduleForResume(); |
| 395 } | 386 } |
| 396 } | 387 } |
| 397 | 388 |
| 398 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) | 389 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 loader->attachThreadedDataReceiver(ParserDataReceiver::create(m_back
groundParser, document()->contextDocument().get())); | 787 loader->attachThreadedDataReceiver(ParserDataReceiver::create(m_back
groundParser, document()->contextDocument().get())); |
| 797 } | 788 } |
| 798 | 789 |
| 799 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); | 790 OwnPtr<BackgroundHTMLParser::Configuration> config = adoptPtr(new Background
HTMLParser::Configuration); |
| 800 config->options = m_options; | 791 config->options = m_options; |
| 801 config->parser = m_weakFactory.createWeakPtr(); | 792 config->parser = m_weakFactory.createWeakPtr(); |
| 802 config->xssAuditor = adoptPtr(new XSSAuditor); | 793 config->xssAuditor = adoptPtr(new XSSAuditor); |
| 803 config->xssAuditor->init(document(), &m_xssAuditorDelegate); | 794 config->xssAuditor->init(document(), &m_xssAuditorDelegate); |
| 804 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), CachedDocumentParameters::create(document()))); | 795 config->preloadScanner = adoptPtr(new TokenPreloadScanner(document()->url().
copy(), CachedDocumentParameters::create(document()))); |
| 805 config->decoder = takeDecoder(); | 796 config->decoder = takeDecoder(); |
| 806 config->parsedChunkQueue = m_parsedChunkQueue.get(); | |
| 807 if (document()->settings()) { | 797 if (document()->settings()) { |
| 808 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit()) | 798 if (document()->settings()->backgroundHtmlParserOutstandingTokenLimit()) |
| 809 config->outstandingTokenLimit = document()->settings()->backgroundHt
mlParserOutstandingTokenLimit(); | 799 config->outstandingTokenLimit = document()->settings()->backgroundHt
mlParserOutstandingTokenLimit(); |
| 810 if (document()->settings()->backgroundHtmlParserPendingTokenLimit()) | 800 if (document()->settings()->backgroundHtmlParserPendingTokenLimit()) |
| 811 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa
rserPendingTokenLimit(); | 801 config->pendingTokenLimit = document()->settings()->backgroundHtmlPa
rserPendingTokenLimit(); |
| 812 } | 802 } |
| 813 | 803 |
| 814 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); | 804 ASSERT(config->xssAuditor->isSafeToSendToAnotherThread()); |
| 815 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); | 805 ASSERT(config->preloadScanner->isSafeToSendToAnotherThread()); |
| 816 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
tart, reference.release(), config.release(), | 806 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::s
tart, reference.release(), config.release(), |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1136 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 1147 { | 1137 { |
| 1148 ASSERT(decoder); | 1138 ASSERT(decoder); |
| 1149 DecodedDataDocumentParser::setDecoder(decoder); | 1139 DecodedDataDocumentParser::setDecoder(decoder); |
| 1150 | 1140 |
| 1151 if (m_haveBackgroundParser) | 1141 if (m_haveBackgroundParser) |
| 1152 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); | 1142 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); |
| 1153 } | 1143 } |
| 1154 | 1144 |
| 1155 } | 1145 } |
| OLD | NEW |