Title: [289483] trunk
Revision
289483
Author
cdu...@apple.com
Date
2022-02-09 10:30:28 -0800 (Wed, 09 Feb 2022)

Log Message

self.location.href is incorrect in shared workers in case of redirects
https://bugs.webkit.org/show_bug.cgi?id=236340

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline WPT tests that are now passing.

* web-platform-tests/workers/baseurl/alpha/importScripts-in-sharedworker-expected.txt:
* web-platform-tests/workers/baseurl/alpha/xhr-in-sharedworker-expected.txt:
* web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker-expected.txt:

Source/WebCore:

self.location.href is incorrect in shared workers in case of redirects. It should be
the URL of the last request, not the first one.

No new tests, rebaselined existing tests.

* loader/DocumentThreadableLoader.cpp:
(WebCore::DocumentThreadableLoader::redirectReceived):
* loader/ThreadableLoaderClient.h:
(WebCore::ThreadableLoaderClient::redirectReceived):
* loader/ThreadableLoaderClientWrapper.h:
(WebCore::ThreadableLoaderClientWrapper::redirectReceived):
* loader/WorkerThreadableLoader.cpp:
(WebCore::WorkerThreadableLoader::MainThreadBridge::redirectReceived):
* loader/WorkerThreadableLoader.h:
* workers/Worker.cpp:
(WebCore::Worker::notifyFinished):
* workers/WorkerFetchResult.h:
(WebCore::WorkerFetchResult::isolatedCopy const):
(WebCore::workerFetchError):
(WebCore::WorkerFetchResult::encode const):
(WebCore::WorkerFetchResult::decode):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::loadSynchronously):
(WebCore::WorkerScriptLoader::loadAsynchronously):
(WebCore::WorkerScriptLoader::redirectReceived):
(WebCore::WorkerScriptLoader::fetchResult const):
* workers/WorkerScriptLoader.h:
(WebCore::WorkerScriptLoader::script const):
(WebCore::WorkerScriptLoader::lastRequestURL const):
(WebCore::WorkerScriptLoader::script): Deleted.
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::jobFinishedLoadingScript):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::notifyFinished):
* workers/service/ServiceWorkerJobClient.h:
* workers/shared/SharedWorkerScriptLoader.cpp:
(WebCore::SharedWorkerScriptLoader::notifyFinished):
* workers/shared/context/SharedWorkerThreadProxy.cpp:
(WebCore::generateWorkerParameters):
(WebCore::SharedWorkerThreadProxy::SharedWorkerThreadProxy):
* workers/shared/context/SharedWorkerThreadProxy.h:

Source/WebKit:

self.location.href is incorrect in shared workers in case of redirects. It should be the URL of
the last request, not the first one.

* NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp:
(WebKit::ServiceWorkerSoftUpdateLoader::didFinishLoading):
* NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp:
(WebKit::WebSharedWorkerServerToContextConnection::launchSharedWorker):
* WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp:
(WebKit::WebSharedWorkerContextManagerConnection::launchSharedWorker):
* WebProcess/Storage/WebSharedWorkerContextManagerConnection.h:
* WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (289482 => 289483)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,5 +1,18 @@
 2022-02-09  Chris Dumez  <cdu...@apple.com>
 
+        self.location.href is incorrect in shared workers in case of redirects
+        https://bugs.webkit.org/show_bug.cgi?id=236340
+
+        Reviewed by Geoffrey Garen.
+
+        Rebaseline WPT tests that are now passing.
+
+        * web-platform-tests/workers/baseurl/alpha/importScripts-in-sharedworker-expected.txt:
+        * web-platform-tests/workers/baseurl/alpha/xhr-in-sharedworker-expected.txt:
+        * web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker-expected.txt:
+
+2022-02-09  Chris Dumez  <cdu...@apple.com>
+
         Exceptions are not properly reported when initializing a worker as a module
         https://bugs.webkit.org/show_bug.cgi?id=236334
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/importScripts-in-sharedworker-expected.txt (289482 => 289483)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/importScripts-in-sharedworker-expected.txt	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/importScripts-in-sharedworker-expected.txt	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,3 +1,3 @@
 
-FAIL importScripts assert_equals: expected "gamma/script.js" but got "beta/script.js"
+PASS importScripts
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/xhr-in-sharedworker-expected.txt (289482 => 289483)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/xhr-in-sharedworker-expected.txt	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/baseurl/alpha/xhr-in-sharedworker-expected.txt	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,3 +1,3 @@
 
