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

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

Issue 2146673002: Move document.write evaluation after standard preloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment explaining double for loop 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ASSERT(token.type() == HTMLToken::TokenType::Character); 307 ASSERT(token.type() == HTMLToken::TokenType::Character);
308 m_queuedDocumentWriteScripts.append(token.data()); 308 m_queuedDocumentWriteScripts.append(token.data());
309 } 309 }
310 } 310 }
311 } else { 311 } else {
312 // We can safely assume that there are no queued preloads request after 312 // We can safely assume that there are no queued preloads request after
313 // the document element is available, as we empty the queue immediately 313 // the document element is available, as we empty the queue immediately
314 // after the document element is created in documentElementAvailable(). 314 // after the document element is created in documentElementAvailable().
315 ASSERT(m_queuedPreloads.isEmpty()); 315 ASSERT(m_queuedPreloads.isEmpty());
316 ASSERT(m_queuedDocumentWriteScripts.isEmpty()); 316 ASSERT(m_queuedDocumentWriteScripts.isEmpty());
317 // Loop through the chunks to generate preloads before any
318 // document.write script evaluation takes place. Preloading these
319 // scripts is valuable and comparably cheap, while evaluating JS can be
320 // expensive.
321 for (auto& chunk : pendingChunks) {
322 m_preloader->takeAndPreload(chunk->preloads);
323 }
317 for (auto& chunk : pendingChunks) { 324 for (auto& chunk : pendingChunks) {
318 for (auto& index : chunk->likelyDocumentWriteScriptIndices) { 325 for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
319 const CompactHTMLToken& token = chunk->tokens->at(index); 326 const CompactHTMLToken& token = chunk->tokens->at(index);
320 ASSERT(token.type() == HTMLToken::TokenType::Character); 327 ASSERT(token.type() == HTMLToken::TokenType::Character);
321 evaluateAndPreloadScriptForDocumentWrite(token.data()); 328 evaluateAndPreloadScriptForDocumentWrite(token.data());
322 } 329 }
323 m_preloader->takeAndPreload(chunk->preloads);
324 } 330 }
325 } 331 }
326 332
327 for (auto& chunk : pendingChunks) 333 for (auto& chunk : pendingChunks)
328 m_speculations.append(std::move(chunk)); 334 m_speculations.append(std::move(chunk));
329 335
330 if (!isWaitingForScripts() && !isScheduledForResume()) { 336 if (!isWaitingForScripts() && !isScheduledForResume()) {
331 if (m_tasksWereSuspended) 337 if (m_tasksWereSuspended)
332 m_parserScheduler->forceResumeAfterYield(); 338 m_parserScheduler->forceResumeAfterYield();
333 else 339 else
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 DecodedDataDocumentParser::setDecoder(std::move(decoder)); 1067 DecodedDataDocumentParser::setDecoder(std::move(decoder));
1062 1068
1063 if (m_haveBackgroundParser) 1069 if (m_haveBackgroundParser)
1064 postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, passed(takeDecoder()))); 1070 postTaskToLookaheadParser(crossThreadBind(&BackgroundHTMLParser::setDeco der, m_backgroundParser, passed(takeDecoder())));
1065 } 1071 }
1066 1072
1067 void HTMLDocumentParser::documentElementAvailable() 1073 void HTMLDocumentParser::documentElementAvailable()
1068 { 1074 {
1069 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable") ; 1075 TRACE_EVENT0("blink,loader", "HTMLDocumentParser::documentElementAvailable") ;
1070 DCHECK(document()->documentElement()); 1076 DCHECK(document()->documentElement());
1077 if (!m_queuedPreloads.isEmpty())
1078 m_preloader->takeAndPreload(m_queuedPreloads);
1079
1071 for (const String& scriptSource : m_queuedDocumentWriteScripts) { 1080 for (const String& scriptSource : m_queuedDocumentWriteScripts) {
1072 evaluateAndPreloadScriptForDocumentWrite(scriptSource); 1081 evaluateAndPreloadScriptForDocumentWrite(scriptSource);
1073 } 1082 }
1074 1083
1075 m_queuedDocumentWriteScripts.clear(); 1084 m_queuedDocumentWriteScripts.clear();
1076 if (!m_queuedPreloads.isEmpty())
1077 m_preloader->takeAndPreload(m_queuedPreloads);
1078 } 1085 }
1079 1086
1080 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::createPreloadScanner() 1087 std::unique_ptr<HTMLPreloadScanner> HTMLDocumentParser::createPreloadScanner()
1081 { 1088 {
1082 return HTMLPreloadScanner::create( 1089 return HTMLPreloadScanner::create(
1083 m_options, 1090 m_options,
1084 document()->url(), 1091 document()->url(),
1085 CachedDocumentParameters::create(document()), 1092 CachedDocumentParameters::create(document()),
1086 MediaValuesCached::MediaValuesCachedData(*document())); 1093 MediaValuesCached::MediaValuesCachedData(*document()));
1087 } 1094 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 (*closure)(); 1146 (*closure)();
1140 return; 1147 return;
1141 case Asynchronous: 1148 case Asynchronous:
1142 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure)); 1149 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, std::move(closure));
1143 return; 1150 return;
1144 } 1151 }
1145 NOTREACHED(); 1152 NOTREACHED();
1146 } 1153 }
1147 1154
1148 } // namespace blink 1155 } // 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