Title: [288201] trunk
Revision
288201
Author
[email protected]
Date
2022-01-19 09:12:35 -0800 (Wed, 19 Jan 2022)

Log Message

Improve computation of service worker FetchEvent.resultingClientId
https://bugs.webkit.org/show_bug.cgi?id=235107

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https-expected.txt:
* web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt:
* web-platform-tests/service-workers/service-worker/historical.https.any.serviceworker-expected.txt:

Source/WebCore:

We are now passing the reserved client ID generated by DocumentLoader to the generated document.
Previously, we would register a temporary ID that we would drop later on when creating a new document.
This allows to be closer to spec, though we need to handle the case of a document whose origin gets unique
due to CSP or sandboxing making a document origin unique.
We are also removing targetClientId, which was renamed in the spec to replacesClientId but is also not implemented in any browser yet.

Covered by existing tests.

* dom/DOMImplementation.cpp:
* dom/DOMImplementation.h:
* dom/Document.cpp:
* dom/Document.h:
* dom/ScriptExecutionContext.cpp:
* dom/ScriptExecutionContext.h:
* html/FTPDirectoryDocument.cpp:
* html/HTMLDocument.cpp:
* html/HTMLDocument.h:
* html/ImageDocument.cpp:
* html/MediaDocument.cpp:
* html/ModelDocument.cpp:
* html/PluginDocument.cpp:
* html/TextDocument.cpp:
* html/TextDocument.h:
* inspector/DOMPatchSupport.cpp:
* loader/DocumentLoader.cpp:
* loader/DocumentLoader.h:
* loader/DocumentWriter.cpp:
* loader/DocumentWriter.h:
* loader/SinkDocument.cpp:
* workers/service/FetchEvent.cpp:
* workers/service/FetchEvent.h:
* workers/service/FetchEvent.idl:
* workers/service/server/SWServer.cpp:
* xml/XMLHttpRequest.cpp:

Source/WebKit:

* WebProcess/Network/WebLoaderStrategy.cpp:
* WebProcess/Storage/WebSWClientConnection.cpp:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288200 => 288201)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,3 +1,14 @@
+2022-01-19  Youenn Fablet  <[email protected]>
+
+        Improve computation of service worker FetchEvent.resultingClientId
+        https://bugs.webkit.org/show_bug.cgi?id=235107
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt:
+        * web-platform-tests/service-workers/service-worker/historical.https.any.serviceworker-expected.txt:
+
 2022-01-19  Alexey Shvayka  <[email protected]>
 
         Callback functions / interfaces should use global object of its _value_ for errors and lifecycle

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https-expected.txt (288200 => 288201)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https-expected.txt	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get-resultingClientId.https-expected.txt	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,8 +1,8 @@
 
 PASS global setup
-FAIL get(resultingClientId) for same-origin document assert_equals: promiseValue expected "client" but got "undefinedValue"
+PASS get(resultingClientId) for same-origin document
 PASS get(resultingClientId) on cross-origin redirect
-PASS get(resultingClientId) for document sandboxed by CSP header
-FAIL get(resultingClientId) for document sandboxed by CSP header with allow-same-origin assert_equals: promiseValue expected "client" but got "undefinedValue"
+FAIL get(resultingClientId) for document sandboxed by CSP header assert_equals: promiseValue expected "undefinedValue" but got "client"
+PASS get(resultingClientId) for document sandboxed by CSP header with allow-same-origin
 PASS global cleanup
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt (288200 => 288201)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/clients-get.https-expected.txt	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,5 +1,5 @@
 
 FAIL Test Clients.get() assert_array_equals: expected property 1 to be false but got true (expected array ["visible", false, "https://localhost:9443/service-workers/service-worker/resources/clients-get-frame.html#2", "window", "nested"] got ["visible", true, "https://localhost:9443/service-workers/service-worker/resources/clients-get-frame.html#2", "window", "nested"])
-FAIL Test successful Clients.get(FetchEvent.resultingClientId) assert_false: Clients.get(FetchEvent.resultingClientId) resolved with a Client expected false got true
+PASS Test successful Clients.get(FetchEvent.resultingClientId)
 PASS Test unsuccessful Clients.get(FetchEvent.resultingClientId)
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/historical.https.any.serviceworker-expected.txt (288200 => 288201)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/historical.https.any.serviceworker-expected.txt	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/historical.https.any.serviceworker-expected.txt	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,3 +1,3 @@
 
-FAIL targetClientId should not be on FetchEvent assert_false: expected false got true
+PASS targetClientId should not be on FetchEvent
 

Modified: trunk/Source/WTF/wtf/UUID.h (288200 => 288201)


--- trunk/Source/WTF/wtf/UUID.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WTF/wtf/UUID.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -85,6 +85,8 @@
     WTF_EXPORT_PRIVATE unsigned hash() const;
     WTF_EXPORT_PRIVATE String toString() const;
 
+    operator bool() const { return !!m_data; }
+
 private:
     WTF_EXPORT_PRIVATE UUID();
 

Modified: trunk/Source/WebCore/ChangeLog (288200 => 288201)