-FAIL xhr-worker assert_equals: expected "gamma\n" but got "beta\n"
+PASS xhr-worker
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker-expected.txt (289482 => 289483)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker-expected.txt	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/workers/interfaces/WorkerGlobalScope/location/redirect-sharedworker-expected.txt	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,3 +1,3 @@
 
-FAIL redirect assert_equals: expected "/workers/interfaces/WorkerGlobalScope/location/redirect.js" but got "/common/redirect.py"
+PASS redirect
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt (289482 => 289483)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,5 +1,5 @@
 
-FAIL Referer header assert_equals: expected "Referer: http://localhost:8800/xhr/resources/workerxhr-origin-referrer.js\n" but got "Referer: http://localhost:8800/xhr/resources/redirect.py?location=workerxhr-origin-referrer.js\n"
+PASS Referer header
 FAIL Origin header assert_equals: expected "Origin: http://localhost:8800\n" but got ""
 PASS Request URL test
 

Modified: trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt (289482 => 289483)


--- trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/xhr/open-url-redirected-sharedworker-origin-expected.txt	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,5 +1,5 @@
 
-FAIL Referer header assert_equals: expected "Referer: http://localhost:8800/xhr/resources/workerxhr-origin-referrer.js\n" but got "Referer: http://localhost:8800/xhr/resources/redirect.py?location=workerxhr-origin-referrer.js\n"
+PASS Referer header
 PASS Origin header
 PASS Request URL test
 

Modified: trunk/Source/WebCore/ChangeLog (289482 => 289483)


--- trunk/Source/WebCore/ChangeLog	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/ChangeLog	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,3 +1,53 @@
+2022-02-09  Chris Dumez  <cdu...@apple.com>
+
+        self.location.href is incorrect in shared workers in case of redirects
+        https://bugs.webkit.org/show_bug.cgi?id=236340
+
+        Reviewed by Geoffrey Garen.
+
+        self.location.href is incorrect in shared workers in case of redirects. It should be
+        the URL of the last request, not the first one.
+
+        No new tests, rebaselined existing tests.
+
+        * loader/DocumentThreadableLoader.cpp:
+        (WebCore::DocumentThreadableLoader::redirectReceived):
+        * loader/ThreadableLoaderClient.h:
+        (WebCore::ThreadableLoaderClient::redirectReceived):
+        * loader/ThreadableLoaderClientWrapper.h:
+        (WebCore::ThreadableLoaderClientWrapper::redirectReceived):
+        * loader/WorkerThreadableLoader.cpp:
+        (WebCore::WorkerThreadableLoader::MainThreadBridge::redirectReceived):
+        * loader/WorkerThreadableLoader.h:
+        * workers/Worker.cpp:
+        (WebCore::Worker::notifyFinished):
+        * workers/WorkerFetchResult.h:
+        (WebCore::WorkerFetchResult::isolatedCopy const):
+        (WebCore::workerFetchError):
+        (WebCore::WorkerFetchResult::encode const):
+        (WebCore::WorkerFetchResult::decode):
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::WorkerScriptLoader::loadSynchronously):
+        (WebCore::WorkerScriptLoader::loadAsynchronously):
+        (WebCore::WorkerScriptLoader::redirectReceived):
+        (WebCore::WorkerScriptLoader::fetchResult const):
+        * workers/WorkerScriptLoader.h:
+        (WebCore::WorkerScriptLoader::script const):
+        (WebCore::WorkerScriptLoader::lastRequestURL const):
+        (WebCore::WorkerScriptLoader::script): Deleted.
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::jobFinishedLoadingScript):
+        * workers/service/ServiceWorkerContainer.h:
+        * workers/service/ServiceWorkerJob.cpp:
+        (WebCore::ServiceWorkerJob::notifyFinished):
+        * workers/service/ServiceWorkerJobClient.h:
+        * workers/shared/SharedWorkerScriptLoader.cpp:
+        (WebCore::SharedWorkerScriptLoader::notifyFinished):
+        * workers/shared/context/SharedWorkerThreadProxy.cpp:
+        (WebCore::generateWorkerParameters):
+        (WebCore::SharedWorkerThreadProxy::SharedWorkerThreadProxy):
+        * workers/shared/context/SharedWorkerThreadProxy.h:
+
 2022-02-09  Philippe Normand  <pnorm...@igalia.com>
 
         [GStreamer] MediaPlayerPrivateGStreamer mishandles failure to create WebKitTextCombiner

