Title: [268872] trunk
Revision
268872
Author
[email protected]
Date
2020-10-22 11:06:44 -0700 (Thu, 22 Oct 2020)

Log Message

Introduce worklet destinations and allow to fetch modules with CORS based on destination
https://bugs.webkit.org/show_bug.cgi?id=218019
<rdar://problem/70526201>

Reviewed by Chris Dumez.

Source/WebCore:

Add support for audioworklet and paintworklet fetch destinations.
In case of those destinations, use cors mode instead of same-origin mode when fetching worklet top level module.

Test: http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html

* Modules/fetch/FetchRequest.idl:
* loader/FetchOptions.h:
(WebCore::isScriptLikeDestination):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadAsynchronously):
* worklets/WorkletGlobalScope.cpp:
(WebCore::WorkletGlobalScope::processNextScriptFetchJobIfNeeded):

Source/WebKit:

Add support to new fetch destinations in enumerations.

* NetworkProcess/NetworkLoadChecker.cpp:
(WebKit::NetworkLoadChecker::isAllowedByContentSecurityPolicy):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::resourceLoadInfo):

LayoutTests:

* http/wpt/webaudio/audioworklet-addModule-cors.sub.https-expected.txt: Added.
* http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html: Added.
* http/wpt/webaudio/resources/dummy-worklet.py: Added.
(main):
(DummyProcessor):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (268871 => 268872)


--- trunk/LayoutTests/ChangeLog	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/LayoutTests/ChangeLog	2020-10-22 18:06:44 UTC (rev 268872)
@@ -1,3 +1,17 @@
+2020-10-22  Youenn Fablet  <[email protected]>
+
+        Introduce worklet destinations and allow to fetch modules with CORS based on destination
+        https://bugs.webkit.org/show_bug.cgi?id=218019
+        <rdar://problem/70526201>
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/webaudio/audioworklet-addModule-cors.sub.https-expected.txt: Added.
+        * http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html: Added.
+        * http/wpt/webaudio/resources/dummy-worklet.py: Added.
+        (main):
+        (DummyProcessor):
+
 2020-10-22  Aditya Keerthi  <[email protected]>
 
         [iOS] Prevent presentation of input peripherals when focusing form controls with a validation message

Added: trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https-expected.txt (0 => 268872)


--- trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https-expected.txt	2020-10-22 18:06:44 UTC (rev 268872)
@@ -0,0 +1,6 @@
+CONSOLE MESSAGE: Origin https://localhost:9443 is not allowed by Access-Control-Allow-Origin.
+
+PASS same origin works
+PASS cross origin fails without CORS headers
+PASS cross origin passes with CORS headers
+

Added: trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html (0 => 268872)


--- trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html	2020-10-22 18:06:44 UTC (rev 268872)
@@ -0,0 +1,29 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>worklet.addModule and CORS</title>
+        <script src=""
+        <script src=""
+    </head>
+    <body>
+<script>
+
+promise_test(() => {
+    const context = new OfflineAudioContext(2, 100, 44100);
+    return context.audioWorklet.addModule("https://{{host}}:{{ports[https][0]}}/WebKit/webaudio/resources/dummy-worklet.py");
+}, "same origin works");
+
+promise_test((t) => {
+    const context = new OfflineAudioContext(2, 100, 44100);
+    return promise_rejects_dom(t, "NetworkError", context.audioWorklet.addModule("https://{{hosts[alt][]}}:{{ports[https][0]}}/WebKit/webaudio/resources/dummy-worklet.py"));
+}, "cross origin fails without CORS headers");
+
+promise_test((t) => {
+    const context = new OfflineAudioContext(2, 100, 44100);
+    return context.audioWorklet.addModule("https://{{hosts[alt][]}}:{{ports[https][0]}}/WebKit/webaudio/resources/dummy-worklet.py?useCORS");
+}, "cross origin passes with CORS headers");
+
+</script>
+</body>
+</html>

Added: trunk/LayoutTests/http/wpt/webaudio/resources/dummy-worklet.py (0 => 268872)


--- trunk/LayoutTests/http/wpt/webaudio/resources/dummy-worklet.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/webaudio/resources/dummy-worklet.py	2020-10-22 18:06:44 UTC (rev 268872)
@@ -0,0 +1,20 @@
+def main(request, response):
+    response.status = (200, "OK")
+    response.headers.set("Content-Type", 'text/_javascript_')
+    response.headers.set("Cache-Control", "max-age=0");
+
+    if "useCORS" in request.GET:
+        response.headers.set("Access-Control-Allow-Origin", "*")
+
+    return """
+class DummyProcessor extends AudioWorkletProcessor {
+  constructor(options) {
+    super();
+  }
+
+  process(inputs, outputs) {
+    return false;
+  }
+}
+
+registerProcessor('dummy-processor', DummyProcessor);"""

