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 // alert(), runModalDialog, and the JavaScript Debugger all run nested event
loops | 320 if (!isParsing()) |
321 // which can cause this method to be re-entered. We detect re-entry using | 321 return; |
322 // hasActiveParser(), save the chunk as a speculation, and return. | 322 |
323 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active
ParserCount() > 0 || m_tasksWereSuspended || isScheduledForResume()) { | 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 } |
| 336 |
| 337 m_speculations.append(chunk); |
| 338 |
| 339 if (!isWaitingForScripts() && !isScheduledForResume()) { |
324 if (m_tasksWereSuspended) | 340 if (m_tasksWereSuspended) |
325 m_parserScheduler->forceResumeAfterYield(); | 341 m_parserScheduler->forceResumeAfterYield(); |
326 m_preloader->takeAndPreload(chunk->preloads); | 342 else |
327 m_speculations.append(chunk); | 343 m_parserScheduler->scheduleForResume(); |
328 return; | |
329 } | 344 } |
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); | |
338 pumpPendingSpeculations(); | |
339 } | 345 } |
340 | 346 |
341 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) | 347 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume
ntEncodingData& data) |
342 { | 348 { |
343 document()->setEncodingData(data); | 349 document()->setEncodingData(data); |
344 } | 350 } |
345 | 351 |
346 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) | 352 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) |
347 { | 353 { |
348 ASSERT(chunk); | 354 ASSERT(chunk); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 ASSERT(m_speculations.isEmpty()); // There should never be any c
hunks after the EOF. | 452 ASSERT(m_speculations.isEmpty()); // There should never be any c
hunks after the EOF. |
447 prepareToStopParsing(); | 453 prepareToStopParsing(); |
448 } | 454 } |
449 break; | 455 break; |
450 } | 456 } |
451 | 457 |
452 m_textPosition = it->textPosition(); | 458 m_textPosition = it->textPosition(); |
453 | 459 |
454 constructTreeFromCompactHTMLToken(*it); | 460 constructTreeFromCompactHTMLToken(*it); |
455 | 461 |
| 462 if (!m_queuedPreloads.isEmpty() && document()->documentElement()) |
| 463 m_preloader->takeAndPreload(m_queuedPreloads); |
| 464 |
456 if (isStopped()) | 465 if (isStopped()) |
457 break; | 466 break; |
458 | 467 |
459 if (isWaitingForScripts()) { | 468 if (isWaitingForScripts()) { |
460 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. | 469 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. |
461 runScriptsForPausedTreeBuilder(); | 470 runScriptsForPausedTreeBuilder(); |
462 validateSpeculations(chunk.release()); | 471 validateSpeculations(chunk.release()); |
463 break; | 472 break; |
464 } | 473 } |
465 | 474 |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1072 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1064 { | 1073 { |
1065 ASSERT(decoder); | 1074 ASSERT(decoder); |
1066 DecodedDataDocumentParser::setDecoder(decoder); | 1075 DecodedDataDocumentParser::setDecoder(decoder); |
1067 | 1076 |
1068 if (m_haveBackgroundParser) | 1077 if (m_haveBackgroundParser) |
1069 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); | 1078 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco
der, m_backgroundParser, takeDecoder())); |
1070 } | 1079 } |
1071 | 1080 |
1072 } | 1081 } |
OLD | NEW |