Modified: trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp (289482 => 289483)


--- trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -314,6 +314,9 @@
     Ref<DocumentThreadableLoader> protectedThis(*this);
     --m_options.maxRedirectCount;
 
+    if (m_client)
+        m_client->redirectReceived(request.url());
+
     // FIXME: We restrict this check to Fetch API for the moment, as this might disrupt WorkerScriptLoader.
     // Reassess this check based on https://github.com/whatwg/fetch/issues/393 discussions.
     // We should also disable that check in navigation mode.

Modified: trunk/Source/WebCore/loader/ThreadableLoaderClient.h (289482 => 289483)


--- trunk/Source/WebCore/loader/ThreadableLoaderClient.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/loader/ThreadableLoaderClient.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -45,6 +45,7 @@
 public:
     virtual void didSendData(unsigned long long /*bytesSent*/, unsigned long long /*totalBytesToBeSent*/) { }
 
+    virtual void redirectReceived(const URL& /*redirectURL*/) { }
     virtual void didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse&) { }
     virtual void didReceiveData(const SharedBuffer&) { }
     virtual void didFinishLoading(ResourceLoaderIdentifier, const NetworkLoadMetrics&) { }

Modified: trunk/Source/WebCore/loader/ThreadableLoaderClientWrapper.h (289482 => 289483)


--- trunk/Source/WebCore/loader/ThreadableLoaderClientWrapper.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/loader/ThreadableLoaderClientWrapper.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -54,6 +54,12 @@
         return m_done;
     }
 
+    void redirectReceived(const URL& redirectURL)
+    {
+        if (m_client)
+            m_client->redirectReceived(redirectURL);
+    }
+
     void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
     {
         if (m_client)

Modified: trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp (289482 => 289483)


--- trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -211,6 +211,14 @@
     m_workerClientWrapper->clearClient();
 }
 
