OLD | NEW |
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 Loading... |
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. |
| 304 if (!m_triedLoadingLinkHeaders && document()->loader() && !pendingChunks.isE
mpty()) { |
| 305 // Note that on commit, the loader dispatched preloads for all the |
| 306 // non-media links. |
| 307 document()->loader()->dispatchLinkHeaderPreloads(&pendingChunks.first()-
>viewport, LinkLoader::OnlyLoadMedia); |
| 308 m_triedLoadingLinkHeaders = true; |
| 309 } |
| 310 |
302 if (!document()->documentElement()) { | 311 if (!document()->documentElement()) { |
| 312 PreloadRequestStream linkRelPreloads; |
303 for (auto& chunk : pendingChunks) { | 313 for (auto& chunk : pendingChunks) { |
304 for (auto& request : chunk->preloads) | 314 for (auto& request : chunk->preloads) { |
305 m_queuedPreloads.append(std::move(request)); | 315 if (request->isLinkRelPreload()) |
| 316 linkRelPreloads.append(std::move(request)); |
| 317 else |
| 318 m_queuedPreloads.append(std::move(request)); |
| 319 } |
306 for (auto& index : chunk->likelyDocumentWriteScriptIndices) { | 320 for (auto& index : chunk->likelyDocumentWriteScriptIndices) { |
307 const CompactHTMLToken& token = chunk->tokens->at(index); | 321 const CompactHTMLToken& token = chunk->tokens->at(index); |
308 ASSERT(token.type() == HTMLToken::TokenType::Character); | 322 ASSERT(token.type() == HTMLToken::TokenType::Character); |
309 m_queuedDocumentWriteScripts.append(token.data()); | 323 m_queuedDocumentWriteScripts.append(token.data()); |
310 } | 324 } |
311 } | 325 } |
| 326 m_preloader->takeAndPreload(linkRelPreloads); |
312 } else { | 327 } else { |
313 // We can safely assume that there are no queued preloads request after | 328 // We can safely assume that there are no queued preloads request after |
314 // the document element is available, as we empty the queue immediately | 329 // the document element is available, as we empty the queue immediately |
315 // after the document element is created in documentElementAvailable(). | 330 // after the document element is created in documentElementAvailable(). |
316 ASSERT(m_queuedPreloads.isEmpty()); | 331 ASSERT(m_queuedPreloads.isEmpty()); |
317 ASSERT(m_queuedDocumentWriteScripts.isEmpty()); | 332 ASSERT(m_queuedDocumentWriteScripts.isEmpty()); |
318 // Loop through the chunks to generate preloads before any | 333 // Loop through the chunks to generate preloads before any |
319 // document.write script evaluation takes place. Preloading these | 334 // document.write script evaluation takes place. Preloading these |
320 // scripts is valuable and comparably cheap, while evaluating JS can be | 335 // scripts is valuable and comparably cheap, while evaluating JS can be |
321 // expensive. | 336 // expensive. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 break; | 476 break; |
462 } | 477 } |
463 | 478 |
464 m_textPosition = it->textPosition(); | 479 m_textPosition = it->textPosition(); |
465 | 480 |
466 constructTreeFromCompactHTMLToken(*it); | 481 constructTreeFromCompactHTMLToken(*it); |
467 | 482 |
468 if (isStopped()) | 483 if (isStopped()) |
469 break; | 484 break; |
470 | 485 |
471 if (!m_triedLoadingLinkHeaders && document()->loader()) { | |
472 String linkHeader = document()->loader()->response().httpHeaderField
(HTTPNames::Link); | |
473 if (!linkHeader.isEmpty()) { | |
474 ASSERT(chunk); | |
475 LinkLoader::loadLinksFromHeader(linkHeader, document()->loader()
->response().url(), | |
476 document(), NetworkHintsInterfaceImpl(), LinkLoader::OnlyLoa
dResources, &(chunk->viewport)); | |
477 m_triedLoadingLinkHeaders = true; | |
478 } | |
479 } | |
480 | |
481 if (isWaitingForScripts()) { | 486 if (isWaitingForScripts()) { |
482 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. | 487 ASSERT(it + 1 == tokens->end()); // The </script> is assumed to be t
he last token of this bunch. |
483 runScriptsForPausedTreeBuilder(); | 488 runScriptsForPausedTreeBuilder(); |
484 validateSpeculations(std::move(chunk)); | 489 validateSpeculations(std::move(chunk)); |
485 break; | 490 break; |
486 } | 491 } |
487 | 492 |
488 if (it->type() == HTMLToken::EndOfFile) { | 493 if (it->type() == HTMLToken::EndOfFile) { |
489 ASSERT(it + 1 == tokens->end()); // The EOF is assumed to be the las
t token of this bunch. | 494 ASSERT(it + 1 == tokens->end()); // The EOF is assumed to be the las
t token of this bunch. |
490 ASSERT(m_speculations.isEmpty()); // There should never be any chunk
s after the EOF. | 495 ASSERT(m_speculations.isEmpty()); // There should never be any chunk
s after the EOF. |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); | 1155 (*WTF::bind(function, std::forward<Ps>(parameters)...))(); |
1151 return; | 1156 return; |
1152 case Asynchronous: | 1157 case Asynchronous: |
1153 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); | 1158 m_loadingTaskRunner->postTask(BLINK_FROM_HERE, WTF::bind(function, std::
forward<Ps>(parameters)...)); |
1154 return; | 1159 return; |
1155 } | 1160 } |
1156 NOTREACHED(); | 1161 NOTREACHED(); |
1157 } | 1162 } |
1158 | 1163 |
1159 } // namespace blink | 1164 } // namespace blink |
OLD | NEW |