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

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

Issue 2148363002: Move document.write evaluation after standard preloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ASSERT(token.type() == HTMLToken::TokenType::Character); 314 ASSERT(token.type() == HTMLToken::TokenType::Character);
315 m_queuedDocumentWriteScripts.append(token.data()); 315 m_queuedDocumentWriteScripts.append(token.data());
316 } 316 }
317 } 317 }
318 } else { 318 } else {
319 // We can safely assume that there are no queued preloads request after 319 // We can safely assume that there are no queued preloads request after
320 // the document element is available, as we empty the queue immediately 320 // the document element is available, as we empty the queue immediately
321 // after the document element is created in documentElementAvailable(). 321 // after the document element is created in documentElementAvailable().
322 ASSERT(m_queuedPreloads.isEmpty()); 322 ASSERT(m_queuedPreloads.isEmpty());
323 ASSERT(m_queuedDocumentWriteScripts.isEmpty()); 323 ASSERT(m_queuedDocumentWriteScripts.isEmpty());
324 // Loop through the chunks to generate preloads before any
325 // document.write script evaluation takes place. Preloading these
326 // scripts is valuable and comparably cheap, while evaluating JS can be
327 // expensive.
328 for (auto& chunk : pendingChunks) {
329 m_preloader->takeAndPreload(chunk->preloads);
330 }
324 for (auto& chunk : pendingChunks) { 331 for (auto& chunk : pendingChunks) {
325 for (auto& index : chunk->likelyDocumentWriteScriptIndices) { 332 for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
326 const CompactHTMLToken& token = chunk->tokens->at(index); 333 const CompactHTMLToken& token = chunk->tokens->at(index);
327 ASSERT(token.type() == HTMLToken::TokenType::Character); 334 ASSERT(token.type() == HTMLToken::TokenType::Character);
328 evaluateAndPreloadScriptForDocumentWrite(token.data()); 335 evaluateAndPreloadScriptForDocumentWrite(token.data());
329 } 336 }
330 m_preloader->takeAndPreload(chunk->preloads);
331 } 337 }
332 } 338 }
333 339
334 for (auto& chunk : pendingChunks) 340 for (auto& chunk : pendingChunks)
335 m_speculations.append(std::move(chunk)); 341 m_speculations.append(std::move(chunk));
336 342
337 if (!isWaitingForScripts() && !isScheduledForResume()) { 343 if (!isWaitingForScripts() && !isScheduledForResume()) {
338 if (m_tasksWereSuspended) 344 if (m_tasksWereSuspended)
339 m_parserScheduler->forceResumeAfterYield(); 345 m_parserScheduler->forceResumeAfterYield();
340 else 346 else
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 DecodedDataDocumentParser::setDecoder(std::move(decoder)); 1074 DecodedDataDocumentParser::setDecoder(std::move(decoder));
1069 1075
1070 if (m_haveBackgroundParser) 1076 if (m_haveBackgroundParser)
1071 postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, passed(takeDecoder()))); 1077 postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, passed(takeDecoder())));
1072 } 1078 }
1073 1079
1074 void HTMLDocumentParser::documentElementAvailable() 1080 void HTMLDocumentParser::documentElementAvailable()
1075 { 1081 {
1076 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable") ; 1082 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable") ;
1077 DCHECK(document()->documentElement()); 1083 DCHECK(document()->documentElement());
1084 if (!m_queuedPreloads.isEmpty())
1085 m_preloader->takeAndPreload(m_queuedPreloads);
1086
1078 for (const String& scriptSource : m_queuedDocumentWriteScripts) { 1087 for (const String& scriptSource : m_queuedDocumentWriteScripts) {
1079 evaluateAndPreloadScriptForDocumentWrite(scriptSource); 1088 evaluateAndPreloadScriptForDocumentWrite(scriptSource);
1080 } 1089 }
1081 1090
1082 m_queuedDocumentWriteScripts.clear(); 1091 m_queuedDocumentWriteScripts.clear();
1083 if (!m_queuedPreloads.isEmpty())
1084 m_preloader->takeAndPreload(m_queuedPreloads);
1085 } 1092 }
1086 1093
1087 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::createPreloadScanner() 1094 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::createPreloadScanner()
1088 { 1095 {
1089 return HTMLPreloadScanner::create( 1096 return HTMLPreloadScanner::create(
1090 m_options, 1097 m_options,
1091 document()->url(), 1098 document()->url(),
1092 CachedDocumentParameters::create(document()), 1099 CachedDocumentParameters::create(document()),
1093 MediaValuesCached::MediaValuesCachedData(*document())); 1100 MediaValuesCached::MediaValuesCachedData(*document()));
1094 } 1101 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 (*closure)(); 1153 (*closure)();
1147 return; 1154 return;
1148 case Asynchronous: 1155 case Asynchronous:
1149 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); 1156 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure));
1150 return; 1157 return;
1151 } 1158 }
1152 NOTREACHED(); 1159 NOTREACHED();
1153 } 1160 }
1154 1161
1155 } // namespace blink 1162 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698