+void WorkerThreadableLoader::MainThreadBridge::redirectReceived(const URL& redirectURL)
+{
+    m_loaderProxy.postTaskForModeToWorkerOrWorkletGlobalScope([protectedWorkerClientWrapper = Ref { *m_workerClientWrapper }, redirectURL = redirectURL.isolatedCopy()] (ScriptExecutionContext& context) mutable {
+        ASSERT_UNUSED(context, context.isWorkerGlobalScope() || context.isWorkletGlobalScope());
+        protectedWorkerClientWrapper->redirectReceived(redirectURL);
+    }, m_taskMode);
+}
+
 void WorkerThreadableLoader::MainThreadBridge::didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent)
 {
     m_loaderProxy.postTaskForModeToWorkerOrWorkletGlobalScope([protectedWorkerClientWrapper = Ref { *m_workerClientWrapper }, bytesSent, totalBytesToBeSent] (ScriptExecutionContext& context) mutable {

Modified: trunk/Source/WebCore/loader/WorkerThreadableLoader.h (289482 => 289483)


--- trunk/Source/WebCore/loader/WorkerThreadableLoader.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/loader/WorkerThreadableLoader.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -103,6 +103,7 @@
         void clearClientWrapper();
 
         // All executed on the main thread.
+        void redirectReceived(const URL& redirectURL) override;
         void didSendData(unsigned long long bytesSent, unsigned long long totalBytesToBeSent) override;
         void didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse&) override;
         void didReceiveData(const SharedBuffer&) override;

Modified: trunk/Source/WebCore/workers/Worker.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/Worker.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/Worker.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -213,12 +213,7 @@
     if (auto policy = parseReferrerPolicy(m_scriptLoader->referrerPolicy(), ReferrerPolicySource::HTTPHeader))
         referrerPolicy = *policy;
 
-    URL responseURL = m_scriptLoader->responseURL();
-    if (!m_scriptLoader->isRedirected() && m_scriptLoader->responseSource() != ResourceResponse::Source::ServiceWorker) {
-        if (m_scriptLoader->url().hasFragmentIdentifier())
-            responseURL.setFragmentIdentifier(m_scriptLoader->url().fragmentIdentifier());
-    }
-    m_contextProxy.startWorkerGlobalScope(responseURL, m_options.name, context->userAgent(responseURL), isOnline, m_scriptLoader->script(), contentSecurityPolicyResponseHeaders, m_shouldBypassMainWorldContentSecurityPolicy, m_scriptLoader->crossOriginEmbedderPolicy(), m_workerCreationTime, referrerPolicy, m_options.type, m_options.credentials, m_runtimeFlags);
+    m_contextProxy.startWorkerGlobalScope(m_scriptLoader->lastRequestURL(), m_options.name, context->userAgent(m_scriptLoader->lastRequestURL()), isOnline, m_scriptLoader->script(), contentSecurityPolicyResponseHeaders, m_shouldBypassMainWorldContentSecurityPolicy, m_scriptLoader->crossOriginEmbedderPolicy(), m_workerCreationTime, referrerPolicy, m_options.type, m_options.credentials, m_runtimeFlags);
     InspectorInstrumentation::scriptImported(*context, m_scriptLoader->identifier(), m_scriptLoader->script().toString());
 }
 

Modified: trunk/Source/WebCore/workers/WorkerFetchResult.h (289482 => 289483)


--- trunk/Source/WebCore/workers/WorkerFetchResult.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/WorkerFetchResult.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -35,6 +35,7 @@
 
 struct WorkerFetchResult {
     ScriptBuffer script;
+    URL lastRequestURL; // Last URL in case of redirects.
     CertificateInfo certificateInfo;
     ContentSecurityPolicyResponseHeaders contentSecurityPolicy;
     CrossOriginEmbedderPolicy crossOriginEmbedderPolicy;
@@ -41,7 +42,7 @@
     String referrerPolicy;
     ResourceError error;
 
-    WorkerFetchResult isolatedCopy() const { return { script.isolatedCopy(), certificateInfo.isolatedCopy(), contentSecurityPolicy.isolatedCopy(), crossOriginEmbedderPolicy.isolatedCopy(), referrerPolicy.isolatedCopy(), error.isolatedCopy() }; }
+    WorkerFetchResult isolatedCopy() const { return { script.isolatedCopy(), lastRequestURL.isolatedCopy(), certificateInfo.isolatedCopy(), contentSecurityPolicy.isolatedCopy(), crossOriginEmbedderPolicy.isolatedCopy(), referrerPolicy.isolatedCopy(), error.isolatedCopy() }; }
 
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, WorkerFetchResult&);
@@ -49,13 +50,13 @@
 
 inline WorkerFetchResult workerFetchError(const ResourceError& error)
 {
-    return { { }, { }, { }, { }, { }, error };
+    return { { }, { }, { }, { }, { }, { }, error };
 }
 
 template<class Encoder>
 void WorkerFetchResult::encode(Encoder& encoder) const
 {
-    encoder << script << contentSecurityPolicy << crossOriginEmbedderPolicy << referrerPolicy << error << certificateInfo;
+    encoder << script << lastRequestURL << contentSecurityPolicy << crossOriginEmbedderPolicy << referrerPolicy << error << certificateInfo;
 }
 
 template<class Decoder>
@@ -63,6 +64,8 @@
 {
     if (!decoder.decode(result.script))
         return false;
+    if (!decoder.decode(result.lastRequestURL))
+        return false;
     if (!decoder.decode(result.contentSecurityPolicy))
         return false;
     if (!decoder.decode(result.crossOriginEmbedderPolicy))

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -37,6 +37,7 @@
 #include "ServiceWorkerContextData.h"
 #include "ServiceWorkerGlobalScope.h"
 #include "TextResourceDecoder.h"
+#include "WorkerFetchResult.h"
 #include "WorkerGlobalScope.h"
 #include "WorkerScriptLoaderClient.h"
 #include "WorkerThreadableLoader.h"
@@ -57,6 +58,7 @@
     auto& workerGlobalScope = downcast<WorkerGlobalScope>(*scriptExecutionContext);
 
     m_url = url;
+    m_lastRequestURL = url;
     m_destination = FetchOptions::Destination::Script;
     m_isCOEPEnabled = scriptExecutionContext->settingsValues().crossOriginEmbedderPolicyEnabled;
 
@@ -116,6 +118,7 @@
 {
     m_client = &client;
     m_url = scriptRequest.url();
+    m_lastRequestURL = scriptRequest.url();
     m_destination = fetchOptions.destination;
     m_isCOEPEnabled = scriptExecutionContext.settingsValues().crossOriginEmbedderPolicyEnabled;
 
@@ -178,6 +181,11 @@
     return { };
 }
 
+void WorkerScriptLoader::redirectReceived(const URL& redirectURL)
+{
+    m_lastRequestURL = redirectURL;
+}
+
 void WorkerScriptLoader::didReceiveResponse(ResourceLoaderIdentifier identifier, const ResourceResponse& response)
 {
     m_error = validateWorkerResponse(response, m_destination);
@@ -266,4 +274,11 @@
     m_threadableLoader = nullptr;
 }
 
+WorkerFetchResult WorkerScriptLoader::fetchResult() const
+{
+    if (m_failed)
+        return workerFetchError(error());
+    return { script(), lastRequestURL(), certificateInfo(), contentSecurityPolicy(), crossOriginEmbedderPolicy(), referrerPolicy(), { } };
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.h (289482 => 289483)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -49,6 +49,7 @@
 class ScriptExecutionContext;
 class TextResourceDecoder;
 class WorkerScriptLoaderClient;
+struct WorkerFetchResult;
 enum class CertificateInfoPolicy : uint8_t;
 
 class WorkerScriptLoader : public RefCounted<WorkerScriptLoader>, public ThreadableLoaderClient {
@@ -64,11 +65,12 @@
 
     void notifyError();
 
-    const ScriptBuffer& script() { return m_script; }
+    const ScriptBuffer& script() const { return m_script; }
     const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy() const { return m_contentSecurityPolicy; }
     const String& referrerPolicy() const { return m_referrerPolicy; }
     const CrossOriginEmbedderPolicy& crossOriginEmbedderPolicy() const { return m_crossOriginEmbedderPolicy; }
     const URL& url() const { return m_url; }
+    const URL& lastRequestURL() const { return m_lastRequestURL; }
     const URL& responseURL() const;
     ResourceResponse::Source responseSource() const { return m_responseSource; }
     bool isRedirected() const { return m_isRedirected; }
@@ -78,6 +80,9 @@
     ResourceLoaderIdentifier identifier() const { return m_identifier; }
     const ResourceError& error() const { return m_error; }
 
+    WorkerFetchResult fetchResult() const;
+
+    void redirectReceived(const URL& redirectURL) override;
     void didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse&) override;
     void didReceiveData(const SharedBuffer&) override;
     void didFinishLoading(ResourceLoaderIdentifier, const NetworkLoadMetrics&) override;
@@ -103,6 +108,7 @@
     RefPtr<TextResourceDecoder> m_decoder;
     ScriptBuffer m_script;
     URL m_url;
+    URL m_lastRequestURL;
     URL m_responseURL;
     CertificateInfo m_certificateInfo;
     String m_responseMIMEType;

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -491,13 +491,13 @@
     job.fetchScriptWithContext(*context, cachePolicy);
 }
 
-void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, const ScriptBuffer& script, const CertificateInfo& certificateInfo, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicy, const CrossOriginEmbedderPolicy& coep, const String& referrerPolicy)
+void ServiceWorkerContainer::jobFinishedLoadingScript(ServiceWorkerJob& job, const WorkerFetchResult& fetchResult)
 {
     ASSERT(m_creationThread.ptr() == &Thread::current());
 
     CONTAINER_RELEASE_LOG("jobFinishedLoadingScript: Successfuly finished fetching script for job %" PRIu64, job.identifier().toUInt64());
 
-    ensureSWClientConnection().finishFetchingScriptInServer(job.data().identifier(), job.data().registrationKey(), WorkerFetchResult { script, certificateInfo, contentSecurityPolicy, coep, referrerPolicy, { } });
+    ensureSWClientConnection().finishFetchingScriptInServer(job.data().identifier(), job.data().registrationKey(), fetchResult);
 }
 
 void ServiceWorkerContainer::jobFailedLoadingScript(ServiceWorkerJob& job, const ResourceError& error, Exception&& exception)

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (289482 => 289483)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -118,7 +118,7 @@
     void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved) final;
     void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) final;
     void startScriptFetchForJob(ServiceWorkerJob&, FetchOptions::Cache) final;