--- trunk/Source/WebCore/ChangeLog	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/ChangeLog	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,3 +1,45 @@
+2022-01-19  Youenn Fablet  <[email protected]>
+
+        Improve computation of service worker FetchEvent.resultingClientId
+        https://bugs.webkit.org/show_bug.cgi?id=235107
+
+        Reviewed by Darin Adler.
+
+        We are now passing the reserved client ID generated by DocumentLoader to the generated document.
+        Previously, we would register a temporary ID that we would drop later on when creating a new document.
+        This allows to be closer to spec, though we need to handle the case of a document whose origin gets unique
+        due to CSP or sandboxing making a document origin unique.
+        We are also removing targetClientId, which was renamed in the spec to replacesClientId but is also not implemented in any browser yet.
+
+        Covered by existing tests.
+
+        * dom/DOMImplementation.cpp:
+        * dom/DOMImplementation.h:
+        * dom/Document.cpp:
+        * dom/Document.h:
+        * dom/ScriptExecutionContext.cpp:
+        * dom/ScriptExecutionContext.h:
+        * html/FTPDirectoryDocument.cpp:
+        * html/HTMLDocument.cpp:
+        * html/HTMLDocument.h:
+        * html/ImageDocument.cpp:
+        * html/MediaDocument.cpp:
+        * html/ModelDocument.cpp:
+        * html/PluginDocument.cpp:
+        * html/TextDocument.cpp:
+        * html/TextDocument.h:
+        * inspector/DOMPatchSupport.cpp:
+        * loader/DocumentLoader.cpp:
+        * loader/DocumentLoader.h:
+        * loader/DocumentWriter.cpp:
+        * loader/DocumentWriter.h:
+        * loader/SinkDocument.cpp:
+        * workers/service/FetchEvent.cpp:
+        * workers/service/FetchEvent.h:
+        * workers/service/FetchEvent.idl:
+        * workers/service/server/SWServer.cpp:
+        * xml/XMLHttpRequest.cpp:
+
 2022-01-19  Michael Catanzaro  <[email protected]>
 
         Fix -Wreturn-type and -Wunused-parameter warnings, January 2022 edition

Modified: trunk/Source/WebCore/dom/DOMImplementation.cpp (288200 => 288201)


--- trunk/Source/WebCore/dom/DOMImplementation.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/DOMImplementation.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -124,7 +124,7 @@
 
 Ref<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
 {
-    auto document = HTMLDocument::create(nullptr, m_document.settings(), URL());
+    auto document = HTMLDocument::create(nullptr, m_document.settings(), URL(), { });
     document->open();
     document->write(nullptr, { "<!doctype html><html><head></head><body></body></html>"_s });
     if (!title.isNull()) {
@@ -138,7 +138,7 @@
     return document;
 }
 
-Ref<Document> DOMImplementation::createDocument(const String& contentType, Frame* frame, const Settings& settings, const URL& url)
+Ref<Document> DOMImplementation::createDocument(const String& contentType, Frame* frame, const Settings& settings, const URL& url, ScriptExecutionContextIdentifier documentIdentifier)
 {
     // FIXME: Inelegant to have this here just because this is the home of DOM APIs for creating documents.
     // This is internal, not a DOM API. Maybe we should put it in a new class called DocumentFactory,
@@ -146,11 +146,11 @@
 
     // Plug-ins cannot take over for HTML, XHTML, plain text, or non-PDF images.
     if (equalLettersIgnoringASCIICase(contentType, "text/html"))
-        return HTMLDocument::create(frame, settings, url);
+        return HTMLDocument::create(frame, settings, url, documentIdentifier);
     if (equalLettersIgnoringASCIICase(contentType, "application/xhtml+xml"))
         return XMLDocument::createXHTML(frame, settings, url);
     if (equalLettersIgnoringASCIICase(contentType, "text/plain"))
-        return TextDocument::create(frame, settings, url);
+        return TextDocument::create(frame, settings, url, documentIdentifier);
     bool isImage = MIMETypeRegistry::isSupportedImageMIMEType(contentType);
     if (frame && isImage && !MIMETypeRegistry::isPDFOrPostScriptMIMEType(contentType))
         return ImageDocument::create(*frame, url);
@@ -193,7 +193,7 @@
     if (frame && isImage)
         return ImageDocument::create(*frame, url);
     if (MIMETypeRegistry::isTextMIMEType(contentType))
-        return TextDocument::create(frame, settings, url);
+        return TextDocument::create(frame, settings, url, documentIdentifier);
     if (equalLettersIgnoringASCIICase(contentType, "image/svg+xml"))
         return SVGDocument::create(frame, settings, url);
     if (MIMETypeRegistry::isXMLMIMEType(contentType)) {
@@ -201,7 +201,8 @@
         document->overrideMIMEType(contentType);
         return document;
     }
-    return HTMLDocument::create(frame, settings, url);
+
+    return HTMLDocument::create(frame, settings, url, documentIdentifier);
 }
 
 }

Modified: trunk/Source/WebCore/dom/DOMImplementation.h (288200 => 288201)


--- trunk/Source/WebCore/dom/DOMImplementation.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/DOMImplementation.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -24,6 +24,7 @@
 #pragma once
 
 #include "ExceptionOr.h"
