Initial Link preload support
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 06:06:42 +0000 (06:06 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Apr 2016 06:06:42 +0000 (06:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=156334

Source/WebCore:

Added basic `<link rel=preload>` functionality that enables preloading
of resources according to their type.

Reviewed by Darin Adler.

Tests: http/tests/preload/download_resources.html
       http/tests/preload/dynamic_adding_preload.html
       http/tests/preload/dynamic_remove_preload_href.html
       http/tests/preload/dynamic_removing_preload.html

* bindings/generic/RuntimeEnabledFeatures.cpp: Added a runtime flag for the feature.
(WebCore::RuntimeEnabledFeatures::RuntimeEnabledFeatures):
* bindings/generic/RuntimeEnabledFeatures.h: Added a runtime flag for the feature.
(WebCore::RuntimeEnabledFeatures::setLinkPreloadEnabled):
(WebCore::RuntimeEnabledFeatures::linkPreloadEnabled):
* html/HTMLAttributeNames.in: Added an `as` attribute.
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::process): Added `as` and `crossorigin` attribute values to the loadLink() call.
(WebCore::HTMLLinkElement::setCrossOrigin): Setter for crossOrigin.
(WebCore::HTMLLinkElement::crossOrigin): Getter for crossOrigin.
* html/HTMLLinkElement.idl: Added `as` and `crossorigin` to HTMLLinkElement.
* html/HTMLLinkElement.h: Added getter and setter for crossorigin.
* html/LinkRelAttribute.cpp:
(WebCore::LinkRelAttribute::LinkRelAttribute): Added "preload" as a potential value.
* html/LinkRelAttribute.h: Added isLinkPreload.
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::resourceTypeFromAsAttribute): Translates an `as` value into a resource type.
(WebCore::preloadIfNeeded): Triggers a resource preload when link element is a preload one.
(WebCore::LinkLoader::loadLink): Added a call to preloadIfNeeded.
* loader/LinkLoader.h: Added signatures.
* loader/ResourceLoadInfo.cpp:
(WebCore::toResourceType): Added LinkPreload as a possible CachedResource::type.
* loader/SubresourceLoader.cpp:
(WebCore::logResourceLoaded): Added LinkPreload as a possible CachedResource::type.
* loader/cache/CachedResource.cpp: Turned defaultPriorityForResourceType into a static member, as it's now also called from LinkLoader.
(WebCore::CachedResource::defaultPriorityForResourceType): Added LinkPreload as a possible CachedResource::type, giving it low priority.
(WebCore::defaultPriorityForResourceType): Deleted.
* loader/cache/CachedResource.h: Added LinkPreload as a possible CachedResource::type. Added defaultPriorityForResourceType as static.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::contentTypeFromResourceType): Added LinkPreload as a possible CachedResource::type.
(WebCore::createResource): Added creation of a LinkPreload resource if needed.
(WebCore::CachedResourceLoader::checkInsecureContent): Added LinkPreload as a possible CachedResource::type.
(WebCore::CachedResourceLoader::canRequest): Added LinkPreload as a possible CachedResource::type.
* testing/Internals.cpp: Added function to turn on the link preload feature.
(WebCore::setLinkPreloadSupport):
* testing/Internals.idl: Added function to turn on the link preload feature.
* testing/Internals.h: Added function signature to turn on the link preload feature.

Source/WebKit2:

Reviewed by Darin Adler.

* WebProcess/Network/WebLoaderStrategy.cpp:
(WebKit::maximumBufferingTime): Added LinkPreload as a possible CachedResource::type.

LayoutTests:

Added tests that make sure that `<link rel=preload>` performs its basic
tasks and preloads resources.

Reviewed by Darin Adler.

* http/tests/preload/download_resources-expected.txt: Added.
* http/tests/preload/download_resources.html: Added.
* http/tests/preload/dynamic_adding_preload-expected.txt: Added.
* http/tests/preload/dynamic_adding_preload.html: Added.
* http/tests/preload/dynamic_remove_preload_href-expected.txt: Added.
* http/tests/preload/dynamic_remove_preload_href.html: Added.
* http/tests/preload/dynamic_removing_preload-expected.txt: Added.
* http/tests/preload/dynamic_removing_preload.html: Added.
* imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt: Adjusted expected results to progressions.
* imported/w3c/web-platform-tests/html/dom/reflection-metadata-expected.txt: Adjusted expected results to progressions.
* platform/ios-simulator/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt: Adjusted expected results to progressions.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@199650 268f45cc-cd09-0410-ab3c-d52691b4dbfc

