| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 153 |
| 154 void HTMLScriptRunner::detach() | 154 void HTMLScriptRunner::detach() |
| 155 { | 155 { |
| 156 if (!m_document) | 156 if (!m_document) |
| 157 return; | 157 return; |
| 158 | 158 |
| 159 m_parserBlockingScript->stopWatchingForLoad(); | 159 m_parserBlockingScript->stopWatchingForLoad(); |
| 160 m_parserBlockingScript->releaseElementAndClear(); | 160 m_parserBlockingScript->releaseElementAndClear(); |
| 161 | 161 |
| 162 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 162 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
| 163 OwnPtrWillBeRawPtr<PendingScript> pendingScript = m_scriptsToExecuteAfte
rParsing.takeFirst(); | 163 RawPtr<PendingScript> pendingScript = m_scriptsToExecuteAfterParsing.tak
eFirst(); |
| 164 pendingScript->stopWatchingForLoad(); | 164 pendingScript->stopWatchingForLoad(); |
| 165 pendingScript->releaseElementAndClear(); | 165 pendingScript->releaseElementAndClear(); |
| 166 } | 166 } |
| 167 m_document = nullptr; | 167 m_document = nullptr; |
| 168 } | 168 } |
| 169 | 169 |
| 170 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) | 170 bool HTMLScriptRunner::isPendingScriptReady(const PendingScript* script) |
| 171 { | 171 { |
| 172 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); | 172 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionReady(); |
| 173 if (m_hasScriptsWaitingForResources) | 173 if (m_hasScriptsWaitingForResources) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 200 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { | 200 if (pendingScriptType == ScriptStreamer::ParsingBlocking) { |
| 201 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); | 201 m_hasScriptsWaitingForResources = !m_document->isScriptExecutionRead
y(); |
| 202 // The parser cannot be unblocked as a microtask requested another r
esource | 202 // The parser cannot be unblocked as a microtask requested another r
esource |
| 203 if (m_hasScriptsWaitingForResources) | 203 if (m_hasScriptsWaitingForResources) |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 TextPosition scriptStartPosition = pendingScript->startingPosition(); | 208 TextPosition scriptStartPosition = pendingScript->startingPosition(); |
| 209 // Clear the pending script before possible re-entrancy from executeScript() | 209 // Clear the pending script before possible re-entrancy from executeScript() |
| 210 RefPtrWillBeRawPtr<Element> element = pendingScript->releaseElementAndClear(
); | 210 RawPtr<Element> element = pendingScript->releaseElementAndClear(); |
| 211 double compilationFinishTime = 0; | 211 double compilationFinishTime = 0; |
| 212 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { | 212 if (ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element.get())) { |
| 213 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); | 213 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); |
| 214 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); | 214 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrem
enter(m_document); |
| 215 if (errorOccurred) { | 215 if (errorOccurred) { |
| 216 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScriptFaile
d", element.get(), TRACE_EVENT_FLAG_FLOW_IN, | 216 TRACE_EVENT_WITH_FLOW1("blink", "HTMLScriptRunner ExecuteScriptFaile
d", element.get(), TRACE_EVENT_FLAG_FLOW_IN, |
| 217 "data", getTraceArgsForScriptElement(element.get(), scriptStartP
osition)); | 217 "data", getTraceArgsForScriptElement(element.get(), scriptStartP
osition)); |
| 218 scriptLoader->dispatchErrorEvent(); | 218 scriptLoader->dispatchErrorEvent(); |
| 219 } else { | 219 } else { |
| 220 ASSERT(isExecutingScript()); | 220 ASSERT(isExecutingScript()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (isExecutingScript() && cachedResource->wasCanceled()) { | 263 if (isExecutingScript() && cachedResource->wasCanceled()) { |
| 264 stopWatchingResourceForLoad(cachedResource); | 264 stopWatchingResourceForLoad(cachedResource); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 m_host->notifyScriptLoaded(cachedResource); | 267 m_host->notifyScriptLoaded(cachedResource); |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Implements the steps for 'An end tag whose tag name is "script"' | 270 // Implements the steps for 'An end tag whose tag name is "script"' |
| 271 // http://whatwg.org/html#scriptEndTag | 271 // http://whatwg.org/html#scriptEndTag |
| 272 // Script handling lives outside the tree builder to keep each class simple. | 272 // Script handling lives outside the tree builder to keep each class simple. |
| 273 void HTMLScriptRunner::execute(PassRefPtrWillBeRawPtr<Element> scriptElement, co
nst TextPosition& scriptStartPosition) | 273 void HTMLScriptRunner::execute(RawPtr<Element> scriptElement, const TextPosition
& scriptStartPosition) |
| 274 { | 274 { |
| 275 ASSERT(scriptElement); | 275 ASSERT(scriptElement); |
| 276 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", | 276 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", |
| 277 "data", getTraceArgsForScriptElement(scriptElement.get(), scriptStartPos
ition)); | 277 "data", getTraceArgsForScriptElement(scriptElement.get(), scriptStartPos
ition)); |
| 278 // FIXME: If scripting is disabled, always just return. | 278 // FIXME: If scripting is disabled, always just return. |
| 279 | 279 |
| 280 bool hadPreloadScanner = m_host->hasPreloadScanner(); | 280 bool hadPreloadScanner = m_host->hasPreloadScanner(); |
| 281 | 281 |
| 282 // Try to execute the script given to us. | 282 // Try to execute the script given to us. |
| 283 runScript(scriptElement.get(), scriptStartPosition); | 283 runScript(scriptElement.get(), scriptStartPosition); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 TRACE_EVENT0("blink", "HTMLScriptRunner::executeScriptsWaitingForParsing"); | 332 TRACE_EVENT0("blink", "HTMLScriptRunner::executeScriptsWaitingForParsing"); |
| 333 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { | 333 while (!m_scriptsToExecuteAfterParsing.isEmpty()) { |
| 334 ASSERT(!isExecutingScript()); | 334 ASSERT(!isExecutingScript()); |
| 335 ASSERT(!hasParserBlockingScript()); | 335 ASSERT(!hasParserBlockingScript()); |
| 336 ASSERT(m_scriptsToExecuteAfterParsing.first()->resource()); | 336 ASSERT(m_scriptsToExecuteAfterParsing.first()->resource()); |
| 337 if (!m_scriptsToExecuteAfterParsing.first()->isReady()) { | 337 if (!m_scriptsToExecuteAfterParsing.first()->isReady()) { |
| 338 m_scriptsToExecuteAfterParsing.first()->watchForLoad(this); | 338 m_scriptsToExecuteAfterParsing.first()->watchForLoad(this); |
| 339 traceParserBlockingScript(m_scriptsToExecuteAfterParsing.first().get
(), !m_document->isScriptExecutionReady()); | 339 traceParserBlockingScript(m_scriptsToExecuteAfterParsing.first().get
(), !m_document->isScriptExecutionReady()); |
| 340 return false; | 340 return false; |
| 341 } | 341 } |
| 342 OwnPtrWillBeRawPtr<PendingScript> first = m_scriptsToExecuteAfterParsing
.takeFirst(); | 342 RawPtr<PendingScript> first = m_scriptsToExecuteAfterParsing.takeFirst()
; |
| 343 executePendingScriptAndDispatchEvent(first.get(), ScriptStreamer::Deferr
ed); | 343 executePendingScriptAndDispatchEvent(first.get(), ScriptStreamer::Deferr
ed); |
| 344 // FIXME: What is this m_document check for? | 344 // FIXME: What is this m_document check for? |
| 345 if (!m_document) | 345 if (!m_document) |
| 346 return false; | 346 return false; |
| 347 } | 347 } |
| 348 return true; | 348 return true; |
| 349 } | 349 } |
| 350 | 350 |
| 351 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) | 351 void HTMLScriptRunner::requestParsingBlockingScript(Element* element) |
| 352 { | 352 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 364 if (scriptState) | 364 if (scriptState) |
| 365 ScriptStreamer::startStreaming(m_parserBlockingScript.get(), Scr
iptStreamer::ParsingBlocking, m_document->frame()->settings(), scriptState, m_do
cument->loadingTaskRunner()); | 365 ScriptStreamer::startStreaming(m_parserBlockingScript.get(), Scr
iptStreamer::ParsingBlocking, m_document->frame()->settings(), scriptState, m_do
cument->loadingTaskRunner()); |
| 366 } | 366 } |
| 367 | 367 |
| 368 m_parserBlockingScript->watchForLoad(this); | 368 m_parserBlockingScript->watchForLoad(this); |
| 369 } | 369 } |
| 370 } | 370 } |
| 371 | 371 |
| 372 void HTMLScriptRunner::requestDeferredScript(Element* element) | 372 void HTMLScriptRunner::requestDeferredScript(Element* element) |
| 373 { | 373 { |
| 374 OwnPtrWillBeRawPtr<PendingScript> pendingScript = PendingScript::create(null
ptr, nullptr); | 374 RawPtr<PendingScript> pendingScript = PendingScript::create(nullptr, nullptr
); |
| 375 if (!requestPendingScript(pendingScript.get(), element)) | 375 if (!requestPendingScript(pendingScript.get(), element)) |
| 376 return; | 376 return; |
| 377 | 377 |
| 378 if (m_document->frame() && !pendingScript->isReady()) { | 378 if (m_document->frame() && !pendingScript->isReady()) { |
| 379 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()
); | 379 ScriptState* scriptState = ScriptState::forMainWorld(m_document->frame()
); |
| 380 if (scriptState) | 380 if (scriptState) |
| 381 ScriptStreamer::startStreaming(pendingScript.get(), ScriptStreamer::
Deferred, m_document->frame()->settings(), scriptState, m_document->loadingTaskR
unner()); | 381 ScriptStreamer::startStreaming(pendingScript.get(), ScriptStreamer::
Deferred, m_document->frame()->settings(), scriptState, m_document->loadingTaskR
unner()); |
| 382 } | 382 } |
| 383 | 383 |
| 384 ASSERT(pendingScript->resource()); | 384 ASSERT(pendingScript->resource()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 447 |
| 448 DEFINE_TRACE(HTMLScriptRunner) | 448 DEFINE_TRACE(HTMLScriptRunner) |
| 449 { | 449 { |
| 450 visitor->trace(m_document); | 450 visitor->trace(m_document); |
| 451 visitor->trace(m_host); | 451 visitor->trace(m_host); |
| 452 visitor->trace(m_parserBlockingScript); | 452 visitor->trace(m_parserBlockingScript); |
| 453 visitor->trace(m_scriptsToExecuteAfterParsing); | 453 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 454 } | 454 } |
| 455 | 455 |
| 456 } // namespace blink | 456 } // namespace blink |
| OLD | NEW |