Modified: trunk/Source/WebCore/ChangeLog (268871 => 268872)


--- trunk/Source/WebCore/ChangeLog	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebCore/ChangeLog	2020-10-22 18:06:44 UTC (rev 268872)
@@ -1,3 +1,24 @@
+2020-10-22  Youenn Fablet  <[email protected]>
+
+        Introduce worklet destinations and allow to fetch modules with CORS based on destination
+        https://bugs.webkit.org/show_bug.cgi?id=218019
+        <rdar://problem/70526201>
+
+        Reviewed by Chris Dumez.
+
+        Add support for audioworklet and paintworklet fetch destinations.
+        In case of those destinations, use cors mode instead of same-origin mode when fetching worklet top level module.
+
+        Test: http/wpt/webaudio/audioworklet-addModule-cors.sub.https.html
+
+        * Modules/fetch/FetchRequest.idl:
+        * loader/FetchOptions.h:
+        (WebCore::isScriptLikeDestination):
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::loadAsynchronously):
+        * worklets/WorkletGlobalScope.cpp:
+        (WebCore::WorkletGlobalScope::processNextScriptFetchJobIfNeeded):
+
 2020-10-22  Don Olmstead  <[email protected]>
 
         [WebGPU] Add Dawn implementation skeleton

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (268871 => 268872)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl	2020-10-22 18:06:44 UTC (rev 268872)
@@ -26,7 +26,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-enum FetchRequestDestination { "", "audio", "document", "embed", "font", "image", "manifest", "object", "report", "script", "serviceworker", "sharedworker", "style", "track", "video", "worker", "xslt" };
+enum FetchRequestDestination { "", "audio", "audioworklet", "document", "embed", "font", "image", "manifest", "object", "paintworklet", "report", "script", "serviceworker", "sharedworker", "style", "track", "video", "worker", "xslt" };
 
 typedef (FetchRequest or USVString) RequestInfo;
 

Modified: trunk/Source/WebCore/loader/FetchOptions.h (268871 => 268872)


