Modified: trunk/Source/WebCore/loader/LinkLoader.cpp (227004 => 227005)
--- trunk/Source/WebCore/loader/LinkLoader.cpp 2018-01-16 22:35:39 UTC (rev 227004)
+++ trunk/Source/WebCore/loader/LinkLoader.cpp 2018-01-16 22:52:47 UTC (rev 227005)
@@ -110,8 +110,7 @@
// Sanity check to avoid re-entrancy here.
if (equalIgnoringFragmentIdentifier(url, baseURL))
continue;
- preconnect(relAttribute, url, document, header.crossOrigin());
- preload(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
+ preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
}
}
@@ -212,28 +211,8 @@
return false;
}
-void LinkLoader::preconnect(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
+std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& media, const String& mimeType, const String& crossOriginMode, LinkLoader* loader)
{
- if (!relAttribute.isLinkPreconnect || !href.isValid() || !href.protocolIsInHTTPFamily() || !document.frame())
- return;
- ASSERT(document.settings().linkPreconnectEnabled());
- StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
- if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
- storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
- ASSERT(document.frame()->loader().networkingContext());
- platformStrategies()->loaderStrategy()->preconnectTo(*document.frame()->loader().networkingContext(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
- if (!weakDocument)
- return;
-
- if (!error.isNull())
- weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Error, makeString(ASCIILiteral("Failed to preconnect to "), href.string(), ASCIILiteral(". Error: "), error.localizedDescription()));
- else
- weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Info, makeString(ASCIILiteral("Successfuly preconnected to "), href.string()));
- });
-}
-
-std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preload(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& media, const String& mimeType, const String& crossOriginMode, LinkLoader* loader)
-{
if (!document.loader() || !relAttribute.isLinkPreload)
return nullptr;
@@ -280,10 +259,25 @@
document.frame()->loader().client().prefetchDNS(href.host());
}
- preconnect(relAttribute, href, document, crossOrigin);
+ if (relAttribute.isLinkPreconnect && href.isValid() && href.protocolIsInHTTPFamily() && document.frame()) {
+ ASSERT(document.settings().linkPreconnectEnabled());
+ StoredCredentialsPolicy storageCredentialsPolicy = StoredCredentialsPolicy::Use;
+ if (equalIgnoringASCIICase(crossOrigin, "anonymous") && document.securityOrigin().canAccess(SecurityOrigin::create(href)))
+ storageCredentialsPolicy = StoredCredentialsPolicy::DoNotUse;
+ ASSERT(document.frame()->loader().networkingContext());
+ platformStrategies()->loaderStrategy()->preconnectTo(*document.frame()->loader().networkingContext(), href, storageCredentialsPolicy, [weakDocument = document.createWeakPtr(), href](ResourceError error) {
+ if (!weakDocument)
+ return;
+ if (!error.isNull())
+ weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Error, makeString(ASCIILiteral("Failed to preconnect to "), href.string(), ASCIILiteral(". Error: "), error.localizedDescription()));
+ else
+ weakDocument->addConsoleMessage(MessageSource::Network, MessageLevel::Info, makeString(ASCIILiteral("Successfuly preconnected to "), href.string()));
+ });
+ }
+
if (m_client.shouldLoadLink()) {
- auto resourceClient = preload(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
+ auto resourceClient = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
if (resourceClient)
m_preloadResourceClient = WTFMove(resourceClient);
else if (m_preloadResourceClient)
Modified: trunk/Source/WebCore/loader/LinkLoader.h (227004 => 227005)
--- trunk/Source/WebCore/loader/LinkLoader.h 2018-01-16 22:35:39 UTC (rev 227004)
+++ trunk/Source/WebCore/loader/LinkLoader.h 2018-01-16 22:52:47 UTC (rev 227005)
@@ -64,8 +64,7 @@
private:
void notifyFinished(CachedResource&) override;
- static void preconnect(const LinkRelAttribute&, const URL& href, Document&, const String& crossOrigin);
- static std::unique_ptr<LinkPreloadResourceClient> preload(const LinkRelAttribute&, const URL& href, Document&, const String& as, const String& media, const String& type, const String& crossOriginMode, LinkLoader*);
+ static std::unique_ptr<LinkPreloadResourceClient> preloadIfNeeded(const LinkRelAttribute&, const URL& href, Document&, const String& as, const String& media, const String& type, const String& crossOriginMode, LinkLoader*);
LinkLoaderClient& m_client;
CachedResourceHandle<CachedResource> m_cachedLinkResource;