33 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/preload/download_resources-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/preload/download_resources.html [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_adding_preload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_adding_preload.html [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_remove_preload_href.html [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_removing_preload-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/preload/dynamic_removing_preload.html [new file with mode: 0644]
LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/dom/reflection-metadata-expected.txt
LayoutTests/platform/ios-simulator/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp
Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h
Source/WebCore/html/HTMLAttributeNames.in
Source/WebCore/html/HTMLLinkElement.cpp
Source/WebCore/html/HTMLLinkElement.h
Source/WebCore/html/HTMLLinkElement.idl
Source/WebCore/html/LinkRelAttribute.cpp
Source/WebCore/html/LinkRelAttribute.h
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/LinkLoader.h
Source/WebCore/loader/ResourceLoadInfo.cpp
Source/WebCore/loader/SubresourceLoader.cpp
Source/WebCore/loader/cache/CachedResource.cpp
Source/WebCore/loader/cache/CachedResource.h
Source/WebCore/loader/cache/CachedResourceLoader.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/Network/WebLoaderStrategy.cpp

index 4c8e8e4..92fc3ba 100644 (file)
@@ -1,3 +1,25 @@
+2016-04-17  Yoav Weiss  <yoav@yoav.ws>
+
+        Initial Link preload support
+        https://bugs.webkit.org/show_bug.cgi?id=156334
+
+        Added tests that make sure that `<link rel=preload>` performs its basic
+        tasks and preloads resources.
+
+        Reviewed by Darin Adler.
+
+        * http/tests/preload/download_resources-expected.txt: Added.
+        * http/tests/preload/download_resources.html: Added.
+        * http/tests/preload/dynamic_adding_preload-expected.txt: Added.
+        * http/tests/preload/dynamic_adding_preload.html: Added.
+        * http/tests/preload/dynamic_remove_preload_href-expected.txt: Added.
+        * http/tests/preload/dynamic_remove_preload_href.html: Added.
+        * http/tests/preload/dynamic_removing_preload-expected.txt: Added.
+        * http/tests/preload/dynamic_removing_preload.html: Added.
+        * imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt: Adjusted expected results to progressions.
+        * imported/w3c/web-platform-tests/html/dom/reflection-metadata-expected.txt: Adjusted expected results to progressions.
+        * platform/ios-simulator/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt: Adjusted expected results to progressions.
+
 2016-04-17  Youenn Fablet  <youenn.fablet@crf.canon.fr>
 
         [Streams] Consume HTTP data as a ReadableStream
diff --git a/LayoutTests/http/tests/preload/download_resources-expected.txt b/LayoutTests/http/tests/preload/download_resources-expected.txt
new file mode 100644 (file)
index 0000000..af135a4
--- /dev/null
@@ -0,0 +1,13 @@
+CONSOLE MESSAGE: line 15: <link rel=preload> must have a valid `as` value
+PASS internals.isPreloaded('../resources/dummy.js'); is true
+PASS internals.isPreloaded('../resources/dummy.css'); is true
+PASS internals.isPreloaded('../resources/square.png'); is true
+PASS internals.isPreloaded('../resources/Ahem.ttf'); is true
+PASS internals.isPreloaded('../resources/test.mp4'); is true
+PASS internals.isPreloaded('../security/resources/captions.vtt'); is true
+PASS internals.isPreloaded('../resources/dummy.xml?badvalue'); is false
+PASS internals.isPreloaded('../resources/dummy.xml'); is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/preload/download_resources.html b/LayoutTests/http/tests/preload/download_resources.html
new file mode 100644 (file)
index 0000000..906dbe1
--- /dev/null
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+</script>
+<script src="/js-test-resources/js-test.js"></script>
+<link rel=preload href="../resources/dummy.js" as=script>
+<link rel=preload href="../resources/dummy.css" as=style>
+<link rel=preload href="../resources/square.png" as=image>
+<link rel=preload href="../resources/Ahem.ttf" as=font crossorigin>
+<link rel=preload href="../resources/test.mp4" as=media>
+<link rel=preload href="../security/resources/captions.vtt" as=track>
+<link rel=preload href="../resources/dummy.xml?badvalue" as=foobarxmlthing>
+<link rel=preload href="../resources/dummy.xml">
+<script src="http://127.0.0.1:8000/resources/slow-script.pl?delay=100"></script>
+</head>
+<body>
+<script>
+    if (window.testRunner)
+        testRunner.dumpAsText();
+    shouldBeTrue("internals.isPreloaded('../resources/dummy.js');");
+    shouldBeTrue("internals.isPreloaded('../resources/dummy.css');");
+    shouldBeTrue("internals.isPreloaded('../resources/square.png');");
+    shouldBeTrue("internals.isPreloaded('../resources/Ahem.ttf');");
+    shouldBeTrue("internals.isPreloaded('../resources/test.mp4');");
+    shouldBeTrue("internals.isPreloaded('../security/resources/captions.vtt');");
+    shouldBeFalse("internals.isPreloaded('../resources/dummy.xml?badvalue');");
+    shouldBeTrue("internals.isPreloaded('../resources/dummy.xml');");
+</script>
+<script>
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(false);
+</script>
diff --git a/LayoutTests/http/tests/preload/dynamic_adding_preload-expected.txt b/LayoutTests/http/tests/preload/dynamic_adding_preload-expected.txt
new file mode 100644 (file)
index 0000000..f76c99c
--- /dev/null
@@ -0,0 +1,5 @@
+PASS internals.isPreloaded('../resources/dummy.js'); is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/preload/dynamic_adding_preload.html b/LayoutTests/http/tests/preload/dynamic_adding_preload.html
new file mode 100644 (file)
index 0000000..e2fb7e4
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+</script>
+<script src="/js-test-resources/js-test.js"></script>
+<body>
+<script>
+    var link = document.createElement("link");
+    link.as = "script";
+    link.rel = "preload";
+    link.href = "../resources/dummy.js";
+    document.body.appendChild(link);
+</script>
+<script src="http://127.0.0.1:8000/resources/slow-script.pl?delay=100"></script>
+<script>
+    shouldBeTrue("internals.isPreloaded('../resources/dummy.js');");
+
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(false);
+</script>
+</body>
diff --git a/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt b/LayoutTests/http/tests/preload/dynamic_remove_preload_href-expected.txt
new file mode 100644 (file)
index 0000000..9521a40
--- /dev/null
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: line 16: <link rel=preload> has an invalid `href` value
+PASS internals.isPreloaded('../resources/dummy.js'); is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html b/LayoutTests/http/tests/preload/dynamic_remove_preload_href.html
new file mode 100644 (file)
index 0000000..ec2fb38
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(true);
+</script>
+<script src="/js-test-resources/js-test.js"></script>
+<body>
+<script>
+    var link = document.createElement("link");
+    link.as = "script";
+    link.rel = "preload";
+    link.href = "../resources/dummy.js";
+    document.body.appendChild(link);
+    link.href = "";
+    window.addEventListener("load", function() {
+        shouldBeFalse("internals.isPreloaded('../resources/dummy.js');");
+    });
+</script>
+<script src="../resources/slow-script.pl?delay=200"></script>
+<script>
+    if (window.internals)
+        window.internals.setLinkPreloadSupport(false);
+</script>
+</body>
diff --git a/LayoutTests/http/tests/preload/dynamic_removing_preload-expected.txt b/LayoutTests/http/tests/preload/dynamic_removing_preload-expected.txt
new file mode 100644 (file)
index 0000000..f630401
--- /dev/null
@@ -0,0 +1,5 @@
+PASS internals.isPreloaded('../resources/dummy.js'); is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/preload/dynamic_removing_preload.html b/LayoutTests/http/tests/preload/dynamic_removing_preload.html
new file mode 100644 (file)
index 0000000..52d676b
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="/js-test-resources/js-test.js"></script>
+<body>
+<script>
+    var link = document.createElement("link");
+    link.as = "script";
+    link.rel = "preload";
+    link.href = "../resources/dummy.js";
+    document.body.appendChild(link);
+    document.body.removeChild(link);
+    window.addEventListener("load", function() {
+        shouldBeFalse("internals.isPreloaded('../resources/dummy.js');");
+    });
+</script>
+<script src="../resources/slow-script.pl?delay=200"></script>
+</body>
index 00e4684..10aeb84 100644 (file)
@@ -1366,7 +1366,7 @@ PASS HTMLLinkElement interface object name
 PASS HTMLLinkElement interface: existence and properties of interface prototype object 
 PASS HTMLLinkElement interface: existence and properties of interface prototype object's "constructor" property 
 PASS HTMLLinkElement interface: attribute href 
-FAIL HTMLLinkElement interface: attribute crossOrigin assert_true: The prototype object must have a property "crossOrigin" expected true got false
+PASS HTMLLinkElement interface: attribute crossOrigin 
 PASS HTMLLinkElement interface: attribute rel 
 PASS HTMLLinkElement interface: attribute relList 
 PASS HTMLLinkElement interface: attribute media 
@@ -1379,7 +1379,7 @@ PASS HTMLLinkElement interface: attribute target
 PASS HTMLLinkElement must be primary interface of document.createElement("link") 
 PASS Stringification of document.createElement("link") 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "href" with the proper type (0) 
-FAIL HTMLLinkElement interface: document.createElement("link") must inherit property "crossOrigin" with the proper type (1) assert_inherits: property "crossOrigin" not found in prototype chain
+PASS HTMLLinkElement interface: document.createElement("link") must inherit property "crossOrigin" with the proper type (1) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "rel" with the proper type (2) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "relList" with the proper type (3) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "media" with the proper type (4) 
index 3084066..d5ba1e6 100644 (file)
@@ -3051,132 +3051,132 @@ PASS link.href: IDL set to object "test-toString" followed by IDL get
 PASS link.href: IDL set to object "test-valueOf" should not throw 
 PASS link.href: IDL set to object "test-valueOf" followed by getAttribute() 
 PASS link.href: IDL set to object "test-valueOf" followed by IDL get 
-FAIL link.crossOrigin: typeof IDL attribute assert_equals: expected "string" but got "undefined"
-FAIL link.crossOrigin: IDL get with DOM attribute unset assert_equals: expected (string) "" but got (undefined) undefined
+FAIL link.crossOrigin: typeof IDL attribute assert_equals: expected "string" but got "object"
+FAIL link.crossOrigin: IDL get with DOM attribute unset assert_equals: expected (string) "" but got (object) null
 PASS link.crossOrigin: setAttribute() to "" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get 
 PASS link.crossOrigin: setAttribute() to undefined followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to undefined followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to undefined followed by IDL get 
 PASS link.crossOrigin: setAttribute() to 7 followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to 7 followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to 7 followed by IDL get 
 PASS link.crossOrigin: setAttribute() to 1.5 followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to 1.5 followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to 1.5 followed by IDL get 
 PASS link.crossOrigin: setAttribute() to true followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to true followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to true followed by IDL get 
 PASS link.crossOrigin: setAttribute() to false followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to false followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to false followed by IDL get 
 PASS link.crossOrigin: setAttribute() to object "[object Object]" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to object "[object Object]" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to object "[object Object]" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to NaN followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to NaN followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to NaN followed by IDL get 
 PASS link.crossOrigin: setAttribute() to Infinity followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to Infinity followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to Infinity followed by IDL get 
 PASS link.crossOrigin: setAttribute() to -Infinity followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to -Infinity followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to -Infinity followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "\0" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "\0" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "\0" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to null followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to null followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to null followed by IDL get 
 PASS link.crossOrigin: setAttribute() to object "test-toString" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to object "test-toString" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to object "test-toString" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to object "test-valueOf" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to object "test-valueOf" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to object "test-valueOf" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "anonymous" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "anonymous" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "anonymous" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "xanonymous" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "xanonymous" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "xanonymous" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "anonymous\0" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "anonymous\0" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "anonymous\0" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "nonymous" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "nonymous" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "nonymous" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "ANONYMOUS" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "ANONYMOUS" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "ANONYMOUS" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "use-credentials" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "use-credentials" followed by IDL get assert_equals: expected (string) "use-credentials" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "use-credentials" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "xuse-credentials" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "xuse-credentials" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "xuse-credentials" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "use-credentials\0" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "use-credentials\0" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "use-credentials\0" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "se-credentials" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "se-credentials" followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "se-credentials" followed by IDL get 
 PASS link.crossOrigin: setAttribute() to "USE-CREDENTIALS" followed by getAttribute() 
-FAIL link.crossOrigin: setAttribute() to "USE-CREDENTIALS" followed by IDL get assert_equals: expected (string) "use-credentials" but got (undefined) undefined
+PASS link.crossOrigin: setAttribute() to "USE-CREDENTIALS" followed by IDL get 
 PASS link.crossOrigin: IDL set to "" should not throw 
-FAIL link.crossOrigin: IDL set to "" followed by getAttribute() assert_equals: expected "" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "" followed by IDL get assert_equals: expected "anonymous" but got ""
+PASS link.crossOrigin: IDL set to "" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "" followed by IDL get 
 PASS link.crossOrigin: IDL set to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " should not throw 
-FAIL link.crossOrigin: IDL set to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by getAttribute() assert_equals: expected " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get assert_equals: expected "anonymous" but got " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo "
+PASS link.crossOrigin: IDL set to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by getAttribute() 
+PASS link.crossOrigin: IDL set to " \0\x01\x02\x03\x04\x05\x06\x07 \b\t\n\v\f\r\x0e\x0f \x10\x11\x12\x13\x14\x15\x16\x17 \x18\x19\x1a\x1b\x1c\x1d\x1e\x1f  foo " followed by IDL get 
 PASS link.crossOrigin: IDL set to undefined should not throw 
-FAIL link.crossOrigin: IDL set to undefined followed by getAttribute() assert_equals: expected "undefined" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to undefined followed by IDL get assert_equals: expected (string) "anonymous" but got (undefined) undefined
+FAIL link.crossOrigin: IDL set to undefined followed by getAttribute() assert_equals: expected (string) "undefined" but got (object) null
+FAIL link.crossOrigin: IDL set to undefined followed by IDL get assert_equals: expected (string) "anonymous" but got (object) null
 PASS link.crossOrigin: IDL set to 7 should not throw 
-FAIL link.crossOrigin: IDL set to 7 followed by getAttribute() assert_equals: expected "7" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to 7 followed by IDL get assert_equals: expected (string) "anonymous" but got (number) 7
+PASS link.crossOrigin: IDL set to 7 followed by getAttribute() 
+PASS link.crossOrigin: IDL set to 7 followed by IDL get 
 PASS link.crossOrigin: IDL set to 1.5 should not throw 
-FAIL link.crossOrigin: IDL set to 1.5 followed by getAttribute() assert_equals: expected "1.5" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to 1.5 followed by IDL get assert_equals: expected (string) "anonymous" but got (number) 1.5
+PASS link.crossOrigin: IDL set to 1.5 followed by getAttribute() 
+PASS link.crossOrigin: IDL set to 1.5 followed by IDL get 
 PASS link.crossOrigin: IDL set to true should not throw 
-FAIL link.crossOrigin: IDL set to true followed by getAttribute() assert_equals: expected "true" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to true followed by IDL get assert_equals: expected (string) "anonymous" but got (boolean) true
+PASS link.crossOrigin: IDL set to true followed by getAttribute() 
+PASS link.crossOrigin: IDL set to true followed by IDL get 
 PASS link.crossOrigin: IDL set to false should not throw 
-FAIL link.crossOrigin: IDL set to false followed by getAttribute() assert_equals: expected "false" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to false followed by IDL get assert_equals: expected (string) "anonymous" but got (boolean) false
+PASS link.crossOrigin: IDL set to false followed by getAttribute() 
+PASS link.crossOrigin: IDL set to false followed by IDL get 
 PASS link.crossOrigin: IDL set to object "[object Object]" should not throw 
-FAIL link.crossOrigin: IDL set to object "[object Object]" followed by getAttribute() assert_equals: expected "[object Object]" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to object "[object Object]" followed by IDL get assert_equals: expected (string) "anonymous" but got (object) object "[object Object]"
+PASS link.crossOrigin: IDL set to object "[object Object]" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to object "[object Object]" followed by IDL get 
 PASS link.crossOrigin: IDL set to NaN should not throw 
-FAIL link.crossOrigin: IDL set to NaN followed by getAttribute() assert_equals: expected "NaN" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to NaN followed by IDL get assert_equals: expected (string) "anonymous" but got (number) NaN
+PASS link.crossOrigin: IDL set to NaN followed by getAttribute() 
+PASS link.crossOrigin: IDL set to NaN followed by IDL get 
 PASS link.crossOrigin: IDL set to Infinity should not throw 
-FAIL link.crossOrigin: IDL set to Infinity followed by getAttribute() assert_equals: expected "Infinity" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to Infinity followed by IDL get assert_equals: expected (string) "anonymous" but got (number) Infinity
+PASS link.crossOrigin: IDL set to Infinity followed by getAttribute() 
+PASS link.crossOrigin: IDL set to Infinity followed by IDL get 
 PASS link.crossOrigin: IDL set to -Infinity should not throw 
-FAIL link.crossOrigin: IDL set to -Infinity followed by getAttribute() assert_equals: expected "-Infinity" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to -Infinity followed by IDL get assert_equals: expected (string) "anonymous" but got (number) -Infinity
+PASS link.crossOrigin: IDL set to -Infinity followed by getAttribute() 
+PASS link.crossOrigin: IDL set to -Infinity followed by IDL get 
 PASS link.crossOrigin: IDL set to "\0" should not throw 
-FAIL link.crossOrigin: IDL set to "\0" followed by getAttribute() assert_equals: expected "\0" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "\0" followed by IDL get assert_equals: expected "anonymous" but got "\0"
+PASS link.crossOrigin: IDL set to "\0" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "\0" followed by IDL get 
 PASS link.crossOrigin: IDL set to null should not throw 
 FAIL link.crossOrigin: IDL set to null followed by IDL get assert_equals: expected (string) "anonymous" but got (object) null
 PASS link.crossOrigin: IDL set to object "test-toString" should not throw 
-FAIL link.crossOrigin: IDL set to object "test-toString" followed by getAttribute() assert_equals: expected "test-toString" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to object "test-toString" followed by IDL get assert_equals: expected (string) "anonymous" but got (object) object "test-toString"
+PASS link.crossOrigin: IDL set to object "test-toString" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to object "test-toString" followed by IDL get 
 PASS link.crossOrigin: IDL set to object "test-valueOf" should not throw 
-FAIL link.crossOrigin: IDL set to object "test-valueOf" followed by getAttribute() assert_equals: expected "test-valueOf" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to object "test-valueOf" followed by IDL get assert_equals: expected (string) "anonymous" but got (object) object "test-valueOf"
+PASS link.crossOrigin: IDL set to object "test-valueOf" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to object "test-valueOf" followed by IDL get 
 PASS link.crossOrigin: IDL set to "anonymous" should not throw 
-FAIL link.crossOrigin: IDL set to "anonymous" followed by getAttribute() assert_equals: expected "anonymous" but got "USE-CREDENTIALS"
+PASS link.crossOrigin: IDL set to "anonymous" followed by getAttribute() 
 PASS link.crossOrigin: IDL set to "anonymous" followed by IDL get 
 PASS link.crossOrigin: IDL set to "xanonymous" should not throw 
-FAIL link.crossOrigin: IDL set to "xanonymous" followed by getAttribute() assert_equals: expected "xanonymous" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "xanonymous" followed by IDL get assert_equals: expected "anonymous" but got "xanonymous"
+PASS link.crossOrigin: IDL set to "xanonymous" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "xanonymous" followed by IDL get 
 PASS link.crossOrigin: IDL set to "anonymous\0" should not throw 
-FAIL link.crossOrigin: IDL set to "anonymous\0" followed by getAttribute() assert_equals: expected "anonymous\0" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "anonymous\0" followed by IDL get assert_equals: expected "anonymous" but got "anonymous\0"
+PASS link.crossOrigin: IDL set to "anonymous\0" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "anonymous\0" followed by IDL get 
 PASS link.crossOrigin: IDL set to "nonymous" should not throw 
-FAIL link.crossOrigin: IDL set to "nonymous" followed by getAttribute() assert_equals: expected "nonymous" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "nonymous" followed by IDL get assert_equals: expected "anonymous" but got "nonymous"
+PASS link.crossOrigin: IDL set to "nonymous" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "nonymous" followed by IDL get 
 PASS link.crossOrigin: IDL set to "ANONYMOUS" should not throw 
-FAIL link.crossOrigin: IDL set to "ANONYMOUS" followed by getAttribute() assert_equals: expected "ANONYMOUS" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "ANONYMOUS" followed by IDL get assert_equals: expected "anonymous" but got "ANONYMOUS"
+PASS link.crossOrigin: IDL set to "ANONYMOUS" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "ANONYMOUS" followed by IDL get 
 PASS link.crossOrigin: IDL set to "use-credentials" should not throw 
-FAIL link.crossOrigin: IDL set to "use-credentials" followed by getAttribute() assert_equals: expected "use-credentials" but got "USE-CREDENTIALS"
+PASS link.crossOrigin: IDL set to "use-credentials" followed by getAttribute() 
 PASS link.crossOrigin: IDL set to "use-credentials" followed by IDL get 
 PASS link.crossOrigin: IDL set to "xuse-credentials" should not throw 
-FAIL link.crossOrigin: IDL set to "xuse-credentials" followed by getAttribute() assert_equals: expected "xuse-credentials" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "xuse-credentials" followed by IDL get assert_equals: expected "anonymous" but got "xuse-credentials"
+PASS link.crossOrigin: IDL set to "xuse-credentials" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "xuse-credentials" followed by IDL get 
 PASS link.crossOrigin: IDL set to "use-credentials\0" should not throw 
-FAIL link.crossOrigin: IDL set to "use-credentials\0" followed by getAttribute() assert_equals: expected "use-credentials\0" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "use-credentials\0" followed by IDL get assert_equals: expected "anonymous" but got "use-credentials\0"
+PASS link.crossOrigin: IDL set to "use-credentials\0" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "use-credentials\0" followed by IDL get 
 PASS link.crossOrigin: IDL set to "se-credentials" should not throw 
-FAIL link.crossOrigin: IDL set to "se-credentials" followed by getAttribute() assert_equals: expected "se-credentials" but got "USE-CREDENTIALS"
-FAIL link.crossOrigin: IDL set to "se-credentials" followed by IDL get assert_equals: expected "anonymous" but got "se-credentials"
+PASS link.crossOrigin: IDL set to "se-credentials" followed by getAttribute() 
+PASS link.crossOrigin: IDL set to "se-credentials" followed by IDL get 
 PASS link.crossOrigin: IDL set to "USE-CREDENTIALS" should not throw 
 PASS link.crossOrigin: IDL set to "USE-CREDENTIALS" followed by getAttribute() 
-FAIL link.crossOrigin: IDL set to "USE-CREDENTIALS" followed by IDL get assert_equals: expected "use-credentials" but got "USE-CREDENTIALS"
+PASS link.crossOrigin: IDL set to "USE-CREDENTIALS" followed by IDL get 
 PASS link.rel: typeof IDL attribute 
 PASS link.rel: IDL get with DOM attribute unset 
 PASS link.rel: setAttribute() to "" followed by getAttribute() 
index 923d0ce..8d2ac9b 100644 (file)
@@ -1366,7 +1366,7 @@ PASS HTMLLinkElement interface object name
 PASS HTMLLinkElement interface: existence and properties of interface prototype object 
 PASS HTMLLinkElement interface: existence and properties of interface prototype object's "constructor" property 
 PASS HTMLLinkElement interface: attribute href 
-FAIL HTMLLinkElement interface: attribute crossOrigin assert_true: The prototype object must have a property "crossOrigin" expected true got false
+PASS HTMLLinkElement interface: attribute crossOrigin 
 PASS HTMLLinkElement interface: attribute rel 
 PASS HTMLLinkElement interface: attribute relList 
 PASS HTMLLinkElement interface: attribute media 
@@ -1379,7 +1379,7 @@ PASS HTMLLinkElement interface: attribute target
 PASS HTMLLinkElement must be primary interface of document.createElement("link") 
 PASS Stringification of document.createElement("link") 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "href" with the proper type (0) 
-FAIL HTMLLinkElement interface: document.createElement("link") must inherit property "crossOrigin" with the proper type (1) assert_inherits: property "crossOrigin" not found in prototype chain
+PASS HTMLLinkElement interface: document.createElement("link") must inherit property "crossOrigin" with the proper type (1) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "rel" with the proper type (2) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "relList" with the proper type (3) 
 PASS HTMLLinkElement interface: document.createElement("link") must inherit property "media" with the proper type (4) 
index f99863d..3256e15 100644 (file)
@@ -1,3 +1,56 @@
+2016-04-17  Yoav Weiss  <yoav@yoav.ws>
+
+        Initial Link preload support
+        https://bugs.webkit.org/show_bug.cgi?id=156334
+
+        Added basic `<link rel=preload>` functionality that enables preloading
+        of resources according to their type.
+
+        Reviewed by Darin Adler.
+
+        Tests: http/tests/preload/download_resources.html
+               http/tests/preload/dynamic_adding_preload.html
+               http/tests/preload/dynamic_remove_preload_href.html
+               http/tests/preload/dynamic_removing_preload.html
+
+        * bindings/generic/RuntimeEnabledFeatures.cpp: Added a runtime flag for the feature.
+        (WebCore::RuntimeEnabledFeatures::RuntimeEnabledFeatures):
+        * bindings/generic/RuntimeEnabledFeatures.h: Added a runtime flag for the feature.
+        (WebCore::RuntimeEnabledFeatures::setLinkPreloadEnabled):
+        (WebCore::RuntimeEnabledFeatures::linkPreloadEnabled):
+        * html/HTMLAttributeNames.in: Added an `as` attribute.
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::process): Added `as` and `crossorigin` attribute values to the loadLink() call.
+        (WebCore::HTMLLinkElement::setCrossOrigin): Setter for crossOrigin.
+        (WebCore::HTMLLinkElement::crossOrigin): Getter for crossOrigin.
+        * html/HTMLLinkElement.idl: Added `as` and `crossorigin` to HTMLLinkElement.
+        * html/HTMLLinkElement.h: Added getter and setter for crossorigin.
+        * html/LinkRelAttribute.cpp:
+        (WebCore::LinkRelAttribute::LinkRelAttribute): Added "preload" as a potential value.
+        * html/LinkRelAttribute.h: Added isLinkPreload.
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::resourceTypeFromAsAttribute): Translates an `as` value into a resource type.
+        (WebCore::preloadIfNeeded): Triggers a resource preload when link element is a preload one.
+        (WebCore::LinkLoader::loadLink): Added a call to preloadIfNeeded.
+        * loader/LinkLoader.h: Added signatures.
+        * loader/ResourceLoadInfo.cpp:
+        (WebCore::toResourceType): Added LinkPreload as a possible CachedResource::type.
+        * loader/SubresourceLoader.cpp:
+        (WebCore::logResourceLoaded): Added LinkPreload as a possible CachedResource::type.
+        * loader/cache/CachedResource.cpp: Turned defaultPriorityForResourceType into a static member, as it's now also called from LinkLoader.
+        (WebCore::CachedResource::defaultPriorityForResourceType): Added LinkPreload as a possible CachedResource::type, giving it low priority.
+        (WebCore::defaultPriorityForResourceType): Deleted.
+        * loader/cache/CachedResource.h: Added LinkPreload as a possible CachedResource::type. Added defaultPriorityForResourceType as static.
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::contentTypeFromResourceType): Added LinkPreload as a possible CachedResource::type.
+        (WebCore::createResource): Added creation of a LinkPreload resource if needed.
+        (WebCore::CachedResourceLoader::checkInsecureContent): Added LinkPreload as a possible CachedResource::type.
+        (WebCore::CachedResourceLoader::canRequest): Added LinkPreload as a possible CachedResource::type.
+        * testing/Internals.cpp: Added function to turn on the link preload feature.
+        (WebCore::setLinkPreloadSupport):
+        * testing/Internals.idl: Added function to turn on the link preload feature.
+        * testing/Internals.h: Added function signature to turn on the link preload feature.
+
 2016-04-17  Conrad Shultz  <conrad_shultz@apple.com>
 
         Try (again) to fix debug builds after r199643.
index 9237340..e1e4c3e 100644 (file)
@@ -50,6 +50,7 @@ RuntimeEnabledFeatures::RuntimeEnabledFeatures()
     , m_isTouchEnabled(true)
     , m_isDeviceMotionEnabled(true)
     , m_isDeviceOrientationEnabled(true)
+    , m_isLinkPreloadEnabled(false)
     , m_isCSSShapesEnabled(true)
     , m_isCSSRegionsEnabled(false)
     , m_isCSSCompositingEnabled(false)
index 041ce40..d524fce 100644 (file)
@@ -123,6 +123,9 @@ public:
     bool deviceOrientationEventEnabled() const { return m_isDeviceOrientationEnabled; }
     bool ondeviceorientationEnabled() const { return m_isDeviceOrientationEnabled; }
 
+    void setLinkPreloadEnabled(bool isEnabled) { m_isLinkPreloadEnabled = isEnabled; }
+    bool linkPreloadEnabled() const { return m_isLinkPreloadEnabled; }
+
 #if ENABLE(JAVASCRIPT_I18N_API)
     bool javaScriptI18NAPIEnabled() const;
     void setJavaScriptI18NAPIEnabled(bool isEnabled) { m_isJavaScriptI18NAPIEnabled = isEnabled; }
@@ -248,6 +251,7 @@ private:
     bool m_isTouchEnabled;
     bool m_isDeviceMotionEnabled;
     bool m_isDeviceOrientationEnabled;
