Commit 57536eaf authored by shivanisha's avatar shivanisha Committed by Commit bot

Sending an async GET request for doc.written blocked scripts.

BUG=639401

While fetching the original request, ScriptLoader sets a member flag.
On receiving notifyFinished for the original request, HTMLScriptRunner
creates a new ScriptLoader instance using the original Element with
another flag set to true. It then calls ScriptLoader::prepareScript which
further calls fetchScript. prepareScript sets the defer flag as LazyLoad and
fetchScript sets the intervention info and header in the resource request.
The intervention info is used to set the priority in ResourceFetcher::requestResource.

This CL also adds a link in the dev tools console warning.

Also added internals.getResourcePriority() for
the layout test to test that the new request goes out with priority very low.

The code was tested using netlog to verify the second request is sent and has
the correct priority (net::IDLE).
One of the example sites created by jkarlin@ is:
http://www.karlin.me/test/docwrite/

Review-Url: https://codereview.chromium.org/2260303002
Cr-Commit-Position: refs/heads/master@{#419476}
parent 2ac9af4c
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 9: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?a, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 9: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?a, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 9: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?a, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 9: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?a, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 36: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?b, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 36: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?b, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 36: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?b, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 36: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?all-conn-types?b, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
main frame - didFinishDocumentLoadForFrame main frame - didFinishDocumentLoadForFrame
main frame - didHandleOnloadEventsForFrame main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame main frame - didFinishLoadForFrame
......
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 12: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 12: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 12: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 12: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 54: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 54: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 54: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 54: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 70: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin2, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 70: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin2, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 70: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin2, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 70: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?cross-origin2, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE MESSAGE: line 82: http://localhost:8000/loading/resources/js-loaded.js?cross-origin2 has priority 0
main frame - didFinishDocumentLoadForFrame main frame - didFinishDocumentLoadForFrame
main frame - didHandleOnloadEventsForFrame main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame main frame - didFinishLoadForFrame
......
...@@ -76,4 +76,9 @@ ...@@ -76,4 +76,9 @@
assert_false(loadSuccess); assert_false(loadSuccess);
assert_true(loadFailed); assert_true(loadFailed);
}, "cross origin doc.written scripts are blocked"); }, "cross origin doc.written scripts are blocked");
if (window.internals) {
priority = internals.getResourcePriority(src, document);
console.log(src + " has priority " + priority);
}
</script> </script>
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 18: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?conn-type, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 18: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?conn-type, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 18: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?conn-type, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 18: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?conn-type, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
main frame - didFinishDocumentLoadForFrame main frame - didFinishDocumentLoadForFrame
main frame - didHandleOnloadEventsForFrame main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame main frame - didFinishLoadForFrame
......
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
main frame - didStartProvisionalLoadForFrame main frame - didStartProvisionalLoadForFrame
main frame - didCommitLoadForFrame main frame - didCommitLoadForFrame
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. CONSOLE WARNING: line 47: A Parser-blocking, cross-origin script, http://localhost:8000/loading/resources/js-loaded.js?reload, is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.
main frame - didFinishDocumentLoadForFrame main frame - didFinishDocumentLoadForFrame
main frame - didHandleOnloadEventsForFrame main frame - didHandleOnloadEventsForFrame
main frame - didFinishLoadForFrame main frame - didFinishLoadForFrame
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "core/events/Event.h" #include "core/events/Event.h"
#include "core/fetch/AccessControlStatus.h" #include "core/fetch/AccessControlStatus.h"
#include "core/fetch/FetchRequest.h" #include "core/fetch/FetchRequest.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ResourceFetcher.h" #include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ScriptResource.h" #include "core/fetch/ScriptResource.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
#include "core/svg/SVGScriptElement.h" #include "core/svg/SVGScriptElement.h"
#include "platform/MIMETypeRegistry.h" #include "platform/MIMETypeRegistry.h"
#include "platform/weborigin/SecurityOrigin.h" #include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/WebCachePolicy.h"
#include "public/platform/WebFrameScheduler.h" #include "public/platform/WebFrameScheduler.h"
#include "wtf/StdLibExtras.h" #include "wtf/StdLibExtras.h"
#include "wtf/text/StringBuilder.h" #include "wtf/text/StringBuilder.h"
...@@ -71,6 +73,7 @@ ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt ...@@ -71,6 +73,7 @@ ScriptLoader::ScriptLoader(Element* element, bool parserInserted, bool alreadySt
, m_forceAsync(!parserInserted) , m_forceAsync(!parserInserted)
, m_createdDuringDocumentWrite(createdDuringDocumentWrite) , m_createdDuringDocumentWrite(createdDuringDocumentWrite)
, m_asyncExecType(ScriptRunner::None) , m_asyncExecType(ScriptRunner::None)
, m_documentWriteIntervention(DocumentWriteIntervention::DocumentWriteInterventionNone)
{ {
DCHECK(m_element); DCHECK(m_element);
if (parserInserted && element->document().scriptableDocumentParser() && !element->document().isInDocumentWrite()) if (parserInserted && element->document().scriptableDocumentParser() && !element->document().isInDocumentWrite())
...@@ -89,6 +92,12 @@ DEFINE_TRACE(ScriptLoader) ...@@ -89,6 +92,12 @@ DEFINE_TRACE(ScriptLoader)
ScriptResourceClient::trace(visitor); ScriptResourceClient::trace(visitor);
} }
void ScriptLoader::setFetchDocWrittenScriptDeferIdle()
{
DCHECK(!m_createdDuringDocumentWrite);
m_documentWriteIntervention = DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle;
}
void ScriptLoader::didNotifySubtreeInsertionsToDocument() void ScriptLoader::didNotifySubtreeInsertionsToDocument()
{ {
if (!m_parserInserted) if (!m_parserInserted)
...@@ -238,10 +247,21 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy ...@@ -238,10 +247,21 @@ bool ScriptLoader::prepareScript(const TextPosition& scriptStartPosition, Legacy
FetchRequest::DeferOption defer = FetchRequest::NoDefer; FetchRequest::DeferOption defer = FetchRequest::NoDefer;
if (!m_parserInserted || client->asyncAttributeValue() || client->deferAttributeValue()) if (!m_parserInserted || client->asyncAttributeValue() || client->deferAttributeValue())
defer = FetchRequest::LazyLoad; defer = FetchRequest::LazyLoad;
if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle)
defer = FetchRequest::IdleLoad;
if (!fetchScript(client->sourceAttributeValue(), defer)) if (!fetchScript(client->sourceAttributeValue(), defer))
return false; return false;
} }
// Since the asynchronous, low priority fetch for doc.written blocked
// script is not for execution, return early from here. Watch for its
// completion to be able to remove it from the memory cache.
if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) {
m_pendingScript = PendingScript::create(m_element, m_resource.get());
m_pendingScript->watchForLoad(this);
return true;
}
if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) { if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parserInserted && !client->asyncAttributeValue()) {
m_willExecuteWhenDocumentFinishedParsing = true; m_willExecuteWhenDocumentFinishedParsing = true;
m_willBeParserExecuted = true; m_willBeParserExecuted = true;
...@@ -317,16 +337,25 @@ bool ScriptLoader::fetchScript(const String& sourceUrl, FetchRequest::DeferOptio ...@@ -317,16 +337,25 @@ bool ScriptLoader::fetchScript(const String& sourceUrl, FetchRequest::DeferOptio
request.setIntegrityMetadata(metadataSet); request.setIntegrityMetadata(metadataSet);
} }
if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) {
request.mutableResourceRequest().setHTTPHeaderField("Intervention", "<https://www.chromestatus.com/feature/5718547946799104>");
}
m_resource = ScriptResource::fetch(request, elementDocument->fetcher()); m_resource = ScriptResource::fetch(request, elementDocument->fetcher());
m_isExternalScript = true; m_isExternalScript = true;
} }
if (m_resource) if (!m_resource) {
return true; dispatchErrorEvent();
return false;
}
dispatchErrorEvent(); if (m_createdDuringDocumentWrite && m_resource->resourceRequest().getCachePolicy() == WebCachePolicy::ReturnCacheDataDontLoad) {
return false; m_documentWriteIntervention = DocumentWriteIntervention::DoNotFetchDocWrittenScript;
}
return true;
} }
bool isHTMLScriptLoader(Element* element) bool isHTMLScriptLoader(Element* element)
...@@ -482,6 +511,17 @@ void ScriptLoader::execute() ...@@ -482,6 +511,17 @@ void ScriptLoader::execute()
void ScriptLoader::notifyFinished(Resource* resource) void ScriptLoader::notifyFinished(Resource* resource)
{ {
DCHECK(!m_willBeParserExecuted); DCHECK(!m_willBeParserExecuted);
// We do not need this script in the memory cache. The primary goals of
// sending this fetch request are to let the third party server know
// about the document.write scripts intervention and populate the http
// cache for subsequent uses.
if (m_documentWriteIntervention == DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) {
memoryCache()->remove(resource);
m_pendingScript->stopWatchingForLoad();
return;
}
DCHECK(m_asyncExecType != ScriptRunner::None); DCHECK(m_asyncExecType != ScriptRunner::None);
Document* contextDocument = m_element->document().contextDocument(); Document* contextDocument = m_element->document().contextDocument();
......
...@@ -91,6 +91,9 @@ public: ...@@ -91,6 +91,9 @@ public:
bool wasCreatedDuringDocumentWrite() { return m_createdDuringDocumentWrite; } bool wasCreatedDuringDocumentWrite() { return m_createdDuringDocumentWrite; }
bool disallowedFetchForDocWrittenScript() { return m_documentWriteIntervention == DocumentWriteIntervention::DoNotFetchDocWrittenScript; }
void setFetchDocWrittenScriptDeferIdle();
protected: protected:
ScriptLoader(Element*, bool createdByParser, bool isEvaluated, bool createdDuringDocumentWrite); ScriptLoader(Element*, bool createdByParser, bool isEvaluated, bool createdDuringDocumentWrite);
...@@ -125,6 +128,20 @@ private: ...@@ -125,6 +128,20 @@ private:
const bool m_createdDuringDocumentWrite : 1; const bool m_createdDuringDocumentWrite : 1;
ScriptRunner::AsyncExecutionType m_asyncExecType; ScriptRunner::AsyncExecutionType m_asyncExecType;
enum DocumentWriteIntervention {
DocumentWriteInterventionNone = 0,
// Based on what shouldDisallowFetchForMainFrameScript() returns.
// This script will be blocked if not present in http cache.
DoNotFetchDocWrittenScript,
// If a parser blocking doc.written script was not fetched and was not
// present in the http cache, send a GET for it with an interventions
// header to allow the server to know of the intervention. This fetch
// will be using DeferOption::IdleLoad to keep it out of the critical
// path.
FetchDocWrittenScriptDeferIdle,
};
DocumentWriteIntervention m_documentWriteIntervention;
Member<PendingScript> m_pendingScript; Member<PendingScript> m_pendingScript;
}; };
......
...@@ -42,7 +42,9 @@ class SecurityOrigin; ...@@ -42,7 +42,9 @@ class SecurityOrigin;
class CORE_EXPORT FetchRequest { class CORE_EXPORT FetchRequest {
STACK_ALLOCATED(); STACK_ALLOCATED();
public: public:
enum DeferOption { NoDefer, LazyLoad }; enum DeferOption { NoDefer,
LazyLoad,
IdleLoad };
enum OriginRestriction { UseDefaultOriginRestrictionForType, RestrictToSameOrigin, NoOriginRestriction }; enum OriginRestriction { UseDefaultOriginRestrictionForType, RestrictToSameOrigin, NoOriginRestriction };
struct ResourceWidth { struct ResourceWidth {
......
...@@ -146,11 +146,13 @@ ResourceLoadPriority ResourceFetcher::computeLoadPriority(Resource::Type type, c ...@@ -146,11 +146,13 @@ ResourceLoadPriority ResourceFetcher::computeLoadPriority(Resource::Type type, c
if (type == Resource::Image) if (type == Resource::Image)
m_imageFetched = true; m_imageFetched = true;
// Special handling for scripts. if (FetchRequest::IdleLoad == request.defer()) {
// Default/Parser-Blocking/Preload early in document: High (set in typeToPriority) priority = ResourceLoadPriorityVeryLow;
// Async/Defer: Low Priority (applies to both preload and parser-inserted) } else if (type == Resource::Script) {
// Preload late in document: Medium // Special handling for scripts.
if (type == Resource::Script) { // Default/Parser-Blocking/Preload early in document: High (set in typeToPriority)
// Async/Defer: Low Priority (applies to both preload and parser-inserted)
// Preload late in document: Medium
if (FetchRequest::LazyLoad == request.defer()) if (FetchRequest::LazyLoad == request.defer())
priority = ResourceLoadPriorityLow; priority = ResourceLoadPriorityLow;
else if (request.forPreload() && m_imageFetched) else if (request.forPreload() && m_imageFetched)
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "core/dom/ScriptLoader.h" #include "core/dom/ScriptLoader.h"
#include "core/dom/TaskRunnerHelper.h" #include "core/dom/TaskRunnerHelper.h"
#include "core/events/Event.h" #include "core/events/Event.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ScriptResource.h" #include "core/fetch/ScriptResource.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
#include "core/html/parser/HTMLInputStream.h" #include "core/html/parser/HTMLInputStream.h"
...@@ -249,6 +250,43 @@ void HTMLScriptRunner::stopWatchingResourceForLoad(Resource* resource) ...@@ -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) void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
{ {
// Handle cancellations of parser-blocking script loads without // Handle cancellations of parser-blocking script loads without
...@@ -261,6 +299,11 @@ void HTMLScriptRunner::notifyFinished(Resource* cachedResource) ...@@ -261,6 +299,11 @@ void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
stopWatchingResourceForLoad(cachedResource); stopWatchingResourceForLoad(cachedResource);
return; 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); m_host->notifyScriptLoaded(cachedResource);
} }
......
...@@ -89,6 +89,8 @@ private: ...@@ -89,6 +89,8 @@ private:
void stopWatchingResourceForLoad(Resource*); void stopWatchingResourceForLoad(Resource*);
void possiblyFetchBlockedDocWriteScript(Resource*);
RefPtr<HTMLParserReentryPermit> m_reentryPermit; RefPtr<HTMLParserReentryPermit> m_reentryPermit;
Member<Document> m_document; Member<Document> m_document;
Member<HTMLScriptRunnerHost> m_host; Member<HTMLScriptRunnerHost> m_host;
......
...@@ -83,7 +83,7 @@ namespace { ...@@ -83,7 +83,7 @@ namespace {
void emitWarningForDocWriteScripts(const String& url, Document& document) void emitWarningForDocWriteScripts(const String& url, Document& document)
{ {
String message = "A Parser-blocking, cross-origin script, " + url + ", is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity."; String message = "A Parser-blocking, cross-origin script, " + url + ", is invoked via document.write. This may be blocked by the browser if the device has poor network connectivity. See https://www.chromestatus.com/feature/5718547946799104 for more details.";
document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message));
WTFLogAlways("%s", message.utf8().data()); WTFLogAlways("%s", message.utf8().data());
} }
......
...@@ -139,7 +139,9 @@ ...@@ -139,7 +139,9 @@
#include "platform/geometry/LayoutRect.h" #include "platform/geometry/LayoutRect.h"
#include "platform/graphics/GraphicsLayer.h" #include "platform/graphics/GraphicsLayer.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/network/ResourceLoadPriority.h"
#include "platform/scroll/ProgrammaticScrollAnimator.h" #include "platform/scroll/ProgrammaticScrollAnimator.h"
#include "platform/testing/URLTestHelpers.h"
#include "platform/weborigin/SchemeRegistry.h" #include "platform/weborigin/SchemeRegistry.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "public/platform/WebConnectionType.h" #include "public/platform/WebConnectionType.h"
...@@ -410,6 +412,19 @@ bool Internals::isLoadingFromMemoryCache(const String& url) ...@@ -410,6 +412,19 @@ bool Internals::isLoadingFromMemoryCache(const String& url)
return resource && resource->getStatus() == Resource::Cached; return resource && resource->getStatus() == Resource::Cached;
} }
int Internals::getResourcePriority(const String& url, Document* document)
{
if (!document)
return ResourceLoadPriority::ResourceLoadPriorityUnresolved;
Resource* resource = document->fetcher()->allResources().get(URLTestHelpers::toKURL(url.utf8().data()));
if (!resource)
return ResourceLoadPriority::ResourceLoadPriorityUnresolved;
return resource->resourceRequest().priority();
}
bool Internals::isSharingStyle(Element* element1, Element* element2) const bool Internals::isSharingStyle(Element* element1, Element* element2) const
{ {
ASSERT(element1 && element2); ASSERT(element1 && element2);
......
...@@ -91,6 +91,7 @@ public: ...@@ -91,6 +91,7 @@ public:
bool isPreloaded(const String& url); bool isPreloaded(const String& url);
bool isPreloadedBy(const String& url, Document*); bool isPreloadedBy(const String& url, Document*);
bool isLoadingFromMemoryCache(const String& url); bool isLoadingFromMemoryCache(const String& url);
int getResourcePriority(const String& url, Document*);
bool isSharingStyle(Element*, Element*) const; bool isSharingStyle(Element*, Element*) const;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
boolean isPreloaded(DOMString url); boolean isPreloaded(DOMString url);
boolean isPreloadedBy(DOMString url, Document document); boolean isPreloadedBy(DOMString url, Document document);
boolean isLoadingFromMemoryCache(DOMString url); boolean isLoadingFromMemoryCache(DOMString url);
unsigned long getResourcePriority (DOMString url, Document document);
boolean isSharingStyle(Element element1, Element element2); boolean isSharingStyle(Element element1, Element element2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment