| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 if (contextTag.matches(scriptTag)) | 85 if (contextTag.matches(scriptTag)) |
| 86 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; | 86 return reportErrors ? HTMLTokenizer::ScriptDataState : HTMLTokenizer::PL
AINTEXTState; |
| 87 if (contextTag.matches(plaintextTag)) | 87 if (contextTag.matches(plaintextTag)) |
| 88 return HTMLTokenizer::PLAINTEXTState; | 88 return HTMLTokenizer::PLAINTEXTState; |
| 89 return HTMLTokenizer::DataState; | 89 return HTMLTokenizer::DataState; |
| 90 } | 90 } |
| 91 | 91 |
| 92 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza
tionPolicy syncPolicy) | 92 HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, ParserSynchroniza
tionPolicy syncPolicy) |
| 93 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) | 93 : HTMLDocumentParser(document, AllowScriptingContent, syncPolicy) |
| 94 { | 94 { |
| 95 m_scriptRunner = HTMLScriptRunner::create(&document, this); | 95 m_scriptRunner = HTMLScriptRunner::create(reentryPermit(), &document, this); |
| 96 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten
t, m_options); | 96 m_treeBuilder = HTMLTreeBuilder::create(this, document, AllowScriptingConten
t, m_options); |
| 97 } | 97 } |
| 98 | 98 |
| 99 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) | 99 HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* cont
extElement, ParserContentPolicy parserContentPolicy) |
| 100 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro
nousParsing) | 100 : HTMLDocumentParser(fragment->document(), parserContentPolicy, ForceSynchro
nousParsing) |
| 101 { | 101 { |
| 102 // No m_scriptRunner in fragment parser. | 102 // No m_scriptRunner in fragment parser. |
| 103 m_treeBuilder = HTMLTreeBuilder::create(this, fragment, contextElement, pars
erContentPolicy, m_options); | 103 m_treeBuilder = HTMLTreeBuilder::create(this, fragment, contextElement, pars
erContentPolicy, m_options); |
| 104 | 104 |
| 105 bool reportErrors = false; // For now document fragment parsing never report
s errors. | 105 bool reportErrors = false; // For now document fragment parsing never report
s errors. |
| 106 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); | 106 m_tokenizer->setState(tokenizerStateForContextElement(contextElement, report
Errors, m_options)); |
| 107 m_xssAuditor.initForFragment(); | 107 m_xssAuditor.initForFragment(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 HTMLDocumentParser::HTMLDocumentParser(Document& document, ParserContentPolicy c
ontentPolicy, ParserSynchronizationPolicy syncPolicy) | 110 HTMLDocumentParser::HTMLDocumentParser(Document& document, ParserContentPolicy c
ontentPolicy, ParserSynchronizationPolicy syncPolicy) |
| 111 : ScriptableDocumentParser(document, contentPolicy) | 111 : ScriptableDocumentParser(document, contentPolicy) |
| 112 , m_options(&document) | 112 , m_options(&document) |
| 113 , m_reentryPermit(HTMLParserReentryPermit::create()) |
| 113 , m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken)
: nullptr) | 114 , m_token(syncPolicy == ForceSynchronousParsing ? wrapUnique(new HTMLToken)
: nullptr) |
| 114 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) | 115 , m_tokenizer(syncPolicy == ForceSynchronousParsing ? HTMLTokenizer::create(
m_options) : nullptr) |
| 115 , m_loadingTaskRunner(TaskRunnerHelper::getLoadingTaskRunner(&document)->clo
ne()) | 116 , m_loadingTaskRunner(TaskRunnerHelper::getLoadingTaskRunner(&document)->clo
ne()) |
| 116 , m_parserScheduler(syncPolicy == AllowAsynchronousParsing ? HTMLParserSched
uler::create(this, m_loadingTaskRunner.get()) : nullptr) | 117 , m_parserScheduler(syncPolicy == AllowAsynchronousParsing ? HTMLParserSched
uler::create(this, m_loadingTaskRunner.get()) : nullptr) |
| 117 , m_xssAuditorDelegate(&document) | 118 , m_xssAuditorDelegate(&document) |
| 118 , m_weakFactory(this) | 119 , m_weakFactory(this) |
| 119 , m_preloader(HTMLResourcePreloader::create(document)) | 120 , m_preloader(HTMLResourcePreloader::create(document)) |
| 120 , m_tokenizedChunkQueue(TokenizedChunkQueue::create()) | 121 , m_tokenizedChunkQueue(TokenizedChunkQueue::create()) |
| 121 , m_evaluator(DocumentWriteEvaluator::create(document)) | 122 , m_evaluator(DocumentWriteEvaluator::create(document)) |
| 122 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) | 123 , m_shouldUseThreading(syncPolicy == AllowAsynchronousParsing) |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 // where the script is transfered from the treebuilder to the script runner. | 949 // where the script is transfered from the treebuilder to the script runner. |
| 949 // The script runner will hold the script until its loaded and run. During | 950 // The script runner will hold the script until its loaded and run. During |
| 950 // any of this time, we want to count ourselves as "waiting for a script" an
d thus | 951 // any of this time, we want to count ourselves as "waiting for a script" an
d thus |
| 951 // run the preload scanner, as well as delay completion of parsing. | 952 // run the preload scanner, as well as delay completion of parsing. |
| 952 bool treeBuilderHasBlockingScript = m_treeBuilder->hasParserBlockingScript()
; | 953 bool treeBuilderHasBlockingScript = m_treeBuilder->hasParserBlockingScript()
; |
| 953 bool scriptRunnerHasBlockingScript = m_scriptRunner && m_scriptRunner->hasPa
rserBlockingScript(); | 954 bool scriptRunnerHasBlockingScript = m_scriptRunner && m_scriptRunner->hasPa
rserBlockingScript(); |
| 954 // Since the parser is paused while a script runner has a blocking script, i
t should | 955 // Since the parser is paused while a script runner has a blocking script, i
t should |
| 955 // never be possible to end up with both objects holding a blocking script. | 956 // never be possible to end up with both objects holding a blocking script. |
| 956 ASSERT(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript)); | 957 ASSERT(!(treeBuilderHasBlockingScript && scriptRunnerHasBlockingScript)); |
| 957 // If either object has a blocking script, the parser should be paused. | 958 // If either object has a blocking script, the parser should be paused. |
| 958 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript; | 959 return treeBuilderHasBlockingScript || scriptRunnerHasBlockingScript || m_re
entryPermit->parserPauseFlag(); |
| 959 } | 960 } |
| 960 | 961 |
| 961 void HTMLDocumentParser::resumeParsingAfterScriptExecution() | 962 void HTMLDocumentParser::resumeParsingAfterScriptExecution() |
| 962 { | 963 { |
| 963 ASSERT(!isExecutingScript()); | 964 ASSERT(!isExecutingScript()); |
| 964 ASSERT(!isWaitingForScripts()); | 965 ASSERT(!isWaitingForScripts()); |
| 965 | 966 |
| 966 if (m_haveBackgroundParser) { | 967 if (m_haveBackgroundParser) { |
| 967 validateSpeculations(std::move(m_lastChunkBeforeScript)); | 968 validateSpeculations(std::move(m_lastChunkBeforeScript)); |
| 968 ASSERT(!m_lastChunkBeforeScript); | 969 ASSERT(!m_lastChunkBeforeScript); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 1172 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
| 1172 return; | 1173 return; |
| 1173 case Asynchronous: | 1174 case Asynchronous: |
| 1174 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); | 1175 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); |
| 1175 return; | 1176 return; |
| 1176 } | 1177 } |
| 1177 NOTREACHED(); | 1178 NOTREACHED(); |
| 1178 } | 1179 } |
| 1179 | 1180 |
| 1180 } // namespace blink | 1181 } // namespace blink |
| OLD | NEW |