+    bool m_isLinkPreloadEnabled;
     bool m_isCSSShapesEnabled;
     bool m_isCSSRegionsEnabled;
     bool m_isCSSCompositingEnabled;
index 84e8119..91f7ae9 100644 (file)
@@ -59,6 +59,7 @@ aria-valuemax
 aria-valuemin
 aria-valuenow
 aria-valuetext
+as
 async
 autocomplete
 autofocus
index d480dac..2b1ea63 100644 (file)
@@ -194,6 +194,16 @@ bool HTMLLinkElement::shouldLoadLink()
     return true;
 }
 
+void HTMLLinkElement::setCrossOrigin(const AtomicString& value)
+{
+    setAttributeWithoutSynchronization(crossoriginAttr, value);
+}
+
+String HTMLLinkElement::crossOrigin() const
+{
+    return parseCORSSettingsAttribute(fastGetAttribute(crossoriginAttr));
+}
+
 void HTMLLinkElement::process()
 {
     if (!inDocument() || m_isInShadowTree) {
@@ -203,7 +213,7 @@ void HTMLLinkElement::process()
 
     URL url = getNonEmptyURLAttribute(hrefAttr);
 
-    if (!m_linkLoader.loadLink(m_relAttribute, url, document()))
+    if (!m_linkLoader.loadLink(m_relAttribute, url, fastGetAttribute(asAttr), fastGetAttribute(crossoriginAttr), document()))
         return;
 
     bool treatAsStyleSheet = m_relAttribute.isStyleSheet
index ab37744..177350d 100644 (file)
@@ -67,6 +67,9 @@ public:
     bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript; }
     DOMTokenList& sizes();
 
+    void setCrossOrigin(const AtomicString&);
+    String crossOrigin() const;
+
     void dispatchPendingEvent(LinkEventSender*);
     static void dispatchPendingLoadEvents();
 
index 853f79a..3882179 100644 (file)
@@ -35,6 +35,8 @@
 #endif
     [Reflect] attribute DOMString target;
     [Reflect] attribute DOMString type;
+    [Reflect] attribute DOMString as;
+    attribute DOMString? crossOrigin;
 
     // DOM Level 2 Style
     readonly attribute StyleSheet sheet;
index d462156..e87d493 100644 (file)
@@ -32,6 +32,7 @@
 #include "config.h"
 #include "LinkRelAttribute.h"
 
+#include "RuntimeEnabledFeatures.h"
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -54,6 +55,8 @@ LinkRelAttribute::LinkRelAttribute(const String& rel)
 #endif
     else if (equalLettersIgnoringASCIICase(rel, "dns-prefetch"))
         isDNSPrefetch = true;
+    else if (RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled() && equalLettersIgnoringASCIICase(rel, "preload"))
+        isLinkPreload = true;
     else if (equalLettersIgnoringASCIICase(rel, "alternate stylesheet") || equalLettersIgnoringASCIICase(rel, "stylesheet alternate")) {
         isStyleSheet = true;
         isAlternate = true;
index 8635814..8df8be7 100644 (file)
@@ -42,6 +42,7 @@ struct LinkRelAttribute {
     IconType iconType { InvalidIcon };
     bool isAlternate { false };
     bool isDNSPrefetch { false };
+    bool isLinkPreload { false };
 #if ENABLE(LINK_PREFETCH)
     bool isLinkPrefetch { false };
     bool isLinkSubresource { false };
index f69e26e..60de49b 100644 (file)
 #include "CachedResourceLoader.h"
 #include "CachedResourceRequest.h"
 #include "ContainerNode.h"
+#include "CrossOriginAccessControl.h"
 #include "Document.h"
 #include "Frame.h"
 #include "FrameLoaderClient.h"
 #include "FrameView.h"
 #include "LinkRelAttribute.h"
+#include "RuntimeEnabledFeatures.h"
 #include "Settings.h"
 #include "StyleResolver.h"
 
@@ -83,7 +85,56 @@ void LinkLoader::notifyFinished(CachedResource* resource)
     m_cachedLinkResource = nullptr;
 }
 
-bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href, Document& document)
+Optional<CachedResource::Type> LinkLoader::resourceTypeFromAsAttribute(const String& as)
+{
+    if (as.isEmpty())
+        return CachedResource::LinkPreload;
+    if (equalLettersIgnoringASCIICase(as, "image"))
+        return CachedResource::ImageResource;
+    if (equalLettersIgnoringASCIICase(as, "script"))
+        return CachedResource::Script;
+    if (equalLettersIgnoringASCIICase(as, "style"))
+        return CachedResource::CSSStyleSheet;
+    if (equalLettersIgnoringASCIICase(as, "media"))
+        return CachedResource::MediaResource;
+    if (equalLettersIgnoringASCIICase(as, "font"))
+        return CachedResource::FontResource;
+#if ENABLE(VIDEO_TRACK)
+    if (equalLettersIgnoringASCIICase(as, "track"))
+        return CachedResource::TextTrackResource;
+#endif
+    return Nullopt;
+}
+
+static void preloadIfNeeded(const LinkRelAttribute& relAttribute, const URL& href, Document& document, const String& as, const String& crossOriginMode)
+{
+    if (!document.loader() || !relAttribute.isLinkPreload)
+        return;
+
+    ASSERT(RuntimeEnabledFeatures::sharedFeatures().linkPreloadEnabled());
+    if (!href.isValid()) {
+        document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, String("<link rel=preload> has an invalid `href` value"));
+        return;
+    }
+    auto type = LinkLoader::resourceTypeFromAsAttribute(as);
+    if (!type) {
+        document.addConsoleMessage(MessageSource::Other, MessageLevel::Error, String("<link rel=preload> must have a valid `as` value"));
+        return;
+    }
+
+    ResourceRequest resourceRequest(document.completeURL(href));
+    CachedResourceRequest linkRequest(resourceRequest, CachedResource::defaultPriorityForResourceType(type.value()));
+    linkRequest.setInitiator("link");
+
+    if (!crossOriginMode.isNull()) {
+        StoredCredentials allowCredentials = equalLettersIgnoringASCIICase(crossOriginMode, "use-credentials") ? AllowStoredCredentials : DoNotAllowStoredCredentials;
+        updateRequestForAccessControl(linkRequest.mutableResourceRequest(), document.securityOrigin(), allowCredentials);
+    }
+    linkRequest.setForPreload(true);
+    document.cachedResourceLoader().preload(type.value(), linkRequest, emptyString());
+}
+
+bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href, const String& as, const String& crossOrigin, Document& document)
 {
     // We'll record this URL per document, even if we later only use it in top level frames
     if (relAttribute.iconType != InvalidIcon && href.isValid() && !href.isEmpty()) {
@@ -101,6 +152,9 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href,
             document.frame()->loader().client().prefetchDNS(href.host());
     }
 
+    if (m_client.shouldLoadLink())
+        preloadIfNeeded(relAttribute, href, document, as, crossOrigin);
+
 #if ENABLE(LINK_PREFETCH)
     if ((relAttribute.isLinkPrefetch || relAttribute.isLinkSubresource) && href.isValid() && document.frame()) {
         if (!m_client.shouldLoadLink())
index e345b4e..eb05121 100644 (file)
@@ -32,6 +32,7 @@
 #ifndef LinkLoader_h
 #define LinkLoader_h
 
+#include "CachedResource.h"
 #include "CachedResourceClient.h"
 #include "CachedResourceHandle.h"
 #include "LinkLoaderClient.h"
@@ -49,7 +50,8 @@ public:
     explicit LinkLoader(LinkLoaderClient&);
     virtual ~LinkLoader();
 
-    bool loadLink(const LinkRelAttribute&, const URL&, Document&);
+    bool loadLink(const LinkRelAttribute&, const URL&, const String& as, const String& crossOrigin, Document&);
+    static Optional<CachedResource::Type> resourceTypeFromAsAttribute(const String& as);
 
 private:
     void notifyFinished(CachedResource*) override;
index a8beca5..8348b64 100644 (file)
@@ -56,6 +56,7 @@ ResourceType toResourceType(CachedResource::Type type)
         return ResourceType::Font;
 
     case CachedResource::MediaResource:
+    case CachedResource::LinkPreload:
     case CachedResource::RawResource:
         return ResourceType::Raw;
 
index 53f1e74..aff286e 100644 (file)
@@ -371,6 +371,7 @@ static void logResourceLoaded(Frame* frame, CachedResource::Type type)
     case CachedResource::SVGDocumentResource:
         resourceType = DiagnosticLoggingKeys::svgDocumentKey();
         break;
+    case CachedResource::LinkPreload:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource:
index 671c75b..6676cbe 100644 (file)
@@ -63,7 +63,7 @@ using namespace WTF;
 
 namespace WebCore {
 
-static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type type)
+ResourceLoadPriority CachedResource::defaultPriorityForResourceType(Type type)
 {
     switch (type) {
     case CachedResource::MainResource:
@@ -86,6 +86,8 @@ static ResourceLoadPriority defaultPriorityForResourceType(CachedResource::Type
 #endif
     case CachedResource::SVGDocumentResource:
         return ResourceLoadPriority::Low;
+    case CachedResource::LinkPreload:
+        return ResourceLoadPriority::Low;
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
         return ResourceLoadPriority::VeryLow;
index e300192..8f91ea2 100644 (file)
@@ -75,6 +75,7 @@ public:
 #if ENABLE(XSLT)
         , XSLStyleSheet
 #endif
+        , LinkPreload
 #if ENABLE(LINK_PREFETCH)
         , LinkPrefetch
         , LinkSubresource
@@ -263,6 +264,7 @@ public:
 #endif
 
     unsigned long identifierForLoadWithoutResourceLoader() const { return m_identifierForLoadWithoutResourceLoader; }
+    static ResourceLoadPriority defaultPriorityForResourceType(Type);
 
 protected:
     void setEncodedSize(unsigned);
index 1fe0efa..235e8a3 100644 (file)
@@ -108,6 +108,8 @@ static CachedResource* createResource(CachedResource::Type type, ResourceRequest
     case CachedResource::XSLStyleSheet:
         return new CachedXSLStyleSheet(request, sessionID);
 #endif
+    case CachedResource::LinkPreload:
+        return new CachedResource(request, CachedResource::LinkPreload, sessionID);
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
         return new CachedResource(request, CachedResource::LinkPrefetch, sessionID);
@@ -313,6 +315,7 @@ static MixedContentChecker::ContentType contentTypeFromResourceType(CachedResour
         return MixedContentChecker::ContentType::Active;
 #endif
 
+    case CachedResource::LinkPreload:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource:
@@ -353,7 +356,8 @@ bool CachedResourceLoader::checkInsecureContent(CachedResource::Type type, const
 #if ENABLE(SVG_FONTS)
     case CachedResource::SVGFontResource:
 #endif
-    case CachedResource::FontResource: {
+    case CachedResource::FontResource:
+    case CachedResource::LinkPreload: {
         // These resources can corrupt only the frame's pixels.
         if (Frame* f = frame()) {
             Frame& topFrame = f->tree().top();
@@ -399,6 +403,7 @@ bool CachedResourceLoader::canRequest(CachedResource::Type type, const URL& url,
     case CachedResource::MediaResource:
     case CachedResource::FontResource:
     case CachedResource::RawResource:
+    case CachedResource::LinkPreload:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource:
@@ -454,6 +459,8 @@ bool CachedResourceLoader::canRequest(CachedResource::Type type, const URL& url,
     }
     case CachedResource::MainResource:
     case CachedResource::RawResource:
+    // FIXME: Preload should be subject to connect-src.
+    case CachedResource::LinkPreload:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource:
index 0390806..72bbb93 100644 (file)
@@ -3328,4 +3328,9 @@ void Internals::setViewportForceAlwaysUserScalable(bool scalable)
 #endif
 }
 
+void Internals::setLinkPreloadSupport(bool enable)
+{
+    RuntimeEnabledFeatures::sharedFeatures().setLinkPreloadEnabled(enable);
+}
+
 }
index bdd3401..e9009ef 100644 (file)
@@ -471,6 +471,7 @@ public:
     String composedTreeAsText(Node&);
     
     void setViewportForceAlwaysUserScalable(bool);
+    void setLinkPreloadSupport(bool);
 
 private:
     explicit Internals(Document&);
index b85de45..f78d567 100644 (file)
@@ -445,4 +445,5 @@ enum AutoFillButtonType {
     DOMString composedTreeAsText(Node parent);
 
     void setViewportForceAlwaysUserScalable(boolean scalable);
+    void setLinkPreloadSupport(boolean scalable);
 };
index f682aaa..e5f4879 100644 (file)
@@ -1,3 +1,13 @@
+2016-04-17  Yoav Weiss  <yoav@yoav.ws>
+
+        Initial Link preload support
+        https://bugs.webkit.org/show_bug.cgi?id=156334
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        (WebKit::maximumBufferingTime): Added LinkPreload as a possible CachedResource::type.
+
 2016-04-17  Chris Dumez  <cdumez@apple.com>
 
         [WK2][iOS] Do not dlopen() QuickLook in the NetworkProcess
index 3b4dda4..f67ff80 100644 (file)
@@ -110,6 +110,7 @@ static std::chrono::milliseconds maximumBufferingTime(CachedResource* resource)
     case CachedResource::MainResource:
     case CachedResource::RawResource:
     case CachedResource::SVGDocumentResource:
+    case CachedResource::LinkPreload:
 #if ENABLE(LINK_PREFETCH)
     case CachedResource::LinkPrefetch:
     case CachedResource::LinkSubresource: