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

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: Test added, failed bot tests fixed, converted to enum. 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, true);
258 DCHECK(scriptLoader);
259 scriptLoader->prepareScript(scriptStartPosition);
260 }
261
252 void HTMLScriptRunner::notifyFinished(Resource* cachedResource) 262 void HTMLScriptRunner::notifyFinished(Resource* cachedResource)
253 { 263 {
254 // Handle cancellations of parser-blocking script loads without 264 // Handle cancellations of parser-blocking script loads without
255 // notifying the host (i.e., parser) if these were initiated by nested 265 // notifying the host (i.e., parser) if these were initiated by nested
256 // document.write()s. The cancellation may have been triggered by 266 // document.write()s. The cancellation may have been triggered by
257 // script execution to signal an abrupt stop (e.g., window.close().) 267 // script execution to signal an abrupt stop (e.g., window.close().)
258 // 268 //
259 // The parser is unprepared to be told, and doesn't need to be. 269 // The parser is unprepared to be told, and doesn't need to be.
260 if (isExecutingScript() && cachedResource->wasCanceled()) { 270 if (isExecutingScript() && cachedResource->wasCanceled()) {
261 stopWatchingResourceForLoad(cachedResource); 271 stopWatchingResourceForLoad(cachedResource);
262 return; 272 return;
263 } 273 }
274
275 // If the script was blocked as part of document.write intervention,
276 // then send an asynchronous GET request with an interventions header.
277 Element* element = nullptr;
278 TextPosition startingPosition;
279 bool blockedDocWriteScriptAsyncFetch = false;
280 bool isParserInserted = false;
281 if (cachedResource->errorOccurred() && m_parserBlockingScript && m_parserBlo ckingScript->resource() == cachedResource) {
282 // Due to dependency violation, not able to check the exact error to be
283 // ERR_CACHE_MISS but other errors are rare with
284 // WebCachePolicy::ReturnCacheDataDontLoad.
285 element = m_parserBlockingScript->element();
286
287 ScriptLoader* scriptLoader = nullptr;
288 if (element && (scriptLoader = toScriptLoaderIfPossible(element)) && scr iptLoader->disallowedFetchForDocWrittenScript()) {
289 blockedDocWriteScriptAsyncFetch = true;
290 startingPosition = m_parserBlockingScript->startingPosition();
291 isParserInserted = scriptLoader->isParserInserted();
292 }
293 }
294
264 m_host->notifyScriptLoaded(cachedResource); 295 m_host->notifyScriptLoaded(cachedResource);
296
297 if (blockedDocWriteScriptAsyncFetch) {
Nate Chapin 2016/08/22 19:47:03 Does this logic absolutely need to be after notify
shivanisha 2016/08/22 20:44:00 I am not completely aware of the other threads tha
Nate Chapin 2016/08/22 20:55:12 Hrm, ok. One option is to move all the new code he
shivanisha 2016/08/23 01:04:46 Sounds good. done
298 // remove this resource entry from memory cache as the new request
299 // should not join onto this existing entry.
300 memoryCache()->remove(cachedResource);
301 fetchBlockedDocWriteScript(element, isParserInserted, startingPosition);
302 }
265 } 303 }
266 304
267 // Implements the steps for 'An end tag whose tag name is "script"' 305 // Implements the steps for 'An end tag whose tag name is "script"'
268 // http://whatwg.org/html#scriptEndTag 306 // http://whatwg.org/html#scriptEndTag
269 // Script handling lives outside the tree builder to keep each class simple. 307 // Script handling lives outside the tree builder to keep each class simple.
270 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition) 308 void HTMLScriptRunner::execute(Element* scriptElement, const TextPosition& scrip tStartPosition)
271 { 309 {
272 ASSERT(scriptElement); 310 ASSERT(scriptElement);
273 TRACE_EVENT1("blink", "HTMLScriptRunner::execute", 311 TRACE_EVENT1("blink", "HTMLScriptRunner::execute",
274 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition) ); 312 "data", getTraceArgsForScriptElement(scriptElement, scriptStartPosition) );
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 DEFINE_TRACE(HTMLScriptRunner) 488 DEFINE_TRACE(HTMLScriptRunner)
451 { 489 {
452 visitor->trace(m_document); 490 visitor->trace(m_document);
453 visitor->trace(m_host); 491 visitor->trace(m_host);
454 visitor->trace(m_parserBlockingScript); 492 visitor->trace(m_parserBlockingScript);
455 visitor->trace(m_scriptsToExecuteAfterParsing); 493 visitor->trace(m_scriptsToExecuteAfterParsing);
456 ScriptResourceClient::trace(visitor); 494 ScriptResourceClient::trace(visitor);
457 } 495 }
458 496
459 } // namespace blink 497 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698