Title: [225996] trunk
Revision
225996
Author
commit-qu...@webkit.org
Date
2017-12-16 01:26:39 -0800 (Sat, 16 Dec 2017)

Log Message

Service worker script fetch request should set the Service-Worker header
https://bugs.webkit.org/show_bug.cgi?id=180889

Patch by Youenn Fablet <you...@apple.com> on 2017-12-16
Reviewed by Chris Dumez.

Source/WebCore:

Test: http/wpt/service-workers/check-service-worker-header.https.html

Update WorkerScriptLoader to take a request instead of an URL.
Updates Worker implementation and use it in ServiceWorkerJob to set the missing request header.

* workers/Worker.cpp:
(WebCore::Worker::create):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadAsynchronously):
* workers/WorkerScriptLoader.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::fetchScriptWithContext):

LayoutTests:

* http/wpt/service-workers/check-service-worker-header.https-expected.txt: Added.
* http/wpt/service-workers/check-service-worker-header.https.html: Added.
* http/wpt/service-workers/check-service-worker-header.py: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225995 => 225996)


--- trunk/LayoutTests/ChangeLog	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/LayoutTests/ChangeLog	2017-12-16 09:26:39 UTC (rev 225996)
@@ -1,3 +1,14 @@
+2017-12-16  Youenn Fablet  <you...@apple.com>
+
+        Service worker script fetch request should set the Service-Worker header
+        https://bugs.webkit.org/show_bug.cgi?id=180889
+
+        Reviewed by Chris Dumez.
+
+        * http/wpt/service-workers/check-service-worker-header.https-expected.txt: Added.
+        * http/wpt/service-workers/check-service-worker-header.https.html: Added.
+        * http/wpt/service-workers/check-service-worker-header.py: Added.
+
 2017-12-15  Youenn Fablet  <you...@apple.com>
 
         WK1 webrtc/datachannel bufferedAmount tests might time out

Added: trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https-expected.txt (0 => 225996)


--- trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https-expected.txt	2017-12-16 09:26:39 UTC (rev 225996)
@@ -0,0 +1,3 @@
+
+PASS Testing loading service worker script with the correct Service-Worker header 
+

Added: trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https.html (0 => 225996)


--- trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.https.html	2017-12-16 09:26:39 UTC (rev 225996)
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<title>Service Worker Fetch Event</title>
+<script src=""
+<script src=""
+<script>
+promise_test(async (test) => {
+    return navigator.serviceWorker.register("check-service-worker-header.py", { scope: "/" })
+}, "Testing loading service worker script with the correct Service-Worker header");
+</script>

Added: trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.py (0 => 225996)


--- trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.py	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/service-workers/check-service-worker-header.py	2017-12-16 09:26:39 UTC (rev 225996)
@@ -0,0 +1,5 @@
+def main(request, response):
+
+    service_worker_header_value = request.headers.get("Service-Worker")
+    code = 200 if service_worker_header_value == "script" else 404
+    return code, [("Content-Type", "application/_javascript_")], ""

Modified: trunk/Source/WebCore/ChangeLog (225995 => 225996)


--- trunk/Source/WebCore/ChangeLog	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/Source/WebCore/ChangeLog	2017-12-16 09:26:39 UTC (rev 225996)
@@ -1,3 +1,23 @@
+2017-12-16  Youenn Fablet  <you...@apple.com>
+
+        Service worker script fetch request should set the Service-Worker header
+        https://bugs.webkit.org/show_bug.cgi?id=180889
+
+        Reviewed by Chris Dumez.
+
+        Test: http/wpt/service-workers/check-service-worker-header.https.html
+
+        Update WorkerScriptLoader to take a request instead of an URL.
+        Updates Worker implementation and use it in ServiceWorkerJob to set the missing request header.
+
+        * workers/Worker.cpp:
+        (WebCore::Worker::create):
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::loadAsynchronously):
+        * workers/WorkerScriptLoader.h:
+        * workers/service/ServiceWorkerJob.cpp:
+        (WebCore::ServiceWorkerJob::fetchScriptWithContext):
+
 2017-12-15  Ryan Haddad  <ryanhad...@apple.com>
 
         Unreviewed, rolling out r225969.

Modified: trunk/Source/WebCore/workers/Worker.cpp (225995 => 225996)


--- trunk/Source/WebCore/workers/Worker.cpp	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/Source/WebCore/workers/Worker.cpp	2017-12-16 09:26:39 UTC (rev 225996)
@@ -98,7 +98,10 @@
 
     worker->m_scriptLoader = WorkerScriptLoader::create();
     auto contentSecurityPolicyEnforcement = shouldBypassMainWorldContentSecurityPolicy ? ContentSecurityPolicyEnforcement::DoNotEnforce : ContentSecurityPolicyEnforcement::EnforceChildSrcDirective;