-    void jobFinishedLoadingScript(ServiceWorkerJob&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const CrossOriginEmbedderPolicy&, const String& referrerPolicy) final;
+    void jobFinishedLoadingScript(ServiceWorkerJob&, const WorkerFetchResult&) final;
     void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&, Exception&&) final;
 
     void notifyFailedFetchingScript(ServiceWorkerJob&, const ResourceError&);

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJob.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -37,6 +37,7 @@
 #include "SecurityOrigin.h"
 #include "ServiceWorkerJobData.h"
 #include "ServiceWorkerRegistration.h"
+#include "WorkerFetchResult.h"
 #include "WorkerRunLoop.h"
 
 namespace WebCore {
@@ -165,7 +166,7 @@
     auto scriptLoader = WTFMove(m_scriptLoader);
 
     if (!scriptLoader->failed()) {
-        m_client.jobFinishedLoadingScript(*this, scriptLoader->script(), scriptLoader->certificateInfo(), scriptLoader->contentSecurityPolicy(), scriptLoader->crossOriginEmbedderPolicy(), scriptLoader->referrerPolicy());
+        m_client.jobFinishedLoadingScript(*this, scriptLoader->fetchResult());
         return;
     }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h (289482 => 289483)


--- trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobClient.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -39,6 +39,7 @@
 class ServiceWorkerJob;
 struct CrossOriginEmbedderPolicy;
 struct ServiceWorkerRegistrationData;
+struct WorkerFetchResult;
 
 class ServiceWorkerJobClient {
 public:
@@ -50,7 +51,7 @@
     virtual void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved) = 0;
     virtual void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) = 0;
     virtual void startScriptFetchForJob(ServiceWorkerJob&, FetchOptions::Cache) = 0;
