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

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: Rebased. 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..93a4f5832694909eaeb77b2594dcfc19d31145d2 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,50 @@ 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);
+}
+
+bool HTMLScriptRunner::possiblyFetchBlockedDocWriteScript(Resource* cachedResource)
Nate Chapin 2016/09/06 20:28:12 Nit: |cachedResource| is anachronistic. Just |reso
shivanisha 2016/09/15 20:35:08 done.
+{
+ // 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 shouldFetchBlockedDocWriteScript = 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()) {
+ shouldFetchBlockedDocWriteScript = true;
haraken 2016/09/07 01:47:36 It's confusing to set "shouldFetch"BlockedDocWrite
shivanisha 2016/09/15 20:35:08 disallowedFetch"ForDocWrittenScript was set when t
+ startingPosition = m_parserBlockingScript->startingPosition();
+ isParserInserted = scriptLoader->isParserInserted();
+ }
+ }
+
+ if (!shouldFetchBlockedDocWriteScript)
+ return false;
+
+ m_host->notifyScriptLoaded(cachedResource);
+
+ // 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);
+ return true;
+}
+
void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
{
// Handle cancellations of parser-blocking script loads without
@@ -261,6 +306,12 @@ 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.
+ if (possiblyFetchBlockedDocWriteScript(cachedResource))
+ return;
+
m_host->notifyScriptLoaded(cachedResource);
}

Powered by Google App Engine
This is Rietveld 408576698