Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "core/dom/Element.h" | 32 #include "core/dom/Element.h" |
| 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 34 #include "core/dom/ScriptLoader.h" | 34 #include "core/dom/ScriptLoader.h" |
| 35 #include "core/dom/TaskRunnerHelper.h" | 35 #include "core/dom/TaskRunnerHelper.h" |
| 36 #include "core/events/Event.h" | 36 #include "core/events/Event.h" |
| 37 #include "core/fetch/MemoryCache.h" | 37 #include "core/fetch/MemoryCache.h" |
| 38 #include "core/frame/LocalFrame.h" | 38 #include "core/frame/LocalFrame.h" |
| 39 #include "core/html/parser/HTMLInputStream.h" | 39 #include "core/html/parser/HTMLInputStream.h" |
| 40 #include "core/html/parser/HTMLParserScriptRunnerHost.h" | 40 #include "core/html/parser/HTMLParserScriptRunnerHost.h" |
| 41 #include "core/html/parser/NestingLevelIncrementer.h" | 41 #include "core/html/parser/NestingLevelIncrementer.h" |
| 42 #include "core/inspector/ConsoleMessage.h" | |
| 42 #include "core/loader/resource/ScriptResource.h" | 43 #include "core/loader/resource/ScriptResource.h" |
| 43 #include "platform/Histogram.h" | 44 #include "platform/Histogram.h" |
| 44 #include "platform/WebFrameScheduler.h" | 45 #include "platform/WebFrameScheduler.h" |
| 45 #include "platform/instrumentation/tracing/TraceEvent.h" | 46 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 46 #include "platform/instrumentation/tracing/TracedValue.h" | 47 #include "platform/instrumentation/tracing/TracedValue.h" |
| 47 #include "public/platform/Platform.h" | 48 #include "public/platform/Platform.h" |
| 48 #include <inttypes.h> | 49 #include <inttypes.h> |
| 49 #include <memory> | 50 #include <memory> |
| 50 | 51 |
| 51 namespace blink { | 52 namespace blink { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 const TextPosition& scriptStartPosition) { | 254 const TextPosition& scriptStartPosition) { |
| 254 DCHECK(script); | 255 DCHECK(script); |
| 255 | 256 |
| 256 ScriptLoader* scriptLoader = | 257 ScriptLoader* scriptLoader = |
| 257 ScriptLoader::create(script, isParserInserted, false, false); | 258 ScriptLoader::create(script, isParserInserted, false, false); |
| 258 DCHECK(scriptLoader); | 259 DCHECK(scriptLoader); |
| 259 scriptLoader->setFetchDocWrittenScriptDeferIdle(); | 260 scriptLoader->setFetchDocWrittenScriptDeferIdle(); |
| 260 scriptLoader->prepareScript(scriptStartPosition); | 261 scriptLoader->prepareScript(scriptStartPosition); |
| 261 } | 262 } |
| 262 | 263 |
| 264 void emitWarningForDocWriteScripts(const String& url, Document& document) { | |
| 265 String message = | |
| 266 "The Parser-blocking, cross site (i.e. different eTLD+1) " | |
| 267 "script, " + | |
| 268 url + | |
| 269 ", invoked via document.write was NOT " | |
| 270 "blocked on this page load, but MAY be blocked by the " | |
| 271 "browser in future page loads with poor network " | |
| 272 "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.
| |
| 273 "https://www.chromestatus.com/feature/5718547946799104 for " | |
| 274 "more details."; | |
| 275 document.addConsoleMessage( | |
| 276 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); | |
| 277 WTFLogAlways("%s", message.utf8().data()); | |
| 278 } | |
| 279 | |
| 280 void emitErrorForDocWriteScripts(const String& url, Document& document) { | |
| 281 String message = | |
| 282 "The Parser-blocking, cross site (i.e. different eTLD+1) " | |
| 283 "script, " + | |
| 284 url + | |
| 285 ", invoked via document.write WAS " | |
| 286 "BLOCKED by the browser due to poor network connectivity. " | |
| 287 "See https://www.chromestatus.com/feature/5718547946799104 " | |
|
Bryan McQuade
2017/01/24 16:45:26
same
shivanisha
2017/01/24 17:22:38
Done.
| |
| 288 "for more details."; | |
| 289 document.addConsoleMessage( | |
| 290 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | |
| 291 WTFLogAlways("%s", message.utf8().data()); | |
| 292 } | |
| 293 | |
| 263 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( | 294 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( |
| 264 PendingScript* pendingScript) { | 295 PendingScript* pendingScript) { |
| 265 // If the script was blocked as part of document.write intervention, | 296 // If the script was blocked as part of document.write intervention, |
| 266 // then send an asynchronous GET request with an interventions header. | 297 // then send an asynchronous GET request with an interventions header. |
| 267 Element* element = nullptr; | |
| 268 TextPosition startingPosition; | 298 TextPosition startingPosition; |
| 269 bool isParserInserted = false; | 299 bool isParserInserted = false; |
| 270 | 300 |
| 271 if (!pendingScript->errorOccurred() || | 301 if (m_parserBlockingScript != pendingScript) |
| 272 m_parserBlockingScript != pendingScript) | |
| 273 return; | 302 return; |
| 274 | 303 |
| 304 Element* element = m_parserBlockingScript->element(); | |
| 305 if (!element) | |
| 306 return; | |
| 307 | |
| 308 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element); | |
| 309 if (!scriptLoader || !scriptLoader->disallowedFetchForDocWrittenScript()) | |
| 310 return; | |
| 311 | |
| 312 if (!pendingScript->errorOccurred()) { | |
| 313 emitWarningForDocWriteScripts(pendingScript->resource()->url().getString(), | |
| 314 *m_document); | |
| 315 return; | |
| 316 } | |
| 317 | |
| 275 // Due to dependency violation, not able to check the exact error to be | 318 // Due to dependency violation, not able to check the exact error to be |
| 276 // ERR_CACHE_MISS but other errors are rare with | 319 // ERR_CACHE_MISS but other errors are rare with |
| 277 // WebCachePolicy::ReturnCacheDataDontLoad. | 320 // WebCachePolicy::ReturnCacheDataDontLoad. |
| 278 element = m_parserBlockingScript->element(); | |
| 279 | 321 |
| 280 ScriptLoader* scriptLoader = nullptr; | 322 emitErrorForDocWriteScripts(pendingScript->resource()->url().getString(), |
| 281 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && | 323 *m_document); |
| 282 scriptLoader->disallowedFetchForDocWrittenScript()) { | 324 startingPosition = m_parserBlockingScript->startingPosition(); |
| 283 startingPosition = m_parserBlockingScript->startingPosition(); | 325 isParserInserted = scriptLoader->isParserInserted(); |
| 284 isParserInserted = scriptLoader->isParserInserted(); | 326 // Remove this resource entry from memory cache as the new request |
| 285 // remove this resource entry from memory cache as the new request | 327 // should not join onto this existing entry. |
| 286 // should not join onto this existing entry. | 328 memoryCache()->remove(pendingScript->resource()); |
| 287 memoryCache()->remove(pendingScript->resource()); | 329 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| 288 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); | |
| 289 } | |
| 290 } | 330 } |
| 291 | 331 |
| 292 void HTMLParserScriptRunner::pendingScriptFinished( | 332 void HTMLParserScriptRunner::pendingScriptFinished( |
| 293 PendingScript* pendingScript) { | 333 PendingScript* pendingScript) { |
| 294 // Handle cancellations of parser-blocking script loads without | 334 // Handle cancellations of parser-blocking script loads without |
| 295 // notifying the host (i.e., parser) if these were initiated by nested | 335 // notifying the host (i.e., parser) if these were initiated by nested |
| 296 // document.write()s. The cancellation may have been triggered by | 336 // document.write()s. The cancellation may have been triggered by |
| 297 // script execution to signal an abrupt stop (e.g., window.close().) | 337 // script execution to signal an abrupt stop (e.g., window.close().) |
| 298 // | 338 // |
| 299 // The parser is unprepared to be told, and doesn't need to be. | 339 // The parser is unprepared to be told, and doesn't need to be. |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 | 555 |
| 516 DEFINE_TRACE(HTMLParserScriptRunner) { | 556 DEFINE_TRACE(HTMLParserScriptRunner) { |
| 517 visitor->trace(m_document); | 557 visitor->trace(m_document); |
| 518 visitor->trace(m_host); | 558 visitor->trace(m_host); |
| 519 visitor->trace(m_parserBlockingScript); | 559 visitor->trace(m_parserBlockingScript); |
| 520 visitor->trace(m_scriptsToExecuteAfterParsing); | 560 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 521 PendingScriptClient::trace(visitor); | 561 PendingScriptClient::trace(visitor); |
| 522 } | 562 } |
| 523 | 563 |
| 524 } // namespace blink | 564 } // namespace blink |
| OLD | NEW |