Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Side by Side Diff: Source/core/html/parser/HTMLDocumentParser.cpp

Issue 673603002: Reland: Make the HTMLDocumentParser yield more aggressively (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 && document()->frame() && document()->frame()->navigationScheduler().loc ationChangePending()) 324 && document()->frame() && document()->frame()->navigationScheduler().loc ationChangePending())
325 return false; 325 return false;
326 326
327 return true; 327 return true;
328 } 328 }
329 329
330 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk) 330 void HTMLDocumentParser::didReceiveParsedChunkFromBackgroundParser(PassOwnPtr<Pa rsedChunk> chunk)
331 { 331 {
332 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser"); 332 TRACE_EVENT0("blink", "HTMLDocumentParser::didReceiveParsedChunkFromBackgrou ndParser");
333 333
334 // alert(), runModalDialog, and the JavaScript Debugger all run nested event loops 334 // ApplicationCache needs to be initialized before issuing preloads.
335 // which can cause this method to be re-entered. We detect re-entry using 335 // We suspend preload until HTMLHTMLElement is inserted and
336 // hasActiveParser(), save the chunk as a speculation, and return. 336 // ApplicationCache is initialized.
337 if (isWaitingForScripts() || !m_speculations.isEmpty() || document()->active ParserCount() > 0) { 337 if (!document()->documentElement()) {
338 for (auto& request : m_queuedPreloads)
339 m_queuedPreloads.append(request.release());
340 } else {
341 ASSERT(m_queuedPreloads.isEmpty());
338 m_preloader->takeAndPreload(chunk->preloads); 342 m_preloader->takeAndPreload(chunk->preloads);
339 m_speculations.append(chunk);
340 return;
341 } 343 }
342 344
343 // processParsedChunkFromBackgroundParser can cause this parser to be detach ed from the Document, 345 m_speculations.append(chunk);
344 // but we need to ensure it isn't deleted yet.
345 RefPtrWillBeRawPtr<HTMLDocumentParser> protect(this);
346 346
347 ASSERT(m_speculations.isEmpty()); 347 if (!isWaitingForScripts())
348 chunk->preloads.clear(); // We don't need to preload because we're going to parse immediately. 348 m_parserScheduler->scheduleForResume();
349 m_speculations.append(chunk);
350 pumpPendingSpeculations();
351 } 349 }
352 350
353 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume ntEncodingData& data) 351 void HTMLDocumentParser::didReceiveEncodingDataFromBackgroundParser(const Docume ntEncodingData& data)
354 { 352 {
355 document()->setEncodingData(data); 353 document()->setEncodingData(data);
356 } 354 }
357 355
358 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk) 356 void HTMLDocumentParser::validateSpeculations(PassOwnPtr<ParsedChunk> chunk)
359 { 357 {
360 ASSERT(chunk); 358 ASSERT(chunk);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ASSERT(m_speculations.isEmpty()); // There should never be any c hunks after the EOF. 455 ASSERT(m_speculations.isEmpty()); // There should never be any c hunks after the EOF.
458 prepareToStopParsing(); 456 prepareToStopParsing();
459 } 457 }
460 break; 458 break;
461 } 459 }
462 460
463 m_textPosition = it->textPosition(); 461 m_textPosition = it->textPosition();
464 462
465 constructTreeFromCompactHTMLToken(*it); 463 constructTreeFromCompactHTMLToken(*it);
466 464
465 if (!m_queuedPreloads.isEmpty() && document()->documentElement())
466 m_preloader->takeAndPreload(m_queuedPreloads);
467
467 if (isStopped()) 468 if (isStopped())
468 break; 469 break;
469 470
470 if (isWaitingForScripts()) { 471 if (isWaitingForScripts()) {
471 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch. 472 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch.
472 runScriptsForPausedTreeBuilder(); 473 runScriptsForPausedTreeBuilder();
473 validateSpeculations(chunk.release()); 474 validateSpeculations(chunk.release());
474 break; 475 break;
475 } 476 }
476 477
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) 1056 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder)
1056 { 1057 {
1057 ASSERT(decoder); 1058 ASSERT(decoder);
1058 DecodedDataDocumentParser::setDecoder(decoder); 1059 DecodedDataDocumentParser::setDecoder(decoder);
1059 1060
1060 if (m_haveBackgroundParser) 1061 if (m_haveBackgroundParser)
1061 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder())); 1062 HTMLParserThread::shared()->postTask(bind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, takeDecoder()));
1062 } 1063 }
1063 1064
1064 } 1065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698