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

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: Test added, failed bot tests fixed, converted to enum. Created 4 years, 4 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..18b71b26af8de775e449e4b6b08c1dcc817e8cd0 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,15 @@ void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource)
}
}
+void fetchBlockedDocWriteScript(Element* script, bool isParserInserted, const TextPosition& scriptStartPosition)
+{
+ DCHECK(script);
+
+ ScriptLoader* scriptLoader = ScriptLoader::create(script, isParserInserted, false, false, true);
+ DCHECK(scriptLoader);
+ scriptLoader->prepareScript(scriptStartPosition);
+}
+
void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
{
// Handle cancellations of parser-blocking script loads without
@@ -261,7 +271,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) {
Nate Chapin 2016/08/22 19:47:03 Does this logic absolutely need to be after notify
shivanisha 2016/08/22 20:44:00 I am not completely aware of the other threads tha
Nate Chapin 2016/08/22 20:55:12 Hrm, ok. One option is to move all the new code he
shivanisha 2016/08/23 01:04:46 Sounds good. done
+ // 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"'

Powered by Google App Engine
This is Rietveld 408576698