Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp |
| diff --git a/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp b/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp |
| index c01b9997fd3c7a10778e6a8bb37931bc91a89541..9eacb1496fe8b5faba178ac25655f4058f9c085c 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp |
| +++ b/third_party/WebKit/Source/core/html/parser/HTMLParserScriptRunner.cpp |
| @@ -39,6 +39,7 @@ |
| #include "core/html/parser/HTMLInputStream.h" |
| #include "core/html/parser/HTMLParserScriptRunnerHost.h" |
| #include "core/html/parser/NestingLevelIncrementer.h" |
| +#include "core/inspector/ConsoleMessage.h" |
| #include "core/loader/resource/ScriptResource.h" |
| #include "platform/Histogram.h" |
| #include "platform/WebFrameScheduler.h" |
| @@ -260,33 +261,72 @@ void fetchBlockedDocWriteScript(Element* script, |
| scriptLoader->prepareScript(scriptStartPosition); |
| } |
| +void emitWarningForDocWriteScripts(const String& url, Document& document) { |
| + String message = |
| + "The Parser-blocking, cross site (i.e. different eTLD+1) " |
| + "script, " + |
| + url + |
| + ", invoked via document.write was NOT " |
| + "blocked on this page load, but MAY be blocked by the " |
| + "browser in future page loads with poor network " |
| + "connectivity. See " |
|
Bryan McQuade
2017/01/24 16:45:26
do we already show the chromestatus link in the pr
shivanisha
2017/01/24 17:22:38
Done.
|
| + "https://www.chromestatus.com/feature/5718547946799104 for " |
| + "more details."; |
| + document.addConsoleMessage( |
| + ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
| + WTFLogAlways("%s", message.utf8().data()); |
| +} |
| + |
| +void emitErrorForDocWriteScripts(const String& url, Document& document) { |
| + String message = |
| + "The Parser-blocking, cross site (i.e. different eTLD+1) " |
| + "script, " + |
| + url + |
| + ", invoked via document.write WAS " |
| + "BLOCKED by the browser due to poor network connectivity. " |
| + "See https://www.chromestatus.com/feature/5718547946799104 " |
|
Bryan McQuade
2017/01/24 16:45:26
same
shivanisha
2017/01/24 17:22:38
Done.
|
| + "for more details."; |
| + document.addConsoleMessage( |
| + ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| + WTFLogAlways("%s", message.utf8().data()); |
| +} |
| + |
| void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( |
| PendingScript* pendingScript) { |
| // 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 (!pendingScript->errorOccurred() || |
| - m_parserBlockingScript != pendingScript) |
| + if (m_parserBlockingScript != pendingScript) |
| return; |
| + Element* element = m_parserBlockingScript->element(); |
| + if (!element) |
| + return; |
| + |
| + ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element); |
| + if (!scriptLoader || !scriptLoader->disallowedFetchForDocWrittenScript()) |
| + return; |
| + |
| + if (!pendingScript->errorOccurred()) { |
| + emitWarningForDocWriteScripts(pendingScript->resource()->url().getString(), |
| + *m_document); |
| + 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(pendingScript->resource()); |
| - fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| - } |
| + |
| + emitErrorForDocWriteScripts(pendingScript->resource()->url().getString(), |
| + *m_document); |
| + 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(pendingScript->resource()); |
| + fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| } |
| void HTMLParserScriptRunner::pendingScriptFinished( |