+#include "ScriptExecutionContextIdentifier.h"
 #include "XMLDocument.h"
 
 namespace WebCore {
@@ -43,7 +44,7 @@
     static bool hasFeature() { return true; }
     WEBCORE_EXPORT static Ref<CSSStyleSheet> createCSSStyleSheet(const String& title, const String& media);
 
-    static Ref<Document> createDocument(const String& contentType, Frame*, const Settings&, const URL&);
+    static Ref<Document> createDocument(const String& contentType, Frame*, const Settings&, const URL&, ScriptExecutionContextIdentifier = { });
 
 private:
     Document& m_document;

Modified: trunk/Source/WebCore/dom/Document.cpp (288200 => 288201)


--- trunk/Source/WebCore/dom/Document.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/Document.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -605,9 +605,10 @@
     return CachedResourceLoader::create(nullptr);
 }
 
-Document::Document(Frame* frame, const Settings& settings, const URL& url, DocumentClasses documentClasses, unsigned constructionFlags)
+Document::Document(Frame* frame, const Settings& settings, const URL& url, DocumentClasses documentClasses, unsigned constructionFlags, ScriptExecutionContextIdentifier identifier)
     : ContainerNode(*this, CreateDocument)
     , TreeScope(*this)
+    , ScriptExecutionContext(identifier)
     , FrameDestructionObserver(frame)
     , m_settings(settings)
     , m_quirks(makeUniqueRef<Quirks>(*this))
@@ -7512,7 +7513,7 @@
         return const_cast<Document&>(*document);
 
     if (isHTMLDocument())
-        m_templateDocument = HTMLDocument::create(nullptr, m_settings, aboutBlankURL());
+        m_templateDocument = HTMLDocument::create(nullptr, m_settings, aboutBlankURL(), { });
     else
         m_templateDocument = create(m_settings, aboutBlankURL());
 

Modified: trunk/Source/WebCore/dom/Document.h (288200 => 288201)


--- trunk/Source/WebCore/dom/Document.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/Document.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1676,7 +1676,7 @@
 
 protected:
     enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
-    WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClasses = { }, unsigned constructionFlags = 0);
+    WEBCORE_EXPORT Document(Frame*, const Settings&, const URL&, DocumentClasses = { }, unsigned constructionFlags = 0, ScriptExecutionContextIdentifier = { });
 
     void clearXMLVersion() { m_xmlVersion = String(); }
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (288200 => 288201)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -111,10 +111,11 @@
     RefPtr<ScriptCallStack> m_callStack;
 };
 
-ScriptExecutionContext::ScriptExecutionContext()
-    : m_identifier(ScriptExecutionContextIdentifier::generate())
+ScriptExecutionContext::ScriptExecutionContext(ScriptExecutionContextIdentifier contextIdentifier)
+    : m_identifier(contextIdentifier ? contextIdentifier : ScriptExecutionContextIdentifier::generate())
 {
     Locker locker { allScriptExecutionContextsMapLock };
+    ASSERT(!allScriptExecutionContextsMap().contains(m_identifier));
     allScriptExecutionContextsMap().add(m_identifier, this);
 }
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (288200 => 288201)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -89,7 +89,7 @@
 
 class ScriptExecutionContext : public SecurityContext, public CanMakeWeakPtr<ScriptExecutionContext> {
 public:
-    ScriptExecutionContext();
+    explicit ScriptExecutionContext(ScriptExecutionContextIdentifier = { });
     virtual ~ScriptExecutionContext();
 
     virtual bool isDocument() const { return false; }

Modified: trunk/Source/WebCore/html/FTPDirectoryDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/FTPDirectoryDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/FTPDirectoryDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -418,7 +418,7 @@
 }
 
 FTPDirectoryDocument::FTPDirectoryDocument(Frame* frame, const Settings& settings, const URL& url)
-    : HTMLDocument(frame, settings, url)
+    : HTMLDocument(frame, settings, url, { })
 {
 #if !LOG_DISABLED
     LogFTP.state = WTFLogChannelState::On;

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -89,11 +89,11 @@
 
 Ref<HTMLDocument> HTMLDocument::createSynthesizedDocument(Frame& frame, const URL& url)
 {
-    return adoptRef(*new HTMLDocument(&frame, frame.settings(), url, { DocumentClass::HTML }, Synthesized));
+    return adoptRef(*new HTMLDocument(&frame, frame.settings(), url, { }, { DocumentClass::HTML }, Synthesized));
 }
 
-HTMLDocument::HTMLDocument(Frame* frame, const Settings& settings, const URL& url, DocumentClasses documentClasses, unsigned constructionFlags)
-    : Document(frame, settings, url, documentClasses | DocumentClasses(DocumentClass::HTML), constructionFlags)
+HTMLDocument::HTMLDocument(Frame* frame, const Settings& settings, const URL& url, ScriptExecutionContextIdentifier documentIdentifier, DocumentClasses documentClasses, unsigned constructionFlags)
+    : Document(frame, settings, url, documentClasses | DocumentClasses(DocumentClass::HTML), constructionFlags, documentIdentifier)
 {
     clearXMLVersion();
 }

Modified: trunk/Source/WebCore/html/HTMLDocument.h (288200 => 288201)


--- trunk/Source/WebCore/html/HTMLDocument.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/HTMLDocument.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -29,7 +29,7 @@
 class HTMLDocument : public Document {
     WTF_MAKE_ISO_ALLOCATED(HTMLDocument);
 public:
-    static Ref<HTMLDocument> create(Frame*, const Settings&, const URL&);
+    static Ref<HTMLDocument> create(Frame*, const Settings&, const URL&, ScriptExecutionContextIdentifier = { });
     static Ref<HTMLDocument> createSynthesizedDocument(Frame&, const URL&);
     virtual ~HTMLDocument();
 
@@ -54,7 +54,7 @@
     static bool isCaseSensitiveAttribute(const QualifiedName&);
 
 protected:
-    HTMLDocument(Frame*, const Settings&, const URL&, DocumentClasses = { }, unsigned constructionFlags = 0);
+    HTMLDocument(Frame*, const Settings&, const URL&, ScriptExecutionContextIdentifier, DocumentClasses = { }, unsigned constructionFlags = 0);
 
 private:
     bool isFrameSet() const final;
@@ -65,9 +65,9 @@
     TreeScopeOrderedMap m_windowNamedItem;
 };
 
-inline Ref<HTMLDocument> HTMLDocument::create(Frame* frame, const Settings& settings, const URL& url)
+inline Ref<HTMLDocument> HTMLDocument::create(Frame* frame, const Settings& settings, const URL& url, ScriptExecutionContextIdentifier identifier)
 {
-    return adoptRef(*new HTMLDocument(frame, settings, url, { DocumentClass::HTML }));
+    return adoptRef(*new HTMLDocument(frame, settings, url, identifier, { DocumentClass::HTML }, 0));
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/ImageDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/ImageDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/ImageDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -198,7 +198,7 @@
 }
 
 ImageDocument::ImageDocument(Frame& frame, const URL& url)
-    : HTMLDocument(&frame, frame.settings(), url, { DocumentClass::Image })
+    : HTMLDocument(&frame, frame.settings(), url, { }, { DocumentClass::Image })
     , m_imageElement(nullptr)
     , m_imageSizeIsKnown(false)
 #if !PLATFORM(IOS_FAMILY)

Modified: trunk/Source/WebCore/html/MediaDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/MediaDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/MediaDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -140,7 +140,7 @@
 }
     
 MediaDocument::MediaDocument(Frame* frame, const Settings& settings, const URL& url)
-    : HTMLDocument(frame, settings, url, { DocumentClass::Media })
+    : HTMLDocument(frame, settings, url, { }, { DocumentClass::Media })
 {
     setCompatibilityMode(DocumentCompatibilityMode::QuirksMode);
     lockCompatibilityMode();

Modified: trunk/Source/WebCore/html/ModelDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/ModelDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/ModelDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -138,7 +138,7 @@
 }
 
 ModelDocument::ModelDocument(Frame* frame, const Settings& settings, const URL& url)
-    : HTMLDocument(frame, settings, url, { DocumentClass::Model })
+    : HTMLDocument(frame, settings, url, { }, { DocumentClass::Model })
 {
     if (frame)
         m_outgoingReferrer = frame->loader().outgoingReferrer();

Modified: trunk/Source/WebCore/html/PluginDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/PluginDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/PluginDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -144,7 +144,7 @@
 }
 
 PluginDocument::PluginDocument(Frame& frame, const URL& url)
