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

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

Issue 2165653004: Don't wait for AppCache for link rel preloads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't wait for appcache for link rel preloads 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
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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 ASSERT(m_parsedChunkQueue); 291 ASSERT(m_parsedChunkQueue);
292 292
293 Vector<std::unique_ptr<ParsedChunk>> pendingChunks; 293 Vector<std::unique_ptr<ParsedChunk>> pendingChunks;
294 m_parsedChunkQueue->takeAll(pendingChunks); 294 m_parsedChunkQueue->takeAll(pendingChunks);
295 295
296 if (!isParsing()) 296 if (!isParsing())
297 return; 297 return;
298 298
299 // ApplicationCache needs to be initialized before issuing preloads. 299 // ApplicationCache needs to be initialized before issuing preloads.
300 // We suspend preload until HTMLHTMLElement is inserted and 300 // We suspend preload until HTMLHTMLElement is inserted and
301 // ApplicationCache is initialized. 301 // ApplicationCache is initialized. Note: link rel preloads don't follow
302 // this policy per the spec. These directives should initiate a fetch as
303 // fast as possible.
302 if (!document()->documentElement()) { 304 if (!document()->documentElement()) {
305 PreloadRequestStream linkRelPreloads;
303 for (auto& chunk : pendingChunks) { 306 for (auto& chunk : pendingChunks) {
304 for (auto& request : chunk->preloads) 307 for (auto& request : chunk->preloads) {
Yoav Weiss 2016/07/22 08:43:28 I don't understand why this waiting is necessary f
Charlie Harrison 2016/07/22 14:03:22 My understanding is that the preload scanner just
305 m_queuedPreloads.append(std::move(request)); 308 if (request->isLinkRelPreload())
309 linkRelPreloads.append(std::move(request));
310 else
311 m_queuedPreloads.append(std::move(request));
312 }
306 for (auto& index : chunk->likelyDocumentWriteScriptIndices) { 313 for (auto& index : chunk->likelyDocumentWriteScriptIndices) {
307 const CompactHTMLToken& token = chunk->tokens->at(index); 314 const CompactHTMLToken& token = chunk->tokens->at(index);
308 ASSERT(token.type() == HTMLToken::TokenType::Character); 315 ASSERT(token.type() == HTMLToken::TokenType::Character);
309 m_queuedDocumentWriteScripts.append(token.data()); 316 m_queuedDocumentWriteScripts.append(token.data());
310 } 317 }
311 } 318 }
319 m_preloader->takeAndPreload(linkRelPreloads);
312 } else { 320 } else {
313 // We can safely assume that there are no queued preloads request after 321 // We can safely assume that there are no queued preloads request after
314 // the document element is available, as we empty the queue immediately 322 // the document element is available, as we empty the queue immediately
315 // after the document element is created in documentElementAvailable(). 323 // after the document element is created in documentElementAvailable().
316 ASSERT(m_queuedPreloads.isEmpty()); 324 ASSERT(m_queuedPreloads.isEmpty());
317 ASSERT(m_queuedDocumentWriteScripts.isEmpty()); 325 ASSERT(m_queuedDocumentWriteScripts.isEmpty());
318 // Loop through the chunks to generate preloads before any 326 // Loop through the chunks to generate preloads before any
319 // document.write script evaluation takes place. Preloading these 327 // document.write script evaluation takes place. Preloading these
320 // scripts is valuable and comparably cheap, while evaluating JS can be 328 // scripts is valuable and comparably cheap, while evaluating JS can be
321 // expensive. 329 // expensive.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 470 }
463 471
464 m_textPosition = it->textPosition(); 472 m_textPosition = it->textPosition();
465 473
466 constructTreeFromCompactHTMLToken(*it); 474 constructTreeFromCompactHTMLToken(*it);
467 475
468 if (isStopped()) 476 if (isStopped())
469 break; 477 break;
470 478
471 if (!m_triedLoadingLinkHeaders && document()->loader()) { 479 if (!m_triedLoadingLinkHeaders && document()->loader()) {
472 String linkHeader = document()->loader()->response().httpHeaderField (HTTPNames::Link); 480 DCHECK(chunk);
473 if (!linkHeader.isEmpty()) { 481 // Note that on commit, the loader dispatched preloads for all the
474 ASSERT(chunk); 482 // non-media links.
475 LinkLoader::loadLinksFromHeader(linkHeader, document()->loader() ->response().url(), 483 document()->loader()->dispatchLinkHeaderPreloads(&chunk->viewport, L inkLoader::OnlyLoadMedia);
476 document(), NetworkHintsInterfaceImpl(), LinkLoader::OnlyLoa dResources, &(chunk->viewport)); 484 m_triedLoadingLinkHeaders = true;
477 m_triedLoadingLinkHeaders = true;
478 }
479 } 485 }
480 486
481 if (isWaitingForScripts()) { 487 if (isWaitingForScripts()) {
482 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch. 488 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t he last token of this bunch.
483 runScriptsForPausedTreeBuilder(); 489 runScriptsForPausedTreeBuilder();
484 validateSpeculations(std::move(chunk)); 490 validateSpeculations(std::move(chunk));
485 break; 491 break;
486 } 492 }
487 493
488 if (it->type() == HTMLToken::EndOfFile) { 494 if (it->type() == HTMLToken::EndOfFile) {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); 1156 (*WTF::bind(function, std::forward<Ps>(parameters)...))();
1151 return; 1157 return;
1152 case Asynchronous: 1158 case Asynchronous:
1153 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std:: forward<Ps>(parameters)...)); 1159 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std:: forward<Ps>(parameters)...));
1154 return; 1160 return;
1155 } 1161 }
1156 NOTREACHED(); 1162 NOTREACHED();
1157 } 1163 }
1158 1164
1159 } // namespace blink 1165 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698