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, bool isParserInserted, const Te
xtPosition& scriptStartPosition) |
| 254 { |
| 255 DCHECK(script); |
| 256 |
| 257 ScriptLoader* scriptLoader = ScriptLoader::create(script, isParserInserted,
false, false); |
| 258 DCHECK(scriptLoader); |
| 259 scriptLoader->setFetchDocWrittenScriptDeferIdle(); |
| 260 scriptLoader->prepareScript(scriptStartPosition); |
| 261 } |
| 262 |
| 263 void HTMLScriptRunner::possiblyFetchBlockedDocWriteScript(Resource* resource) |
| 264 { |
| 265 // If the script was blocked as part of document.write intervention, |
| 266 // then send an asynchronous GET request with an interventions header. |
| 267 Element* element = nullptr; |
| 268 TextPosition startingPosition; |
| 269 bool isParserInserted = false; |
| 270 |
| 271 if (!resource->errorOccurred() || !m_parserBlockingScript || !(m_parserBlock
ingScript->resource() == resource)) |
| 272 return; |
| 273 |
| 274 // Due to dependency violation, not able to check the exact error to be |
| 275 // ERR_CACHE_MISS but other errors are rare with |
| 276 // WebCachePolicy::ReturnCacheDataDontLoad. |
| 277 element = m_parserBlockingScript->element(); |
| 278 |
| 279 ScriptLoader* scriptLoader = nullptr; |
| 280 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && scriptL
oader->disallowedFetchForDocWrittenScript()) { |
| 281 startingPosition = m_parserBlockingScript->startingPosition(); |
| 282 isParserInserted = scriptLoader->isParserInserted(); |
| 283 // remove this resource entry from memory cache as the new request |
| 284 // should not join onto this existing entry. |
| 285 memoryCache()->remove(resource); |
| 286 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition); |
| 287 } |
| 288 } |
| 289 |
252 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) | 290 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) |
253 { | 291 { |
254 // Handle cancellations of parser-blocking script loads without | 292 // Handle cancellations of parser-blocking script loads without |
255 // notifying the host (i.e., parser) if these were initiated by nested | 293 // notifying the host (i.e., parser) if these were initiated by nested |
256 // document.write()s. The cancellation may have been triggered by | 294 // document.write()s. The cancellation may have been triggered by |
257 // script execution to signal an abrupt stop (e.g., window.close().) | 295 // script execution to signal an abrupt stop (e.g., window.close().) |
258 // | 296 // |
259 // The parser is unprepared to be told, and doesn't need to be. | 297 // The parser is unprepared to be told, and doesn't need to be. |
260 if (isExecutingScript() && cachedResource->wasCanceled()) { | 298 if (isExecutingScript() && cachedResource->wasCanceled()) { |
261 stopWatchingResourceForLoad(cachedResource); | 299 stopWatchingResourceForLoad(cachedResource); |
262 return; | 300 return; |
263 } | 301 } |
| 302 |
| 303 // If the script was blocked as part of document.write intervention, |
| 304 // then send an asynchronous GET request with an interventions header. |
| 305 possiblyFetchBlockedDocWriteScript(cachedResource); |
| 306 |
264 m_host->notifyScriptLoaded(cachedResource); | 307 m_host->notifyScriptLoaded(cachedResource); |
265 } | 308 } |
266 | 309 |
267 // Implements the steps for 'An end tag whose tag name is "script"' | 310 // Implements the steps for 'An end tag whose tag name is "script"' |
268 // http://whatwg.org/html#scriptEndTag | 311 // http://whatwg.org/html#scriptEndTag |
269 // Script handling lives outside the tree builder to keep each class simple. | 312 // Script handling lives outside the tree builder to keep each class simple. |
270 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip
tStartPosition) | 313 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip
tStartPosition) |
271 { | 314 { |
272 ASSERT(scriptElement); | 315 ASSERT(scriptElement); |
273 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", | 316 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 DEFINE_TRACE(HTMLScriptRunner) | 493 DEFINE_TRACE(HTMLScriptRunner) |
451 { | 494 { |
452 visitor->trace(m_document); | 495 visitor->trace(m_document); |
453 visitor->trace(m_host); | 496 visitor->trace(m_host); |
454 visitor->trace(m_parserBlockingScript); | 497 visitor->trace(m_parserBlockingScript); |
455 visitor->trace(m_scriptsToExecuteAfterParsing); | 498 visitor->trace(m_scriptsToExecuteAfterParsing); |
456 ScriptResourceClient::trace(visitor); | 499 ScriptResourceClient::trace(visitor); |
457 } | 500 } |
458 | 501 |
459 } // namespace blink | 502 } // namespace blink |
OLD | NEW |