--- trunk/Source/WebCore/loader/FetchOptions.h	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebCore/loader/FetchOptions.h	2020-10-22 18:06:44 UTC (rev 268872)
@@ -36,7 +36,7 @@
 namespace WebCore {
 
 struct FetchOptions {
-    enum class Destination : uint8_t { EmptyString, Audio, Document, Embed, Font, Image, Manifest, Object, Report, Script, Serviceworker, Sharedworker, Style, Track, Video, Worker, Xslt };
+    enum class Destination : uint8_t { EmptyString, Audio, Audioworklet, Document, Embed, Font, Image, Manifest, Object, Paintworklet, Report, Script, Serviceworker, Sharedworker, Style, Track, Video, Worker, Xslt };
     enum class Mode : uint8_t { Navigate, SameOrigin, NoCors, Cors };
     enum class Credentials : uint8_t { Omit, SameOrigin, Include };
     enum class Cache : uint8_t { Default, NoStore, Reload, NoCache, ForceCache, OnlyIfCached };
@@ -91,7 +91,9 @@
 
 inline bool isScriptLikeDestination(FetchOptions::Destination destination)
 {
-    return destination == FetchOptions::Destination::Script
+    return destination == FetchOptions::Destination::Audioworklet
+        || destination == FetchOptions::Destination::Paintworklet
+        || destination == FetchOptions::Destination::Script
         || destination == FetchOptions::Destination::Serviceworker
         || destination == FetchOptions::Destination::Worker;
 }
@@ -105,6 +107,7 @@
         WebCore::FetchOptions::Destination,
         WebCore::FetchOptions::Destination::EmptyString,
         WebCore::FetchOptions::Destination::Audio,
+        WebCore::FetchOptions::Destination::Audioworklet,
         WebCore::FetchOptions::Destination::Document,
         WebCore::FetchOptions::Destination::Embed,
         WebCore::FetchOptions::Destination::Font,
@@ -111,6 +114,7 @@
         WebCore::FetchOptions::Destination::Image,
         WebCore::FetchOptions::Destination::Manifest,
         WebCore::FetchOptions::Destination::Object,
+        WebCore::FetchOptions::Destination::Paintworklet,
         WebCore::FetchOptions::Destination::Report,
         WebCore::FetchOptions::Destination::Script,
         WebCore::FetchOptions::Destination::Serviceworker,

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (268871 => 268872)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2020-10-22 18:06:44 UTC (rev 268872)
@@ -119,11 +119,11 @@
     if (!request)
         return;
 
-    // Only used for loading worker scripts in classic mode.
-    // FIXME: We should add an option to set credential mode.
-    ASSERT(fetchOptions.mode == FetchOptions::Mode::SameOrigin);
+    // https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-single-module-script
+    ASSERT(fetchOptions.mode == FetchOptions::Mode::SameOrigin || (fetchOptions.destination != FetchOptions::Destination::Serviceworker && fetchOptions.destination != FetchOptions::Destination::Worker));
 
     ThreadableLoaderOptions options { WTFMove(fetchOptions) };
+    // FIXME: We should add an option to set credential mode.
     options.credentials = FetchOptions::Credentials::SameOrigin;
     options.sendLoadCallbacks = SendCallbackPolicy::SendCallbacks;
     options.contentSecurityPolicyEnforcement = contentSecurityPolicyEnforcement;

Modified: trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp (268871 => 268872)


--- trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp	2020-10-22 18:06:44 UTC (rev 268872)
@@ -171,11 +171,18 @@
     ResourceRequest request { scriptFetchJob.moduleURL };
 
     FetchOptions fetchOptions;
-    fetchOptions.mode = FetchOptions::Mode::SameOrigin;
+    fetchOptions.mode = FetchOptions::Mode::Cors;
     fetchOptions.cache = FetchOptions::Cache::Default;
     fetchOptions.redirect = FetchOptions::Redirect::Follow;
-    fetchOptions.destination = FetchOptions::Destination::Worker;
     fetchOptions.credentials = scriptFetchJob.credentials;
+#if ENABLE(WEB_AUDIO)
+    if (isAudioWorkletGlobalScope())
+        fetchOptions.destination = FetchOptions::Destination::Audioworklet;
+#endif
+#if ENABLE(CSS_PAINTING_API)
+    if (isPaintWorkletGlobalScope())
+        fetchOptions.destination = FetchOptions::Destination::Paintworklet;
+#endif
 
     auto contentSecurityPolicyEnforcement = shouldBypassMainWorldContentSecurityPolicy() ? ContentSecurityPolicyEnforcement::DoNotEnforce : ContentSecurityPolicyEnforcement::EnforceChildSrcDirective;
 

Modified: trunk/Source/WebKit/ChangeLog (268871 => 268872)


--- trunk/Source/WebKit/ChangeLog	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebKit/ChangeLog	2020-10-22 18:06:44 UTC (rev 268872)
@@ -1,3 +1,18 @@
+2020-10-22  Youenn Fablet  <[email protected]>
+
+        Introduce worklet destinations and allow to fetch modules with CORS based on destination
+        https://bugs.webkit.org/show_bug.cgi?id=218019
+        <rdar://problem/70526201>
+
+        Reviewed by Chris Dumez.
+
+        Add support to new fetch destinations in enumerations.
+
+        * NetworkProcess/NetworkLoadChecker.cpp:
+        (WebKit::NetworkLoadChecker::isAllowedByContentSecurityPolicy):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::NetworkResourceLoader::resourceLoadInfo):
+
 2020-10-22  Nitzan Uziely  <[email protected]>
 
         Elements in Shadow DOM are wrongly marked as stale by the WebDriver

Modified: trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp (268871 => 268872)


--- trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp	2020-10-22 18:06:44 UTC (rev 268872)
@@ -308,6 +308,8 @@
 
     auto redirectResponseReceived = isRedirected() ? ContentSecurityPolicy::RedirectResponseReceived::Yes : ContentSecurityPolicy::RedirectResponseReceived::No;
     switch (m_options.destination) {
+    case FetchOptions::Destination::Audioworklet:
+    case FetchOptions::Destination::Paintworklet:
     case FetchOptions::Destination::Worker:
     case FetchOptions::Destination::Serviceworker:
     case FetchOptions::Destination::Sharedworker:

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (268871 => 268872)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2020-10-22 17:45:53 UTC (rev 268871)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2020-10-22 18:06:44 UTC (rev 268872)
@@ -380,6 +380,8 @@
             return ResourceLoadInfo::Type::Other;
         case WebCore::FetchOptions::Destination::Audio:
             return ResourceLoadInfo::Type::Media;
+        case WebCore::FetchOptions::Destination::Audioworklet:
+            return ResourceLoadInfo::Type::Other;
         case WebCore::FetchOptions::Destination::Document:
             return ResourceLoadInfo::Type::Document;
         case WebCore::FetchOptions::Destination::Embed:
@@ -392,6 +394,8 @@
             return ResourceLoadInfo::Type::ApplicationManifest;
         case WebCore::FetchOptions::Destination::Object:
             return ResourceLoadInfo::Type::Object;
+        case WebCore::FetchOptions::Destination::Paintworklet:
+            return ResourceLoadInfo::Type::Other;
         case WebCore::FetchOptions::Destination::Report:
             return ResourceLoadInfo::Type::CSPReport;
         case WebCore::FetchOptions::Destination::Script:
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to