-    : HTMLDocument(&frame, frame.settings(), url, { DocumentClass::Plugin })
+    : HTMLDocument(&frame, frame.settings(), url, { }, { DocumentClass::Plugin })
 {
     setCompatibilityMode(DocumentCompatibilityMode::QuirksMode);
     lockCompatibilityMode();

Modified: trunk/Source/WebCore/html/TextDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/html/TextDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/TextDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -32,8 +32,8 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(TextDocument);
 
-TextDocument::TextDocument(Frame* frame, const Settings& settings, const URL& url)
-    : HTMLDocument(frame, settings, url, { DocumentClass::Text })
+TextDocument::TextDocument(Frame* frame, const Settings& settings, const URL& url, ScriptExecutionContextIdentifier identifier)
+    : HTMLDocument(frame, settings, url, identifier, { DocumentClass::Text })
 {
     setCompatibilityMode(DocumentCompatibilityMode::QuirksMode);
     lockCompatibilityMode();

Modified: trunk/Source/WebCore/html/TextDocument.h (288200 => 288201)


--- trunk/Source/WebCore/html/TextDocument.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/html/TextDocument.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -31,13 +31,13 @@
 class TextDocument final : public HTMLDocument {
     WTF_MAKE_ISO_ALLOCATED(TextDocument);
 public:
-    static Ref<TextDocument> create(Frame* frame, const Settings& settings, const URL& url)
+    static Ref<TextDocument> create(Frame* frame, const Settings& settings, const URL& url, ScriptExecutionContextIdentifier identifier)
     {
-        return adoptRef(*new TextDocument(frame, settings, url));
+        return adoptRef(*new TextDocument(frame, settings, url, identifier));
     }
 
 private:
-    TextDocument(Frame*, const Settings&, const URL&);
+    TextDocument(Frame*, const Settings&, const URL&, ScriptExecutionContextIdentifier);
     
     Ref<DocumentParser> createParser() override;
 };

Modified: trunk/Source/WebCore/inspector/DOMPatchSupport.cpp (288200 => 288201)


--- trunk/Source/WebCore/inspector/DOMPatchSupport.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/inspector/DOMPatchSupport.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -77,7 +77,7 @@
 {
     RefPtr<Document> newDocument;
     if (m_document.isHTMLDocument())
-        newDocument = HTMLDocument::create(nullptr, m_document.settings(), URL());
+        newDocument = HTMLDocument::create(nullptr, m_document.settings(), URL(), { });
     else if (m_document.isXHTMLDocument())
         newDocument = XMLDocument::createXHTML(nullptr, m_document.settings(), URL());
     else if (m_document.isSVGDocument())

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (288200 => 288201)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -150,15 +150,15 @@
         loader->setDefersLoading(defers);
 }
 
-static HashMap<ScriptExecutionContextIdentifier, DocumentLoader*>& temporaryIdentifierToLoaderMap()
+static HashMap<ScriptExecutionContextIdentifier, DocumentLoader*>& scriptExecutionContextIdentifierToLoaderMap()
 {
     static NeverDestroyed<HashMap<ScriptExecutionContextIdentifier, DocumentLoader*>> map;
     return map.get();
 }
 
-DocumentLoader* DocumentLoader::fromTemporaryDocumentIdentifier(ScriptExecutionContextIdentifier identifier)
+DocumentLoader* DocumentLoader::fromScriptExecutionContextIdentifier(ScriptExecutionContextIdentifier identifier)
 {
-    return temporaryIdentifierToLoaderMap().get(identifier);
+    return scriptExecutionContextIdentifierToLoaderMap().get(identifier);
 }
 
 DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(DocumentLoader);
@@ -200,9 +200,9 @@
     clearMainResource();
 
 #if ENABLE(SERVICE_WORKER)
-    if (m_temporaryServiceWorkerClient) {
-        ASSERT(temporaryIdentifierToLoaderMap().contains(*m_temporaryServiceWorkerClient));
-        temporaryIdentifierToLoaderMap().remove(*m_temporaryServiceWorkerClient);
+    if (m_resultingClientId) {
+        ASSERT(scriptExecutionContextIdentifierToLoaderMap().contains(m_resultingClientId));
+        scriptExecutionContextIdentifierToLoaderMap().remove(m_resultingClientId);
     }
 #endif
 }
@@ -555,6 +555,11 @@
     return true;
 }
 
+ScriptExecutionContextIdentifier DocumentLoader::resultingClientId() const
+{
+    return m_resultingClientId;
+}
+
 void DocumentLoader::matchRegistration(const URL& url, SWClientConnection::RegistrationCallback&& callback)
 {
     auto shouldTryLoadingThroughServiceWorker = !frameLoader()->isReloadingFromOrigin() && m_frame->page() && RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled() && url.protocolIsInHTTPFamily();
@@ -589,8 +594,9 @@
 #if ENABLE(SERVICE_WORKER)
     if (m_serviceWorkerRegistrationData) {
         m_serviceWorkerRegistrationData = { };
-        unregisterTemporaryServiceWorkerClient();
+        unregisterReservedServiceWorkerClient();
     }
+
     willSendRequest(WTFMove(request), redirectResponse, [completionHandler = WTFMove(completionHandler), protectedThis = Ref { *this }, this] (auto&& request) mutable {
         ASSERT(!m_substituteData.isValid());
         if (request.isNull() || !m_mainDocumentError.isNull() || !m_frame) {
@@ -1202,7 +1208,7 @@
 {
     if (!m_gotFirstByte) {
         m_gotFirstByte = true;
-        bool hasBegun = m_writer.begin(documentURL(), false);
+        bool hasBegun = m_writer.begin(documentURL(), false, nullptr, m_resultingClientId);
         if (!hasBegun)
             return;
 
@@ -1230,20 +1236,25 @@
 #endif
 #if ENABLE(SERVICE_WORKER)
         if (RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled()) {
-            if (m_serviceWorkerRegistrationData && m_serviceWorkerRegistrationData->activeWorker) {
-                document.setActiveServiceWorker(ServiceWorker::getOrCreate(document, WTFMove(m_serviceWorkerRegistrationData->activeWorker.value())));
-                m_serviceWorkerRegistrationData = { };
-            } else if (auto* parent = document.parentDocument()) {
-                if (shouldUseActiveServiceWorkerFromParent(document, *parent))
-                    document.setActiveServiceWorker(parent->activeServiceWorker());
+            if (!document.securityOrigin().isUnique()) {
+                if (m_serviceWorkerRegistrationData && m_serviceWorkerRegistrationData->activeWorker) {
+                    document.setActiveServiceWorker(ServiceWorker::getOrCreate(document, WTFMove(m_serviceWorkerRegistrationData->activeWorker.value())));
+                    m_serviceWorkerRegistrationData = { };
+                } else if (auto* parent = document.parentDocument()) {
+                    if (shouldUseActiveServiceWorkerFromParent(document, *parent))
+                        document.setActiveServiceWorker(parent->activeServiceWorker());
+                }
             }
 
             if (m_frame->document()->activeServiceWorker() || document.url().protocolIsInHTTPFamily() || (document.page() && document.page()->isServiceWorkerPage()))
                 document.setServiceWorkerConnection(&ServiceWorkerProvider::singleton().serviceWorkerConnection());
 
-            // We currently unregister the temporary service worker client since we now registered the real document.
-            // FIXME: We should make the real document use the temporary client identifier.
-            unregisterTemporaryServiceWorkerClient();
+            if (m_resultingClientId) {
+                if (m_resultingClientId != document.identifier())
+                    unregisterReservedServiceWorkerClient();
+                scriptExecutionContextIdentifierToLoaderMap().remove(m_resultingClientId);
+                m_resultingClientId = { };
+            }
         }
 #endif
         // Call receivedFirstData() exactly once per load. We should only reach this point multiple times
@@ -2066,14 +2077,14 @@
     });
 }
 
-void DocumentLoader::unregisterTemporaryServiceWorkerClient()
+void DocumentLoader::unregisterReservedServiceWorkerClient()
 {
 #if ENABLE(SERVICE_WORKER)
-    if (!m_temporaryServiceWorkerClient || !RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled())
+    if (!m_resultingClientId || !RuntimeEnabledFeatures::sharedFeatures().serviceWorkerEnabled())
         return;
 
     auto& serviceWorkerConnection = ServiceWorkerProvider::singleton().serviceWorkerConnection();
-    serviceWorkerConnection.unregisterServiceWorkerClient(*m_temporaryServiceWorkerClient);
+    serviceWorkerConnection.unregisterServiceWorkerClient(m_resultingClientId);
 #endif
 }
 
@@ -2092,15 +2103,16 @@
         ContentSecurityPolicyImposition::SkipPolicyCheck,
         DefersLoadingPolicy::AllowDefersLoading,
         CachingPolicy::AllowCaching);
+
 #if ENABLE(SERVICE_WORKER)
-    if (!m_temporaryServiceWorkerClient) {
-        // The main navigation load will trigger the registration of the temp client.
-        m_temporaryServiceWorkerClient = ScriptExecutionContextIdentifier::generate();
-        ASSERT(!temporaryIdentifierToLoaderMap().contains(*m_temporaryServiceWorkerClient));
-        temporaryIdentifierToLoaderMap().add(*m_temporaryServiceWorkerClient, this);
-    }
-    mainResourceLoadOptions.clientIdentifier = m_temporaryServiceWorkerClient;
+    // The main navigation load will trigger the registration of the client.
+    if (m_resultingClientId)
+        scriptExecutionContextIdentifierToLoaderMap().remove(m_resultingClientId);
+    m_resultingClientId = ScriptExecutionContextIdentifier::generate();
+    ASSERT(!scriptExecutionContextIdentifierToLoaderMap().contains(m_resultingClientId));
+    scriptExecutionContextIdentifierToLoaderMap().add(m_resultingClientId, this);
 #endif
+
     CachedResourceRequest mainResourceRequest(WTFMove(request), mainResourceLoadOptions);
     if (!m_frame->isMainFrame() && m_frame->document()) {
         // If we are loading the main resource of a subframe, use the cache partition of the main document.
@@ -2212,7 +2224,7 @@
     m_mainResource = nullptr;
     m_isContinuingLoadAfterProvisionalLoadStarted = false;
 
-    unregisterTemporaryServiceWorkerClient();
+    unregisterReservedServiceWorkerClient();
 }
 
 void DocumentLoader::subresourceLoaderFinishedLoadingOnePart(ResourceLoader& loader)

Modified: trunk/Source/WebCore/loader/DocumentLoader.h (288200 => 288201)


--- trunk/Source/WebCore/loader/DocumentLoader.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/loader/DocumentLoader.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -171,7 +171,7 @@
         return adoptRef(*new DocumentLoader(request, data));
     }
 
-    WEBCORE_EXPORT static DocumentLoader* fromTemporaryDocumentIdentifier(ScriptExecutionContextIdentifier);
+    WEBCORE_EXPORT static DocumentLoader* fromScriptExecutionContextIdentifier(ScriptExecutionContextIdentifier);
 
     WEBCORE_EXPORT virtual ~DocumentLoader();
 
@@ -439,6 +439,7 @@
 
 #if ENABLE(SERVICE_WORKER)
     WEBCORE_EXPORT bool setControllingServiceWorkerRegistration(ServiceWorkerRegistrationData&&);
+    WEBCORE_EXPORT ScriptExecutionContextIdentifier resultingClientId() const;
 #endif
 
     bool lastNavigationWasAppInitiated() const { return m_lastNavigationWasAppInitiated; }
@@ -468,7 +469,7 @@
 #if ENABLE(SERVICE_WORKER)
     void matchRegistration(const URL&, CompletionHandler<void(std::optional<ServiceWorkerRegistrationData>&&)>&&);
 #endif
-    void unregisterTemporaryServiceWorkerClient();
+    void unregisterReservedServiceWorkerClient();
 
     std::optional<CrossOriginOpenerPolicyEnforcementResult> doCrossOriginOpenerHandlingOfResponse(const ResourceResponse&);
 
@@ -688,8 +689,8 @@
 
 #if ENABLE(SERVICE_WORKER)
     std::optional<ServiceWorkerRegistrationData> m_serviceWorkerRegistrationData;
-    std::optional<ScriptExecutionContextIdentifier> m_temporaryServiceWorkerClient;
 #endif
+    ScriptExecutionContextIdentifier m_resultingClientId;
 
 #if ASSERT_ENABLED
     bool m_hasEverBeenAttached { false };

Modified: trunk/Source/WebCore/loader/DocumentWriter.cpp (288200 => 288201)


--- trunk/Source/WebCore/loader/DocumentWriter.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/loader/DocumentWriter.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -112,7 +112,7 @@
     return begin(URL());
 }
 
-Ref<Document> DocumentWriter::createDocument(const URL& url)
+Ref<Document> DocumentWriter::createDocument(const URL& url, ScriptExecutionContextIdentifier documentIdentifier)
 {
     if (!m_frame->loader().stateMachine().isDisplayingInitialEmptyDocument() && m_frame->loader().client().shouldAlwaysUsePluginDocument(m_mimeType))
         return PluginDocument::create(*m_frame, url);
@@ -122,10 +122,10 @@
 #endif
     if (!m_frame->loader().client().hasHTMLView())
         return Document::createNonRenderedPlaceholder(*m_frame, url);
-    return DOMImplementation::createDocument(m_mimeType, m_frame.get(), m_frame->settings(), url);
+    return DOMImplementation::createDocument(m_mimeType, m_frame.get(), m_frame->settings(), url, documentIdentifier);
 }
 
-bool DocumentWriter::begin(const URL& urlReference, bool dispatch, Document* ownerDocument)
+bool DocumentWriter::begin(const URL& urlReference, bool dispatch, Document* ownerDocument, ScriptExecutionContextIdentifier documentIdentifier)
 {
     // We grab a local copy of the URL because it's easy for callers to supply
     // a URL that will be deallocated during the execution of this function.
@@ -134,7 +134,7 @@
 
     // Create a new document before clearing the frame, because it may need to
     // inherit an aliased security context.
-    Ref<Document> document = createDocument(url);
+    Ref<Document> document = createDocument(url, documentIdentifier);
     
     // If the new document is for a Plugin but we're supposed to be sandboxed from Plugins,
     // then replace the document with one whose parser will ignore the incoming data (bug 39323)

Modified: trunk/Source/WebCore/loader/DocumentWriter.h (288200 => 288201)


--- trunk/Source/WebCore/loader/DocumentWriter.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/loader/DocumentWriter.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -28,6 +28,7 @@
 
 #pragma once
 
+#include "ScriptExecutionContextIdentifier.h"
 #include <wtf/WeakPtr.h>
 #include <wtf/text/WTFString.h>
 
@@ -47,7 +48,7 @@
     void replaceDocumentWithResultOfExecutingJavascriptURL(const String&, Document* ownerDocument);
 
     bool begin();
-    bool begin(const URL&, bool dispatchWindowObjectAvailable = true, Document* ownerDocument = nullptr);
+    bool begin(const URL&, bool dispatchWindowObjectAvailable = true, Document* ownerDocument = nullptr, ScriptExecutionContextIdentifier = { });
     void addData(const SharedBuffer&);
     void insertDataSynchronously(const String&); // For an internal use only to prevent the parser from yielding.
     WEBCORE_EXPORT void end();
@@ -67,7 +68,7 @@
     void setDocumentWasLoadedAsPartOfNavigation();
 
 private:
-    Ref<Document> createDocument(const URL&);
+    Ref<Document> createDocument(const URL&, ScriptExecutionContextIdentifier);
     void clear();
 
     WeakPtr<Frame> m_frame;

Modified: trunk/Source/WebCore/loader/SinkDocument.cpp (288200 => 288201)


--- trunk/Source/WebCore/loader/SinkDocument.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/loader/SinkDocument.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -54,7 +54,7 @@
 };
 
 SinkDocument::SinkDocument(Frame& frame, const URL& url)
-    : HTMLDocument(&frame, frame.settings(), url)
+    : HTMLDocument(&frame, frame.settings(), url, { })
 {
     setCompatibilityMode(DocumentCompatibilityMode::QuirksMode);
     lockCompatibilityMode();

Modified: trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h (288200 => 288201)


--- trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/platform/ScriptExecutionContextIdentifier.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -53,7 +53,7 @@
     {
     }
 
-    operator bool() const { return !!m_processIdentifier; }
+    operator bool() const { return !!m_object; }
 
     const UUID& object() const { return m_object; }
     ProcessIdentifier processIdentifier() const { return m_processIdentifier; }

Modified: trunk/Source/WebCore/workers/service/FetchEvent.cpp (288200 => 288201)


--- trunk/Source/WebCore/workers/service/FetchEvent.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/workers/service/FetchEvent.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -62,7 +62,6 @@
     , m_request(initializer.request.releaseNonNull())
     , m_clientId(WTFMove(initializer.clientId))
     , m_resultingClientId(WTFMove(initializer.resultingClientId))
-    , m_targetClientId(WTFMove(initializer.targetClientId))
     , m_handled(retrieveHandledPromise(globalObject, WTFMove(initializer.handled)))
 {
 }

Modified: trunk/Source/WebCore/workers/service/FetchEvent.h (288200 => 288201)


--- trunk/Source/WebCore/workers/service/FetchEvent.h	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/workers/service/FetchEvent.h	2022-01-19 17:12:35 UTC (rev 288201)
@@ -50,7 +50,6 @@
         RefPtr<FetchRequest> request;
         String clientId;
         String resultingClientId;
-        String targetClientId;
         RefPtr<DOMPromise> handled;
     };
 
@@ -72,7 +71,6 @@
     FetchRequest& request() { return m_request.get(); }
     const String& clientId() const { return m_clientId; }
     const String& resultingClientId() const { return m_resultingClientId; }
-    const String& targetClientId() const { return m_targetClientId; }
     DOMPromise& handled() const { return m_handled.get(); }
 
     bool respondWithEntered() const { return m_respondWithEntered; }
@@ -94,7 +92,6 @@
     Ref<FetchRequest> m_request;
     String m_clientId;
     String m_resultingClientId;
-    String m_targetClientId;
 
     bool m_respondWithEntered { false };
     bool m_waitToRespond { false };

Modified: trunk/Source/WebCore/workers/service/FetchEvent.idl (288200 => 288201)


--- trunk/Source/WebCore/workers/service/FetchEvent.idl	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/workers/service/FetchEvent.idl	2022-01-19 17:12:35 UTC (rev 288201)
@@ -36,7 +36,6 @@
     [CallWith=ScriptExecutionContext, EnabledBySetting=ServiceWorkerNavigationPreloadEnabled] readonly attribute Promise<any> preloadResponse;
     readonly attribute DOMString clientId;
     readonly attribute DOMString resultingClientId;
-    readonly attribute DOMString targetClientId;
     readonly attribute Promise<undefined> handled;
 
     undefined respondWith(Promise<FetchResponse> r);
@@ -46,6 +45,5 @@
     required FetchRequest request;
     DOMString clientId = "";
     DOMString resultingClientId = "";
-    DOMString targetClientId = "";
     Promise<undefined> handled;
 };

Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (288200 => 288201)


--- trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -942,7 +942,13 @@
             updateAppInitiatedValueForWorkers(clientOrigin, data.lastNavigationWasAppInitiated);
     }
 