-    virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const ScriptBuffer&, const CertificateInfo&, const ContentSecurityPolicyResponseHeaders&, const CrossOriginEmbedderPolicy&, const String& referrerPolicy) = 0;
+    virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const WorkerFetchResult&) = 0;
     virtual void jobFailedLoadingScript(ServiceWorkerJob&, const ResourceError&, Exception&&) = 0;
 };
 

Modified: trunk/Source/WebCore/workers/shared/SharedWorkerScriptLoader.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/shared/SharedWorkerScriptLoader.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerScriptLoader.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -58,12 +58,9 @@
 
 void SharedWorkerScriptLoader::notifyFinished()
 {
-    if (m_loader->failed())
-        return m_completionHandler(workerFetchError(m_loader->error()));
-
-    if (auto* scriptExecutionContext = m_worker->scriptExecutionContext())
+    if (auto* scriptExecutionContext = m_worker->scriptExecutionContext(); !m_loader->failed())
         InspectorInstrumentation::scriptImported(*scriptExecutionContext, m_loader->identifier(), m_loader->script().toString());
-    m_completionHandler({ m_loader->script(), m_loader->certificateInfo(), m_loader->contentSecurityPolicy(), m_loader->crossOriginEmbedderPolicy(), m_loader->referrerPolicy(), { } }); // deletes this.
+    m_completionHandler(m_loader->fetchResult()); // deletes this.
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp (289482 => 289483)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -55,10 +55,10 @@
     return set;
 }
 
-static WorkerParameters generateWorkerParameters(const URL& scriptURL, const WorkerFetchResult& workerFetchResult, WorkerOptions&& workerOptions, const String& userAgent, Document& document)
+static WorkerParameters generateWorkerParameters(const WorkerFetchResult& workerFetchResult, WorkerOptions&& workerOptions, const String& userAgent, Document& document)
 {
     return WorkerParameters {
-        scriptURL,
+        workerFetchResult.lastRequestURL,
         workerOptions.name,
         "sharedworker:" + Inspector::IdentifiersFactory::createIdentifier(),
         userAgent,
@@ -74,10 +74,10 @@
     };
 }
 
-SharedWorkerThreadProxy::SharedWorkerThreadProxy(UniqueRef<Page>&& page, SharedWorkerIdentifier sharedWorkerIdentifier, const ClientOrigin& clientOrigin, const URL& scriptURL, WorkerFetchResult&& workerFetchResult, WorkerOptions&& workerOptions, const String& userAgent, CacheStorageProvider& cacheStorageProvider)
+SharedWorkerThreadProxy::SharedWorkerThreadProxy(UniqueRef<Page>&& page, SharedWorkerIdentifier sharedWorkerIdentifier, const ClientOrigin& clientOrigin, WorkerFetchResult&& workerFetchResult, WorkerOptions&& workerOptions, const String& userAgent, CacheStorageProvider& cacheStorageProvider)
     : m_page(WTFMove(page))
     , m_document(*m_page->mainFrame().document())
