Index: third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp |
diff --git a/third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp b/third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp |
index 05c63f6a5e263a17e414899171190371b90a2073..a215bb962ae555550ab8aa9e0dce731bb45ee2ee 100644 |
--- a/third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp |
+++ b/third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp |
@@ -34,6 +34,7 @@ |
#include "core/dom/ScriptLoader.h" |
#include "core/dom/TaskRunnerHelper.h" |
#include "core/events/Event.h" |
+#include "core/fetch/MemoryCache.h" |
#include "core/fetch/ScriptResource.h" |
#include "core/frame/LocalFrame.h" |
#include "core/html/parser/HTMLInputStream.h" |
@@ -249,6 +250,22 @@ void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) |
} |
} |
+void fetchBlockedDocWriteScript(Element* script, const TextPosition& scriptStartPosition) |
+{ |
+ ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script); |
+ // This contains both and ASSERTION and a null check since we should not |
+ // be getting into the case of a null script element, but seem to be from |
+ // time to time. The assertion is left in to help find those cases and |
+ // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. |
+ DCHECK(scriptLoader); |
+ if (!scriptLoader) |
+ return; |
+ DCHECK(scriptLoader->isParserInserted()); |
+ |
+ scriptLoader = ScriptLoader::create(script, scriptLoader->isParserInserted(), false, false, true); |
+ scriptLoader->prepareScript(scriptStartPosition); |
+} |
+ |
void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
{ |
// Handle cancellations of parser-blocking script loads without |
@@ -261,7 +278,30 @@ void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
stopWatchingResourceForLoad(cachedResource); |
return; |
} |
+ |
+ // If the script was blocked as part of document.write intervention, |
+ // then send an asynchronous GET request with an interventions header. |
+ Element* element = m_parserBlockingScript->element(); |
+ TextPosition startingPosition = m_parserBlockingScript->startingPosition(); |
+ ScriptLoader* scriptLoader = toScriptLoaderIfPossible(m_parserBlockingScript->element()); |
+ bool blockedDocWriteScriptAsyncFetch = false; |
+ |
+ // Due to dependency violation, not able to check the exact error to be |
+ // ERR_CACHE_MISS but other errors are rare with |
+ // WebCachePolicy::ReturnCacheDataDontLoad. |
+ if (cachedResource->errorOccurred() && m_parserBlockingScript->resource() == cachedResource |
+ && scriptLoader->disallowedFetchForDocWrittenScript()) { |
+ blockedDocWriteScriptAsyncFetch = true; |
+ } |
+ |
m_host->notifyScriptLoaded(cachedResource); |
+ |
+ if (blockedDocWriteScriptAsyncFetch) { |
+ // remove this resource entry from memory cache as the new request |
+ // should not join onto this existing entry. |
+ memoryCache()->remove(cachedResource); |
+ fetchBlockedDocWriteScript(element, startingPosition); |
+ } |
} |
// Implements the steps for 'An end tag whose tag name is "script"' |