| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 scriptLoader->dispatchErrorEvent(); | 242 scriptLoader->dispatchErrorEvent(); |
| 243 } else { | 243 } else { |
| 244 element->dispatchEvent(Event::create(EventTypeNames::load)); | 244 element->dispatchEvent(Event::create(EventTypeNames::load)); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 DCHECK(!isExecutingScript()); | 249 DCHECK(!isExecutingScript()); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void HTMLParserScriptRunner::stopWatchingResourceForLoad(Resource* resource) { | |
| 253 if (m_parserBlockingScript->resource() == resource) { | |
| 254 m_parserBlockingScript->dispose(); | |
| 255 return; | |
| 256 } | |
| 257 for (auto& script : m_scriptsToExecuteAfterParsing) { | |
| 258 if (script->resource() == resource) { | |
| 259 script->dispose(); | |
| 260 return; | |
| 261 } | |
| 262 } | |
| 263 } | |
| 264 | |
| 265 void fetchBlockedDocWriteScript(Element* script, | 252 void fetchBlockedDocWriteScript(Element* script, |
| 266 bool isParserInserted, | 253 bool isParserInserted, |
| 267 const TextPosition& scriptStartPosition) { | 254 const TextPosition& scriptStartPosition) { |
| 268 DCHECK(script); | 255 DCHECK(script); |
| 269 | 256 |
| 270 ScriptLoader* scriptLoader = | 257 ScriptLoader* scriptLoader = |
| 271 ScriptLoader::create(script, isParserInserted, false, false); | 258 ScriptLoader::create(script, isParserInserted, false, false); |
| 272 DCHECK(scriptLoader); | 259 DCHECK(scriptLoader); |
| 273 scriptLoader->setFetchDocWrittenScriptDeferIdle(); | 260 scriptLoader->setFetchDocWrittenScriptDeferIdle(); |
| 274 scriptLoader->prepareScript(scriptStartPosition); | 261 scriptLoader->prepareScript(scriptStartPosition); |
| 275 } | 262 } |
| 276 | 263 |
| 277 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( | 264 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( |
| 278 Resource* resource) { | 265 PendingScript* pendingScript) { |
| 279 // If the script was blocked as part of document.write intervention, | 266 // If the script was blocked as part of document.write intervention, |
| 280 // then send an asynchronous GET request with an interventions header. | 267 // then send an asynchronous GET request with an interventions header. |
| 281 Element* element = nullptr; | 268 Element* element = nullptr; |
| 282 TextPosition startingPosition; | 269 TextPosition startingPosition; |
| 283 bool isParserInserted = false; | 270 bool isParserInserted = false; |
| 284 | 271 |
| 285 if (!resource->errorOccurred() || !m_parserBlockingScript || | 272 if (!pendingScript->errorOccurred() || |
| 286 !(m_parserBlockingScript->resource() == resource)) | 273 m_parserBlockingScript != pendingScript) |
| 287 return; | 274 return; |
| 288 | 275 |
| 289 // Due to dependency violation, not able to check the exact error to be | 276 // Due to dependency violation, not able to check the exact error to be |
| 290 // ERR_CACHE_MISS but other errors are rare with | 277 // ERR_CACHE_MISS but other errors are rare with |
| 291 // WebCachePolicy::ReturnCacheDataDontLoad. | 278 // WebCachePolicy::ReturnCacheDataDontLoad. |
| 292 element = m_parserBlockingScript->element(); | 279 element = m_parserBlockingScript->element(); |
| 293 | 280 |
| 294 ScriptLoader* scriptLoader = nullptr; | 281 ScriptLoader* scriptLoader = nullptr; |
| 295 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && | 282 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && |
| 296 scriptLoader->disallowedFetchForDocWrittenScript()) { | 283 scriptLoader->disallowedFetchForDocWrittenScript()) { |
| 297 startingPosition = m_parserBlockingScript->startingPosition(); | 284 startingPosition = m_parserBlockingScript->startingPosition(); |
| 298 isParserInserted = scriptLoader->isParserInserted(); | 285 isParserInserted = scriptLoader->isParserInserted(); |
| 299 // remove this resource entry from memory cache as the new request | 286 // remove this resource entry from memory cache as the new request |
| 300 // should not join onto this existing entry. | 287 // should not join onto this existing entry. |
| 301 memoryCache()->remove(resource); | 288 memoryCache()->remove(pendingScript->resource()); |
| 302 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); | 289 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| 303 } | 290 } |
| 304 } | 291 } |
| 305 | 292 |
| 306 void HTMLParserScriptRunner::notifyFinished(Resource* cachedResource) { | 293 void HTMLParserScriptRunner::pendingScriptFinished( |
| 294 PendingScript* pendingScript) { |
| 307 // Handle cancellations of parser-blocking script loads without | 295 // Handle cancellations of parser-blocking script loads without |
| 308 // notifying the host (i.e., parser) if these were initiated by nested | 296 // notifying the host (i.e., parser) if these were initiated by nested |
| 309 // document.write()s. The cancellation may have been triggered by | 297 // document.write()s. The cancellation may have been triggered by |
| 310 // script execution to signal an abrupt stop (e.g., window.close().) | 298 // script execution to signal an abrupt stop (e.g., window.close().) |
| 311 // | 299 // |
| 312 // The parser is unprepared to be told, and doesn't need to be. | 300 // The parser is unprepared to be told, and doesn't need to be. |
| 313 if (isExecutingScript() && cachedResource->wasCanceled()) { | 301 if (isExecutingScript() && pendingScript->resource()->wasCanceled()) { |
| 314 stopWatchingResourceForLoad(cachedResource); | 302 pendingScript->dispose(); |
| 315 return; | 303 return; |
| 316 } | 304 } |
| 317 | 305 |
| 318 // If the script was blocked as part of document.write intervention, | 306 // If the script was blocked as part of document.write intervention, |
| 319 // then send an asynchronous GET request with an interventions header. | 307 // then send an asynchronous GET request with an interventions header. |
| 320 possiblyFetchBlockedDocWriteScript(cachedResource); | 308 possiblyFetchBlockedDocWriteScript(pendingScript); |
| 321 | 309 |
| 322 m_host->notifyScriptLoaded(cachedResource); | 310 m_host->notifyScriptLoaded(pendingScript); |
| 323 } | 311 } |
| 324 | 312 |
| 325 // Implements the steps for 'An end tag whose tag name is "script"' | 313 // Implements the steps for 'An end tag whose tag name is "script"' |
| 326 // http://whatwg.org/html#scriptEndTag | 314 // http://whatwg.org/html#scriptEndTag |
| 327 // Script handling lives outside the tree builder to keep each class simple. | 315 // Script handling lives outside the tree builder to keep each class simple. |
| 328 void HTMLParserScriptRunner::processScriptElement( | 316 void HTMLParserScriptRunner::processScriptElement( |
| 329 Element* scriptElement, | 317 Element* scriptElement, |
| 330 const TextPosition& scriptStartPosition) { | 318 const TextPosition& scriptStartPosition) { |
| 331 DCHECK(scriptElement); | 319 DCHECK(scriptElement); |
| 332 TRACE_EVENT1( | 320 TRACE_EVENT1( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 DCHECK(m_document); | 355 DCHECK(m_document); |
| 368 DCHECK(!isExecutingScript()); | 356 DCHECK(!isExecutingScript()); |
| 369 DCHECK(m_document->isScriptExecutionReady()); | 357 DCHECK(m_document->isScriptExecutionReady()); |
| 370 | 358 |
| 371 InsertionPointRecord insertionPointRecord(m_host->inputStream()); | 359 InsertionPointRecord insertionPointRecord(m_host->inputStream()); |
| 372 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), | 360 executePendingScriptAndDispatchEvent(m_parserBlockingScript.get(), |
| 373 ScriptStreamer::ParsingBlocking); | 361 ScriptStreamer::ParsingBlocking); |
| 374 } | 362 } |
| 375 } | 363 } |
| 376 | 364 |
| 377 void HTMLParserScriptRunner::executeScriptsWaitingForLoad(Resource* resource) { | 365 void HTMLParserScriptRunner::executeScriptsWaitingForLoad( |
| 366 PendingScript* pendingScript) { |
| 378 TRACE_EVENT0("blink", "HTMLParserScriptRunner::executeScriptsWaitingForLoad"); | 367 TRACE_EVENT0("blink", "HTMLParserScriptRunner::executeScriptsWaitingForLoad"); |
| 379 DCHECK(!isExecutingScript()); | 368 DCHECK(!isExecutingScript()); |
| 380 DCHECK(hasParserBlockingScript()); | 369 DCHECK(hasParserBlockingScript()); |
| 381 DCHECK_EQ(resource, m_parserBlockingScript->resource()); | 370 DCHECK_EQ(pendingScript, m_parserBlockingScript); |
| 382 DCHECK(m_parserBlockingScript->isReady()); | 371 DCHECK(m_parserBlockingScript->isReady()); |
| 383 executeParsingBlockingScripts(); | 372 executeParsingBlockingScripts(); |
| 384 } | 373 } |
| 385 | 374 |
| 386 void HTMLParserScriptRunner::executeScriptsWaitingForResources() { | 375 void HTMLParserScriptRunner::executeScriptsWaitingForResources() { |
| 387 TRACE_EVENT0("blink", | 376 TRACE_EVENT0("blink", |
| 388 "HTMLParserScriptRunner::executeScriptsWaitingForResources"); | 377 "HTMLParserScriptRunner::executeScriptsWaitingForResources"); |
| 389 DCHECK(m_document); | 378 DCHECK(m_document); |
| 390 DCHECK(!isExecutingScript()); | 379 DCHECK(!isExecutingScript()); |
| 391 DCHECK(m_document->isScriptExecutionReady()); | 380 DCHECK(m_document->isScriptExecutionReady()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 requestParsingBlockingScript(script); | 512 requestParsingBlockingScript(script); |
| 524 } | 513 } |
| 525 } | 514 } |
| 526 } | 515 } |
| 527 | 516 |
| 528 DEFINE_TRACE(HTMLParserScriptRunner) { | 517 DEFINE_TRACE(HTMLParserScriptRunner) { |
| 529 visitor->trace(m_document); | 518 visitor->trace(m_document); |
| 530 visitor->trace(m_host); | 519 visitor->trace(m_host); |
| 531 visitor->trace(m_parserBlockingScript); | 520 visitor->trace(m_parserBlockingScript); |
| 532 visitor->trace(m_scriptsToExecuteAfterParsing); | 521 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 533 ScriptResourceClient::trace(visitor); | 522 PendingScriptClient::trace(visitor); |
| 534 } | 523 } |
| 535 | 524 |
| 536 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |