| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 && document()->frame() && document()->frame()->navigationScheduler().loc
ationChangePending()) | 310 && document()->frame() && document()->frame()->navigationScheduler().loc
ationChangePending()) |
| 311 return false; | 311 return false; |
| 312 | 312 |
| 313 return true; | 313 return true; |
| 314 } | 314 } |
| 315 | 315 |
| 316 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa
rsedChunk> chunk) | 316 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa
rsedChunk> chunk) |
| 317 { | 317 { |
| 318 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser"); | 318 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou
ndParser"); |
| 319 | 319 |
| 320 if (!isParsing()) | 320 // alert(), runModalDialog, and the JavaScript Debugger all run nested event
loops |
| 321 // which can cause this method to be re-entered. We detect re-entry using |
| 322 // hasActiveParser(), save the chunk as a speculation, and return. |
| 323 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active
ParserCount() > 0 || m_tasksWereSuspended || isScheduledForResume()) { |
| 324 if (m_tasksWereSuspended) |
| 325 m_parserScheduler->forceResumeAfterYield(); |
| 326 m_preloader->takeAndPreload(chunk->preloads); |
| 327 m_speculations.append(chunk); |
| 321 return; | 328 return; |
| 322 | |
| 323 // ApplicationCache needs to be initialized before issuing preloads. | |
| 324 // We suspend preload until HTMLHTMLElement is inserted and | |
| 325 // ApplicationCache is initialized. | |
| 326 if (!document()->documentElement()) { | |
| 327 for (auto& request : chunk->preloads) | |
| 328 m_queuedPreloads.append(request.release()); | |
| 329 } else { | |
| 330 // We can safely assume that there are no queued preloads request after | |
| 331 // the document element is available, as we empty the queue immediately | |
| 332 // after the document element is created in pumpPendingSpeculations(). | |
| 333 ASSERT(m_queuedPreloads.isEmpty()); | |
| 334 m_preloader->takeAndPreload(chunk->preloads); | |
| 335 } | 329 } |
| 336 | 330 |
| 331 // processParsedChunkFromBackgroundParser can cause this parser to be detach
ed from the Document, |
| 332 // but we need to ensure it isn't deleted yet. |
| 333 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); |
| 334 |
| 335 ASSERT(m_speculations.isEmpty()); |
| 336 chunk->preloads.clear(); // We don't need to preload because we're going to
parse immediately. |
| 337 m_speculations.append(chunk); | 337 m_speculations.append(chunk); |
| 338 | 338 pumpPendingSpeculations(); |
| 339 if (!isWaitingForScripts() && !isScheduledForResume()) { | |
| 340 if (m_tasksWereSuspended) | |
| 341 m_parserScheduler->forceResumeAfterYield(); | |
| 342 else | |
| 343 m_parserScheduler->scheduleForResume(); | |
| 344 } | |
| 345 } | 339 } |
| 346 | 340 |
| 347 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) | 341 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) |
| 348 { | 342 { |
| 349 document()->setEncodingData(data); | 343 document()->setEncodingData(data); |
| 350 } | 344 } |
| 351 | 345 |
| 352 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) | 346 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) |
| 353 { | 347 { |
| 354 ASSERT(chunk); | 348 ASSERT(chunk); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 ASSERT(m_speculations.isEmpty()); // There should never be any c
hunks after the EOF. | 446 ASSERT(m_speculations.isEmpty()); // There should never be any c
hunks after the EOF. |
| 453 prepareToStopParsing(); | 447 prepareToStopParsing(); |
| 454 } | 448 } |
| 455 break; | 449 break; |
| 456 } | 450 } |
| 457 | 451 |
| 458 m_textPosition = it->textPosition(); | 452 m_textPosition = it->textPosition(); |
| 459 | 453 |
| 460 constructTreeFromCompactHTMLToken(*it); | 454 constructTreeFromCompactHTMLToken(*it); |
| 461 | 455 |
| 462 if (!m_queuedPreloads.isEmpty() && document()->documentElement()) | |
| 463 m_preloader->takeAndPreload(m_queuedPreloads); | |
| 464 | |
| 465 if (isStopped()) | 456 if (isStopped()) |
| 466 break; | 457 break; |
| 467 | 458 |
| 468 if (isWaitingForScripts()) { | 459 if (isWaitingForScripts()) { |
| 469 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. | 460 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. |
| 470 runScriptsForPausedTreeBuilder(); | 461 runScriptsForPausedTreeBuilder(); |
| 471 validateSpeculations(chunk.release()); | 462 validateSpeculations(chunk.release()); |
| 472 break; | 463 break; |
| 473 } | 464 } |
| 474 | 465 |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1063 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
| 1073 { | 1064 { |
| 1074 ASSERT(decoder); | 1065 ASSERT(decoder); |
| 1075 DecodedDataDocumentParser::setDecoder(decoder); | 1066 DecodedDataDocumentParser::setDecoder(decoder); |
| 1076 | 1067 |
| 1077 if (m_haveBackgroundParser) | 1068 if (m_haveBackgroundParser) |
| 1078 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); | 1069 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); |
| 1079 } | 1070 } |
| 1080 | 1071 |
| 1081 } | 1072 } |
| OLD | NEW |