| 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 BLOCKED on this page load, but MAY " |
| 270 "be blocked by the browser in future page loads with poor network " |
| 271 "connectivity."; |
| 272 document.addConsoleMessage( |
| 273 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, message)); |
| 274 WTFLogAlways("%s", message.utf8().data()); |
| 275 } |
| 276 |
| 277 void emitErrorForDocWriteScripts(const String& url, Document& document) { |
| 278 String message = |
| 279 "The Parser-blocking, cross site (i.e. different eTLD+1) " |
| 280 "script, " + |
| 281 url + |
| 282 ", invoked via document.write was BLOCKED by the browser due to poor " |
| 283 "network connectivity. "; |
| 284 document.addConsoleMessage( |
| 285 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 286 WTFLogAlways("%s", message.utf8().data()); |
| 287 } |
| 288 |
| 263 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( | 289 void HTMLParserScriptRunner::possiblyFetchBlockedDocWriteScript( |
| 264 PendingScript* pendingScript) { | 290 PendingScript* pendingScript) { |
| 265 // If the script was blocked as part of document.write intervention, | 291 // If the script was blocked as part of document.write intervention, |
| 266 // then send an asynchronous GET request with an interventions header. | 292 // then send an asynchronous GET request with an interventions header. |
| 267 Element* element = nullptr; | |
| 268 TextPosition startingPosition; | 293 TextPosition startingPosition; |
| 269 bool isParserInserted = false; | 294 bool isParserInserted = false; |
| 270 | 295 |
| 271 if (!pendingScript->errorOccurred() || | 296 if (m_parserBlockingScript != pendingScript) |
| 272 m_parserBlockingScript != pendingScript) | |
| 273 return; | 297 return; |
| 274 | 298 |
| 299 Element* element = m_parserBlockingScript->element(); |
| 300 if (!element) |
| 301 return; |
| 302 |
| 303 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(element); |
| 304 if (!scriptLoader || !scriptLoader->disallowedFetchForDocWrittenScript()) |
| 305 return; |
| 306 |
| 307 if (!pendingScript->errorOccurred()) { |
| 308 emitWarningForDocWriteScripts(pendingScript->resource()->url().getString(), |
| 309 *m_document); |
| 310 return; |
| 311 } |
| 312 |
| 275 // Due to dependency violation, not able to check the exact error to be | 313 // Due to dependency violation, not able to check the exact error to be |
| 276 // ERR_CACHE_MISS but other errors are rare with | 314 // ERR_CACHE_MISS but other errors are rare with |
| 277 // WebCachePolicy::ReturnCacheDataDontLoad. | 315 // WebCachePolicy::ReturnCacheDataDontLoad. |
| 278 element = m_parserBlockingScript->element(); | |
| 279 | 316 |
| 280 ScriptLoader* scriptLoader = nullptr; | 317 emitErrorForDocWriteScripts(pendingScript->resource()->url().getString(), |
| 281 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && | 318 *m_document); |
| 282 scriptLoader->disallowedFetchForDocWrittenScript()) { | 319 startingPosition = m_parserBlockingScript->startingPosition(); |
| 283 startingPosition = m_parserBlockingScript->startingPosition(); | 320 isParserInserted = scriptLoader->isParserInserted(); |
| 284 isParserInserted = scriptLoader->isParserInserted(); | 321 // Remove this resource entry from memory cache as the new request |
| 285 // remove this resource entry from memory cache as the new request | 322 // should not join onto this existing entry. |
| 286 // should not join onto this existing entry. | 323 memoryCache()->remove(pendingScript->resource()); |
| 287 memoryCache()->remove(pendingScript->resource()); | 324 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| 288 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); | |
| 289 } | |
| 290 } | 325 } |
| 291 | 326 |
| 292 void HTMLParserScriptRunner::pendingScriptFinished( | 327 void HTMLParserScriptRunner::pendingScriptFinished( |
| 293 PendingScript* pendingScript) { | 328 PendingScript* pendingScript) { |
| 294 // Handle cancellations of parser-blocking script loads without | 329 // Handle cancellations of parser-blocking script loads without |
| 295 // notifying the host (i.e., parser) if these were initiated by nested | 330 // notifying the host (i.e., parser) if these were initiated by nested |
| 296 // document.write()s. The cancellation may have been triggered by | 331 // document.write()s. The cancellation may have been triggered by |
| 297 // script execution to signal an abrupt stop (e.g., window.close().) | 332 // script execution to signal an abrupt stop (e.g., window.close().) |
| 298 // | 333 // |
| 299 // The parser is unprepared to be told, and doesn't need to be. | 334 // 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 | 550 |
| 516 DEFINE_TRACE(HTMLParserScriptRunner) { | 551 DEFINE_TRACE(HTMLParserScriptRunner) { |
| 517 visitor->trace(m_document); | 552 visitor->trace(m_document); |
| 518 visitor->trace(m_host); | 553 visitor->trace(m_host); |
| 519 visitor->trace(m_parserBlockingScript); | 554 visitor->trace(m_parserBlockingScript); |
| 520 visitor->trace(m_scriptsToExecuteAfterParsing); | 555 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 521 PendingScriptClient::trace(visitor); | 556 PendingScriptClient::trace(visitor); |
| 522 } | 557 } |
| 523 | 558 |
| 524 } // namespace blink | 559 } // namespace blink |
| OLD | NEW |