Commit 48ac6111 authored by yoav's avatar yoav Committed by Commit bot

Fix link header preload on subresources

Link header preloads were not working when sent over subresources.
This CL fixes that.

BUG=568025

Review URL: https://codereview.chromium.org/1627203002

Cr-Commit-Position: refs/heads/master@{#372024}
parent 4dd5f8bb
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
var t = async_test('Makes sure link preload headers are loaded on subresources');
</script>
<script src="resources/link-preload-js.php"></script>
<script src="../resources/slow-script.pl?delay=200"></script>
<script>
window.addEventListener("load", t.step_func(function() {
assert_equals(performance.getEntriesByType("resource").length, 5);
t.done();
}));
</script>
<?php
header("Link: <../resources/dummy.js>; rel=preload; as=script");
?>
......@@ -250,14 +250,17 @@ void FrameFetchContext::dispatchWillSendRequest(unsigned long identifier, Resour
void FrameFetchContext::dispatchDidReceiveResponse(unsigned long identifier, const ResourceResponse& response, ResourceLoader* resourceLoader)
{
LinkLoader::CanLoadResources resourceLoadingPolicy = LinkLoader::LoadResourcesAndPreconnect;
MixedContentChecker::checkMixedPrivatePublic(frame(), response.remoteIPAddress());
LinkLoader::loadLinkFromHeader(response.httpHeaderField(HTTPNames::Link), frame()->document(), NetworkHintsInterfaceImpl(), LinkLoader::DoNotLoadResources);
if (m_documentLoader == frame()->loader().provisionalDocumentLoader()) {
ResourceFetcher* fetcher = nullptr;
if (frame()->document())
fetcher = frame()->document()->fetcher();
m_documentLoader->clientHintsPreferences().updateFromAcceptClientHintsHeader(response.httpHeaderField(HTTPNames::Accept_CH), fetcher);
// When response is received with a provisional docloader, the resource haven't committed yet, and we cannot load resources, only preconnect.
resourceLoadingPolicy = LinkLoader::DoNotLoadResources;
}
LinkLoader::loadLinkFromHeader(response.httpHeaderField(HTTPNames::Link), frame()->document(), NetworkHintsInterfaceImpl(), resourceLoadingPolicy);
if (response.hasMajorCertificateErrors() && resourceLoader)
MixedContentChecker::handleCertificateError(frame(), resourceLoader->originalRequest(), response);
......
......@@ -441,7 +441,7 @@ void FrameLoader::didBeginDocument(bool dispatch)
m_frame->document()->initContentSecurityPolicy(m_documentLoader ? m_documentLoader->releaseContentSecurityPolicy() : ContentSecurityPolicy::create());
if (m_documentLoader) {
m_frame->document()->clientHintsPreferences().updateFrom(m_documentLoader->clientHintsPreferences());
LinkLoader::loadLinkFromHeader(m_documentLoader->response().httpHeaderField(HTTPNames::Link), m_frame->document(), NetworkHintsInterfaceImpl(), LinkLoader::LoadResources);
LinkLoader::loadLinkFromHeader(m_documentLoader->response().httpHeaderField(HTTPNames::Link), m_frame->document(), NetworkHintsInterfaceImpl(), LinkLoader::OnlyLoadResources);
}
Settings* settings = m_frame->document()->settings();
......
......@@ -253,13 +253,14 @@ bool LinkLoader::loadLinkFromHeader(const String& headerValue, Document* documen
LinkRelAttribute relAttribute(header.rel());
KURL url = document->completeURL(header.url());
if (canLoadResources == DoNotLoadResources) {
if (canLoadResources != OnlyLoadResources) {
if (RuntimeEnabledFeatures::linkHeaderEnabled())
dnsPrefetchIfNeeded(relAttribute, url, *document, networkHintsInterface, LinkCalledFromHeader);
if (RuntimeEnabledFeatures::linkPreconnectEnabled())
preconnectIfNeeded(relAttribute, url, *document, header.crossOrigin(), networkHintsInterface, LinkCalledFromHeader);
} else {
}
if (canLoadResources != DoNotLoadResources) {
if (RuntimeEnabledFeatures::linkPreloadEnabled())
preloadIfNeeded(relAttribute, url, *document, header.as(), LinkCalledFromHeader);
}
......
......@@ -74,7 +74,7 @@ public:
void released();
bool loadLink(const LinkRelAttribute&, CrossOriginAttributeValue, const String& type, const String& as, const KURL&, Document&, const NetworkHintsInterface&);
enum CanLoadResources { LoadResources, DoNotLoadResources };
enum CanLoadResources { OnlyLoadResources, DoNotLoadResources, LoadResourcesAndPreconnect };
static bool loadLinkFromHeader(const String& headerValue, Document*, const NetworkHintsInterface&, CanLoadResources);
static Resource::Type getTypeFromAsAttribute(const String& as, Document*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment