| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "bindings/core/v8/Microtask.h" | 28 #include "bindings/core/v8/Microtask.h" |
| 29 #include "bindings/core/v8/ScriptSourceCode.h" | 29 #include "bindings/core/v8/ScriptSourceCode.h" |
| 30 #include "bindings/core/v8/V8PerIsolateData.h" | 30 #include "bindings/core/v8/V8PerIsolateData.h" |
| 31 #include "core/dom/DocumentParserTiming.h" | 31 #include "core/dom/DocumentParserTiming.h" |
| 32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
| 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 34 #include "core/dom/ScriptLoader.h" | 34 #include "core/dom/ScriptLoader.h" |
| 35 #include "core/dom/TaskRunnerHelper.h" | 35 #include "core/dom/TaskRunnerHelper.h" |
| 36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
| 37 #include "core/fetch/MemoryCache.h" |
| 37 #include "core/fetch/ScriptResource.h" | 38 #include "core/fetch/ScriptResource.h" |
| 38 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 39 #include "core/html/parser/HTMLInputStream.h" | 40 #include "core/html/parser/HTMLInputStream.h" |
| 40 #include "core/html/parser/HTMLScriptRunnerHost.h" | 41 #include "core/html/parser/HTMLScriptRunnerHost.h" |
| 41 #include "core/html/parser/NestingLevelIncrementer.h" | 42 #include "core/html/parser/NestingLevelIncrementer.h" |
| 42 #include "platform/Histogram.h" | 43 #include "platform/Histogram.h" |
| 43 #include "platform/TraceEvent.h" | 44 #include "platform/TraceEvent.h" |
| 44 #include "platform/TracedValue.h" | 45 #include "platform/TracedValue.h" |
| 45 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 46 #include "public/platform/WebFrameScheduler.h" | 47 #include "public/platform/WebFrameScheduler.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 243 } |
| 243 for (auto& script : m_scriptsToExecuteAfterParsing) { | 244 for (auto& script : m_scriptsToExecuteAfterParsing) { |
| 244 if (script->resource() == resource) { | 245 if (script->resource() == resource) { |
| 245 script->stopWatchingForLoad(); | 246 script->stopWatchingForLoad(); |
| 246 script->releaseElementAndClear(); | 247 script->releaseElementAndClear(); |
| 247 return; | 248 return; |
| 248 } | 249 } |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 253 void fetchBlockedDocWriteScript(Element* script, bool isParserInserted, const Te
xtPosition& scriptStartPosition) |
| 254 { |
| 255 DCHECK(script); |
| 256 |
| 257 ScriptLoader* scriptLoader = ScriptLoader::create(script, isParserInserted,
false, false); |
| 258 DCHECK(scriptLoader); |
| 259 scriptLoader->setBlockedDocWriteScriptAsyncFetch(); |
| 260 scriptLoader->prepareScript(scriptStartPosition); |
| 261 } |
| 262 |
| 252 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 263 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
| 253 { | 264 { |
| 254 // Handle cancellations of parser-blocking script loads without | 265 // Handle cancellations of parser-blocking script loads without |
| 255 // notifying the host (i.e., parser) if these were initiated by nested | 266 // notifying the host (i.e., parser) if these were initiated by nested |
| 256 // document.write()s. The cancellation may have been triggered by | 267 // document.write()s. The cancellation may have been triggered by |
| 257 // script execution to signal an abrupt stop (e.g., window.close().) | 268 // script execution to signal an abrupt stop (e.g., window.close().) |
| 258 // | 269 // |
| 259 // The parser is unprepared to be told, and doesn't need to be. | 270 // The parser is unprepared to be told, and doesn't need to be. |
| 260 if (isExecutingScript() && cachedResource->wasCanceled()) { | 271 if (isExecutingScript() && cachedResource->wasCanceled()) { |
| 261 stopWatchingResourceForLoad(cachedResource); | 272 stopWatchingResourceForLoad(cachedResource); |
| 262 return; | 273 return; |
| 263 } | 274 } |
| 275 |
| 276 // If the script was blocked as part of document.write intervention, |
| 277 // then send an asynchronous GET request with an interventions header. |
| 278 Element* element = nullptr; |
| 279 TextPosition startingPosition; |
| 280 bool blockedDocWriteScriptAsyncFetch = false; |
| 281 bool isParserInserted = false; |
| 282 if (cachedResource->errorOccurred() && m_parserBlockingScript && m_parserBlo
ckingScript->resource() == cachedResource) { |
| 283 // Due to dependency violation, not able to check the exact error to be |
| 284 // ERR_CACHE_MISS but other errors are rare with |
| 285 // WebCachePolicy::ReturnCacheDataDontLoad. |
| 286 element = m_parserBlockingScript->element(); |
| 287 |
| 288 ScriptLoader* scriptLoader = nullptr; |
| 289 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && scr
iptLoader->disallowedFetchForDocWrittenScript()) { |
| 290 blockedDocWriteScriptAsyncFetch = true; |
| 291 startingPosition = m_parserBlockingScript->startingPosition(); |
| 292 isParserInserted = scriptLoader->isParserInserted(); |
| 293 } |
| 294 } |
| 295 |
| 264 m_host->notifyScriptLoaded(cachedResource); | 296 m_host->notifyScriptLoaded(cachedResource); |
| 297 |
| 298 if (blockedDocWriteScriptAsyncFetch) { |
| 299 // remove this resource entry from memory cache as the new request |
| 300 // should not join onto this existing entry. |
| 301 memoryCache()->remove(cachedResource); |
| 302 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| 303 } |
| 265 } | 304 } |
| 266 | 305 |
| 267 // Implements the steps for 'An end tag whose tag name is "script"' | 306 // Implements the steps for 'An end tag whose tag name is "script"' |
| 268 // http://whatwg.org/html#scriptEndTag | 307 // http://whatwg.org/html#scriptEndTag |
| 269 // Script handling lives outside the tree builder to keep each class simple. | 308 // Script handling lives outside the tree builder to keep each class simple. |
| 270 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip
tStartPosition) | 309 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip
tStartPosition) |
| 271 { | 310 { |
| 272 ASSERT(scriptElement); | 311 ASSERT(scriptElement); |
| 273 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", | 312 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", |
| 274 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition)
); | 313 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition)
); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 DEFINE_TRACE(HTMLScriptRunner) | 489 DEFINE_TRACE(HTMLScriptRunner) |
| 451 { | 490 { |
| 452 visitor->trace(m_document); | 491 visitor->trace(m_document); |
| 453 visitor->trace(m_host); | 492 visitor->trace(m_host); |
| 454 visitor->trace(m_parserBlockingScript); | 493 visitor->trace(m_parserBlockingScript); |
| 455 visitor->trace(m_scriptsToExecuteAfterParsing); | 494 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 456 ScriptResourceClient::trace(visitor); | 495 ScriptResourceClient::trace(visitor); |
| 457 } | 496 } |
| 458 | 497 |
| 459 } // namespace blink | 498 } // namespace blink |
| OLD | NEW |