-    , m_workerThread(SharedWorkerThread::create(sharedWorkerIdentifier, generateWorkerParameters(scriptURL, workerFetchResult, WTFMove(workerOptions), userAgent, m_document), WTFMove(workerFetchResult.script), *this, *this, *this, WorkerThreadStartMode::Normal, clientOrigin.topOrigin.securityOrigin(), m_document->idbConnectionProxy(), m_document->socketProvider(), JSC::RuntimeFlags::createAllEnabled()))
+    , m_workerThread(SharedWorkerThread::create(sharedWorkerIdentifier, generateWorkerParameters(workerFetchResult, WTFMove(workerOptions), userAgent, m_document), WTFMove(workerFetchResult.script), *this, *this, *this, WorkerThreadStartMode::Normal, clientOrigin.topOrigin.securityOrigin(), m_document->idbConnectionProxy(), m_document->socketProvider(), JSC::RuntimeFlags::createAllEnabled()))
     , m_cacheStorageProvider(cacheStorageProvider)
 {
     ASSERT(!allSharedWorkerThreadProxies().contains(this));

Modified: trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h (289482 => 289483)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -54,7 +54,7 @@
     void setAsTerminatingOrTerminated() { m_isTerminatingOrTerminated = true; }
 
 private:
-    WEBCORE_EXPORT SharedWorkerThreadProxy(UniqueRef<Page>&&, SharedWorkerIdentifier, const ClientOrigin&, const URL& scriptURL, WorkerFetchResult&&, WorkerOptions&&, const String& userAgent, CacheStorageProvider&);
+    WEBCORE_EXPORT SharedWorkerThreadProxy(UniqueRef<Page>&&, SharedWorkerIdentifier, const ClientOrigin&, WorkerFetchResult&&, WorkerOptions&&, const String& userAgent, CacheStorageProvider&);
 
     // WorkerObjectProxy.
     void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) final;

Modified: trunk/Source/WebKit/ChangeLog (289482 => 289483)


--- trunk/Source/WebKit/ChangeLog	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/ChangeLog	2022-02-09 18:30:28 UTC (rev 289483)
@@ -1,3 +1,22 @@
+2022-02-09  Chris Dumez  <cdu...@apple.com>
+
+        self.location.href is incorrect in shared workers in case of redirects
+        https://bugs.webkit.org/show_bug.cgi?id=236340
+
+        Reviewed by Geoffrey Garen.
+
+        self.location.href is incorrect in shared workers in case of redirects. It should be the URL of
+        the last request, not the first one.
+
+        * NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp:
+        (WebKit::ServiceWorkerSoftUpdateLoader::didFinishLoading):
+        * NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp:
+        (WebKit::WebSharedWorkerServerToContextConnection::launchSharedWorker):
+        * WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp:
+        (WebKit::WebSharedWorkerContextManagerConnection::launchSharedWorker):
+        * WebProcess/Storage/WebSharedWorkerContextManagerConnection.h:
+        * WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in:
+
 2022-02-09  J Pascoe  <j_pas...@apple.com>
 
         [WebAuthn] Specify LocalAuthenticatorAccessGroup when importing credentials

Modified: trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp (289482 => 289483)


--- trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/NetworkProcess/ServiceWorker/ServiceWorkerSoftUpdateLoader.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -196,7 +196,7 @@
 {
     if (m_decoder)
         m_script.append(m_decoder->flush());
-    m_completionHandler({ ScriptBuffer { m_script.toString() }, m_certificateInfo, m_contentSecurityPolicy, m_crossOriginEmbedderPolicy, m_referrerPolicy, { } });
+    m_completionHandler({ ScriptBuffer { m_script.toString() }, m_jobData.scriptURL, m_certificateInfo, m_contentSecurityPolicy, m_crossOriginEmbedderPolicy, m_referrerPolicy, { } });
     didComplete();
 }
 

Modified: trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp (289482 => 289483)


--- trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/NetworkProcess/SharedWorker/WebSharedWorkerServerToContextConnection.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -90,7 +90,7 @@
 {
     CONTEXT_CONNECTION_RELEASE_LOG("launchSharedWorker: sharedWorkerIdentifier=%" PRIu64, sharedWorker.identifier().toUInt64());
     sharedWorker.markAsRunning();
-    send(Messages::WebSharedWorkerContextManagerConnection::LaunchSharedWorker { sharedWorker.origin(), sharedWorker.identifier(), sharedWorker.url(), sharedWorker.workerOptions(), sharedWorker.fetchResult() });
+    send(Messages::WebSharedWorkerContextManagerConnection::LaunchSharedWorker { sharedWorker.origin(), sharedWorker.identifier(), sharedWorker.workerOptions(), sharedWorker.fetchResult() });
     for (auto& port : sharedWorker.sharedWorkerObjects().values())
         postConnectEvent(sharedWorker, port);
 }

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp (289482 => 289483)


--- trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.cpp	2022-02-09 18:30:28 UTC (rev 289483)
@@ -89,7 +89,7 @@
     m_preferencesStore = store;
 }
 
-void WebSharedWorkerContextManagerConnection::launchSharedWorker(WebCore::ClientOrigin&& origin, WebCore::SharedWorkerIdentifier sharedWorkerIdentifier, URL&& url, WebCore::WorkerOptions&& workerOptions, WebCore::WorkerFetchResult&& workerFetchResult)
+void WebSharedWorkerContextManagerConnection::launchSharedWorker(WebCore::ClientOrigin&& origin, WebCore::SharedWorkerIdentifier sharedWorkerIdentifier, WebCore::WorkerOptions&& workerOptions, WebCore::WorkerFetchResult&& workerFetchResult)
 {
     RELEASE_LOG(SharedWorker, "WebSharedWorkerContextManagerConnection::launchSharedWorker: sharedWorkerIdentifier=%" PRIu64, sharedWorkerIdentifier.toUInt64());
     auto pageConfiguration = WebCore::pageConfigurationWithEmptyClients(WebProcess::singleton().sessionID());
@@ -110,8 +110,8 @@
         WebPage::updateSettingsGenerated(*m_preferencesStore, page->settings());
         page->settings().setStorageBlockingPolicy(static_cast<WebCore::StorageBlockingPolicy>(m_preferencesStore->getUInt32ValueForKey(WebPreferencesKey::storageBlockingPolicyKey())));
     }
-    page->setupForRemoteWorker(url, origin.topOrigin, workerFetchResult.referrerPolicy);
-    auto sharedWorkerThreadProxy = WebCore::SharedWorkerThreadProxy::create(WTFMove(page), sharedWorkerIdentifier, origin, url, WTFMove(workerFetchResult), WTFMove(workerOptions), m_userAgent, WebProcess::singleton().cacheStorageProvider());
+    page->setupForRemoteWorker(workerFetchResult.lastRequestURL, origin.topOrigin, workerFetchResult.referrerPolicy);
+    auto sharedWorkerThreadProxy = WebCore::SharedWorkerThreadProxy::create(WTFMove(page), sharedWorkerIdentifier, origin, WTFMove(workerFetchResult), WTFMove(workerOptions), m_userAgent, WebProcess::singleton().cacheStorageProvider());
 
     WebCore::SharedWorkerContextManager::singleton().registerSharedWorkerThread(WTFMove(sharedWorkerThreadProxy));
 }

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.h (289482 => 289483)


--- trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.h	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.h	2022-02-09 18:30:28 UTC (rev 289483)
@@ -58,7 +58,7 @@
 
 private:
     // IPC Messages.
-    void launchSharedWorker(WebCore::ClientOrigin&&, WebCore::SharedWorkerIdentifier, URL&&, WebCore::WorkerOptions&&, WebCore::WorkerFetchResult&&);
+    void launchSharedWorker(WebCore::ClientOrigin&&, WebCore::SharedWorkerIdentifier, WebCore::WorkerOptions&&, WebCore::WorkerFetchResult&&);
     void updatePreferencesStore(const WebPreferencesStore&);
     void setUserAgent(String&& userAgent) { m_userAgent = WTFMove(userAgent); }
     void close();

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in (289482 => 289483)


--- trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in	2022-02-09 18:17:43 UTC (rev 289482)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSharedWorkerContextManagerConnection.messages.in	2022-02-09 18:30:28 UTC (rev 289483)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> WebSharedWorkerContextManagerConnection NotRefCounted {
-    LaunchSharedWorker(struct WebCore::ClientOrigin origin, WebCore::SharedWorkerIdentifier sharedWorkerIdentifier, URL url, struct WebCore::WorkerOptions workerOptions, struct WebCore::WorkerFetchResult workerFetchResult)
+    LaunchSharedWorker(struct WebCore::ClientOrigin origin, WebCore::SharedWorkerIdentifier sharedWorkerIdentifier, struct WebCore::WorkerOptions workerOptions, struct WebCore::WorkerFetchResult workerFetchResult)
     PostConnectEvent(WebCore::SharedWorkerIdentifier sharedWorkerIdentifier, WebCore::TransferredMessagePort port, String sourceOrigin)
     TerminateSharedWorker(WebCore::SharedWorkerIdentifier sharedWorkerIdentifier)
     UpdatePreferencesStore(struct WebKit::WebPreferencesStore store)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to