Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Unified Diff: third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp

Issue 2260303002: Sending an async GET request for doc.written blocked scripts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Windows compile error for GetResourcePriority return type fixed. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8b2229b67f1ba46051bb5e094c97ecfb7c0b6320 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,43 @@ 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->setFetchDocWrittenScriptDeferIdle();
+ scriptLoader->prepareScript(scriptStartPosition);
+}
+
+void HTMLScriptRunner::possiblyFetchBlockedDocWriteScript(Resource* resource)
+{
+ // 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 isParserInserted = false;
+
+ if (!resource->errorOccurred() || !m_parserBlockingScript || !(m_parserBlockingScript->resource() == resource))
+ return;
+
+ // 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()) {
+ startingPosition = m_parserBlockingScript->startingPosition();
+ isParserInserted = scriptLoader->isParserInserted();
+ // remove this resource entry from memory cache as the new request
+ // should not join onto this existing entry.
+ memoryCache()->remove(resource);
+ fetchBlockedDocWriteScript(element, isParserInserted, startingPosition);
+ }
+}
+
void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
{
// Handle cancellations of parser-blocking script loads without
@@ -261,6 +299,11 @@ 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.
+ possiblyFetchBlockedDocWriteScript(cachedResource);
+
m_host->notifyScriptLoaded(cachedResource);
}

Powered by Google App Engine
This is Rietveld 408576698