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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 #include "bindings/core/v8/Microtask.h" | 28 #include "bindings/core/v8/Microtask.h" |
| 29 #include "bindings/core/v8/ScriptSourceCode.h" | 29 #include "bindings/core/v8/ScriptSourceCode.h" |
| 30 #include "bindings/core/v8/V8PerIsolateData.h" | 30 #include "bindings/core/v8/V8PerIsolateData.h" |
| 31 #include "core/dom/DocumentParserTiming.h" | 31 #include "core/dom/DocumentParserTiming.h" |
| 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/ScriptResource.h" | 38 #include "core/fetch/ScriptResource.h" |
| 38 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 39 #include "core/html/parser/HTMLInputStream.h" | 40 #include "core/html/parser/HTMLInputStream.h" |
| 40 #include "core/html/parser/HTMLScriptRunnerHost.h" | 41 #include "core/html/parser/HTMLScriptRunnerHost.h" |
| 41 #include "core/html/parser/NestingLevelIncrementer.h" | 42 #include "core/html/parser/NestingLevelIncrementer.h" |
| 42 #include "platform/Histogram.h" | 43 #include "platform/Histogram.h" |
| 43 #include "platform/TraceEvent.h" | 44 #include "platform/TraceEvent.h" |
| 44 #include "platform/TracedValue.h" | 45 #include "platform/TracedValue.h" |
| 45 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 46 #include "public/platform/WebFrameScheduler.h" | 47 #include "public/platform/WebFrameScheduler.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 } | 243 } |
| 243 for (auto& script : m_scriptsToExecuteAfterParsing) { | 244 for (auto& script : m_scriptsToExecuteAfterParsing) { |
| 244 if (script->resource() == resource) { | 245 if (script->resource() == resource) { |
| 245 script->stopWatchingForLoad(); | 246 script->stopWatchingForLoad(); |
| 246 script->releaseElementAndClear(); | 247 script->releaseElementAndClear(); |
| 247 return; | 248 return; |
| 248 } | 249 } |
| 249 } | 250 } |
| 250 } | 251 } |
| 251 | 252 |
| 253 void fetchBlockedDocWriteScript(Element* script, const TextPosition& scriptStart Position) | |
| 254 { | |
| 255 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script); | |
| 256 // This contains both and ASSERTION and a null check since we should not | |
| 257 // be getting into the case of a null script element, but seem to be from | |
| 258 // time to time. The assertion is left in to help find those cases and | |
| 259 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. | |
| 260 DCHECK(scriptLoader); | |
| 261 if (!scriptLoader) | |
| 262 return; | |
| 263 DCHECK(scriptLoader->isParserInserted()); | |
| 264 | |
| 265 scriptLoader = ScriptLoader::create(script, scriptLoader->isParserInserted() , false, false, true); | |
| 266 scriptLoader->prepareScript(scriptStartPosition); | |
| 267 } | |
| 268 | |
| 252 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 269 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
| 253 { | 270 { |
| 254 // Handle cancellations of parser-blocking script loads without | 271 // Handle cancellations of parser-blocking script loads without |
| 255 // notifying the host (i.e., parser) if these were initiated by nested | 272 // notifying the host (i.e., parser) if these were initiated by nested |
| 256 // document.write()s. The cancellation may have been triggered by | 273 // document.write()s. The cancellation may have been triggered by |
| 257 // script execution to signal an abrupt stop (e.g., window.close().) | 274 // script execution to signal an abrupt stop (e.g., window.close().) |
| 258 // | 275 // |
| 259 // The parser is unprepared to be told, and doesn't need to be. | 276 // The parser is unprepared to be told, and doesn't need to be. |
| 260 if (isExecutingScript() && cachedResource->wasCanceled()) { | 277 if (isExecutingScript() && cachedResource->wasCanceled()) { |
|
Charlie Harrison
2016/08/19 21:24:27
Will we ever hit this condition? Judging from the
shivanisha
2016/08/22 16:15:22
Since its a canceled scenario, its fine to return
| |
| 261 stopWatchingResourceForLoad(cachedResource); | 278 stopWatchingResourceForLoad(cachedResource); |
| 262 return; | 279 return; |
| 263 } | 280 } |
| 281 | |
| 282 // If the script was blocked as part of document.write intervention, | |
| 283 // then send an asynchronous GET request with an interventions header. | |
| 284 Element* element = m_parserBlockingScript->element(); | |
| 285 TextPosition startingPosition = m_parserBlockingScript->startingPosition(); | |
| 286 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(m_parserBlockingScript ->element()); | |
| 287 bool blockedDocWriteScriptAsyncFetch = false; | |
| 288 | |
| 289 // Due to dependency violation, not able to check the exact error to be | |
| 290 // ERR_CACHE_MISS but other errors are rare with | |
| 291 // WebCachePolicy::ReturnCacheDataDontLoad. | |
| 292 if (cachedResource->errorOccurred() && m_parserBlockingScript->resource() == cachedResource | |
| 293 && scriptLoader->disallowedFetchForDocWrittenScript()) { | |
| 294 blockedDocWriteScriptAsyncFetch = true; | |
| 295 } | |
| 296 | |
| 264 m_host->notifyScriptLoaded(cachedResource); | 297 m_host->notifyScriptLoaded(cachedResource); |
| 298 | |
| 299 if (blockedDocWriteScriptAsyncFetch) { | |
| 300 // remove this resource entry from memory cache as the new request | |
| 301 // should not join onto this existing entry. | |
| 302 memoryCache()->remove(cachedResource); | |
| 303 fetchBlockedDocWriteScript(element, startingPosition); | |
| 304 } | |
| 265 } | 305 } |
| 266 | 306 |
| 267 // Implements the steps for 'An end tag whose tag name is "script"' | 307 // Implements the steps for 'An end tag whose tag name is "script"' |
| 268 // http://whatwg.org/html#scriptEndTag | 308 // http://whatwg.org/html#scriptEndTag |
| 269 // Script handling lives outside the tree builder to keep each class simple. | 309 // Script handling lives outside the tree builder to keep each class simple. |
| 270 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition) | 310 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition) |
| 271 { | 311 { |
| 272 ASSERT(scriptElement); | 312 ASSERT(scriptElement); |
| 273 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", | 313 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", |
| 274 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition) ); | 314 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition) ); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 DEFINE_TRACE(HTMLScriptRunner) | 490 DEFINE_TRACE(HTMLScriptRunner) |
| 451 { | 491 { |
| 452 visitor->trace(m_document); | 492 visitor->trace(m_document); |
| 453 visitor->trace(m_host); | 493 visitor->trace(m_host); |
| 454 visitor->trace(m_parserBlockingScript); | 494 visitor->trace(m_parserBlockingScript); |
| 455 visitor->trace(m_scriptsToExecuteAfterParsing); | 495 visitor->trace(m_scriptsToExecuteAfterParsing); |
| 456 ScriptResourceClient::trace(visitor); | 496 ScriptResourceClient::trace(visitor); |
| 457 } | 497 } |
| 458 | 498 |
| 459 } // namespace blink | 499 } // namespace blink |
| OLD | NEW |