OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
3 * Copyright (C) 2011 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 ASSERT(!fragment->hasChildNodes()); | 351 ASSERT(!fragment->hasChildNodes()); |
352 } | 352 } |
353 | 353 |
354 HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext() | 354 HTMLTreeBuilder::FragmentParsingContext::~FragmentParsingContext() |
355 { | 355 { |
356 } | 356 } |
357 | 357 |
358 PassRefPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPosition& scriptSta
rtPosition) | 358 PassRefPtr<Element> HTMLTreeBuilder::takeScriptToProcess(TextPosition& scriptSta
rtPosition) |
359 { | 359 { |
360 ASSERT(m_scriptToProcess); | 360 ASSERT(m_scriptToProcess); |
| 361 ASSERT(!m_tree.hasPendingTasks()); |
361 // Unpause ourselves, callers may pause us again when processing the script. | 362 // Unpause ourselves, callers may pause us again when processing the script. |
362 // The HTML5 spec is written as though scripts are executed inside the tree | 363 // The HTML5 spec is written as though scripts are executed inside the tree |
363 // builder. We pause the parser to exit the tree builder, and then resume | 364 // builder. We pause the parser to exit the tree builder, and then resume |
364 // before running scripts. | 365 // before running scripts. |
365 scriptStartPosition = m_scriptToProcessStartPosition; | 366 scriptStartPosition = m_scriptToProcessStartPosition; |
366 m_scriptToProcessStartPosition = uninitializedPositionValue1(); | 367 m_scriptToProcessStartPosition = uninitializedPositionValue1(); |
367 return m_scriptToProcess.release(); | 368 return m_scriptToProcess.release(); |
368 } | 369 } |
369 | 370 |
370 void HTMLTreeBuilder::constructTree(AtomicHTMLToken* token) | 371 void HTMLTreeBuilder::constructTree(AtomicHTMLToken* token) |
(...skipping 20 matching lines...) Expand all Loading... |
391 // We might be detached now. | 392 // We might be detached now. |
392 } | 393 } |
393 | 394 |
394 void HTMLTreeBuilder::processToken(AtomicHTMLToken* token) | 395 void HTMLTreeBuilder::processToken(AtomicHTMLToken* token) |
395 { | 396 { |
396 if (token->type() == HTMLToken::Character) { | 397 if (token->type() == HTMLToken::Character) { |
397 processCharacter(token); | 398 processCharacter(token); |
398 return; | 399 return; |
399 } | 400 } |
400 | 401 |
| 402 // Any non-character token needs to cause us to flush any pending text immed
iately. |
| 403 // NOTE: flush() can cause any queued tasks to execute, possibly re-entering
the parser. |
| 404 m_tree.flush(); |
401 m_shouldSkipLeadingNewline = false; | 405 m_shouldSkipLeadingNewline = false; |
402 | 406 |
403 switch (token->type()) { | 407 switch (token->type()) { |
404 case HTMLToken::Uninitialized: | 408 case HTMLToken::Uninitialized: |
405 case HTMLToken::Character: | 409 case HTMLToken::Character: |
406 ASSERT_NOT_REACHED(); | 410 ASSERT_NOT_REACHED(); |
407 break; | 411 break; |
408 case HTMLToken::DOCTYPE: | 412 case HTMLToken::DOCTYPE: |
409 processDoctypeToken(token); | 413 processDoctypeToken(token); |
410 break; | 414 break; |
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2710 if (token->type() == HTMLToken::Character) | 2714 if (token->type() == HTMLToken::Character) |
2711 return false; | 2715 return false; |
2712 } | 2716 } |
2713 if (token->type() == HTMLToken::EndOfFile) | 2717 if (token->type() == HTMLToken::EndOfFile) |
2714 return false; | 2718 return false; |
2715 return true; | 2719 return true; |
2716 } | 2720 } |
2717 | 2721 |
2718 void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token) | 2722 void HTMLTreeBuilder::processTokenInForeignContent(AtomicHTMLToken* token) |
2719 { | 2723 { |
| 2724 if (token->type() == HTMLToken::Character) { |
| 2725 const String& characters = token->characters(); |
| 2726 m_tree.insertTextNode(characters); |
| 2727 if (m_framesetOk && !isAllWhitespaceOrReplacementCharacters(characters)) |
| 2728 m_framesetOk = false; |
| 2729 return; |
| 2730 } |
| 2731 |
| 2732 m_tree.flush(); |
2720 RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem(); | 2733 RefPtr<HTMLStackItem> adjustedCurrentNode = adjustedCurrentStackItem(); |
2721 | 2734 |
2722 switch (token->type()) { | 2735 switch (token->type()) { |
2723 case HTMLToken::Uninitialized: | 2736 case HTMLToken::Uninitialized: |
2724 ASSERT_NOT_REACHED(); | 2737 ASSERT_NOT_REACHED(); |
2725 break; | 2738 break; |
2726 case HTMLToken::DOCTYPE: | 2739 case HTMLToken::DOCTYPE: |
2727 parseError(token); | 2740 parseError(token); |
2728 break; | 2741 break; |
2729 case HTMLToken::StartTag: { | 2742 case HTMLToken::StartTag: { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 if (nodeRecord->stackItem()->isInHTMLNamespace()) | 2821 if (nodeRecord->stackItem()->isInHTMLNamespace()) |
2809 break; | 2822 break; |
2810 } | 2823 } |
2811 } | 2824 } |
2812 // Otherwise, process the token according to the rules given in the sect
ion corresponding to the current insertion mode in HTML content. | 2825 // Otherwise, process the token according to the rules given in the sect
ion corresponding to the current insertion mode in HTML content. |
2813 processEndTag(token); | 2826 processEndTag(token); |
2814 break; | 2827 break; |
2815 } | 2828 } |
2816 case HTMLToken::Comment: | 2829 case HTMLToken::Comment: |
2817 m_tree.insertComment(token); | 2830 m_tree.insertComment(token); |
2818 return; | |
2819 case HTMLToken::Character: { | |
2820 const String& characters = token->characters(); | |
2821 m_tree.insertTextNode(characters); | |
2822 if (m_framesetOk && !isAllWhitespaceOrReplacementCharacters(characters)) | |
2823 m_framesetOk = false; | |
2824 break; | 2831 break; |
2825 } | 2832 case HTMLToken::Character: |
2826 case HTMLToken::EndOfFile: | 2833 case HTMLToken::EndOfFile: |
2827 ASSERT_NOT_REACHED(); | 2834 ASSERT_NOT_REACHED(); |
2828 break; | 2835 break; |
2829 } | 2836 } |
2830 } | 2837 } |
2831 | 2838 |
2832 void HTMLTreeBuilder::finished() | 2839 void HTMLTreeBuilder::finished() |
2833 { | 2840 { |
2834 if (isParsingFragment()) | 2841 if (isParsingFragment()) |
2835 return; | 2842 return; |
2836 | 2843 |
2837 ASSERT(m_templateInsertionModes.isEmpty()); | 2844 ASSERT(m_templateInsertionModes.isEmpty()); |
2838 ASSERT(m_isAttached); | 2845 ASSERT(m_isAttached); |
2839 // Warning, this may detach the parser. Do not do anything else after this. | 2846 // Warning, this may detach the parser. Do not do anything else after this. |
2840 m_tree.finishedParsing(); | 2847 m_tree.finishedParsing(); |
2841 } | 2848 } |
2842 | 2849 |
2843 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) | 2850 void HTMLTreeBuilder::parseError(AtomicHTMLToken*) |
2844 { | 2851 { |
2845 } | 2852 } |
2846 | 2853 |
2847 } // namespace WebCore | 2854 } // namespace WebCore |
OLD | NEW |