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..0b07e997b4e0f67596215a50e45b606e5ed246cc 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,16 @@ void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) |
} |
} |
+void fetchBlockedDocWriteScript(Element* script, bool isParserInserted, const TextPosition& scriptStartPosition) |
+{ |
+ DCHECK(script); |
+ |
+ ScriptLoader* scriptLoader = ScriptLoader::create(script, isParserInserted, false, false); |
+ DCHECK(scriptLoader); |
+ scriptLoader->setBlockedDocWriteScriptAsyncFetch(); |
+ scriptLoader->prepareScript(scriptStartPosition); |
+} |
+ |
void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
{ |
// Handle cancellations of parser-blocking script loads without |
@@ -261,7 +272,35 @@ 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 = nullptr; |
+ TextPosition startingPosition; |
+ bool blockedDocWriteScriptAsyncFetch = false; |
+ bool isParserInserted = false; |
+ if (cachedResource->errorOccurred() && m_parserBlockingScript && m_parserBlockingScript->resource() == cachedResource) { |
+ // Due to dependency violation, not able to check the exact error to be |
+ // ERR_CACHE_MISS but other errors are rare with |
+ // WebCachePolicy::ReturnCacheDataDontLoad. |
+ element = m_parserBlockingScript->element(); |
+ |
+ ScriptLoader* scriptLoader = nullptr; |
+ if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && scriptLoader->disallowedFetchForDocWrittenScript()) { |
+ blockedDocWriteScriptAsyncFetch = true; |
+ startingPosition = m_parserBlockingScript->startingPosition(); |
+ isParserInserted = scriptLoader->isParserInserted(); |
+ } |
+ } |
+ |
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, isParserInserted, startingPosition); |
+ } |
} |
// Implements the steps for 'An end tag whose tag name is "script"' |