Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLScriptRunner.cpp

Issue 2260303002: Sending an async GET request for doc.written blocked scripts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 bool HTMLScriptRunner::possiblyFetchBlockedDocWriteScript(Resource* cachedResour ce)
Nate Chapin 2016/09/06 20:28:12 Nit: |cachedResource| is anachronistic. Just |reso
shivanisha 2016/09/15 20:35:08 done.
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 shouldFetchBlockedDocWriteScript = false;
270 bool isParserInserted = false;
271 if (cachedResource->errorOccurred() && m_parserBlockingScript && m_parserBlo ckingScript->resource() == cachedResource) {
272 // Due to dependency violation, not able to check the exact error to be
273 // ERR_CACHE_MISS but other errors are rare with
274 // WebCachePolicy::ReturnCacheDataDontLoad.
275 element = m_parserBlockingScript->element();
276
277 ScriptLoader* scriptLoader = nullptr;
278 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && scr iptLoader->disallowedFetchForDocWrittenScript()) {
279 shouldFetchBlockedDocWriteScript = true;
haraken 2016/09/07 01:47:36 It's confusing to set "shouldFetch"BlockedDocWrite
shivanisha 2016/09/15 20:35:08 disallowedFetch"ForDocWrittenScript was set when t
280 startingPosition = m_parserBlockingScript->startingPosition();
281 isParserInserted = scriptLoader->isParserInserted();
282 }
283 }
284
285 if (!shouldFetchBlockedDocWriteScript)
286 return false;
287
288 m_host->notifyScriptLoaded(cachedResource);
289
290 // remove this resource entry from memory cache as the new request
291 // should not join onto this existing entry.
292 memoryCache()->remove(cachedResource);
293 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition);
294 return true;
295 }
296
252 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) 297 void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
253 { 298 {
254 // Handle cancellations of parser-blocking script loads without 299 // Handle cancellations of parser-blocking script loads without
255 // notifying the host (i.e., parser) if these were initiated by nested 300 // notifying the host (i.e., parser) if these were initiated by nested
256 // document.write()s. The cancellation may have been triggered by 301 // document.write()s. The cancellation may have been triggered by
257 // script execution to signal an abrupt stop (e.g., window.close().) 302 // script execution to signal an abrupt stop (e.g., window.close().)
258 // 303 //
259 // The parser is unprepared to be told, and doesn't need to be. 304 // The parser is unprepared to be told, and doesn't need to be.
260 if (isExecutingScript() && cachedResource->wasCanceled()) { 305 if (isExecutingScript() && cachedResource->wasCanceled()) {
261 stopWatchingResourceForLoad(cachedResource); 306 stopWatchingResourceForLoad(cachedResource);
262 return; 307 return;
263 } 308 }
309
310 // If the script was blocked as part of document.write intervention,
311 // then send an asynchronous GET request with an interventions header.
312 if (possiblyFetchBlockedDocWriteScript(cachedResource))
313 return;
314
264 m_host->notifyScriptLoaded(cachedResource); 315 m_host->notifyScriptLoaded(cachedResource);
265 } 316 }
266 317
267 // Implements the steps for 'An end tag whose tag name is "script"' 318 // Implements the steps for 'An end tag whose tag name is "script"'
268 // http://whatwg.org/html#scriptEndTag 319 // http://whatwg.org/html#scriptEndTag
269 // Script handling lives outside the tree builder to keep each class simple. 320 // Script handling lives outside the tree builder to keep each class simple.
270 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition) 321 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition)
271 { 322 {
272 ASSERT(scriptElement); 323 ASSERT(scriptElement);
273 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", 324 TRACE_EVENT1("blink", "HTMLScriptRunner::execute",
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 DEFINE_TRACE(HTMLScriptRunner) 501 DEFINE_TRACE(HTMLScriptRunner)
451 { 502 {
452 visitor->trace(m_document); 503 visitor->trace(m_document);
453 visitor->trace(m_host); 504 visitor->trace(m_host);
454 visitor->trace(m_parserBlockingScript); 505 visitor->trace(m_parserBlockingScript);
455 visitor->trace(m_scriptsToExecuteAfterParsing); 506 visitor->trace(m_scriptsToExecuteAfterParsing);
456 ScriptResourceClient::trace(visitor); 507 ScriptResourceClient::trace(visitor);
457 } 508 }
458 509
459 } // namespace blink 510 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698