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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 return; | 252 return; |
253 | 253 |
254 attemptToRunDeferredScriptsAndEnd(); | 254 attemptToRunDeferredScriptsAndEnd(); |
255 } | 255 } |
256 | 256 |
257 bool HTMLDocumentParser::isParsingFragment() const | 257 bool HTMLDocumentParser::isParsingFragment() const |
258 { | 258 { |
259 return m_treeBuilder->isParsingFragment(); | 259 return m_treeBuilder->isParsingFragment(); |
260 } | 260 } |
261 | 261 |
262 bool HTMLDocumentParser::processingData() const | |
263 { | |
264 return isScheduledForResume() || inPumpSession() || m_haveBackgroundParser; | |
265 } | |
266 | |
267 void HTMLDocumentParser::pumpTokenizerIfPossible() | 262 void HTMLDocumentParser::pumpTokenizerIfPossible() |
268 { | 263 { |
269 if (isStopped() || isWaitingForScripts()) | 264 if (isStopped() || isWaitingForScripts()) |
270 return; | 265 return; |
271 | 266 |
272 pumpTokenizer(); | 267 pumpTokenizer(); |
273 } | 268 } |
274 | 269 |
275 bool HTMLDocumentParser::isScheduledForResume() const | 270 bool HTMLDocumentParser::isScheduledForResume() const |
276 { | 271 { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 422 |
428 ASSERT(checkpoint->unparsedInput.isSafeToSendToAnotherThread()); | 423 ASSERT(checkpoint->unparsedInput.isSafeToSendToAnotherThread()); |
429 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::r
esumeFrom, AllowCrossThreadAccess(m_backgroundParser), checkpoint.release())); | 424 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParser::r
esumeFrom, AllowCrossThreadAccess(m_backgroundParser), checkpoint.release())); |
430 } | 425 } |
431 | 426 |
432 size_t HTMLDocumentParser::processParsedChunkFromBackgroundParser(PassOwnPtr<Par
sedChunk> popChunk) | 427 size_t HTMLDocumentParser::processParsedChunkFromBackgroundParser(PassOwnPtr<Par
sedChunk> popChunk) |
433 { | 428 { |
434 TRACE_EVENT0("blink", "HTMLDocumentParser::processParsedChunkFromBackgroundP
arser"); | 429 TRACE_EVENT0("blink", "HTMLDocumentParser::processParsedChunkFromBackgroundP
arser"); |
435 TemporaryChange<bool> hasLineNumber(m_isParsingAtLineNumber, true); | 430 TemporaryChange<bool> hasLineNumber(m_isParsingAtLineNumber, true); |
436 | 431 |
437 ASSERT_WITH_SECURITY_IMPLICATION(document()->activeParserCount() == 1); | 432 ASSERT_WITH_SECURITY_IMPLICATION(m_pumpSpeculationsSessionNestingLevel == 1)
; |
| 433 ASSERT_WITH_SECURITY_IMPLICATION(!inPumpSession()); |
438 ASSERT(!isParsingFragment()); | 434 ASSERT(!isParsingFragment()); |
439 ASSERT(!isWaitingForScripts()); | 435 ASSERT(!isWaitingForScripts()); |
440 ASSERT(!isStopped()); | 436 ASSERT(!isStopped()); |
441 #if !ENABLE(OILPAN) | 437 #if !ENABLE(OILPAN) |
442 // ASSERT that this object is both attached to the Document and protected. | 438 // ASSERT that this object is both attached to the Document and protected. |
443 ASSERT(refCount() >= 2); | 439 ASSERT(refCount() >= 2); |
444 #endif | 440 #endif |
445 ASSERT(shouldUseThreading()); | 441 ASSERT(shouldUseThreading()); |
446 ASSERT(!m_tokenizer); | 442 ASSERT(!m_tokenizer); |
447 ASSERT(!m_token); | 443 ASSERT(!m_token); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 539 |
544 // Do not allow pumping speculations in nested event loops. | 540 // Do not allow pumping speculations in nested event loops. |
545 if (m_pumpSpeculationsSessionNestingLevel) { | 541 if (m_pumpSpeculationsSessionNestingLevel) { |
546 m_parserScheduler->scheduleForResume(); | 542 m_parserScheduler->scheduleForResume(); |
547 return; | 543 return; |
548 } | 544 } |
549 | 545 |
550 // FIXME: Pass in current input length. | 546 // FIXME: Pass in current input length. |
551 TRACE_EVENT_BEGIN1("devtools.timeline", "ParseHTML", "beginData", InspectorP
arseHtmlEvent::beginData(document(), lineNumber().zeroBasedInt())); | 547 TRACE_EVENT_BEGIN1("devtools.timeline", "ParseHTML", "beginData", InspectorP
arseHtmlEvent::beginData(document(), lineNumber().zeroBasedInt())); |
552 | 548 |
553 SpeculationsPumpSession session(m_pumpSpeculationsSessionNestingLevel, conte
xtForParsingSession()); | 549 SpeculationsPumpSession session(m_pumpSpeculationsSessionNestingLevel); |
554 while (!m_speculations.isEmpty()) { | 550 while (!m_speculations.isEmpty()) { |
555 ASSERT(!isScheduledForResume()); | 551 ASSERT(!isScheduledForResume()); |
556 size_t elementTokenCount = processParsedChunkFromBackgroundParser(m_spec
ulations.takeFirst().release()); | 552 size_t elementTokenCount = processParsedChunkFromBackgroundParser(m_spec
ulations.takeFirst().release()); |
557 session.addedElementTokens(elementTokenCount); | 553 session.addedElementTokens(elementTokenCount); |
558 | 554 |
559 // Always check isParsing first as m_document may be null. | 555 // Always check isParsing first as m_document may be null. |
560 // Surprisingly, isScheduledForResume() may be set here as a result of | 556 // Surprisingly, isScheduledForResume() may be set here as a result of |
561 // processParsedChunkFromBackgroundParser running arbitrary javascript | 557 // processParsedChunkFromBackgroundParser running arbitrary javascript |
562 // which invokes nested event loops. (e.g. inspector breakpoints) | 558 // which invokes nested event loops. (e.g. inspector breakpoints) |
563 if (!isParsing() || isWaitingForScripts() || isScheduledForResume()) | 559 if (!isParsing() || isWaitingForScripts() || isScheduledForResume()) |
(...skipping 13 matching lines...) Expand all Loading... |
577 // This method is called before any data is appended, so we have to star
t | 573 // This method is called before any data is appended, so we have to star
t |
578 // the background parser ourselves. | 574 // the background parser ourselves. |
579 if (!m_haveBackgroundParser) | 575 if (!m_haveBackgroundParser) |
580 startBackgroundParser(); | 576 startBackgroundParser(); |
581 | 577 |
582 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::forcePlaintextForTextDocument, AllowCrossThreadAccess(m_backgroundParser))); | 578 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::forcePlaintextForTextDocument, AllowCrossThreadAccess(m_backgroundParser))); |
583 } else | 579 } else |
584 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); | 580 m_tokenizer->setState(HTMLTokenizer::PLAINTEXTState); |
585 } | 581 } |
586 | 582 |
587 Document* HTMLDocumentParser::contextForParsingSession() | |
588 { | |
589 // The parsing session should interact with the document only when parsing | |
590 // non-fragments. Otherwise, we might delay the load event mistakenly. | |
591 if (isParsingFragment()) | |
592 return nullptr; | |
593 return document(); | |
594 } | |
595 | |
596 void HTMLDocumentParser::pumpTokenizer() | 583 void HTMLDocumentParser::pumpTokenizer() |
597 { | 584 { |
598 ASSERT(!isStopped()); | 585 ASSERT(!isStopped()); |
599 #if !ENABLE(OILPAN) | 586 #if !ENABLE(OILPAN) |
600 // ASSERT that this object is both attached to the Document and protected. | 587 // ASSERT that this object is both attached to the Document and protected. |
601 ASSERT(refCount() >= 2); | 588 ASSERT(refCount() >= 2); |
602 #endif | 589 #endif |
603 ASSERT(m_tokenizer); | 590 ASSERT(m_tokenizer); |
604 ASSERT(m_token); | 591 ASSERT(m_token); |
605 | 592 |
606 PumpSession session(m_pumpSessionNestingLevel, contextForParsingSession()); | 593 PumpSession session(m_pumpSessionNestingLevel); |
607 | 594 |
608 // We tell the InspectorInstrumentation about every pump, even if we | 595 // We tell the InspectorInstrumentation about every pump, even if we |
609 // end up pumping nothing. It can filter out empty pumps itself. | 596 // end up pumping nothing. It can filter out empty pumps itself. |
610 // FIXME: m_input.current().length() is only accurate if we | 597 // FIXME: m_input.current().length() is only accurate if we |
611 // end up parsing the whole buffer in this pump. We should pass how | 598 // end up parsing the whole buffer in this pump. We should pass how |
612 // much we parsed as part of didWriteHTML instead of willWriteHTML. | 599 // much we parsed as part of didWriteHTML instead of willWriteHTML. |
613 TRACE_EVENT_BEGIN1("devtools.timeline", "ParseHTML", "beginData", InspectorP
arseHtmlEvent::beginData(document(), m_input.current().currentLine().zeroBasedIn
t())); | 600 TRACE_EVENT_BEGIN1("devtools.timeline", "ParseHTML", "beginData", InspectorP
arseHtmlEvent::beginData(document(), m_input.current().currentLine().zeroBasedIn
t())); |
614 | 601 |
615 if (!isParsingFragment()) | 602 if (!isParsingFragment()) |
616 m_xssAuditor.init(document(), &m_xssAuditorDelegate); | 603 m_xssAuditor.init(document(), &m_xssAuditorDelegate); |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 m_scriptRunner->executeScriptsWaitingForResources(); | 1041 m_scriptRunner->executeScriptsWaitingForResources(); |
1055 if (!isWaitingForScripts()) | 1042 if (!isWaitingForScripts()) |
1056 resumeParsingAfterScriptExecution(); | 1043 resumeParsingAfterScriptExecution(); |
1057 } | 1044 } |
1058 | 1045 |
1059 void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFra
gment* fragment, Element* contextElement, ParserContentPolicy parserContentPolic
y) | 1046 void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFra
gment* fragment, Element* contextElement, ParserContentPolicy parserContentPolic
y) |
1060 { | 1047 { |
1061 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f
ragment, contextElement, parserContentPolicy); | 1048 RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(f
ragment, contextElement, parserContentPolicy); |
1062 parser->append(source); | 1049 parser->append(source); |
1063 parser->finish(); | 1050 parser->finish(); |
1064 ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/
3963151> | |
1065 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. | 1051 parser->detach(); // Allows ~DocumentParser to assert it was detached before
destruction. |
1066 } | 1052 } |
1067 | 1053 |
1068 void HTMLDocumentParser::suspendScheduledTasks() | 1054 void HTMLDocumentParser::suspendScheduledTasks() |
1069 { | 1055 { |
1070 ASSERT(!m_tasksWereSuspended); | 1056 ASSERT(!m_tasksWereSuspended); |
1071 m_tasksWereSuspended = true; | 1057 m_tasksWereSuspended = true; |
1072 if (m_parserScheduler) | 1058 if (m_parserScheduler) |
1073 m_parserScheduler->suspend(); | 1059 m_parserScheduler->suspend(); |
1074 } | 1060 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) | 1113 void HTMLDocumentParser::setDecoder(PassOwnPtr<TextResourceDecoder> decoder) |
1128 { | 1114 { |
1129 ASSERT(decoder); | 1115 ASSERT(decoder); |
1130 DecodedDataDocumentParser::setDecoder(decoder); | 1116 DecodedDataDocumentParser::setDecoder(decoder); |
1131 | 1117 |
1132 if (m_haveBackgroundParser) | 1118 if (m_haveBackgroundParser) |
1133 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); | 1119 HTMLParserThread::shared()->postTask(threadSafeBind(&BackgroundHTMLParse
r::setDecoder, AllowCrossThreadAccess(m_backgroundParser), takeDecoder())); |
1134 } | 1120 } |
1135 | 1121 |
1136 } // namespace blink | 1122 } // namespace blink |
OLD | NEW |