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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 && document()->frame() && document()->frame()->navigationScheduler().loc ationChangePending()) | 321 && document()->frame() && document()->frame()->navigationScheduler().loc ationChangePending()) |
322 return false; | 322 return false; |
323 | 323 |
324 return true; | 324 return true; |
325 } | 325 } |
326 | 326 |
327 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk) | 327 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk) |
328 { | 328 { |
329 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser"); | 329 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser"); |
330 | 330 |
331 // alert(), runModalDialog, and the JavaScript Debugger all run nested event loops | 331 if (!isParsing()) |
332 // which can cause this method to be re-entered. We detect re-entry using | 332 return; |
333 // hasActiveParser(), save the chunk as a speculation, and return. | 333 |
334 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active ParserCount() > 0 || m_tasksWereSuspended || isScheduledForResume()) { | 334 // ApplicationCache needs to be initialized before issuing preloads. |
335 // We suspend preload until HTMLHTMLElement is inserted and | |
336 // ApplicationCache is initialized. | |
337 if (!document()->documentElement()) { | |
338 for (auto& request : chunk->preloads) | |
339 m_queuedPreloads.append(request.release()); | |
340 } else { | |
341 ASSERT(m_queuedPreloads.isEmpty()); | |
tyoshino (SeeGerritForStatus)
2014/12/04 06:48:21
please write the reason that we're sure that m_que
| |
342 m_preloader->takeAndPreload(chunk->preloads); | |
343 } | |
344 | |
345 m_speculations.append(chunk); | |
346 | |
347 if (!isWaitingForScripts() && !isScheduledForResume()) { | |
335 if (m_tasksWereSuspended) | 348 if (m_tasksWereSuspended) |
336 m_parserScheduler->forceResumeAfterYield(); | 349 m_parserScheduler->forceResumeAfterYield(); |
337 m_preloader->takeAndPreload(chunk->preloads); | 350 else |
338 m_speculations.append(chunk); | 351 m_parserScheduler->scheduleForResume(); |
339 return; | |
340 } | 352 } |
341 | |
342 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document, | |
343 // but we need to ensure it isn't deleted yet. | |
344 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this); | |
345 | |
346 ASSERT(m_speculations.isEmpty()); | |
347 chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately. | |
348 m_speculations.append(chunk); | |
349 pumpPendingSpeculations(); | |
350 } | 353 } |
351 | 354 |
352 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume ntEncodingData& data) | 355 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume ntEncodingData& data) |
353 { | 356 { |
354 document()->setEncodingData(data); | 357 document()->setEncodingData(data); |
355 } | 358 } |
356 | 359 |
357 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) | 360 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) |
358 { | 361 { |
359 ASSERT(chunk); | 362 ASSERT(chunk); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 ASSERT(m_speculations.isEmpty()); // There should never be any c hunks after the EOF. | 459 ASSERT(m_speculations.isEmpty()); // There should never be any c hunks after the EOF. |
457 prepareToStopParsing(); | 460 prepareToStopParsing(); |
458 } | 461 } |
459 break; | 462 break; |
460 } | 463 } |
461 | 464 |
462 m_textPosition = it->textPosition(); | 465 m_textPosition = it->textPosition(); |
463 | 466 |
464 constructTreeFromCompactHTMLToken(*it); | 467 constructTreeFromCompactHTMLToken(*it); |
465 | 468 |
469 if (!m_queuedPreloads.isEmpty() && document()->documentElement()) | |
470 m_preloader->takeAndPreload(m_queuedPreloads); | |
471 | |
tyoshino (SeeGerritForStatus)
2014/12/04 06:48:21
before this CL we were calling chunk->preloads.cle
| |
466 if (isStopped()) | 472 if (isStopped()) |
467 break; | 473 break; |
468 | 474 |
469 if (isWaitingForScripts()) { | 475 if (isWaitingForScripts()) { |
470 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch. | 476 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch. |
471 runScriptsForPausedTreeBuilder(); | 477 runScriptsForPausedTreeBuilder(); |
472 validateSpeculations(chunk.release()); | 478 validateSpeculations(chunk.release()); |
473 break; | 479 break; |
474 } | 480 } |
475 | 481 |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1065 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1071 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1066 { | 1072 { |
1067 ASSERT(decoder); | 1073 ASSERT(decoder); |
1068 DecodedDataDocumentParser::setDecoder(decoder); | 1074 DecodedDataDocumentParser::setDecoder(decoder); |
1069 | 1075 |
1070 if (m_haveBackgroundParser) | 1076 if (m_haveBackgroundParser) |
1071 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); | 1077 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); |
1072 } | 1078 } |
1073 | 1079 |
1074 } | 1080 } |
OLD | NEW |