-    worker->m_scriptLoader->loadAsynchronously(&context, scriptURL.releaseReturnValue(), FetchOptions::Mode::SameOrigin, FetchOptions::Cache::Default, contentSecurityPolicyEnforcement, worker->m_identifier, worker.ptr());
+
+    ResourceRequest request { scriptURL.releaseReturnValue() };
+    request.setInitiatorIdentifier(worker->m_identifier);
+    worker->m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, FetchOptions::Cache::Default, contentSecurityPolicyEnforcement, worker);
     return WTFMove(worker);
 }
 

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (225995 => 225996)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-12-16 09:26:39 UTC (rev 225996)
@@ -73,15 +73,14 @@
     WorkerThreadableLoader::loadResourceSynchronously(workerGlobalScope, WTFMove(*request), *this, options);
 }
 
-void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext* scriptExecutionContext, const URL& url, FetchOptions::Mode mode, FetchOptions::Cache cachePolicy, ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement, const String& initiatorIdentifier, WorkerScriptLoaderClient* client)
+void WorkerScriptLoader::loadAsynchronously(ScriptExecutionContext& scriptExecutionContext, ResourceRequest&& scriptRequest, FetchOptions::Mode mode, FetchOptions::Cache cachePolicy, ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement, WorkerScriptLoaderClient& client)
 {
-    ASSERT(client);
-    ASSERT(scriptExecutionContext);
+    m_client = &client;
+    m_url = scriptRequest.url();
 
-    m_client = client;
-    m_url = url;
+    ASSERT(scriptRequest.httpMethod() == "GET");
 
-    std::unique_ptr<ResourceRequest> request(createResourceRequest(initiatorIdentifier));
+    auto request = std::make_unique<ResourceRequest>(WTFMove(scriptRequest));
     if (!request)
         return;
 
@@ -97,12 +96,12 @@
     options.contentSecurityPolicyEnforcement = contentSecurityPolicyEnforcement;
 #if ENABLE(SERVICE_WORKER)
     options.serviceWorkersMode = m_client->isServiceWorkerClient() ? ServiceWorkersMode::None : ServiceWorkersMode::All;
-    if (auto* activeServiceWorker = scriptExecutionContext->activeServiceWorker())
+    if (auto* activeServiceWorker = scriptExecutionContext.activeServiceWorker())
         options.serviceWorkerIdentifier = activeServiceWorker->identifier();
 #endif
     // During create, callbacks may happen which remove the last reference to this object.
     Ref<WorkerScriptLoader> protectedThis(*this);
-    m_threadableLoader = ThreadableLoader::create(*scriptExecutionContext, *this, WTFMove(*request), options);
+    m_threadableLoader = ThreadableLoader::create(scriptExecutionContext, *this, WTFMove(*request), options);
 }
 
 const URL& WorkerScriptLoader::responseURL() const

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.h (225995 => 225996)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.h	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.h	2017-12-16 09:26:39 UTC (rev 225996)
@@ -53,7 +53,7 @@
     }
 
     void loadSynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier);
-    void loadAsynchronously(ScriptExecutionContext*, const URL&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, const String& initiatorIdentifier, WorkerScriptLoaderClient*);
+    void loadAsynchronously(ScriptExecutionContext&, ResourceRequest&&, FetchOptions::Mode, FetchOptions::Cache, ContentSecurityPolicyEnforcement, WorkerScriptLoaderClient&);
 
     void notifyError();
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp (225995 => 225996)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-12-16 07:22:28 UTC (rev 225995)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2017-12-16 09:26:39 UTC (rev 225996)
@@ -92,7 +92,12 @@
 
     // FIXME: WorkerScriptLoader is the wrong loader class to use here, but there's nothing else better right now.
     m_scriptLoader = WorkerScriptLoader::create();
-    m_scriptLoader->loadAsynchronously(&context, m_jobData.scriptURL, FetchOptions::Mode::SameOrigin, cachePolicy, ContentSecurityPolicyEnforcement::DoNotEnforce, "serviceWorkerScriptLoad:", this);
+
+    ResourceRequest request { m_jobData.scriptURL };
+    request.setInitiatorIdentifier("serviceWorkerScriptLoad:");
+    request.addHTTPHeaderField(ASCIILiteral("Service-Worker"), ASCIILiteral("script"));
+
+    m_scriptLoader->loadAsynchronously(context, WTFMove(request), FetchOptions::Mode::SameOrigin, cachePolicy, ContentSecurityPolicyEnforcement::DoNotEnforce, *this);
 }
 
 void ServiceWorkerJob::didReceiveResponse(unsigned long, const ResourceResponse& response)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to