Title: [226962] trunk
Revision
226962
Author
[email protected]
Date
2018-01-15 22:44:41 -0800 (Mon, 15 Jan 2018)

Log Message

Support for preconnect Link headers
https://bugs.webkit.org/show_bug.cgi?id=181657

Reviewed by Darin Adler.

Source/WebCore:

Move the preconnect functionality into its own function, and
also call this function when Link headers are processed.

Test: http/tests/preconnect/link-header-rel-preconnect-http.php

* loader/LinkLoader.cpp:
(WebCore::LinkLoader::loadLinksFromHeader): Call preconnect.
(WebCore::LinkLoader::preconnect): Preconnect to a host functionality moved here.
(WebCore::LinkLoader::preload): Renamed `preloadIfNeeded` to `preload`.
(WebCore::LinkLoader::loadLink): Call preconnect.
* loader/LinkLoader.h:

LayoutTests:

Add test to see Link preconnect headers trigger a connection.

* http/tests/preconnect/link-header-rel-preconnect-http-expected.txt: Added.
* http/tests/preconnect/link-header-rel-preconnect-http.php: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (226961 => 226962)


--- trunk/LayoutTests/ChangeLog	2018-01-16 02:44:14 UTC (rev 226961)
+++ trunk/LayoutTests/ChangeLog	2018-01-16 06:44:41 UTC (rev 226962)
@@ -1,3 +1,15 @@
+2018-01-15  Yoav Weiss  <[email protected]>
+
+        Support for preconnect Link headers
+        https://bugs.webkit.org/show_bug.cgi?id=181657
+
+        Reviewed by Darin Adler.
+
+        Add test to see Link preconnect headers trigger a connection.
+
+        * http/tests/preconnect/link-header-rel-preconnect-http-expected.txt: Added.
+        * http/tests/preconnect/link-header-rel-preconnect-http.php: Added.
+
 2018-01-15  Michael Catanzaro  <[email protected]>
 
         Unreviewed GTK layout test gardening

Added: trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http-expected.txt (0 => 226962)


--- trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http-expected.txt	2018-01-16 06:44:41 UTC (rev 226962)
@@ -0,0 +1,10 @@
+CONSOLE MESSAGE: Successfuly preconnected to http://localhost:8000/
+Tests that Link header's rel=preconnect works as expected over HTTP.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http.php (0 => 226962)


--- trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/preconnect/link-header-rel-preconnect-http.php	2018-01-16 06:44:41 UTC (rev 226962)
@@ -0,0 +1,19 @@
+<?php
+   header('Link: <http://localhost:8000>; rel=preconnect');
+?>
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+description("Tests that Link header's rel=preconnect works as expected over HTTP.");
+jsTestIsAsync = true;
+
+internals.setConsoleMessageListener(function() {
+    finishJSTest();
+});
+</script>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (226961 => 226962)


--- trunk/Source/WebCore/ChangeLog	2018-01-16 02:44:14 UTC (rev 226961)
+++ trunk/Source/WebCore/ChangeLog	2018-01-16 06:44:41 UTC (rev 226962)
@@ -1,3 +1,22 @@
+2018-01-15  Yoav Weiss  <[email protected]>
+
+        Support for preconnect Link headers
+        https://bugs.webkit.org/show_bug.cgi?id=181657
+
+        Reviewed by Darin Adler.
+
+        Move the preconnect functionality into its own function, and
+        also call this function when Link headers are processed.
+
+        Test: http/tests/preconnect/link-header-rel-preconnect-http.php
+
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::loadLinksFromHeader): Call preconnect.
+        (WebCore::LinkLoader::preconnect): Preconnect to a host functionality moved here.
+        (WebCore::LinkLoader::preload): Renamed `preloadIfNeeded` to `preload`.
+        (WebCore::LinkLoader::loadLink): Call preconnect.
+        * loader/LinkLoader.h:
+
 2018-01-15  Michael Catanzaro  <[email protected]>
 
         Improve use of ExportMacros

Modified: trunk/Source/WebCore/loader/LinkLoader.cpp (226961 => 226962)


--- trunk/Source/WebCore/loader/LinkLoader.cpp	2018-01-16 02:44:14 UTC (rev 226961)
+++ trunk/Source/WebCore/loader/LinkLoader.cpp	2018-01-16 06:44:41 UTC (rev 226962)
@@ -110,7 +110,8 @@
         // Sanity check to avoid re-entrancy here.
         if (equalIgnoringFragmentIdentifier(url, baseURL))
             continue;
-        preloadIfNeeded(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
+        preconnect(relAttribute, url, document, header.crossOrigin());
+        preload(relAttribute, url, document, header.as(), header.media(), header.mimeType(), header.crossOrigin(), nullptr);
     }
 }
 
@@ -211,8 +212,28 @@
     return false;
 }
 
-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)
+void LinkLoader::preconnect(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& crossOrigin)
 {
+    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;
 
@@ -259,25 +280,10 @@
             document.frame()->loader().client().prefetchDNS(href.host());
     }
 
-    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;
+    preconnect(relAttribute, href, document, crossOrigin);
 
-            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 = preloadIfNeeded(relAttribute, href, document, as, media, mimeType, crossOrigin, this);
+        auto resourceClient = preload(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 (226961 => 226962)


--- trunk/Source/WebCore/loader/LinkLoader.h	2018-01-16 02:44:14 UTC (rev 226961)
+++ trunk/Source/WebCore/loader/LinkLoader.h	2018-01-16 06:44:41 UTC (rev 226962)
@@ -64,7 +64,8 @@
 
 private:
     void notifyFinished(CachedResource&) override;
-    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*);
+    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*);
 
     LinkLoaderClient& m_client;
     CachedResourceHandle<CachedResource> m_cachedLinkResource;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to