-    m_visibleClientIdToInternalClientIdMap.add(data.identifier.object().toString(), clientIdentifier);
+    auto addResult = m_visibleClientIdToInternalClientIdMap.add(data.identifier.object().toString(), clientIdentifier);
+    if (!addResult.isNewEntry) {
+        ASSERT(m_visibleClientIdToInternalClientIdMap.get(data.identifier.object().toString()) == clientIdentifier);
+        ASSERT(m_clientsById.contains(clientIdentifier));
+        m_clientsById.set(clientIdentifier, WTFMove(data));
+        return;
+    }
 
     ASSERT(!m_clientsById.contains(clientIdentifier));
     m_clientsById.add(clientIdentifier, WTFMove(data));

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (288200 => 288201)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -181,7 +181,7 @@
             m_responseDocument = nullptr;
         } else {
             if (isHTML)
-                m_responseDocument = HTMLDocument::create(nullptr, context.settings(), m_response.url());
+                m_responseDocument = HTMLDocument::create(nullptr, context.settings(), m_response.url(), { });
             else
                 m_responseDocument = XMLDocument::create(nullptr, context.settings(), m_response.url());
             m_responseDocument->overrideLastModified(m_response.lastModified());

Modified: trunk/Source/WebKit/ChangeLog (288200 => 288201)


--- trunk/Source/WebKit/ChangeLog	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebKit/ChangeLog	2022-01-19 17:12:35 UTC (rev 288201)
@@ -1,5 +1,15 @@
 2022-01-19  Youenn Fablet  <[email protected]>
 
+        Improve computation of service worker FetchEvent.resultingClientId
+        https://bugs.webkit.org/show_bug.cgi?id=235107
+
+        Reviewed by Darin Adler.
+
+        * WebProcess/Network/WebLoaderStrategy.cpp:
+        * WebProcess/Storage/WebSWClientConnection.cpp:
+
+2022-01-19  Youenn Fablet  <[email protected]>
+
         [Cocoa] Do not change preferred AudioSession buffer size when VPIO is running
         https://bugs.webkit.org/show_bug.cgi?id=235317
         <rdar://87709485>

Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (288200 => 288201)


--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -441,6 +441,13 @@
         for (auto* frame = resourceLoader.frame()->tree().parent(); frame; frame = frame->tree().parent())
             frameAncestorOrigins.append(&frame->document()->securityOrigin());
         loadParameters.frameAncestorOrigins = WTFMove(frameAncestorOrigins);
+
+#if ENABLE(SERVICE_WORKER)
+        if (auto* documentLoader = resourceLoader.documentLoader()) {
+            if (auto resultingClientId = static_cast<WebDocumentLoader&>(*documentLoader).resultingClientId())
+                loadParameters.options.clientIdentifier = resultingClientId;
+        }
+#endif
     }
 
     ASSERT((loadParameters.webPageID && loadParameters.webFrameID) || loadParameters.clientCredentialPolicy == ClientCredentialPolicy::CannotAskClientForCredentials);

Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (288200 => 288201)


--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2022-01-19 15:55:58 UTC (rev 288200)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp	2022-01-19 17:12:35 UTC (rev 288201)
@@ -178,7 +178,7 @@
 
 void WebSWClientConnection::setDocumentIsControlled(ScriptExecutionContextIdentifier documentIdentifier, ServiceWorkerRegistrationData&& data, CompletionHandler<void(bool)>&& completionHandler)
 {
-    auto* documentLoader = DocumentLoader::fromTemporaryDocumentIdentifier(documentIdentifier);
+    auto* documentLoader = DocumentLoader::fromScriptExecutionContextIdentifier(documentIdentifier);
     bool result = documentLoader ? documentLoader->setControllingServiceWorkerRegistration(WTFMove(data)) : false;
     completionHandler(result);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to